Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: improve buf.fill() documentation #19846

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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