How to chain write stream, immediately with a read stream in Node.js 0.10?

前端 未结 3 973
自闭症患者
自闭症患者 2020-12-17 17:37

The following line will download an image file from a specified url variable:

var filename = path.join(__dirname, url.replace(/^.*[\\\\\\/]/, \'         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-17 17:40

    // create 'fs' module variable
    var fs = require("fs");
    
    // open the streams
    var readerStream = fs.createReadStream('inputfile.txt');
    var writerStream = fs.createWriteStream('outputfile.txt');
    
    // pipe the read and write operations
    // read input file and write data to output file
    readerStream.pipe(writerStream);
    

提交回复
热议问题