流
【Stream】
源代码: 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.】