Created
January 16, 2014 00:47
-
-
Save sintaxi/8447765 to your computer and use it in GitHub Desktop.
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 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)) |
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
{ | |
"name": "uploadtest", | |
"version": "0.0.0", | |
"description": "test upload streams", | |
"scripts": { | |
"start": "node server.js" | |
}, | |
"dependencies": { | |
"request": "" | |
} | |
} |
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 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