-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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: correct crypto.randomFill() and randomFillSync() #21550
Conversation
doc/api/crypto.md
Outdated
@@ -2061,13 +2061,13 @@ Any `TypedArray` or `DataView` instance may be passed as `buffer`. | |||
|
|||
```js | |||
const a = new Uint32Array(10); | |||
console.log(crypto.randomFillSync(a).toString('hex')); | |||
console.log(Buffer.from(crypto.randomFillSync(a).buffer).toString('hex')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just using .buffer
works in these cases, but I’m not sure we should include it in our documentation like this – most of the time when you’re doing this, you’ll want to consider .byteLength
and .byteOffset
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just modified the samples to work without thinking to much about it. Printing a Float64Array
formatted as 'hex' is usually not a typical use. I will update the samples to use also .byteLength
and .byteOffset
but I'm not sure if doc of randomFillSync()
is the right place to show how to work with typed arrays.
Correct return type of `crypto.randomFillSync()` which is of same type as passed as `buffer` argument. Correct samples for `randomFill()` and `randomFillSync()` using a `TypeArray` or `DataView` as these types don't support `.toString(encoding)`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM even though I wonder if we should explain the example at least once?
Landed in acc633c |
Correct return type of `crypto.randomFillSync()` which is of same type as passed as `buffer` argument. Correct samples for `randomFill()` and `randomFillSync()` using a `TypeArray` or `DataView` as these types don't support `.toString(encoding)`. PR-URL: #21550 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Correct return type of `crypto.randomFillSync()` which is of same type as passed as `buffer` argument. Correct samples for `randomFill()` and `randomFillSync()` using a `TypeArray` or `DataView` as these types don't support `.toString(encoding)`. PR-URL: #21550 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Correct return type of
crypto.randomFillSync()
which is of same type as passed asbuffer
argument.Correct samples for
randomFill()
andrandomFillSync()
using aTypeArray
orDataView
as these types don't support.toString(encoding)
.