使 Node.js 流信息不可枚举



我试图在执行console.log()时从从node.js-stream继承的类中省略此类数据:

asset: 
   PassThrough {
     filename: 'old_man',
     data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 f0 00 f0 00 00 ff db 00 43 00 05 03 04 04 04 03 05 04 04 04 05 05 05 06 07 0c 08 07 07 07 07 0f 0b 0b 09 ... >,
     originalLocation: '/path/to/lib/image.jpg',
     contentType: [Getter/Setter],
     _readableState: 
      ReadableState {
        objectMode: false,
        highWaterMark: 16384,
        buffer: [],
        length: 0,
        pipes: null,
        pipesCount: 0,
        flowing: null,
        ended: false,
        endEmitted: false,
        reading: false,

。等。

通常我会尝试这样的事情:

Object.defineProperty(self, 'PassThrough', {
    configurable: true,
    writable: true,
    enumerable: false
})

但由于PassThrough实际上不是对象的属性,因此它不起作用。如何对console.log()隐藏流信息?

(免责声明:我确实意识到这是设计使然,将其隐藏;)可能是一个坏主意

console.log

落到util.inspect。如果您完全控制该类,则您所要做的就是使用自定义逻辑实现检查。请参阅此处的文档:https://nodejs.org/api/util.html#util_util_inspect_object_options

最新更新