Browse Source

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>
v6
Vse Mozhet Byt 8 years ago
committed by Anna Henningsen
parent
commit
0d0028935b
No known key found for this signature in database GPG Key ID: D8B9F5AEAE84E4CF
  1. 14
      doc/api/buffer.md

14
doc/api/buffer.md

@ -1,4 +1,4 @@
# Buffer
# Buffer
> Stability: 2 - Stable
@ -404,14 +404,14 @@ are unknown and *could contain sensitive data*. Use
Example:
```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);
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);
```
@ -523,14 +523,14 @@ initialized*. The contents of the newly created `Buffer` are unknown and
Example:
```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);
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);
```

Loading…
Cancel
Save