Skip to content

Commit 755520c

Browse files
committedAug 15, 2018
buffer: show hidden item count
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>
1 parent 8a41470 commit 755520c

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed
 

‎lib/buffer.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,9 @@ Buffer.prototype[customInspectSymbol] = function inspect() {
683683
var str = '';
684684
var max = exports.INSPECT_MAX_BYTES;
685685
str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
686-
if (this.length > max)
687-
str += ' ... ';
686+
const remaining = this.length - max;
687+
if (remaining > 0)
688+
str += ` ... ${remaining} more byte${remaining > 1 ? 's' : ''}`;
688689
return `<${this.constructor.name} ${str}>`;
689690
};
690691
Buffer.prototype.inspect = Buffer.prototype[customInspectSymbol];

‎test/parallel/test-buffer-inspect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ b.fill('1234');
3333
let s = buffer.SlowBuffer(4);
3434
s.fill('1234');
3535

36-
let expected = '<Buffer 31 32 ... >';
36+
let expected = '<Buffer 31 32 ... 2 more bytes>';
3737

3838
assert.strictEqual(util.inspect(b), expected);
3939
assert.strictEqual(util.inspect(s), expected);

‎test/parallel/test-buffer-prototype-inspect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ const util = require('util');
1919

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

0 commit comments

Comments
 (0)