Skip to main content

fromReadableStreamReader

Types

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

Definition

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

See fromAsyncIterator for more details.

caution

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 function.

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

Example

Read data from a Response (Body)

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

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

run();

Output:

next: ArrayBuffer
next: ArrayBuffer
complete