Created
July 9, 2018 21:02
-
-
Save harrietty/18805889bf988455077629dfa880b7ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const zlib = require('zlib'); | |
const directoryFiles = fs.readdirSync('./data'); | |
Promise.all(directoryFiles.map(filename => { | |
return new Promise((resolve, reject) => { | |
const fileContents = fs.createReadStream(`./data/${filename}`); | |
const writeStream = fs.createWriteStream(`./data/${filename}.gz`); | |
const zip = zlib.createGzip(); | |
fileContents.pipe(zip).pipe(writeStream).on('finish', (err) => { | |
if (err) return reject(err); | |
else resolve(); | |
}) | |
}) | |
})) | |
.then(console.log('done')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment