Node.js 管道大文件占用大量内存

Node.js 管道大文件占用大量内存,node.js,express,stream,Node.js,Express,Stream,我有一个程序,它从一个流中读取一个大文件并将其写入一个文件 下面是从流中读取文件 var stream = new Stream.PassThrough(); Request(options, function (error, res, body) { if (error) { Logger.error('ProxyManager', 'getStream', error); return callback(error); } }).pi

我有一个程序,它从一个流中读取一个大文件并将其写入一个文件

下面是从流中读取文件

var stream = new Stream.PassThrough();

Request(options, function (error, res, body) {
    if (error) {
         Logger.error('ProxyManager', 'getStream', error);
         return callback(error);
      }
}).pipe(stream); // first pipe call
这里正在写文件

var outputFile = fs.createWriteStream(filePath);
stream.pipe(outputFile); // second pipe call

我的问题是,当传输一个大文件时,这个过程占用了大量内存,这就像管道在第一个管道或第二个调用中将整个文件保存在内存中一样。有人能帮上忙吗?

您有一个回调,它有一个body参数,即整个文件。忽略回调,改用error event.Yep。正是这样。它缓冲了看起来的反应。我把它改成了一个普通的https呼叫,现在可以正常工作了。谢谢