|
|
@ -211,23 +211,33 @@ Buffer.prototype.write = function write (string, offset, encoding) { |
|
|
|
// Make sure we are not going to overflow
|
|
|
|
var maxLength = this.length - offset; |
|
|
|
|
|
|
|
var ret; |
|
|
|
switch (encoding) { |
|
|
|
case 'utf8': |
|
|
|
case 'utf-8': |
|
|
|
return this.parent.utf8Write(string, this.offset + offset, maxLength); |
|
|
|
ret = this.parent.utf8Write(string, this.offset + offset, maxLength); |
|
|
|
break; |
|
|
|
|
|
|
|
case 'ascii': |
|
|
|
return this.parent.asciiWrite(string, this.offset + offset, maxLength); |
|
|
|
ret = this.parent.asciiWrite(string, this.offset + offset, maxLength); |
|
|
|
break; |
|
|
|
|
|
|
|
case 'binary': |
|
|
|
return this.parent.binaryWrite(string, this.offset + offset, maxLength); |
|
|
|
ret = this.parent.binaryWrite(string, this.offset + offset, maxLength); |
|
|
|
break; |
|
|
|
|
|
|
|
case 'base64': |
|
|
|
return this.parent.base64Write(string, this.offset + offset, maxLength); |
|
|
|
// Warning: maxLength not taken into account in base64Write
|
|
|
|
ret = this.parent.base64Write(string, this.offset + offset, maxLength); |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
throw new Error('Unknown encoding'); |
|
|
|
} |
|
|
|
|
|
|
|
Buffer._charsWritten = SlowBuffer._charsWritten; |
|
|
|
|
|
|
|
return ret; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|