如何克隆 NodeJS 流?
How to clone a NodeJS stream?
我需要以某种方式在 nodeJS 中克隆一个 readstream
。
也就是说,如果我有一个 readStream
我需要它的两个副本 stream1,stream2。我可以在哪里单独阅读流 stream1
和 stream2
。
据我所知,即使我尝试将原始 readStream
传输到 stream1
,stream2
我也无法单独使用它们中的每一个
我在 npmjs 包文档中找到了这个文档
const fs = require("fs");
const ReadableStreamClone = require("readable-stream-clone");
const readStream = fs.createReadStream('text.txt');
const readStream1 = new ReadableStreamClone(readStream);
const readStream2 = new ReadableStreamClone(readStream);
const writeStream1 = fs.createWriteStream('sample1.txt');
const writeStream2 = fs.createWriteStream('sample2.txt');
readStream1.pipe(writeStream1)
readStream2.pipe(writeStream2)
尝试这些代码行可能对您有所帮助
我需要以某种方式在 nodeJS 中克隆一个 readstream
。
也就是说,如果我有一个 readStream
我需要它的两个副本 stream1,stream2。我可以在哪里单独阅读流 stream1
和 stream2
。
据我所知,即使我尝试将原始 readStream
传输到 stream1
,stream2
我也无法单独使用它们中的每一个
我在 npmjs 包文档中找到了这个文档
const fs = require("fs");
const ReadableStreamClone = require("readable-stream-clone");
const readStream = fs.createReadStream('text.txt');
const readStream1 = new ReadableStreamClone(readStream);
const readStream2 = new ReadableStreamClone(readStream);
const writeStream1 = fs.createWriteStream('sample1.txt');
const writeStream2 = fs.createWriteStream('sample2.txt');
readStream1.pipe(writeStream1)
readStream2.pipe(writeStream2)
尝试这些代码行可能对您有所帮助