Node.js异步提取zip

z

我目前正在使用adm-zip将zip文件提取到某个路径的extractAllTo方法,但是它的方法是同步的。

有没有一种方法可以异步提取zip文件?

德格斯

尝试在npm上使用async-unzip库:https ://www.npmjs.com/package/async-unzip

这在内存中有效,并且100%异步,这将使您获得想要的行为=)

这是一个例子:

var async = require('async'),
        path = require('path'),
        ZipFile = require('async-unzip').ZipFile,
        zipFile = new ZipFile('/home/user/Name.app.dSYM.zip'),
        noMoreFiles = false;

async.whilst(function () {
    return !noMoreFiles;
}, function (cb) {
    async.waterfall([
        function (cb) {
            zipFile.getNextEntry(cb);
        },
        function (entry, cb) {
            if (entry) {
                if (entry.isFile) {
                    var match = entry.filename.match(/^[^\/]+\.dSYM\/Contents\/Resources\/DWARF\/(.+)/);

                    if (match) {
                        console.log(match);
                        console.log(entry);

                        async.waterfall([
                            function (cb) {
                                entry.getData(cb);
                            },
                            function (data, cb) {
                                // `data` is a binary data of the entry.
                                console.log(data.length);

                                cb();
                            }
                        ], cb);
                    }
                }
            } else {
                noMoreFiles = true;
            }

            cb();
        }
    ], cb);
}, function () {
    // DO NOT FORGET to call `close()` to release the open file descriptor,
    // otherwise, you will quickly run out of file descriptors.
    zipFile.close();
    console.log(arguments);
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章