我正在使用NodeJs“torrent-stream”打开到torrent文件的流,然后选择目标Zip文件并将目标文件流压缩到UnZip流。
let torrentStream = require("torrent-stream");
let unzip = require("unzip-stream");
let engine = torrentStream(torrentMagentURL);
engine.on("ready", () => {
//select the target zip file
let file = engine.files[0];
//open a stream to the remote zip file from torrent connection
let stream = file.createReadStream();
//pip the remote file to a Zip reader
let zip = stream.pipe(unzip.Parse());
//listen to every entry parsed from the zip file
zip.on("entry", entry => {
// the problem is here ::
// for the every entry in the zip file
// this call back wont be called unless
// all the content of the previous entry
// in the zip file are downloaded
// what I really need is to SEEK to the next entry
// NOT download the previous entry entirely before
// seek to the next one.
// because mostly the needed file to be downloaded
// from the zip file wont be the first entry.
// noting that "torrent-stream" support seeking
// in its remote stream.
})
})
答案 0 :(得分:0)
从unzip-stream文档中,您似乎可以调用autodrain()来忽略未使用的任何条目,并前进到下一个条目。 https://www.npmjs.com/package/unzip-stream
zip.on("entry", entry => {
if (entry.path !== 'path/filename.ext') {
entry.autodrain();
} else {
// Process the entry
}
})