GeezerVison is showing github.com — doc: clarify `length` param in `buffer.write` · nodejs/node@b4ba9b8
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: doc/api/buffer.md +9-2Lines changed: 9 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1994,8 +1994,8 @@ added: v0.1.90 |
1994 | 1994 | * `string` {string} String to write to `buf`. |
1995 | 1995 | * `offset` {integer} Number of bytes to skip before starting to write `string`. |
1996 | 1996 | **Default:** `0`. |
1997 | | -* `length` {integer} Maximum number of bytes to write. **Default:** |
1998 | | - `buf.length - offset`. |
| 1997 | +* `length` {integer} Maximum number of bytes to write (written bytes will not |
| 1998 | + exceed `buf.length - offset`). **Default:** `buf.length - offset`. |
1999 | 1999 | * `encoding` {string} The character encoding of `string`. **Default:** `'utf8'`. |
2000 | 2000 | * Returns: {integer} Number of bytes written. |
2001 | 2001 |
|
@@ -2011,6 +2011,13 @@ const len = buf.write('\u00bd + \u00bc = \u00be', 0); |
2011 | 2011 |
|
2012 | 2012 | console.log(`${len} bytes: ${buf.toString('utf8', 0, len)}`); |
2013 | 2013 | // Prints: 12 bytes: ½ + ¼ = ¾ |
| 2014 | + |
| 2015 | +const buffer = Buffer.alloc(10); |
| 2016 | + |
| 2017 | +const length = buffer.write('abcd', 8); |
| 2018 | + |
| 2019 | +console.log(`${length} bytes: ${buffer.toString('utf8', 8, 10)}`); |
| 2020 | +// Prints: 2 bytes : ab |
2014 | 2021 | ``` |
2015 | 2022 |
|
2016 | 2023 | ### `buf.writeBigInt64BE(value[, offset])` |
|