How to unzip file which is downloaded in local folder?

Hello,

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?

Regards,
Smit

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()
    {
        return this.data;
    }
}
const reader = new zip.ZipReader(new zip.Uint8ArrayReader(new Uint8Array(bufferAsset._buffer)));
  reader.getEntries().then((entries)=>{
      if (entries.length) {
          entries[0].getData(
              new zip.TextWriter()
          ).then((text)=>{
              //todo text extracted from zip
          });
      }
      reader.close();
  });

@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.zip => 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.