我想在 Node 中制作一个 tar 存档。 canonical tar archiving example基于文件流:
fstream
.Reader({path: 'src', type: "Directory"})
.pipe(tar.Pack())
.pipe(zlib.createGzip())
.pipe(fstream.Writer("output.tar.gz"));
我的数据实际上以字符串形式存在于内存中,我想将其写入存档,而不必在两者之间创建临时文件。
有什么方法可以做到这一点,例如也许用字符串制作一个 fstream?
最佳答案
tar-stream模块也可以这样做:
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
也可以使用流作为文件内容的来源。
关于javascript - Node : adding a string as a file into a tar archive (without temporary files),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21730746/