Change Buffer.toString to conform to CommonJS Binary/F
Also add Buffer.inspect
This commit is contained in:
parent
7ed80451ca
commit
bb00fef3cd
@ -7,7 +7,7 @@ function toHex (n) {
|
|||||||
return n.toString(16);
|
return n.toString(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer.prototype.toString = function () {
|
Buffer.prototype.inspect = function () {
|
||||||
var s = "<Buffer ";
|
var s = "<Buffer ";
|
||||||
for (var i = 0; i < this.length; i++) {
|
for (var i = 0; i < this.length; i++) {
|
||||||
s += toHex(this[i]);
|
s += toHex(this[i]);
|
||||||
@ -17,8 +17,20 @@ Buffer.prototype.toString = function () {
|
|||||||
return s;
|
return s;
|
||||||
};
|
};
|
||||||
|
|
||||||
Buffer.prototype.toJSON = function () {
|
Buffer.prototype.toString = function (encoding, start, stop) {
|
||||||
return this.utf8Slice(0, this.length);
|
encoding = encoding || 'utf8';
|
||||||
|
if (!start) start = 0;
|
||||||
|
if (!stop) stop = this.length;
|
||||||
|
|
||||||
|
if (encoding == 'utf8') {
|
||||||
|
return this.utf8Slice(start, stop);
|
||||||
|
} else if (encoding == 'ascii') {
|
||||||
|
return this.asciiSlice(start, stop);
|
||||||
|
} else if (encoding == 'binary') {
|
||||||
|
return this.binarySlice(start, stop);
|
||||||
|
} else {
|
||||||
|
throw new Error('Unknown encoding');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user