Skip to content

Commit fc6db13

Browse files
committed
Proper fix, soft-detecting there is a custom inspect.
1 parent 6ec7d8a commit fc6db13

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

build/files.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,28 @@ module.exports['_stream_writable.js'] = [
319319
, useCorkedRequest
320320
, addConstructors
321321
]
322+
322323
module.exports['internal/streams/BufferList.js'] = [
323-
safeBufferFix
324+
[
325+
/(?:var|const) (?:{ )Buffer(?: }) = require\('buffer'\)(?:\.Buffer)?;/,
326+
`
327+
const Buffer = require('safe-buffer').Buffer
328+
const util = require('util')
329+
`
330+
]
324331
, fixCopyBuffer
332+
, [
333+
/$/,
334+
`
335+
336+
if (util && util.inspect.custom) {
337+
module.exports.prototype[util.inspect.custom] = function () {
338+
const obj = util.inspect({ length: this.length });
339+
return \`\${this.constructor.name} \${obj}\`;
340+
}
341+
}
342+
`
343+
]
325344

326345
]
327346
module.exports['internal/streams/destroy.js'] = [

lib/internal/streams/BufferList.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
'use strict';
22

3-
/*<replacement>*/
4-
53
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
64

75
var Buffer = require('safe-buffer').Buffer;
8-
/*</replacement>*/
6+
var util = require('util');
97

108
function copyBuffer(src, target, offset) {
119
src.copy(target, offset);
@@ -71,4 +69,11 @@ module.exports = function () {
7169
};
7270

7371
return BufferList;
74-
}();
72+
}();
73+
74+
if (util && util.inspect.custom) {
75+
module.exports.prototype[util.inspect.custom] = function () {
76+
var obj = util.inspect({ length: this.length });
77+
return this.constructor.name + ' ' + obj;
78+
};
79+
}

0 commit comments

Comments
 (0)