diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2011-08-08 17:50:23 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2011-08-08 17:50:43 -0700 |
commit | 7332c4022f90995a2ff7d9b8822f86df64ff8164 (patch) | |
tree | c2129a841a92c4dc40f4e843edcbb8975aae73ac /lib | |
parent | ab0b1f9f13ed507c6cafbfb4fe5164a7e470a9a3 (diff) | |
download | node-new-7332c4022f90995a2ff7d9b8822f86df64ff8164.tar.gz |
Truncate Buffer.inspect at 50 bytes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/buffer.js | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/buffer.js b/lib/buffer.js index dc3848b0e0..2510d9c223 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 '<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(' ') + '>'; }; |