Skip to content

Instantly share code, notes, and snippets.

@geNAZt
Created January 25, 2013 20:01
Show Gist options
  • Save geNAZt/4637372 to your computer and use it in GitHub Desktop.
Save geNAZt/4637372 to your computer and use it in GitHub Desktop.
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