Compress the specified directory in node. js while maintaining the directory structure

Source: Internet
Author: User

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

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.