mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 21:58:48 +02:00
buffer: allow Uint8Array input to methods
Allow all methods on `buffer` and `Buffer` to take `Uint8Array` arguments where it makes sense. On the native side, there is effectively no difference, and as a bonus the `isUint8Array` check is faster than `instanceof Buffer`. PR-URL: https://github.com/nodejs/node/pull/10236 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
This commit is contained in:
parent
6cb33c0764
commit
beca3244e2
10 changed files with 81 additions and 45 deletions
|
@ -35,7 +35,8 @@ function assertWrongList(value) {
|
|||
Buffer.concat(value);
|
||||
}, function(err) {
|
||||
return err instanceof TypeError &&
|
||||
err.message === '"list" argument must be an Array of Buffers';
|
||||
err.message === '"list" argument must be an Array of Buffer ' +
|
||||
'or Uint8Array instances';
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -60,3 +61,7 @@ assert.deepStrictEqual(Buffer.concat([empty], 4096), Buffer.alloc(4096));
|
|||
assert.deepStrictEqual(
|
||||
Buffer.concat([random10], 40),
|
||||
Buffer.concat([random10, Buffer.alloc(30)]));
|
||||
|
||||
assert.deepStrictEqual(Buffer.concat([new Uint8Array([0x41, 0x42]),
|
||||
new Uint8Array([0x43, 0x44])]),
|
||||
Buffer.from('ABCD'));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue