-
-
Save sithu/9061445 to your computer and use it in GitHub Desktop.
This file contains 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
// to test... | |
// curl -T path/to/file.tar.gz http://localhost:8000 | |
var http = require('http') | |
var fs = require('fs') | |
http.createServer(function(req, rsp){ | |
var file = fs.createWriteStream("mynewfile") | |
file.on("drain", function(){ | |
req.resume() | |
}) | |
req.on("data", function(chunk) { | |
req.pause() | |
file.write(chunk, "binary") | |
}) | |
req.on("end", function(){ | |
file.end() | |
rsp.writeHead(200) | |
rsp.end("it worked!") | |
}) | |
}).listen(8000) |
This file contains 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
// same as above | |
var http = require('http') | |
var fs = require('fs') | |
var util = require('util') | |
http.createServer(function(req, rsp){ | |
var file = fs.createWriteStream("mynewfile") | |
util.pump(req, file) | |
req.on("end", function(){ | |
file.end() | |
rsp.writeHead(200) | |
rsp.end("done!") | |
}) | |
}).listen(8001) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment