UCS-2 partial character write example. #916

Closed
ry opened this Issue Apr 13, 2011 · 2 comments

Projects

None yet

2 participants

@ry
ry commented Apr 13, 2011

UCS-2 is also multibyte encoding (2-byte, fixed-length), and it is written in partially.

> process.version
'v0.4.5'
> buf = new Buffer(5);
<Buffer 90 77 28 00 90>
> buf.write('あいう', 'ucs2');
6
> buf
<Buffer 42 30 44 30 46>
> Buffer._charsWritten
2
> buf.toString('ucs2');
'あい'

The 5th byte (0x46) of buf is a part of 3rd char (, U+3046).
And, write() should return 4 (2-chars * 2-bytes), not 6.

from @koichik. possibly V8 bug.

@koichik

This is a Node's matter.

Patch:
https://gist.github.com/917865

@ry ry closed this in 9533e87 Apr 13, 2011
@ry
ry commented Apr 13, 2011

thanks @koichik!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment