-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
doc: buffer.from will return internal pool buffer #24312
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -788,6 +788,29 @@ const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]); | |||||
|
|
||||||
| A `TypeError` will be thrown if `array` is not an `Array`. | ||||||
|
|
||||||
| `Buffer.from(array)` will also use the internal `Buffer` pool if `array.length` | ||||||
| is less than or equal to half [`Buffer.poolSize`] just like | ||||||
| [`Buffer.allocUnsafe()`] does. | ||||||
|
mritunjayz marked this conversation as resolved.
|
||||||
|
|
||||||
| ```js | ||||||
| const nodeBuffers = new Buffer.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); | ||||||
|
mritunjayz marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| console.log(nodeBuffers.offset); | ||||||
| // prints: 344 | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not always correct. It may return 0, and any subsequent call will probably increase it.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| // Default Buffer.poolsize is 8192 | ||||||
| console.log(Buffer.poolSize); | ||||||
| // prints: 8192 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| // But you can change it | ||||||
| Buffer.poolSize = 5; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be misleading. Changing |
||||||
|
|
||||||
| const buf = new Buffer.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); | ||||||
|
mritunjayz marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| console.log(buf.offset); | ||||||
| // prints: 0 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| ``` | ||||||
|
|
||||||
| ### Class Method: Buffer.from(arrayBuffer[, byteOffset[, length]]) | ||||||
| <!-- YAML | ||||||
| added: v5.10.0 | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.