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

Adding clarity to buffer toString docs. #8984

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
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
15 changes: 9 additions & 6 deletions doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -1811,8 +1811,8 @@ 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} They byte offset to start decoding at. **Default:** `0`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: They

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silly me. Resolved!

* `end` {Integer} The byte offset to stop decoding at (not inclusive). **Default:** [`buf.length`]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: long line

* Return: {String}

Decodes `buf` to a string according to the specified character encoding in `encoding`.
Expand All @@ -1837,11 +1837,14 @@ console.log(buf.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'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this isn’t mentioned in #8971, but the console.log(buf.toString(…)) statements should probably refer to buf1, not buf, so it would make sense to fix that, too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, totally missed that. Sure.


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

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

### buf.toJSON()
Expand Down