Skip to content

Instantly share code, notes, and snippets.

@kapouer
Last active December 21, 2015 11:49
Show Gist options
  • Save kapouer/6301360 to your computer and use it in GitHub Desktop.
Save kapouer/6301360 to your computer and use it in GitHub Desktop.
however bad these examples are, they show the basic way to pipe stuff into node-tar
function createEntry(data, path, root) {
var entry = new stream.Readable();
var allpushed = false;
entry._read = function(s) {
if (allpushed) {
this.push(null);
} else {
this.push(data);
allpushed = true;
}
};
entry.props = {
type: "File",
mode: 0644,
mtime: Date.now() / 1000,
size: data.length
};
entry.path = Path.join(root, path);
entry.root = root;
return entry;
}
var root = "mydir/"
var tarStream = tar.Pack({ noProprietary: true });
var sourceStream = new stream.PassThrough();
sourceStream.props = {type: 'Directory'};
sourceStream.path = root;
sourceStream.pipe(tarStream, {end: false});
tarStream.add(createEntry("file content here", "test.txt", root));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment