相关疑难解决方法(0)

通过NodeJS下载Tar文件

我有两个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)

javascript http node.js

4
推荐指数
2
解决办法
7276
查看次数

标签 统计

http ×1

javascript ×1

node.js ×1