From 80da4ff8ba4b8ae0a1abd0e34bb3647785606201 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Sat, 22 May 2021 12:25:23 +0200 Subject: [PATCH] deflate: allow writing compressed data to byte-aligned chunks --- nihav-core/src/compr/deflate.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/nihav-core/src/compr/deflate.rs b/nihav-core/src/compr/deflate.rs index 9120789..2509fc2 100644 --- a/nihav-core/src/compr/deflate.rs +++ b/nihav-core/src/compr/deflate.rs @@ -1857,6 +1857,20 @@ impl Deflate { self.write_zlib_footer(wr); } } + ///! Tells the encoder to compress the data it received and flush it. + pub fn compress_flush(&mut self, wr: &mut DeflateWriter) { + if self.ssize > 0 { + self.do_block(wr, false); + } + if (wr.bits & 7) != 0 { + // write zero-length copy block for byte-alignment + wr.write(0, 1); + wr.write(0, 2); + wr.align(); + wr.write(0, 16); + wr.write(0xFFFF, 16); + } + } fn do_block(&mut self, wr: &mut DeflateWriter, final_block: bool) { const CRC_BASE: u32 = 65521; for &b in self.srcbuf[..self.ssize].iter() { -- 2.39.5