core/compr: allow inflate work with a custom dictionary
authorKostya Shishkov <kostya.shishkov@gmail.com>
Mon, 1 Nov 2021 17:16:17 +0000 (18:16 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Mon, 1 Nov 2021 17:16:17 +0000 (18:16 +0100)
nihav-core/src/compr/deflate.rs

index 7b36eadff327dcb3d300d058c79633a527040c98..b1266619b87d5b05228dfd21d1d61904e195bef8 100644 (file)
@@ -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 {