nodejs之stream、fs学习笔记
nodejs之stream、fs学习笔记 代码区 代码区 const fs = require ( 'fs' ) ; const writer = fs . createWriteStream ( "./test/write.js" ) ; // for(let i=0;i<100;i++){ // writer.write(`写入#${i}!\n`); // } // writer.end('写入结尾\n'); // writer.on('finish',()=>{ // console.log("写入完毕"); // }) const reader = fs . createReadStream ( "./test.js" ) ; writer . on ( 'pipe' , ( src ) => { //被调用者 console . log ( '有数据正通过管道流写入器' ) ; console . log ( src == reader ) ; } ) writer . on ( 'unpipe' , ( src ) => { console . log ( '管道流被移除' ) } ) writer . on ( 'finish' , function ( ) { reader . unpipe ( writer ) } ) let string = "" ;