|
|
@ -443,20 +443,23 @@ Stream.prototype._writeOut = function (data, encoding) { |
|
|
|
allocNewPool(); |
|
|
|
} |
|
|
|
|
|
|
|
if (encoding == 'utf8' || encoding == 'utf-8') { |
|
|
|
if (encoding == 'binary') { |
|
|
|
bytesWritten = pool.binaryWrite(data, pool.used); |
|
|
|
charsWritten = bytesWritten; |
|
|
|
} else if (encoding == 'ascii') { |
|
|
|
bytesWritten = pool.asciiWrite(data, pool.used); |
|
|
|
charsWritten = bytesWritten; |
|
|
|
|
|
|
|
} else { |
|
|
|
// default to utf8
|
|
|
|
bytesWritten = pool.utf8Write(data, pool.used); |
|
|
|
// Don't include the null
|
|
|
|
if (pool[pool.used + bytesWritten-1] == 0) bytesWritten--; |
|
|
|
// XXX Hacky way to find out the number of characters written.
|
|
|
|
// Waiting for a more optimal way: http://codereview.chromium.org/1539013
|
|
|
|
var _s = pool.utf8Slice(pool.used, pool.used + bytesWritten); |
|
|
|
charsWritten = _s.length; |
|
|
|
} else if (encoding == 'ascii') { |
|
|
|
bytesWritten = pool.asciiWrite(data, pool.used); |
|
|
|
charsWritten = bytesWritten; |
|
|
|
assert(charsWritten <= data.length); |
|
|
|
} else { |
|
|
|
bytesWritten = pool.binaryWrite(data, pool.used); |
|
|
|
charsWritten = bytesWritten; |
|
|
|
assert(charsWritten <= data.length); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
assert(bytesWritten > 0); |
|
|
|