用node.js / io.js文件传输(压缩)

什么是通过tcp套接字在两个服务器之间传输二进制压缩文件(大约100MB,tar.gz)的正确方法。 一般来说,我的转换工作正常,但目标上传输的文件几乎是不可用的两倍。

client.js:

var net = require('net'); var fs = require('fs'); //read file var myFile = fs.readFileSync('e:/test/console/deploy/test.tar.gz'); upload = function(ip, port, callback){ var client = new net.Socket(); // connect client.connect(port, ip, function () { console.log('Connecting ....'); // Send file client.end(myFile); }); } // end upload // Uploading file upload('127.0.0.1', '9001', function(reponse){ console.log(reponse) }); 

server.js:

 var net = require('net'); var fs = require('fs'); var uplsrv = net.createServer(function (socket) { console.log('Upload Server started ....'); var payload = Buffer(0); socket.on('data', function(chunk){ console.log('Reiceiving data ....'); payload += chunk; }); socket.on('end', function(){ var path = 'e:/test/software_repo/test.tar.gz' fs.open(path, 'w', function(err, fd) { if (err) { throw 'error opening file: ' + err; } fs.writeSync(fd, payload, 0, payload.length, 'base64', function(err) { if (err) throw 'error writing file: ' + err; fs.close(fd, function() { console.log('Upload finished .... and file written'); }) }); }); }); socket.on('close', function(){ console.log('Connection to Upload Server was closed ...'); }); }).listen(9001); 

有什么build议么?? 样品欢迎。

干杯

TMOE

       

网上收集的解决方案 "用node.js / io.js文件传输(压缩)"