Created
April 6, 2015 18:23
-
-
Save wanderview/ac6052184c62d2f165ee to your computer and use it in GitHub Desktop.
Request body writing as a stream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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