A WHATWG-compliant polyfill for ReadableStream
based on the eponymous implementation in Node.js.
npm install readable-stream-polyfill
const { ReadableStream } = require('readable-stream-polyfill')
const stream = new ReadableStream({
start(controller) {
controller.enqueue('hello')
controller.enqueue('world')
controller.end()
},
})
const reader = await stream.getReader()
// Polyfills the global "ReadableStream" class
// if it's not already implemented.
require('readable-stream-polyfill/globals')