readableStreamBYOBReader.read(view[, options])


  • view <Buffer> | <TypedArray> | <DataView>

  • options <Object>

    • min <number> 设置后,只有当 min 个元素可用时,返回的 promise 才会被履行。如果未设置,则当至少有一个元素可用时,promise 就会履行。

      ¥min <number> When set, the returned promise will only be fulfilled as soon as min number of elements are available. When not set, the promise fulfills when at least one element is available.

  • 返回:用对象实现的 promise:

    ¥Returns: A promise fulfilled with an object:

从底层 <ReadableStream> 请求下一个数据块,并返回一个 promise,一旦数据可用,该 promise 就会实现。

¥Requests the next chunk of data from the underlying <ReadableStream> and returns a promise that is fulfilled with the data once it is available.

不要将池化的 <Buffer> 对象实例传递给此方法。池化的 Buffer 对象是使用 Buffer.allocUnsafe()Buffer.from() 创建的,或者通常由各种 node:fs 模块回调返回。这些类型的 Buffer 使用共享的底层 <ArrayBuffer> 对象,该对象包含来自所有池化的 Buffer 实例的所有数据。当 Buffer<TypedArray><DataView> 传递给 readableStreamBYOBReader.read() 时,视图的底层 ArrayBuffer 被分离,使该 ArrayBuffer 上可能存在的所有现有视图无效。这可能会给你的应用带来灾难性的后果。

¥Do not pass a pooled <Buffer> object instance in to this method. Pooled Buffer objects are created using Buffer.allocUnsafe(), or Buffer.from(), or are often returned by various node:fs module callbacks. These types of Buffers use a shared underlying <ArrayBuffer> object that contains all of the data from all of the pooled Buffer instances. When a Buffer, <TypedArray>, or <DataView> is passed in to readableStreamBYOBReader.read(), the view's underlying ArrayBuffer is detached, invalidating all existing views that may exist on that ArrayBuffer. This can have disastrous consequences for your application.