Skip to content

Commit

Permalink
buffer: show hidden item count
Browse files Browse the repository at this point in the history
This adds the number of hidden items in case INSPECT_MAX_BYTES is
exceeded.

PR-URL: #22289
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
BridgeAR committed Aug 15, 2018
1 parent 8a41470 commit 755520c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,9 @@ Buffer.prototype[customInspectSymbol] = function inspect() {
var str = '';
var max = exports.INSPECT_MAX_BYTES;
str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
if (this.length > max)
str += ' ... ';
const remaining = this.length - max;
if (remaining > 0)
str += ` ... ${remaining} more byte${remaining > 1 ? 's' : ''}`;
return `<${this.constructor.name} ${str}>`;
};
Buffer.prototype.inspect = Buffer.prototype[customInspectSymbol];
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-buffer-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ b.fill('1234');
let s = buffer.SlowBuffer(4);
s.fill('1234');

let expected = '<Buffer 31 32 ... >';
let expected = '<Buffer 31 32 ... 2 more bytes>';

assert.strictEqual(util.inspect(b), expected);
assert.strictEqual(util.inspect(s), expected);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-buffer-prototype-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ const util = require('util');

{
const buf = Buffer.from('x'.repeat(51));
assert.ok(/^<Buffer (?:78 ){50}\.\.\. >$/.test(util.inspect(buf)));
assert.ok(/^<Buffer (?:78 ){50}\.\.\. 1 more byte>$/.test(util.inspect(buf)));
}

0 comments on commit 755520c

Please sign in to comment.