Last active
July 7, 2020 16:45
-
-
Save mushfiq/7274231 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
node_modules/* | |
*.data |
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
npm install archiver; |
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
var archiver = require('archiver'), | |
archive = archiver('zip'), | |
fs = require('fs'); | |
var output = fs.createWriteStream(__dirname + '/mocks.zip'); | |
archive.pipe(output); | |
var getStream = function(fileName){ | |
return fs.readFileSync(fileName); | |
} | |
//these are the files, want to put into zip archive | |
var fileNames = ['mock1.data', 'mock2.data', 'mock3.data']; | |
for(i=0; i<fileNames.length; i++){ | |
var path = __dirname + '/'+fileNames[i]; | |
archive.append(getStream(path), { name: fileNames[i]}); | |
} | |
archive.finalize(function(err, bytes) { | |
if (err) { | |
throw err; | |
} | |
console.log(bytes + ' total bytes'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment