From: Kostya Shishkov Date: Sat, 22 May 2021 10:25:23 +0000 (+0200) Subject: deflate: allow writing compressed data to byte-aligned chunks X-Git-Url: https://git.nihav.org/?p=nihav.git;a=commitdiff_plain;h=80da4ff8ba4b8ae0a1abd0e34bb3647785606201 deflate: allow writing compressed data to byte-aligned chunks --- 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() {