Skip to content

Commit

Permalink
doc: clarify buffer toString docs.
Browse files Browse the repository at this point in the history
Fixes: #8971
PR-URL: #8984
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
Olan Byrne authored and evanlucas committed Nov 3, 2016
1 parent 0ce0abf commit a0074e2
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -1809,12 +1809,13 @@ added: v0.1.90
-->

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

Decodes `buf` to a string according to the specified character encoding in `encoding`.
`start` and `end` may be passed to decode only a subset of `buf`.
Decodes `buf` to a string according to the specified character encoding in
`encoding`. `start` and `end` may be passed to decode only a subset of `buf`.

Examples:

Expand All @@ -1827,19 +1828,22 @@ for (var i = 0 ; i < 26 ; i++) {
}

// Prints: abcdefghijklmnopqrstuvwxyz
console.log(buf.toString('ascii'));
console.log(buf1.toString('ascii'));

// Prints: abcde
console.log(buf.toString('ascii', 0, 5));
console.log(buf1.toString('ascii', 0, 5));


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

// Prints: tés
console.log(buf.toString('utf8', 0, 3));
// Prints: 74c3a97374
console.log(buf2.toString('hex'));

// Prints: té
console.log(buf2.toString('utf8', 0, 3));

// Prints: tés
console.log(buf.toString(undefined, 0, 3));
// Prints:
console.log(buf2.toString(undefined, 0, 3));
```

### buf.toJSON()
Expand Down

0 comments on commit a0074e2

Please sign in to comment.