Skip to content

Instantly share code, notes, and snippets.

@tdegrunt
Created November 28, 2011 13:28
Show Gist options
  • Save tdegrunt/1400402 to your computer and use it in GitHub Desktop.
Save tdegrunt/1400402 to your computer and use it in GitHub Desktop.
tarring & zipping files
var tar = require('tar-async'),
streamBuffers = require('stream-buffers'),
fs = require('fs'),
zlib = require('zlib');
var myWritableStreamBuffer = new streamBuffers.WritableStreamBuffer({
initialSize: (100 * 1024), // start as 100 kilobytes.
incrementAmount: (10 * 1024) // grow by 10 kilobytes each time buffer overflows.
});
tape = new tar({output: myWritableStreamBuffer});
tape.append('test.json', '{"test":"bla"}');
tape.append('test2.json', '{"test2":"bla"}');
tape.append('justText.txt', 'This is just some text. Fun, huh?', function () {
tape.close();
myWritableStreamBuffer.destroy();
var gzip = zlib.createGzip()
fs.open('./export.tar.gz', 'w+', function(e, fd) {
zlib.gzip(myWritableStreamBuffer.getContents(), function(err, buffer) {
if (!err) {
fs.write(fd, buffer, 0, buffer.length, 0, function(e, w, buffer) {
console.log("error:",e);
})
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment