Skip to content

Buffer.concat documentation is wrong #60400

@ChALkeR

Description

@ChALkeR

If `totalLength` is provided, it is coerced to an unsigned integer. If the

This is not what happens. Instead, non-integers throw:

> Buffer.concat([Buffer.of()],2.6)
Uncaught:
RangeError [ERR_OUT_OF_RANGE]: The value of "length" is out of range. It must be an integer. Received 2.6
    at validateOffset (node:buffer:123:3)
    at Buffer.concat (node:buffer:590:5) {
  code: 'ERR_OUT_OF_RANGE'
}
> Buffer.concat([Buffer.of()],'10')
Uncaught:
TypeError [ERR_INVALID_ARG_TYPE]: The "length" argument must be of type number. Received type string ('10')
    at validateOffset (node:buffer:123:3)
    at Buffer.concat (node:buffer:590:5) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Less significant, but also confusing (ref: #55562)

node/doc/api/buffer.md

Lines 1044 to 1045 in 2bda7cb

truncated to `totalLength`. If the combined length of the `Buffer`s in `list` is
less than `totalLength`, the remaining space is filled with zeros.

This is not always true, as this happens on empty lists:

node/doc/api/buffer.md

Lines 1036 to 1037 in 2bda7cb

If the list has no items, or if the `totalLength` is 0, then a new zero-length
`Buffer` is returned.

> Buffer.concat([],100)
<Buffer >

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions