Skip to content

Commit 146c0b5

Browse files
gurgundayChALkeR
andcommitted
doc: align Buffer.concat documentation with behavior
Co-authored-by: Сковорода Никита Андреевич <[email protected]>
1 parent 2bda7cb commit 146c0b5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

doc/api/buffer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ If the list has no items, or if the `totalLength` is 0, then a new zero-length
10391039
If `totalLength` is not provided, it is calculated from the `Buffer` instances
10401040
in `list` by adding their lengths.
10411041

1042-
If `totalLength` is provided, it is coerced to an unsigned integer. If the
1042+
If `totalLength` is provided, it must be an unsigned integer. If the
10431043
combined length of the `Buffer`s in `list` exceeds `totalLength`, the result is
10441044
truncated to `totalLength`. If the combined length of the `Buffer`s in `list` is
10451045
less than `totalLength`, the remaining space is filled with zeros.

test/parallel/test-buffer-concat.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ assert.throws(() => {
7272
'or Uint8Array. Received type number (3)'
7373
});
7474

75+
assert.throws(() => {
76+
Buffer.concat([Buffer.from('hello')], 3.5);
77+
}, {
78+
code: 'ERR_OUT_OF_RANGE',
79+
message: 'The value of "length" is out of range. It must be an integer. ' +
80+
'Received 3.5'
81+
});
82+
83+
assert.throws(() => {
84+
Buffer.concat([Buffer.from('hello')], -2);
85+
}, {
86+
code: 'ERR_OUT_OF_RANGE',
87+
message: 'The value of "length" is out of range. It must be >= 0 && <= 9007199254740991. ' +
88+
'Received -2'
89+
});
90+
7591
// eslint-disable-next-line node-core/crypto-check
7692
const random10 = common.hasCrypto ?
7793
require('crypto').randomBytes(10) :

0 commit comments

Comments
 (0)