From bc23de6bedc2e151caea241b073a65d30f62c134 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Mon, 1 Nov 2021 18:16:17 +0100 Subject: [PATCH] core/compr: allow inflate work with a custom dictionary --- nihav-core/src/compr/deflate.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nihav-core/src/compr/deflate.rs b/nihav-core/src/compr/deflate.rs index 7b36ead..b126661 100644 --- a/nihav-core/src/compr/deflate.rs +++ b/nihav-core/src/compr/deflate.rs @@ -356,6 +356,14 @@ impl Inflate { self.full_pos += len; Ok(()) } + ///! Sets custom history for decoding an update for already decoded data. + pub fn set_dict(&mut self, dict: &[u8]) { + let len = dict.len().min(self.buf.len()); + let start = dict.len() - len; + self.buf[..len].copy_from_slice(&dict[start..]); + self.bpos = len; + self.full_pos = len; + } ///! Reports whether decoder has finished decoding the input. pub fn is_finished(&self) -> bool { match self.state { -- 2.39.5