Skip to content

Commit f098b7a

Browse files
committed
Fix to catch needing more output when compressing op finish
1 parent 61fcde7 commit f098b7a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/stream.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl CompressStream {
121121
let op = BrotliEncoderOperation::BROTLI_OPERATION_FINISH;
122122
let input = Vec::new().into_boxed_slice();
123123
let mut available_in = 0;
124-
while BrotliEncoderIsFinished(&mut self.state) == 0 {
124+
while BrotliEncoderIsFinished(&mut self.state) == 0 && available_out > 0 {
125125
let ret = BrotliEncoderCompressStream(
126126
&mut self.state,
127127
op,
@@ -141,8 +141,12 @@ impl CompressStream {
141141
));
142142
}
143143
}
144-
output.truncate(output_offset);
145-
self.result = BrotliStreamResult::ResultSuccess as i32;
144+
self.result = if available_out == 0 {
145+
BrotliStreamResult::NeedsMoreOutput as i32
146+
} else {
147+
output.truncate(output_offset);
148+
BrotliStreamResult::ResultSuccess as i32
149+
};
146150
self.last_input_offset = 0;
147151
Ok(output.into_boxed_slice())
148152
}

0 commit comments

Comments
 (0)