Skip to content

Instantly share code, notes, and snippets.

@sithu
Forked from sintaxi/upload.js
Created February 17, 2014 23:31
Show Gist options
  • Save sithu/9061445 to your computer and use it in GitHub Desktop.
Save sithu/9061445 to your computer and use it in GitHub Desktop.
// 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)
// 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