node.js - How do I stream large files over ssh in Node? -


i'm trying stream cat command using ssh2 module hangs @ point of execution. i'm executing cat there.txt there.txt around 10 mb or so.

for example:

local = fs.createwritestream('here.txt'); conn.exec('cat there.txt', function(err, stream) {      if (err) throw err;      stream.pipe(local).on('finish, function() { console.log('done'); }); } 

this stops @ 1 point. i've piped stream local stdout, , hangs after while. in actual code, pipe through bunch of other transform streams think better transferring files local system first (the files may larger 200mb).

try out createreadstream serving huge files:

fs.exists(correctfilepath, function(exists) {   if (exists) {     var readstream = fs.createreadstream(correctfilepath);      console.log("about serve " + correctfilepath);      res.writehead(200);     readstream.setencoding("binary");      readstream.on("data", function (chunk) {         res.write(chunk, "binary");     });      readstream.on("end", function () {         console.log("served file " + correctfilepath);         res.end();     });      readstream.on('error', function(err) {         res.write(err + "\n");         res.end();         return;     });   } else {     res.writehead(404);     res.write("no data\n");     res.end();   } }); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -