doc: warn against filling buffer with invalid data
PR-URL: https://github.com/nodejs/node/pull/17428 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
parent
90b257eafe
commit
b31626ef98
@ -1254,6 +1254,19 @@ Example: Fill a `Buffer` with a two-byte character
|
|||||||
console.log(Buffer.allocUnsafe(3).fill('\u0222'));
|
console.log(Buffer.allocUnsafe(3).fill('\u0222'));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If `value` is contains invalid characters, it is truncated; if no valid
|
||||||
|
fill data remains, no filling is performed:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const buf = Buffer.allocUnsafe(5);
|
||||||
|
// Prints: <Buffer 61 61 61 61 61>
|
||||||
|
console.log(buf.fill('a'));
|
||||||
|
// Prints: <Buffer aa aa aa aa aa>
|
||||||
|
console.log(buf.fill('aazz', 'hex'));
|
||||||
|
// Prints: <Buffer aa aa aa aa aa>
|
||||||
|
console.log(buf.fill('zz', 'hex'));
|
||||||
|
```
|
||||||
|
|
||||||
### buf.includes(value[, byteOffset][, encoding])
|
### buf.includes(value[, byteOffset][, encoding])
|
||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v5.3.0
|
added: v5.3.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user