substack/node-browserify — pull request #143 by toots (2012-05-11 03:43:55+00:00)
Title: Added support for utf8, ascii, hex and base64 encodings in Buffer module.

It seems to work pretty well:

```
> buffer = require("./builtins/buffer.js")
{ INSPECT_MAX_BYTES: 50,
SlowBuffer: { [Function: SlowBuffer] byteLength: [Function] },
Buffer:
{ [Function: Buffer]
poolSize: 8192,
isBuffer: [Function: isBuffer],
byteLength: [Function] } }
> x = new buffer.Buffer("Ձ","utf8")

> x.toString("utf8")
'Ձ'
> new buffer.Buffer(x.toString("base64"),"base64").toString("utf8")
'Ձ'
> new buffer.Buffer(x.toString("hex"),"hex").toString("utf8")
'Ձ'
> x = new buffer.Buffer("foo","ascii")

> x.toString("ascii")
'foo'
> new buffer.Buffer(x.toString("base64"),"base64").toString("utf8")
'foo'
> new buffer.Buffer(x.toString("hex"),"hex").toString("utf8")
'foo'
> new buffer.Buffer(x.toString("ascii"),"ascii").toString("utf8")
'foo'

```