2016-10-01 45 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 });