1
我正在研究设置简单Node服务器的代码here。我已经看到并习惯了将数据块保存在一个数组中并最终将它们连接在一起的习惯用法。Node http请求中的数据块的类型
http.createServer(function(request, response) {
var body = [];
request.on('data', function(chunk) { body.push(chunk); });
request.on('end', function() { body = Buffer.concat(body).toString();
...
什么是
chunk
类型?Documentation说这是Buffer
或string
,但哪一个?安全呼叫
Buffer.concat(body)
其中body
是一个字符串数组吗?Documentation ofBuffer.concat(list)
表示list
应该是Buffer实例的列表。字符串是“缓冲区实例”吗?