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

Buffer.toString docs != actual #8971

Closed
Bonuspunkt opened this issue Oct 7, 2016 · 2 comments
Closed

Buffer.toString docs != actual #8971

Bonuspunkt opened this issue Oct 7, 2016 · 2 comments
Labels
buffer Issues and PRs related to the buffer subsystem. doc Issues and PRs related to the documentations.

Comments

@Bonuspunkt
Copy link

  • Version: v6.7.0
  • Platform: Win10 x64 v1511

according to the docs

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

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

the actual output is

@addaleax addaleax added question Issues that look for answers. buffer Issues and PRs related to the buffer subsystem. doc Issues and PRs related to the documentations. labels Oct 7, 2016
@addaleax
Copy link
Member

addaleax commented Oct 7, 2016

The start and end indices of .toString() refer to byte offsets in the Buffer, and are not character counts.

So, when looking at buf2, which contains the bytes 74 c3 a9 73 74, what gets decoded are the first 3 bytes, namely 74 c3 a9, and those correspond to .

So, yeah, this is expected behaviour, and the docs are not wrong here either, but they could be a little clearer.

@addaleax
Copy link
Member

addaleax commented Oct 7, 2016

Oh, right, sorry, the docs are wrong here. They don’t even use the right buf2 variable in the example.

(That doesn’t change that returning is the expected behaviour, though.)

@addaleax addaleax added good first issue Issues that are suitable for first-time contributors. and removed question Issues that look for answers. labels Oct 7, 2016
olanb7 pushed a commit to olanb7/node that referenced this issue Oct 8, 2016
As discussed in nodejs#8971, the docs for this method could be improved.

Fixes: nodejs#8971
@addaleax addaleax removed the good first issue Issues that are suitable for first-time contributors. label Oct 8, 2016
evanlucas pushed a commit that referenced this issue Nov 3, 2016
Fixes: #8971
PR-URL: #8984
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Nov 17, 2016
Fixes: #8971
PR-URL: #8984
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Nov 19, 2016
Fixes: #8971
PR-URL: #8984
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem. doc Issues and PRs related to the documentations.
Projects
None yet
Development

No branches or pull requests

2 participants