收藏
回答

我想知道FileSystemManager.readFile的复杂度是什么样的

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小游戏 需求 FileSystemManager 客户端 6.5.3 2.0.0

假如我在第一次读取文件的时候将这些文件路径都存到一个csv下,第二次就从csv中读取这些文件路径,而不是通过

 FileSystemManager.readdirSync

或者

 FileSystemManager.readdir

来再次获取文件路径,效率会不会提高


最后一次编辑于  2018-09-13
回答关注问题邀请回答
收藏

1 个回答

  • 桑羊
    桑羊
    2018-09-13
    function cleanAllFiles(path, newAssets, finish) {
        fs.readdir({
            dirPath: path,
            success: function (res) {
                var files = res.files;
                (function next(idx) {
                    if (idx < files.length) {
                        var dirPath = path + '/' + files[idx];
                        var stat = fs.statSync(dirPath);
                        if (stat.isDirectory()) {
                            cleanAllFiles(dirPath, newAssets, function () {
                                next(idx + 1);
                            });
                        } else {
                            // remove old assets
                            if (newAssets && newAssets.indexOf(dirPath) !== -1) {
                                next(idx + 1);
                                return;
                            }
                            fs.unlink({
                                filePath: dirPath,
                                success: function () {
                                    cc.log('unlink local file ' + dirPath + ' successfully!');
                                },
                                fail: function (res) {
                                    cc.warn('failed to unlink file(' + dirPath + '): ' + res ? res.errMsg : 'unknown error');
                                },
                                complete: function () {
                                    next(idx + 1);
                                }
                            });
                        }
                    } else {
                        finish && finish();
                    }
     
                })(0);
            },
            fail: function (res) {
                finish && finish();
            },
        });
    }

    比如官方WX-Downloader.js里这个cleanAllFiles,假如我把这个readdir改成从预存的csv中读取,效率能提高吗

    2018-09-13
    有用 1
    回复
登录 后发表内容