Skip to content

Instantly share code, notes, and snippets.

@horatio-sans-serif
Created April 6, 2010 00:35
Show Gist options
  • Save horatio-sans-serif/357054 to your computer and use it in GitHub Desktop.
Save horatio-sans-serif/357054 to your computer and use it in GitHub Desktop.
bytes written to buffer: 12
AssertionError: "\u00f6\u65e5\u672c\u8a9e" == "\u00f6\u65e5\u672c\u8a9e\u0000"
at Object.<anonymous> (/tmp/utf8slice.js:10:8)
at Module._compile (node.js:704:23)
at node.js:732:20
at fs:51:23
at node.js:813:9
assert = require("assert");
sys = require("sys");
Buffer = require("buffer").Buffer;
var testValue = '\u00F6\u65E5\u672C\u8A9E'; // ö日本語
var buffer = new Buffer(32);
var size = buffer.utf8Write(testValue, 0);
sys.puts('bytes written to buffer: ' + size);
var slice = buffer.utf8Slice(0, size);
assert.equal(slice, testValue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment