Monday, June 13, 2022
HomeGame DevelopmentMethods to unzip file which is downloaded in native folder? - Cocos...

Methods to unzip file which is downloaded in native folder? – Cocos Creator


Hi there,

I’m utilizing Creator 3.4.2
I wish to obtain packages dynamically from my server in zip file, which is working effective.
So might i understand how am i able to unzip it in Creator for native platforms?

Regards,
Smit


You need to use jszip : JSZip

Sure, making an attempt to make use of that lib solely.
However learn how to load from native storage and move to JSZip?
For instance

// Use absolute path to load information on machine storage
let absolutePath = "/dara/information/some/path/to/picture.png"
assetManager.loadRemote<ImageAsset>(absolutePath, perform (err, imageAsset) {
    const spriteFrame = new SpriteFrame();
    // ...
});

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

You need to use fsUtils to learn file. let fsUtils = window[‘fsUtils’];

this may work on native/Android as properly?

yeah, it has implement in native.

You need to use zip.js to extract file: zip.js – JavaScript library to zip and unzip information within the browser and Deno
Instance code i’ve examined, it work on net and native:

if(cc.sys.isNative && !Blob.prototype.textual content)
{
    Blob.prototype.textual content = perform()
    {
        return this.information;
    }
}
const reader = new zip.ZipReader(new zip.Uint8ArrayReader(new Uint8Array(bufferAsset._buffer)));
  reader.getEntries().then((entries)=>{
      if (entries.size) {
          entries[0].getData(
              new zip.TextWriter()
          ).then((textual content)=>{
              //todo textual content extracted from zip
          });
      }
      reader.shut();
  });

@thaihoangduylinh How did you bought bufferAsset._buffer ?

bufferAsset that is cc.BufferAsset reference in my scene. You rename zip file to bin file and it may be drag to reference (instance.zip => instance.bin). And bufferAsset._buffer is a ArrayBuffer kind.

That is config of library that i used

This matter was robotically closed 24 hours after the final reply. New replies are not allowed.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments