Advertisement
Intermediate JavaScript, Async Iterators & Streams

What is the ReadableStream API used for?

Short answer

ReadableStream represents a source of data (like a network response body) that can be read incrementally in chunks, rather than waiting for the entire payload to load into memory at once.

Save JavaScript mock interview
Advertisement
AModel answer
ReadableStream represents a source of data (like a network response body) that can be read incrementally in chunks, rather than waiting for the entire payload to load into memory at once.
const response = await fetch(url);
const reader = response.body.getReader();
const { value, done } = await reader.read();
Real-world example
Displaying a progress bar while downloading a large file, based on bytes received so far.
Likely follow-ups
  • How do ReadableStream and async iterators relate to each other?
Related topics