transform._flush(callback)
callback<Function> 当剩余数据已被刷新时要调用的回调函数(可选包含一个错误参数和数据)。
此函数绝对不能被应用代码直接调用。它应由子类实现,并且仅由内部的 Readable 类方法调用。
【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.】
在某些情况下,变换操作可能需要在流的末尾输出额外的数据位。例如,zlib 压缩流会存储一定量的内部状态,以便对输出进行最佳压缩。然而,当流结束时,需要将这些额外的数据刷新,以确保压缩数据完整。
【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.】
自定义 Transform 实现 可能 会实现 transform._flush() 方法。当没有更多写入的数据需要被处理时,该方法将被调用,但在发出 'end' 事件以表示 Readable 流结束之前。
【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.】
在 transform._flush() 的实现中,transform.push() 方法可以根据需要调用零次或多次。当刷新操作完成时,必须调用 callback 函数。
【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.】
transform._flush() 方法以下划线开头,因为它是定义该方法的类的内部方法,用户程序不应直接调用它。
【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.】