Last active
December 21, 2015 11:49
-
-
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
This file contains 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
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