Skip to content

Commit ae3ce7f

Browse files
Olan ByrneMylesBorins
Olan Byrne
authored andcommitted
doc: clarify buffer toString docs.
Fixes: #8971 PR-URL: #8984 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent a5860b4 commit ae3ce7f

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

doc/api/buffer.md

+14-10
Original file line numberDiff line numberDiff line change
@@ -1811,12 +1811,13 @@ added: v0.1.90
18111811
-->
18121812

18131813
* `encoding` {String} The character encoding to decode to. **Default:** `'utf8'`
1814-
* `start` {Integer} Where to start decoding. **Default:** `0`
1815-
* `end` {Integer} Where to stop decoding (not inclusive). **Default:** [`buf.length`]
1814+
* `start` {Integer} The byte offset to start decoding at. **Default:** `0`
1815+
* `end` {Integer} The byte offset to stop decoding at (not inclusive).
1816+
**Default:** [`buf.length`]
18161817
* Return: {String}
18171818

1818-
Decodes `buf` to a string according to the specified character encoding in `encoding`.
1819-
`start` and `end` may be passed to decode only a subset of `buf`.
1819+
Decodes `buf` to a string according to the specified character encoding in
1820+
`encoding`. `start` and `end` may be passed to decode only a subset of `buf`.
18201821

18211822
Examples:
18221823

@@ -1829,19 +1830,22 @@ for (var i = 0 ; i < 26 ; i++) {
18291830
}
18301831

18311832
// Prints: abcdefghijklmnopqrstuvwxyz
1832-
console.log(buf.toString('ascii'));
1833+
console.log(buf1.toString('ascii'));
18331834

18341835
// Prints: abcde
1835-
console.log(buf.toString('ascii', 0, 5));
1836+
console.log(buf1.toString('ascii', 0, 5));
18361837

18371838

18381839
const buf2 = Buffer.from('tést');
18391840

1840-
// Prints: tés
1841-
console.log(buf.toString('utf8', 0, 3));
1841+
// Prints: 74c3a97374
1842+
console.log(buf2.toString('hex'));
1843+
1844+
// Prints: té
1845+
console.log(buf2.toString('utf8', 0, 3));
18421846

1843-
// Prints: tés
1844-
console.log(buf.toString(undefined, 0, 3));
1847+
// Prints:
1848+
console.log(buf2.toString(undefined, 0, 3));
18451849
```
18461850

18471851
### buf.toJSON()

0 commit comments

Comments
 (0)