Created
March 17, 2013 03:46
-
-
Save dyoder/5179473 to your computer and use it in GitHub Desktop.
Demonstration of Node's support for chunked encoding.
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
http = require "http" | |
fs = require "fs" | |
app = (request,response) -> | |
n = 0 | |
out = fs.createWriteStream "./test.png" | |
request.pipe out | |
request.on "data", (data) -> | |
console.log "CHUNK #{++n}: #{data.length} bytes" | |
request.on "end", -> | |
response.statusCode = 200 | |
response.write "OK" | |
response.end() | |
http.createServer(app).listen(1337,"127.0.0.1").on "listening", -> | |
console.log "Listening on port 1337" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Node's HTTP implementation handles chunked encoded requests by default. The request is already a stream so your code doesn't need to change to handle stream based data. Here's a simple demonstration that writes the request data to a file. Try it from
curl
with or withouttransfer-encoding
.