-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DOC] Buffer.from / new Buffer accept Uint8Array (missing) #14118
Comments
@nodejs/documentation |
@reviewher the docs already specify it takes a Was the unclear part the fact it's not obvious that a |
@benjamingr The documentation lists 4 signatures for
None of those cases cover an actual Uint8Array object! We are not talking about "the > var x = new Uint8Array([1,2,3,4,5])
> x
Uint8Array [ 1, 2, 3, 4, 5 ]
> Buffer.from(x.buffer) // <-- this is from the docs
<Buffer 01 02 03 04 05>
> x.buffer instanceof ArrayBuffer // <-- x.buffer is an ArrayBuffer, not a typed array
true
> x.buffer instanceof Uint8Array // <-- x.buffer is definitely not a Uint8Array
false
> Buffer.from(x) // <-- this is the case that works and is not covered in the docs
<Buffer 01 02 03 04 05>
> Buffer.isBuffer(x) // <-- x is definitely not a buffer
false
> x instanceof ArrayBuffer // <-- x is definitely not an ArrayBuffer
false
> x instanceof Uint8Array // <-- x is definitely a Uint8Array
true To contrast with other areas of the documentation:
@benjamingr it's also possible you took a cursory glance at https://nodejs.org/dist/latest-v8.x/docs/api/buffer.html#buffer_buffers_and_typedarray and assumed it was covered, but alas it is not. The ending of that section does discuss typed arrays, but it is merely contrasting the signatures of Buffer.from and TypedArray.from. @Trott to be consistent with the other areas of the documentation, assuming that -* `buffer` {Buffer} An existing `Buffer` to copy data from
+* `buffer` {Buffer|Uint8Array} An existing `Buffer` or [`Uint8Array`] to copy data from |
@nodejs/documentation This has been around for a while and looks like a valid bug report for the docs. |
This is a one-line change to |
@reviwher I think they had the same first look thought which is that it mentions |
Buffer.from / new Buffer accept Uint8Array Fixes: #14118 PR-URL: #19949 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
Buffer.from / new Buffer accept Uint8Array Fixes: #14118 Backport-PR-URL: #21590 PR-URL: #19949 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
Buffer.from / new Buffer accept Uint8Array Fixes: #14118 Backport-PR-URL: #21590 PR-URL: #19949 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
Buffer.from / new Buffer accept Uint8Array Fixes: #14118 Backport-PR-URL: #21590 PR-URL: #19949 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
Buffer.from / new Buffer accept Uint8Array Fixes: #14118 Backport-PR-URL: #21590 PR-URL: #19949 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
Buffer.from / new Buffer accept Uint8Array Fixes: #14118 Backport-PR-URL: #21590 PR-URL: #19949 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
Buffer.from / new Buffer accept Uint8Array Fixes: nodejs/node#14118 PR-URL: nodejs/node#19949 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
Both can accept a Uint8Array. Buffer.from explicitly checks for Uint8Array
It looks like a documentation omission. If so, I can send a PR.
The text was updated successfully, but these errors were encountered: