Concatenate two (or n) streams

前端 未结 10 1286
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-24 02:34
  • 2 streams:

    Given readable streams stream1 and stream2, what\'s an idiomatic (concise) way to get a stream containing

10条回答
  •  误落风尘
    2020-12-24 02:59

    https://github.com/joepie91/node-combined-stream2 is a drop-in Streams2-compatible replacement for the combined-stream module (which is described above.) It automatically wraps Streams1 streams.

    Example code for combined-stream2:

    var CombinedStream = require('combined-stream2');
    var fs = require('fs');
    
    var combinedStream = CombinedStream.create();
    combinedStream.append(fs.createReadStream('file1.txt'));
    combinedStream.append(fs.createReadStream('file2.txt'));
    
    combinedStream.pipe(fs.createWriteStream('combined.txt'));
    

提交回复
热议问题