GeezerVison is showing github.com — stream: improve buffer list inspection · nodejs/node@25bf1f5
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/streams/buffer_list.js +9-3Lines changed: 9 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -158,8 +158,14 @@ module.exports = class BufferList { |
158 | 158 | return ret; |
159 | 159 | } |
160 | 160 |
|
161 | | - [inspect.custom]() { |
162 | | - const obj = inspect({ length: this.length }); |
163 | | - return `${this.constructor.name} ${obj}`; |
| 161 | + // Make sure the linked list only shows the minimal necessary information. |
| 162 | + [inspect.custom](_, options) { |
| 163 | + return inspect(this, { |
| 164 | + ...options, |
| 165 | + // Only inspect one level. |
| 166 | + depth: 0, |
| 167 | + // It should not recurse. |
| 168 | + customInspect: false |
| 169 | + }); |
164 | 170 | } |
165 | 171 | }; |
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-stream2-readable-from-list.js +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,6 +25,7 @@ require('../common'); |
25 | 25 | const assert = require('assert'); |
26 | 26 | const fromList = require('_stream_readable')._fromList; |
27 | 27 | const BufferList = require('internal/streams/buffer_list'); |
| 28 | +const util = require('util'); |
28 | 29 |
|
29 | 30 | function bufferListFromArray(arr) { |
30 | 31 | const bl = new BufferList(); |
@@ -41,6 +42,16 @@ function bufferListFromArray(arr) { |
41 | 42 | Buffer.from('kuel') ]; |
42 | 43 | list = bufferListFromArray(list); |
43 | 44 |
|
| 45 | + assert.strictEqual( |
| 46 | + util.inspect([ list ], { compact: false }), |
| 47 | + `[ |
| 48 | + BufferList { |
| 49 | + head: [Object], |
| 50 | + tail: [Object], |
| 51 | + length: 4 |
| 52 | + } |
| 53 | +]`); |
| 54 | + |
44 | 55 | // read more than the first element. |
45 | 56 | let ret = fromList(6, { buffer: list, length: 16 }); |
46 | 57 | assert.strictEqual(ret.toString(), 'foogba'); |
|