Sample Usage of nodejs Compressed File Module archiver
- 2021-07-12 04:45:46
- OfStack
This paper describes the usage of archiver, a compressed file module of nodejs. Share it for your reference, as follows:
Found a better zip-local
https://www.npmjs.com/package/zip-local
var zipper = require("zip-local");
zipper.sync.zip("/Users/xxx/xx/xx").compress().save("/Users/xxx/xx/xx.zip");
The following code compresses everything in the a folder to generate the a. zip file
cwd: Path to compress source file
src: Files to be compressed ** are all files
dest is the decompressed hierarchy. If it is not set, all the hierarchies of src will be used
Installation
npm install archiver In fact, in fact, the save
var archive = archiver('zip');
var output = fs.createWriteStream(path.join(__dirname, 'a.zip'));
archive.pipe(output);
archive.bulk([
{
src: ['**'],
dest: mainItem.path + '/',
cwd: path.join(__dirname, 'a/'),
expand: true
}
]);
archive.finalize();
I hope this article is helpful to everyone's nodejs programming.