I would like to make a tar archive in node. The canonical tar archiving example is based on a file stream:
fstream
.Reader({path: 'src', type: "Directory"})
.pipe(tar.Pack())
.pipe(zlib.createGzip())
.pipe(fstream.Writer("output.tar.gz"));
My data is actually in memory as a string, which I would like to write to the archive without having to make a temporary file in between.
Is there some way I can do this, e.g. maybe make an fstream out of a string?
I would like to make a tar archive in node. The canonical tar archiving example is based on a file stream:
fstream
.Reader({path: 'src', type: "Directory"})
.pipe(tar.Pack())
.pipe(zlib.createGzip())
.pipe(fstream.Writer("output.tar.gz"));
My data is actually in memory as a string, which I would like to write to the archive without having to make a temporary file in between.
Is there some way I can do this, e.g. maybe make an fstream out of a string?
Share Improve this question edited Feb 12, 2014 at 14:40 mikemaccana asked Feb 12, 2014 at 14:28 mikemaccanamikemaccana 124k110 gold badges432 silver badges534 bronze badges 1- How to create stream from string: stackoverflow./questions/12755997/… – Hector Correa Commented Feb 12, 2014 at 14:35
2 Answers
Reset to default 5The tar-stream module can do this too:
var tar = require('tar-stream')
var content = "whatever string you have"
var pack = tar.pack()
pack.entry({name: 'src', type: 'directory'})
pack.entry({name: 'src/someFile.txt'}, content) // file
pack.finalize()
tar-stream
can also use streams as sources for file contents.
The tar-async module handles this quite simply, without needing to make fake streams:
var uploadArchive = new Tar({output: fs.createWriteStream('archive.tar')});
uploadArchive.append('somefile.txt', 'someString', function() {
tape.close();
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745111319a4611869.html
评论列表(0条)