Skip to content

Latest commit

 

History

History
21 lines (16 loc) · 798 Bytes

File metadata and controls

21 lines (16 loc) · 798 Bytes

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.