Truncate Buffer.inspect at 50 bytes

pull/5370/head
Ryan Dahl 2011-08-08 17:50:23 -07:00
parent ab0b1f9f13
commit 7332c4022f
1 changed files with 12 additions and 0 deletions

View File

@ -22,6 +22,8 @@
var SlowBuffer = process.binding('buffer').SlowBuffer;
var assert = require('assert');
var INSPECT_MAX_BYTES = 50;
function toHex(n) {
if (n < 16) return '0' + n.toString(16);
@ -34,6 +36,10 @@ SlowBuffer.prototype.inspect = function() {
len = this.length;
for (var i = 0; i < len; i++) {
out[i] = toHex(this[i]);
if (i == INSPECT_MAX_BYTES) {
out[i + 1] = '...';
break;
}
}
return '<SlowBuffer ' + out.join(' ') + '>';
};
@ -278,9 +284,15 @@ Buffer.isBuffer = function isBuffer(b) {
Buffer.prototype.inspect = function inspect() {
var out = [],
len = this.length;
for (var i = 0; i < len; i++) {
out[i] = toHex(this.parent[i + this.offset]);
if (i == INSPECT_MAX_BYTES) {
out[i + 1] = '...';
break;
}
}
return '<Buffer ' + out.join(' ') + '>';
};