Open jfromaniello opened 12 years ago
I just found a very hacky way to do this by overwriting the emit method, and removing the root property of every emitted entry;
var reader = fstream.Reader({path: source, type: "Directory"});
oldEmit = reader.emit;
reader.emit = function(ev, entry){
if(ev === "entry") entry.root = null;
return oldEmit.apply(reader, arguments);
};
@jfromaniello
A "better" solution is to use the filter option, and use it to modify the root of all the immediate entries of the the given directory. Hope this helps :
// Requires
var path = require('path');
var tar = require("tar");
var zlib = require("zlib");
var fstream = require("fstream");
function pipeTarGzDir(dirPath) {
var fullPath = path.resolve(dirPath);
return fstream.Reader({
path: fullPath,
type: "Directory",
filter: function () {
if(this.dirname == fullPath) {
this.root = null;
}
return !(this.basename.match(/^\.git/) || this.basename.match(/^node_modules/));
}
})
.pipe(tar.Pack())
.pipe(zlib.createGzip());
}
// Exports
exports.pipeTarGzDir = pipeTarGzDir;
I have directory like:
and I do something like
the problem I have is that the generated .tgz has the "bar" directory in the root and I'd like to have only the content of that directory (i.e. foo.txt, bar.bin, folder).
Is there a way i can do this?
thanks,