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:
Anna Henningsen 2017-12-02 16:28:06 +01:00
parent 90b257eafe
commit b31626ef98
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9

View File

@ -1254,6 +1254,19 @@ Example: Fill a `Buffer` with a two-byte character
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])
<!-- YAML
added: v5.3.0