2016-10-01 44 views
1

在我的NodeJS有此使用ExpressJS(其中res是可写入的流)如何在管道后写入流?

const readableStream = someAsyncTask(); 
readableStream.pipe(res); 
readableStrean.on('end',() => { 
    res.write('a bit more'); 
    res.end(); 
}); 

这导致:

uncaught exception Error: write after end

所以我假定管引起该可写流关闭。如何将可读流传输到输出,然后当流结束时,将其他数据传输到输出?

+0

妈的,这是一种明显的,是不是。您想将其作为答案发布吗? – Andrew

回答

0

documentation

readable.pipe(destination[, options])

  • destination<stream.Writable> The destination for writing data
  • options <Object> Pipe options
    end<Boolean> End the writer when the reader ends. Defaults to true.
    ...

如果你不希望它结束​​时,管道,通{end : false}作为选项

readableStream.pipe(res, { end: false });