微信小游戏,Bundle包使用zip方式,有坑

微信小游戏,Bundle包使用zip方式,有坑
在本地缓存文件满的时候解压不出来,直接返回,文件都没解压出来,就访问不了。
就算上层加了重试机制,那个clearLRU也是每500毫秒清理一个文件,没什么用。
配置表用的zip打包,缓存一满,游戏就一直卡死了,重启也没用。

1赞

建议解压zip失败后,清理后立即重试。

unzipAndCacheBundle (id, zipFilePath, cacheBundleRoot, onComplete) {
        let time = Date.now().toString();
        let targetPath = `${this.cacheDir}/${cacheBundleRoot}/${time}${suffix++}`;
        let self = this;
        makeDirSync(targetPath, true);
        unzip(zipFilePath, targetPath, function (err) {
            if (err) {
                rmdirSync(targetPath, true);
                if (isOutOfStorage(err.message)) {
                    self.outOfStorage = true;
                    self.clearLRUImmediate();
                    self.unzipAndCacheBundle (id, zipFilePath, cacheBundleRoot, onComplete);
                    return;
                }
                onComplete && onComplete(err);
                return;
            }
            self.cachedFiles.add(id, { bundle: cacheBundleRoot, url: targetPath, lastTime: time });
            self.writeCacheFile();
            onComplete && onComplete(null, targetPath);
        });
2赞

这解压用的是什么库

微信的file manager的unzip函数,刚那个代码是cocos 自己的,在platform里面。我改了一小点

哥们你怎么不放全呀

不清楚你们做做增量更新,还是全更新。
我们之前做的是Manifest+zip压缩的方式,大版本全更新(压缩),小版本增量更新(不压缩)。
做大版本更新也遇到过你说的情况,我们是全部清理上一个版本的内容,然后再解压。

后面我改了很多,放不全,整个cache的释放机制都改了。这里提供个思路就可以了。

直接干掉全部缓存