Skip to content

Instantly share code, notes, and snippets.

@mushfiq
Last active July 7, 2020 16:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mushfiq/7274231 to your computer and use it in GitHub Desktop.
Save mushfiq/7274231 to your computer and use it in GitHub Desktop.
node_modules/*
*.data
npm install archiver;
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