Skip to content

Latest commit

 

History

History
22 lines (14 loc) · 711 Bytes

what-is-stream.md

File metadata and controls

22 lines (14 loc) · 711 Bytes

什么是流

A stream is an abstract interface implemented by various objects in Node.js.

这里所谓的“流”,或stream,指的是Node.js中stream模块提供的接口。

var Stream = require('stream')
var Readable = Stream.Readable
var Writable = Stream.Writable
var Transform = Stream.Transform
var Duplex = Stream.Duplex

这些接口提供流式的数据处理功能。

流中具体的数据格式,数据如何产生,如何消耗,需要在实现流时,由用户自己定义。

譬如fs.createReadStream,其返回对象便是一个ReadStream类的实例。 ReadStream继承了Readable,并实现了_read方法,从而定义了一个具体的可读流。