I have a file open in the browser that I want to create a stream and read with JS. I want to read the file in chunks of 1kb, but it always reads the whole file.
import { ReadableStream as PolyfillReadableStream } from 'web-streams-polyfill';
import { createReadableStreamWrapper } from '@mattiasbuelens/web-streams-adapter';
const toPolyfillReadable = createReadableStreamWrapper(PolyfillReadableStream);
const file = myFile;
const fStreamReader = toPolyfillReadable(file.stream(), new ByteLengthQueuingStrategy({
highWaterMark: 1024,
}));
const stream = [];
for await (const value of fStreamReader) { // This works because I'm using web-streams-polyfill
console.log(value); // This only runs once and prints the whole file.
}