From 1910467b6bac3f164ea4b71efcade4cfb6470a11 Mon Sep 17 00:00:00 2001 From: Daniel Reiter Horn Date: Mon, 11 Feb 2019 14:59:05 -0800 Subject: [PATCH] finish brotli output when into_inner is called --- Cargo.toml | 2 +- src/enc/writer.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 42d5087e..d131925e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "brotli" -version = "3.2.0" +version = "3.2.1" authors = ["Daniel Reiter Horn ", "The Brotli Authors"] description = "A brotli compressor and decompressor that with an interface avoiding the rust stdlib. This makes it suitable for embedded devices and kernels. It is designed with a pluggable allocator so that the standard lib's allocator may be employed. The default build also includes a stdlib allocator and stream interface. Disable this with --features=no-stdlib. All included code is safe." license = "BSD-3-Clause/MIT" diff --git a/src/enc/writer.rs b/src/enc/writer.rs index 1d02d77f..337c1150 100755 --- a/src/enc/writer.rs +++ b/src/enc/writer.rs @@ -213,6 +213,10 @@ CompressorWriterCustomIo self.output.as_ref().unwrap() } pub fn into_inner(mut self) -> W { + match self.flush_or_close(BrotliEncoderOperation::BROTLI_OPERATION_FINISH) { + Ok(_) => {}, + Err(_) => {}, + } core::mem::replace(&mut self.output, None).unwrap() } } @@ -223,9 +227,11 @@ impl Drop for CompressorWriterCustomIo { fn drop(&mut self) { - match self.flush_or_close(BrotliEncoderOperation::BROTLI_OPERATION_FINISH) { - Ok(_) => {}, + if self.output.is_some() { + match self.flush_or_close(BrotliEncoderOperation::BROTLI_OPERATION_FINISH) { + Ok(_) => {}, Err(_) => {}, + } } BrotliEncoderDestroyInstance(&mut self.state); }