readable.take(limit[, options])


稳定性: 1 - 实验

此方法返回带有前 limit 个块的新流。

import { Readable } from 'node:stream';

await Readable.from([1, 2, 3, 4]).take(2).toArray(); // [1, 2]

Stability: 1 - Experimental

  • limit <number> the number of chunks to take from the readable.
  • options <Object>
    • signal <AbortSignal> allows destroying the stream if the signal is aborted.
  • Returns: <Readable> a stream with limit chunks taken.

This method returns a new stream with the first limit chunks.

import { Readable } from 'node:stream';

await Readable.from([1, 2, 3, 4]).take(2).toArray(); // [1, 2]