diff options
author | Kostya Shishkov <kostya.shishkov@gmail.com> | 2021-05-22 12:25:23 +0200 |
---|---|---|
committer | Kostya Shishkov <kostya.shishkov@gmail.com> | 2021-05-22 12:25:23 +0200 |
commit | 80da4ff8ba4b8ae0a1abd0e34bb3647785606201 (patch) | |
tree | 8d75d51cc1476b82e3fe74481d524856ecd540a7 /nihav-core/src | |
parent | 8570a0b3c0fc320f0482f4bcc1d5a73d89903bfe (diff) | |
download | nihav-80da4ff8ba4b8ae0a1abd0e34bb3647785606201.tar.gz |
deflate: allow writing compressed data to byte-aligned chunks
Diffstat (limited to 'nihav-core/src')
-rw-r--r-- | nihav-core/src/compr/deflate.rs | 14 |
1 files changed, 14 insertions, 0 deletions
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() { |