流的类型
¥Types of streams
Node.js 中有四种基本的流类型:
¥There are four fundamental stream types within Node.js:
-
Writable
:可以写入数据的流(例如,fs.createWriteStream()
)。¥
Writable
: streams to which data can be written (for example,fs.createWriteStream()
). -
Readable
:可以从中读取数据的流(例如,fs.createReadStream()
)。¥
Readable
: streams from which data can be read (for example,fs.createReadStream()
). -
Duplex
:Readable
和Writable
的流(例如,net.Socket
)。¥
Duplex
: streams that are bothReadable
andWritable
(for example,net.Socket
). -
Transform
:可以在写入和读取数据时修改或转换数据的Duplex
流(例如,zlib.createDeflate()
)。¥
Transform
:Duplex
streams that can modify or transform the data as it is written and read (for example,zlib.createDeflate()
).
此外,此模块还包括实用函数 stream.duplexPair()
、stream.pipeline()
、stream.finished()
stream.Readable.from()
和 stream.addAbortSignal()
。
¥Additionally, this module includes the utility functions
stream.duplexPair()
,
stream.pipeline()
,
stream.finished()
stream.Readable.from()
, and
stream.addAbortSignal()
.