Flush flushes any pending data to the underlying writer. It is useful mainly in compressed network protocols, to ensure that a remote reader has enough data to reconstruct a packet. Flush does not return until the data has been written. Calling Flush when there is no pending data still causes the Writer to emit a sync marker of at least 4 bytes. If the underlying writer returns an error, Flush returns that error.
There should be a
Writer.Flush
method that forces all buffered data to be compressed and flushed to the underlying writer.This is useful when writing to network or disk where we need the guarantee that data is readable by the consumer up until flush is called.
The
flate.Writer
has a similar API: