https://stackoverflow.com/questions/42992604/crete-zip-file-in-memory-using-any-node-module
If GZip will do, you can use the built-in
zlib
module and not even have to load an external module.const zlib = require('zlib');
const gzip = zlib.createGzip();
// If you have an inputStream and an outputStream:
inputStream.pipe(gzip).pipe(outputStream);
For Zip and not GZip, you can check out archiver or zip-stream.
All the unzipping for all the files
const fs = require('fs'); | |
const zlib = require('zlib'); | |
const directoryFiles = fs.readdirSync('./data'); | |
directoryFiles.forEach(filename => { | |
const fileContents = fs.createReadStream(`./data/${filename}`); | |
const writeStream = fs.createWriteStream(`./data/${filename.slice(0, -3)}`); | |
const unzip = zlib.createGunzip(); | |
fileContents.pipe(unzip).pipe(writeStream); | |
}); |
Không có nhận xét nào:
Đăng nhận xét