Skip to content

Instantly share code, notes, and snippets.

@sintaxi
Created January 16, 2014 00:47
Show Gist options
  • Save sintaxi/8447765 to your computer and use it in GitHub Desktop.
Save sintaxi/8447765 to your computer and use it in GitHub Desktop.
var fs = require("fs")
var request = require("request")
var filePath = __dirname + "/payload.tar.gz"
fs.createReadStream(filePath).pipe(request.put('http://api.lvh.me:3001/').pipe(process.stdout))
{
"name": "uploadtest",
"version": "0.0.0",
"description": "test upload streams",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"request": ""
}
}
var http = require("http")
var fs = require('fs')
var port = process.env.PORT || 3001
http.createServer(function(req, rsp){
rsp.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive'
})
req.pipe(fs.createWriteStream(__dirname + "/heyo.tar.gz"))
// req.on('data', function(chunk){
// rsp.write("got a chunk: " + chunk + "\n")
// })
// req.on('end', function() {
// rsp.end("all done" + "\n")
// })
setInterval(function(){
rsp.write("progress")
}, 100)
setTimeout(function(){
rsp.end("done")
}, 5000)
}).listen(port)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment