Skip to content

Instantly share code, notes, and snippets.

@AaronO
Created May 17, 2014 21:46
Show Gist options
  • Save AaronO/ef4639e7ed160fb3cc55 to your computer and use it in GitHub Desktop.
Save AaronO/ef4639e7ed160fb3cc55 to your computer and use it in GitHub Desktop.
// Requires
var path = require('path');
var tar = require("tar");
var zlib = require("zlib");
var fstream = require("fstream");
function streamTarGzDir(dirPath, includeBaseDir) {
includeBaseDir = includeBaseDir || false;
// Absolute path of the directory
var fullPath = path.resolve(dirPath);
return fstream.Reader({
path: fullPath,
type: "Directory",
filter: function () {
// Exclude the base directory itself in the tar
if(!includeBaseDir && this.dirname == fullPath) {
this.root = null;
}
return !(this.basename.match(/^\.git/) || this.basename.match(/^node_modules/));
}
})
.pipe(tar.Pack())
.pipe(zlib.createGzip());
}
// Exports
module.exports = streamTarGzDir;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment