I am studying code here of setting up a simple Node server. I have seen and used many times this idiom of saving data chunks in an array and finally concatenating them together.
http.createServer(function(request, response) {
var body = [];
request.on('data', function(chunk) { body.push(chunk); });
request.on('end', function() { body = Buffer.concat(body).toString();
...
-
What is the type of
chunk
? Documentation says it's eitherBuffer
orstring
, but which one? -
Is it safe to call
Buffer.concat(body)
wherebody
is an array of strings? Documentation ofBuffer.concat(list)
sayslist
should be a list of Buffer instances. Are strings "Buffer instances"?
via sam
No comments:
Post a Comment