Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

UCS-2 partial character write example. #916

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

UCS-2 partial character write example. #916

ry opened this issue Apr 13, 2011 · 2 comments

Comments

@ry
Copy link

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
Copy link

koichik commented Apr 13, 2011

This is a Node's matter.

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

@ry ry closed this as completed in 9533e87 Apr 13, 2011
@ry
Copy link
Author

ry commented Apr 13, 2011

thanks @koichik!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants