Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)));
}