Created
May 10, 2018 07:30
-
-
Save emilioriosvz/a5a348adfc456a014db8e64add6a499e to your computer and use it in GitHub Desktop.
Node targz example
This file contains hidden or 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 fs = require('fs'); | |
var fstream = require('fstream') | |
var tar = require('tar'); | |
var zlib = require('zlib'); | |
var gzip = zlib.createGzip(); | |
//var deflate = zlib.createDeflate(); | |
var dirSrcName = process.argv[2] || __dirname; | |
var dirDestName = process.argv[3] || './dir.tar.gz' | |
var dirDestStream = fs.createWriteStream(dirDestName); | |
var onError = (err) => console.error('An error occurred:', err); | |
var packer = tar.Pack({noProprietary: true}) | |
.on('error', onError) | |
.on('end', () => console.timeEnd('Packed') | |
) | |
console.time('Packed') | |
fstream.Reader({path: dirSrcName, type: "Directory"}) | |
.on('error', onError) | |
.pipe(packer) | |
.pipe(gzip) // Remove this line if you want to get rid of gzip processing | |
.pipe(dirDestStream) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment