Egret Compression and decompression (Jszip)

Source: Internet
Author: User

What's a jszip?

Two why use Jszip

Three if using zip

What's a jszip?

Jszip is a JavaScript library that creates zip archives directly on your browser.

Two why use Jszip

When a large number of configuration files (TXT or JSON) need to be downloaded from the server in the game,

You can compress the file into a zip package and unzip it after downloading it in Egret.

When the configuration file is only a few, but there are 50 60, I think it is necessary to put in the zip package.

Previously in a listed game company with Egret developed projects, there are a considerable number of configuration files, is placed in a zip package to download.

Three If you use Jszip

First download the Jszip third-party library, Egret on GitHub: https://github.com/egret-labs/egret-game-library

Put Jszip in the project directory, where you choose, as long as the configuration to add the path is correct.

Third-party libraries are then referenced in Egret, and the Egretproperties.json file in the project directory is added

{  "native": {    "Path_ignore": []  },  "Publish": {    "Web":0,    "native":1,    "Path":"Bin-release"  },  "egret_version":"3.0.6",  "Modules": [    {      "name":"Egret"    },    {      "name":"Game"    },    {      "name":"Tween"    },    {      "name":"Res"    },    {    "name": "Jszip", "path": "Jszip"    }  ]}

Create a new TXT test file a.txt, which says "a"

Compress the a.txt into a assets.zip test package

Put it under the Resource/assets folder

Load this zip package in Egret, then unzip the a.txt inside and output the contents.

Res.getresbyurl ("resource/assets/assets.zip", function (data) {       var  New  jszip (data);       Console.log (Zip.file ("a.txt"). Astext ());  // output A},this, RES. Resourceitem.type_bin);

Of course, A.txt is JSON, and the output string can be converted to JSON to use

var json = Json.parse (Zip.file ("a.txt"). Astext ());

Egret Compression and decompression (Jszip)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.