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)