|
|
@ -111,6 +111,9 @@ function Buffer (subject, encoding, legacy, slice_legacy) { |
|
|
|
break; |
|
|
|
|
|
|
|
case 'string': |
|
|
|
length = Buffer.byteLength(subject); |
|
|
|
break; |
|
|
|
|
|
|
|
case 'object': // Assume object is an array
|
|
|
|
length = subject.length; |
|
|
|
break; |
|
|
@ -186,7 +189,7 @@ Buffer.prototype.set = function set (i, v) { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// write(string, offset = 0, encoding = 'uft8')
|
|
|
|
// write(string, offset = 0, encoding = 'utf8')
|
|
|
|
Buffer.prototype.write = function write (string, offset, encoding) { |
|
|
|
if (!isFinite(offset)) { |
|
|
|
var swap = encoding; |
|
|
@ -195,11 +198,12 @@ Buffer.prototype.write = function write (string, offset, encoding) { |
|
|
|
} |
|
|
|
|
|
|
|
offset || (offset = 0); |
|
|
|
encoding || (encoding = 'uft8'); |
|
|
|
encoding || (encoding = 'utf8'); |
|
|
|
|
|
|
|
// Make sure we are not going to overflow
|
|
|
|
var max_length = this.length - offset; |
|
|
|
if (string.length > max_length) { |
|
|
|
if (Buffer.byteLength(string) > max_length) { |
|
|
|
// FIXME: Char length !== byte length
|
|
|
|
string = string.slice(0, max_length); |
|
|
|
} |
|
|
|
|
|
|
|