Recently in the function of doing a file upgrade, you need to specify files from the directory under the download server. After studying zlib, we found that this module could not reach this function.
After finding the data found Archiver module is very useful, but I also found that most of the Chinese information is not if the query compression progress, so here to share:
Archiver's GitHub Address:
Https://github.com/archiverjs/node-archiver
API Document Address:
https://archiverjs.com/docs/
Compression level Description:
var archive = archiver (' Zip ', { zlib: {level:9}//sets the compression level.});
Looking for a document found that no description of the compression level, so had to turn over the source code, and then copied to the notepad+, the results in writing this article accidentally turned off, the parameters are not very certain.
-1 is the default
0 is the lowest (not very confirmed)
9 is the highest
Get progress information:
Global.packageprogress={};archive.on (' Progress ', function (progress) {Console.log (progress); packageprogress=progress;});
Only need to bind this time, the event can be bound in this way, the specific event can refer to the API documentation.
I used 2 get routes, the first used to get node. js to start packing, set a Globel variable, and then continue to assign values in the bound Progress event.
The second one is to return the progress information. (Front-end polling)
Compress the specified directory in node. js while maintaining the directory structure