stream 流


稳定性: 2 - 稳定

源代码: lib/stream.js

流是用于在 Node.js 中处理流数据的抽象接口。 node:stream 模块提供了用于实现流接口的 API。

Node.js 提供了许多流对象。 例如,对 HTTP 服务器的请求process.stdout 都是流的实例。

流可以是可读的、可写的、或两者兼而有之。 所有的流都是 EventEmitter 的实例。

要访问 node:stream 模块:

const stream = require('node:stream');

node:stream 模块对于创建新类型的流实例很有用。 通常不需要使用 node:stream 模块来消费流。

Stability: 2 - Stable

Source Code: lib/stream.js

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.

There are many stream objects provided by Node.js. For instance, a request to an HTTP server and process.stdout are both stream instances.

Streams can be readable, writable, or both. All streams are instances of EventEmitter.

To access the node:stream module:

const stream = require('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.