Node: Bug in Buffer.concat

Created on 22 Feb 2016  路  2Comments  路  Source: nodejs/node

Hi,
I suppose this is a bug

var b = new Buffer(1)
var c = new Buffer(0)
var a = Buffer.concat(b,c)

buffer.js:223
throw new TypeError('list argument must be an Array of Buffers.');
TypeError: list argument must be an Array of Buffers.
at Function.Buffer.concat (buffer.js:223:11)

seems the concat function does not accept zero-size Buffer

node v. 4.3.1

invalid

Most helpful comment

Hello,
Buffer.concat expects an Array of Buffer objects as its first argument. In you test case you are passing two separate arguments to the function.

The correct code would be:

var b = new Buffer(1)
var c = new Buffer(0)
var a = Buffer.concat([b,c])

All 2 comments

sorry, my mistake

var b = new Buffer(1)
var c = new Buffer(0)
var a = Buffer.concat([b,c])

Hello,
Buffer.concat expects an Array of Buffer objects as its first argument. In you test case you are passing two separate arguments to the function.

The correct code would be:

var b = new Buffer(1)
var c = new Buffer(0)
var a = Buffer.concat([b,c])
Was this page helpful?
0 / 5 - 0 ratings