buffer: show hidden item count
This adds the number of hidden items in case INSPECT_MAX_BYTES is exceeded. PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
8a41470c85
commit
755520c4c3
@ -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];
|
||||
|
@ -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);
|
||||
|
@ -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)));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user