You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 té.
So, yeah, this is expected behaviour, and the docs are not wrong here either, but they could be a little clearer.
Activity
addaleax commentedon Oct 7, 2016
The start and end indices of
.toString()refer to byte offsets in theBuffer, and are not character counts.So, when looking at
buf2, which contains the bytes74 c3 a9 73 74, what gets decoded are the first3bytes, namely74 c3 a9, and those correspond toté.So, yeah, this is expected behaviour, and the docs are not wrong here either, but they could be a little clearer.
addaleax commentedon Oct 7, 2016
Oh, right, sorry, the docs are wrong here. They don’t even use the right
buf2variable in the example.(That doesn’t change that returning
téis the expected behaviour, though.)doc: clarify buffer toString docs.
doc: clarify buffer toString docs.
doc: clarify buffer toString docs.
doc: clarify buffer toString docs.