transform._flush(callback)
-
callback
<Function> 在刷新剩余数据时调用的回调函数(可选地带有错误参数和数据)。¥
callback
<Function> A callback function (optionally with an error argument and data) to be called when remaining data has been flushed.
此函数不得由应用代码直接调用。它应该由子类实现,并且只能由内部 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()
方法可能会被调用零次或多次,视情况而定。flush 操作完成后必须调用 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.