diff --git a/lib/buffer.js b/lib/buffer.js index dc3848b0e0b..2510d9c223c 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -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 ''; }; @@ -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 ''; };