joyent/node — Issue #2446: Buffer#write trailing 0x00 for utf-8 but not ascii
Author: felixge
Created: 2011-12-31 12:14:04+00:00
State: open

I'd love to fix this (make it consistent), but first I'm wondering if anybody has comments on this:

When writing out a 'utf-8' string, it gets a terminating `0x00` (C-Style String):

```
> buffer = new Buffer([255, 255, 255])

> buffer.write('Ö', 'utf-8')
2
> buffer

```

However, when writing out a string using 'ascii' encoding, no trailing `0x00` is added:

```
> buffer = new Buffer([255, 255, 255])

> buffer.write('Oe', 'ascii')
2
> buffer

```

IMO this is very inconsistent. Personally I'd favor never adding a trailing `0x00` since the underlaying assumption (everything is stored as a 0x00-terminated string) is not true.