doc: fix examples in buffer.md to avoid confusion
On some systems, some first bytes of allocated buffer can be zeroed by default, so the example doesn't work well - the buffer looks zeroed even before the fill. Fixes: https://github.com/nodejs/node/issues/9786 PR-URL: https://github.com/nodejs/node/pull/9795 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
ae2b19687b
commit
0d0028935b
@ -1,4 +1,4 @@
|
|||||||
# Buffer
|
# Buffer
|
||||||
|
|
||||||
> Stability: 2 - Stable
|
> Stability: 2 - Stable
|
||||||
|
|
||||||
@ -404,14 +404,14 @@ are unknown and *could contain sensitive data*. Use
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const buf = new Buffer(5);
|
const buf = new Buffer(10);
|
||||||
|
|
||||||
// Prints: (contents may vary): <Buffer 78 e0 82 02 01>
|
// Prints: (contents may vary): <Buffer 48 21 4b 00 00 00 00 00 30 dd>
|
||||||
console.log(buf);
|
console.log(buf);
|
||||||
|
|
||||||
buf.fill(0);
|
buf.fill(0);
|
||||||
|
|
||||||
// Prints: <Buffer 00 00 00 00 00>
|
// Prints: <Buffer 00 00 00 00 00 00 00 00 00 00>
|
||||||
console.log(buf);
|
console.log(buf);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -523,14 +523,14 @@ initialized*. The contents of the newly created `Buffer` are unknown and
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const buf = Buffer.allocUnsafe(5);
|
const buf = Buffer.allocUnsafe(10);
|
||||||
|
|
||||||
// Prints: (contents may vary): <Buffer 78 e0 82 02 01>
|
// Prints: (contents may vary): <Buffer a0 8b 28 3f 01 00 00 00 50 32>
|
||||||
console.log(buf);
|
console.log(buf);
|
||||||
|
|
||||||
buf.fill(0);
|
buf.fill(0);
|
||||||
|
|
||||||
// Prints: <Buffer 00 00 00 00 00>
|
// Prints: <Buffer 00 00 00 00 00 00 00 00 00 00>
|
||||||
console.log(buf);
|
console.log(buf);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user