流
¥Stream
¥Stability: 2 - Stable
源代码: lib/stream.js
流是用于在 Node.js 中处理流数据的抽象接口。node:stream
模块提供了用于实现流接口的 API。
¥A stream is an abstract interface for working with streaming data in Node.js.
The node:stream
module provides an API for implementing the stream interface.
Node.js 提供了许多流对象。例如,向 HTTP 服务器请求 和 process.stdout
都是流实例。
¥There are many stream objects provided by Node.js. For instance, a
request to an HTTP server and process.stdout
are both stream instances.
流可以是可读的、可写的、或两者兼而有之。所有的流都是 EventEmitter
的实例。
¥Streams can be readable, writable, or both. All streams are instances of
EventEmitter
.
要访问 node:stream
模块:
¥To access the node:stream
module:
const stream = require('node:stream');
node:stream
模块对于创建新类型的流实例很有用。通常不需要使用 node:stream
模块来消费流。
¥The node:stream
module is useful for creating new types of stream instances.
It is usually not necessary to use the node:stream
module to consume streams.