Created
January 25, 2013 20:01
-
-
Save geNAZt/4637372 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 MuxDemux = require('mux-demux'); | |
var net = require('net'); | |
var fs = require('fs'); | |
function StreamConnection() { | |
var con = net.connect(12345, function() { | |
var mdm1 = MuxDemux(); | |
con.pipe(mdm1).pipe(con); | |
var ds1 = mdm1.createStream('update'); | |
function sendFile(file, cb) { | |
ds1.write({file: file, type: "start" }); | |
var fsReadStream = fs.createReadStream(__dirname + "/" + file, {encoding: "binary"}); | |
fsReadStream.on('end', function () { | |
ds1.write({ type: "end" }); | |
}); | |
fsReadStream.on('data', function(data) { | |
ds1.write(data); | |
}); | |
fsReadStream.on('end', function() { | |
cb(); | |
}); | |
} | |
sendFile("test.png", function() { | |
sendFile("app.js", function() { | |
sendFile("app.exe", function() { | |
}); | |
}); | |
}); | |
}); | |
} | |
StreamConnection(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment