transform._flush(callback)


  • callback <Function> 在刷新剩余数据时调用的回调函数(可选地带有错误参数和数据)。

此函数不得由应用程序代码直接调用。 它应该由子类实现,并且只能由内部 Readable 类方法调用。

在某些情况下,转换操作可能需要在流的末尾触发额外的数据位。 例如,zlib 压缩流将存储用于优化压缩输出的内部状态量。 但是,当流结束时,需要刷新额外的数据,以便完成压缩数据。

自定义的 Transform 实现可以实现 transform._flush() 方法。 当没有更多的写入数据被消耗时,但在触发 'end' 事件以表示 Readable 流结束之前,将调用此方法。

transform._flush() 实现中,transform.push() 方法可以被调用零次或多次,视情况而定。 必须在刷新操作完成时调用 callback 函数。

transform._flush() 方法以下划线为前缀,因为它是定义它的类的内部方法,不应由用户程序直接调用。

  • callback <Function> A callback function (optionally with an error argument and data) to be called when remaining data has been flushed.

This function MUST NOT be called by application code directly. It should be implemented by child classes, and called by the internal Readable class methods only.

In some cases, a transform operation may need to emit an additional bit of data at the end of the stream. For example, a zlib compression stream will store an amount of internal state used to optimally compress the output. When the stream ends, however, that additional data needs to be flushed so that the compressed data will be complete.

Custom Transform implementations may implement the transform._flush() method. This will be called when there is no more written data to be consumed, but before the 'end' event is emitted signaling the end of the Readable stream.

Within the transform._flush() implementation, the transform.push() method may be called zero or more times, as appropriate. The callback function must be called when the flush operation is complete.

The transform._flush() method is prefixed with an underscore because it is internal to the class that defines it, and should never be called directly by user programs.