How to unzip file which is downloaded in local folder?


I am using Creator 3.4.2
I want to download packages dynamically from my server in zip file, which is working fine.
So may i know how can i unzip it in Creator for native platforms?


You can use jszip : JSZip

Yes, trying to use that lib only.
But how to load from local storage and pass to JSZip?
For example

// Use absolute path to load files on device storage
let absolutePath = "/dara/data/some/path/to/image.png"
assetManager.loadRemote<ImageAsset>(absolutePath, function (err, imageAsset) {
    const spriteFrame = new SpriteFrame();
    // ...

This works for loading png but what about non-asset format or ZIP format?

You can use fsUtils to read file. let fsUtils = window[‘fsUtils’];

this will work on native/Android as well?

yeah, it has implement in native.

You can use zip.js to extract file: zip.js - JavaScript library to zip and unzip files in the browser and Deno
Example code i have tested, it work on web and native:

if(cc.sys.isNative && !Blob.prototype.text)
    Blob.prototype.text = function()
const reader = new zip.ZipReader(new zip.Uint8ArrayReader(new Uint8Array(bufferAsset._buffer)));
      if (entries.length) {
              new zip.TextWriter()
              //todo text extracted from zip

@thaihoangduylinh How did you got bufferAsset._buffer ?

bufferAsset this is cc.BufferAsset reference in my scene. You rename zip file to bin file and it can be drag to reference ( => example.bin). And bufferAsset._buffer is a ArrayBuffer type.

This is config of library that i used

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.