Native get error when unzip using zip.js. creator v3.7

Hello, cocos developers!

I’m developing unzip function.

I’ve read this article.

So I’m using zip.js.

It works well in web but get error in windows native.

Here’s my code and screenshot of plugin.

        const zip = window["zip"];
        const zipReader = new zip.ZipReader(new zip.Uint8ArrayReader(binArray));
        const entries = await zipReader.getEntries();
        log(entries);
        if (entries.length > 0) {
          for (let i = 0; i < entries.length; i++) {
            const entry = entries[i];
            const data = await entry.getData(
              new zip.BlobWriter(zip.getMimeType(entry.filename))
            );
            log(entry.filename);
            const filePath = native.fileUtils.getWritablePath() + entry.filename;
            if (entry.compressionMethod == 0){ // directory
              if (!native.fileUtils.isDirectoryExist(filePath)) {
                native.fileUtils.createDirectory(filePath);
              }
            } else if (entry.compressionMethod == 8) { // file
              native.fileUtils.writeDataToFile(data, filePath);
            }
          }
        }

        await zipReader.close();
        zip.terminateWorkers();

image

And some one good idea?

I have test with library on time thaihoangduylinh’s topic written, it run ok on cocos creator both native and web. But with newest library download from github, it run error like you describe. You can try with old library that i attach here
zip-no-worker-inflate.min.js.zip (18.1 KB)

1 Like

Thanks for your first reply, @anonus.

I replaced by your js file. Rebuild windows, same error.

Does no-worker mean it doesn’t work in web?

Try clean your project, may be it cached. I have test on cocos creator 3.7.2 it work with both web and native. “zip-no-worker-inflate” mean decompress without using webworker (cocos native doesn’t have WebWorker). You can see describe in here: https://github.com/gildas-lormeau/zip.js/blob/master/dist/README.md

1 Like

I enabled zip-no-worker-inflate, and disabled other plugin.
Build again for windows.
Clean in Visual Studio, and debug, same error.
Could you send your test project please?

May you doesn’t have this script config:
zip.configure({
useWebWorkers: false
});

Try add this on before extract zip

@anonus ,
Added it but same.
Could you share your test project please?

zip is not loaded in windows.


This is my project test
Unzip.zip (4.3 MB)

1 Like

This project is working. Thank you very much.
It helped me a lot. Thanks again.

1 Like