我有两个nodejs http服务器,一个请求另一个tar文件.它通过浏览器测试工作正常,但我永远无法让第二台服务器正确粘合块.我对fwrite的尝试一直没有用
// Receives File
var complete_file = '';
response.on('data', function(chunk){
complete_file += chunk
}).on('end', function(){
fs.writeFile('/tmp/test.tgz', complete_file, 'binary')
});
// Send File
fs.readFile('/tmp/test_send.tgz', function(err, data){
if (err) throw err;
response.writeHead('200', {
'Content-Type' : 'application/x-compressed',
'Content-Length' : data.length
});
response.write(data);
response.end();
});
Run Code Online (Sandbox Code Playgroud)