Home > Web Front-end > JS Tutorial > Detailed explanation of archiver packaging module under nodejs_node.js

Detailed explanation of archiver packaging module under nodejs_node.js

WBOY
Release: 2016-05-16 16:29:21
Original
1814 people have browsed it

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

Install the archive module before use.

Copy code The code is as follows:

npm install archiver

Create a piece of code

Copy code The code is as follows:

var archiver = require('archiver');
var fs = require('fs');
//Packed file
var files = [
'files/001.png',
'files/002.png'
];
var zipPath = 'test.zip';
//Create an output stream for the final packaged file
var output = fs.createWriteStream(zipPath);
//Generate archive object, the packaging 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 archive object
zipArchiver.append(fs.createReadStream(files[i]), {'name': files[i]});
}
//Package
zipArchiver.finalize();

It is very simple to complete the packaging function.

Download address of this module: https://github.com/ctalkington/node-archiver

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template