Skip to content

Commit

Permalink
doc: improve buf.fill() documentation
Browse files Browse the repository at this point in the history
* Improve prepositions.
* Wrap at 80 characters.
* Formalize colloquial text.
* Remove unnecessary sentence.
* Use colons to introduce example code.

PR-URL: nodejs#19846
Reviewed-By: Daniel Bevenius <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Beth Griggs <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
Trott committed Apr 7, 2018
1 parent a639ec4 commit 4545cc1
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -1164,16 +1164,17 @@ changes:
description: The `encoding` parameter is supported now.
-->

* `value` {string|Buffer|integer} The value to fill `buf` with.
* `offset` {integer} Number of bytes to skip before starting to fill `buf`. **Default:** `0`.
* `end` {integer} Where to stop filling `buf` (not inclusive). **Default:** [`buf.length`].
* `encoding` {string} If `value` is a string, this is its encoding.
* `value` {string|Buffer|integer} The value with which to fill `buf`.
* `offset` {integer} Number of bytes to skip before starting to fill `buf`.
**Default:** `0`.
* `end` {integer} Where to stop filling `buf` (not inclusive). **Default:**
[`buf.length`].
* `encoding` {string} The encoding for `value` if `value` is a string.
**Default:** `'utf8'`.
* Returns: {Buffer} A reference to `buf`.

Fills `buf` with the specified `value`. If the `offset` and `end` are not given,
the entire `buf` will be filled. This is meant to be a small simplification to
allow the creation and filling of a `Buffer` to be done on a single line.
the entire `buf` will be filled:

```js
// Fill a `Buffer` with the ASCII character 'h'.
Expand All @@ -1184,10 +1185,10 @@ console.log(b.toString());
// Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
```

`value` is coerced to a `uint32` value if it is not a String or Integer.
`value` is coerced to a `uint32` value if it is not a string or integer.

If the final write of a `fill()` operation falls on a multi-byte character,
then only the first bytes of that character that fit into `buf` are written.
then only the bytes of that character that fit into `buf` are written:

```js
// Fill a `Buffer` with a two-byte character.
Expand Down

0 comments on commit 4545cc1

Please sign in to comment.