node中response在触发end()的时候才会发数据到客户端吗?
发布于 1 天前 作者 zhoushx3 184 次浏览 来自 问答
var http = require('http');
var fs = require('fs');

var server = http.createServer(function (req, res) {
    var stream = fs.createReadStream(__dirname + '/data.txt');
    stream.pipe(res);
});
server.listen(8000);

这段代码是在stream-handbook中摘取的,带有下面这句解释:

now the data.txt file will be written to clients one chunk at a time immediately as they are received from the disk.

我的疑问是:response在接收到每一个小chunk之后,会立即发往客户端吗?不是在response.end时候才一起发往客户端的吗? 如果是前者,那浏览器会怎么处理这些小chunk,会跟bigpipe的处理方式一样吗?

回到顶部