Detailed description of archiver in the packaging module of nodejs, nodejsarchiver

Source: Internet
Author: User

Detailed description of archiver in the packaging module of nodejs, nodejsarchiver

Archiver is a module that supports cross-platform packaging in nodejs. It can be zip and tar packages. It is a relatively easy-to-use third-party module.

Install the archiver module before use.

Copy codeThe Code is as follows:
Npm install archiver

Create a piece of code

Copy codeThe Code is as follows:
Var archiver = require ('archiveer ');
Var fs = require ('fs ');
// Package the file
Var files = [
'Files/001.png ',
'Files/002.png'
];
Var zipPath = 'test.zip ';
// Create an output stream of the final packaged File
Var output = fs. createWriteStream (zipPath );
// Generate an archiver object. The package type is zip.
Var zipArchiver = archiver ('zip ');
// Associate the packaging object with the output stream
ZipArchiver. pipe (output );
For (var I = 0; I <files. length; I ++ ){
Console. log (files [I]);
// Add the stream of the packaged file to the archiver object
ZipArchiver. append (fs. createReadStream (files [I]), {'name': files [I]});
}
// Package
ZipArchiver. finalize ();

It is very simple to complete the packaging function.

This module: https://github.com/ctalkington/node-archiver

Related Article

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.