Skip to content

ReadableStream Reader with byte length read(n) for JavaScript/TypeScript

License

Notifications You must be signed in to change notification settings

nwtgck/readable-stream-sized-reader-npm

Repository files navigation

readable-stream-sized-reader

Node CI

ReadableStream Reader with specified byte length read()

Usage

const readable = ...; // ReadableStream, e.g. (await fetch("...")).body
const reader = new ReadableStreamSizedReader(readable.getReader());

while(true) {
  // Read 1024 bytes at most
  const { done, value } = await reader.read(1024);
  if (done) break;
  console.log('value:', value);
}

Disable read-as-possible

By default, .read(n) reads n bytes as possible. When you use await reader.read(1024, false), it read at most 1024 bytes, but sometimes the bytes can be less than 1024 bytes.

About

ReadableStream Reader with byte length read(n) for JavaScript/TypeScript

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •