|
|
@ -12,22 +12,21 @@ Buffer.isBuffer = function (b) { |
|
|
|
}; |
|
|
|
|
|
|
|
Buffer.prototype.inspect = function () { |
|
|
|
var s = "<Buffer "; |
|
|
|
for (var i = 0; i < this.length; i++) { |
|
|
|
s += toHex(this[i]); |
|
|
|
if (i != this.length - 1) s += ' '; |
|
|
|
var out = [], |
|
|
|
len = this.length; |
|
|
|
for (var i = 0; i < len; i++) { |
|
|
|
out[i] = toHex(this[i]); |
|
|
|
} |
|
|
|
s += ">"; |
|
|
|
return s; |
|
|
|
return "<Buffer " + out.join(" ") + ">"; |
|
|
|
}; |
|
|
|
|
|
|
|
Buffer.prototype.toString = function (encoding, start, stop) { |
|
|
|
encoding = (encoding || 'utf8').toLowerCase(); |
|
|
|
if (!start) start = 0; |
|
|
|
if (stop === undefined) stop = this.length; |
|
|
|
encoding = String(encoding || 'utf8').toLowerCase(); |
|
|
|
start = +start || 0; |
|
|
|
if (typeof stop == "undefined") stop = this.length; |
|
|
|
|
|
|
|
// Fastpath empty strings
|
|
|
|
if (stop === start) { |
|
|
|
if (+stop == start) { |
|
|
|
return ''; |
|
|
|
} |
|
|
|
|
|
|
@ -50,21 +49,17 @@ Buffer.prototype.toString = function (encoding, start, stop) { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
Buffer.prototype.write = function (string) { |
|
|
|
Buffer.prototype.write = function (string, offset, encoding) { |
|
|
|
// Support both (string, offset, encoding)
|
|
|
|
// and the legacy (string, encoding, offset)
|
|
|
|
var offset, encoding; |
|
|
|
|
|
|
|
if (typeof arguments[1] == 'string') { |
|
|
|
encoding = arguments[1]; |
|
|
|
offset = arguments[2]; |
|
|
|
} else { |
|
|
|
offset = arguments[1]; |
|
|
|
encoding = arguments[2]; |
|
|
|
if (!isFinite(offset)) { |
|
|
|
var swap = encoding; |
|
|
|
encoding = offset; |
|
|
|
offset = swap; |
|
|
|
} |
|
|
|
|
|
|
|
offset = offset || 0; |
|
|
|
encoding = encoding || 'utf8'; |
|
|
|
offset = +offset || 0; |
|
|
|
encoding = String(encoding || 'utf8').toLowerCase(); |
|
|
|
|
|
|
|
switch (encoding) { |
|
|
|
case 'utf8': |
|
|
@ -83,10 +78,4 @@ Buffer.prototype.write = function (string) { |
|
|
|
default: |
|
|
|
throw new Error('Unknown encoding'); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}; |