Node模块-Stream

本节主要讲述Node模块-Stream

Stream模块

两个程序之间的数据传输格式

四种类型

  • Readable:可读流
  • Writable:可写流
  • Duplex:既可读,也可写
  • Transform:操做写入的数据,然后读取数据

案例

Readable

1
2
3
4
5
6
7
8
var stream = require('stream');
var fs = require('fs');

var readStream = fs.createReadStream('foo.txt',"utf-8");

readStream.on('data',function(data){
console.log(data.toString())
})

————-未完待续