Skip to content

Instantly share code, notes, and snippets.

@wanderview
Created April 6, 2015 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wanderview/ac6052184c62d2f165ee to your computer and use it in GitHub Desktop.
Save wanderview/ac6052184c62d2f165ee to your computer and use it in GitHub Desktop.
Request body writing as a stream
var req = new Request('https://example.com' { bodyAsWriter: true });
// throws because writer is not set yet
req.bodyWriter.write(/*...*/);
// fetch calls setWriter
fetch(req).then(/*...*/);
req.bodyWriter.write(/*...*/)
var req2 = new Request('https://example.com' { body: arrayBuffer, bodyAsWriter: true });
// fetch calls setWriter and body.PipeTo(bodyWriter)
fetch(req2).then(/*...*/);
// wait for constructor body to be complete and then write a trailer
req2.body.closed.then(function() {
req.bodyWriter.write(/*...*/);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment