response.end([数据], [编码])
This method signals to the server that all of the response headers and body have been sent; that server should consider this message complete. The method, response.end(), MUST be called on each response.
但是在使用createReadStream
给出的许多示例中,例如,
fs.createReadStream(filename,{...}).pipe(response)
我从未见过 response.end()
被调用。
它需要 resonse.end()
与 createReadStream()
一起使用吗?如果是这样,它出现在程序流中的什么位置 - 您不希望在管道完成之前调用它,对吗?
最佳答案
在读取完成(end
事件)或遇到错误(error
事件)后执行 response.end()
。
检查这个例子:http://elegantcode.com/2011/04/06/taking-baby-steps-with-node-js-pumping-data-between-streams/
关于javascript - 在node.js中,如果使用createReadStream()还需要response.end(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12723192/