Skip to content
This repository was archived by the owner on Dec 20, 2022. It is now read-only.

Latest commit

 

History

History
43 lines (31 loc) · 1.15 KB

File metadata and controls

43 lines (31 loc) · 1.15 KB

fromReadableStreamReader

function fromReadableStreamReader<GValue>(
  reader: ReadableStreamReader<GValue>
): IObservable<IFromReadableStreamReaderObservableNotifications<GValue>>

Creates an Observable from a ReadableStreamReader. It emits values in the form of Notifications.

See fromAsyncIterator for more details.

⚠️ use with caution, if you subscribe twice to the same ReadableStreamReader, the emitted values probably won't be what you expect, due to concurrent calls on the .read.

You should prefer to use fromReadableStream which ensures that the ReadableStream is not locked.

Examples

Read data from a Response (Body)

async function run() {
  const response = await fetch('https://somefile');
  const subscribe = fromReadableStream(response.body.getReader());

  subscribe((notification) => {
    console.log(notification.name, ':', notification.value);
  })
}

run();

Output:

next: ArrayBuffer
next: ArrayBuffer
complete