Re: [fetch] Question — Why can I not read the stream again ? (#196)

The Fetch API and Streams API used in it are designed to allow efficient data processing. Calling json(), etc. progressively consumes data from the Response object so that buffering at intermediate objects can be kept small.

Suppose that an app fetches 1MB HTTP response and parse it as a JSON file and then use it, but for nothing else (i.e. once the JSON is generated, the response would be never touched). If the Response is designed to hold the original response body data even after .json() call is made on it, even if we made the response object unreachable from the root so that GC collects it asap, the peak memory foot print for the processing reaches 1MB+1MB (assuming the resulting object is 1MB for simplicity).

If we design the API to allow releasing the parsed data immediately as the resulting object is built, the foot print can be kept around 1MB+(small buffer).

Only who really want to reuse the Response body should use clone() to manually duplicate the object.

---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/196#issuecomment-171935172

Received on Friday, 15 January 2016 11:10:38 UTC