Skip to content

Commit

Permalink
Fix partial flush on flush_or_close()
Browse files Browse the repository at this point in the history
BROTLI_OPERATION_FLUSH must be re-tried until no more data is
available as input and internal buffers are empty (this can take
more than one call). Otherwise, the writer is left in a "flushing"
state which will make further writes fail.
  • Loading branch information
mtth-bfft authored and danielrh committed Sep 13, 2022
1 parent 5d82b69 commit 96ccf6b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/enc/writer.rs
Expand Up @@ -2,7 +2,8 @@
use core;
use super::encode::{BrotliEncoderCreateInstance, BrotliEncoderDestroyInstance,
BrotliEncoderParameter, BrotliEncoderSetParameter, BrotliEncoderOperation,
BrotliEncoderStateStruct, BrotliEncoderCompressStream, BrotliEncoderIsFinished};
BrotliEncoderStateStruct, BrotliEncoderCompressStream, BrotliEncoderIsFinished,
BrotliEncoderHasMoreOutput};
use super::backward_references::BrotliEncoderParams;
use brotli_decompressor::CustomWrite;
use super::interface;
Expand Down Expand Up @@ -207,6 +208,9 @@ CompressorWriterCustomIo<ErrType, W, BufferType, Alloc>
return Err(self.error_if_invalid_data.take().unwrap());
}
if let BrotliEncoderOperation::BROTLI_OPERATION_FLUSH = op {
if BrotliEncoderHasMoreOutput(&mut self.state) != 0 {
continue;
}
return Ok(());
}
if BrotliEncoderIsFinished(&mut self.state) != 0 {
Expand Down

0 comments on commit 96ccf6b

Please sign in to comment.