Node.js come alone with many Stream API. Stream is useful when handling large trunck of data. For example, we have a big file to read from file system: // create-big-file.js const fs = require('fs') const file = fs.createWriteStream('./big.file') for…
//10个数 10个字节,每次读4b,写1b let fs=require("fs"); function pipe(source,target) { //先创建可读流,再创建可写流 //先读一次,rs.on(data) //将读到的类容写入目标中 ,返回布尔值,如果是ture,继续写,默认情况应该是false,暂停读取 //ws.on('drain'),抽干后,回复读取 //监听读取文件完毕后,关闭读取rs.on('end') let rs=fs.createReadStream(s…
Stream: 类似这样:a.pipe(b).pipe(c); 我想写一个b.所以: var rs=new (require('stream').Readable)(); var ws=new (require('stream').Writable)(); rs._read=function(){ this.push('send a msn for the first time'); this.push('send a msn for the second time'); this.push(n…