| 1 | use superrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/::{Compressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#, Dictionaryrust-analyzer cargo lzzzz 2.0.0 lz4f/dictionary/Dictionary#, Preferencesrust-analyzer cargo lzzzz 2.0.0 lz4f/preferences/Preferences#}; |
| 2 | use craterust-analyzer cargo lzzzz 2.0.0 crate/::lz4frust-analyzer cargo lzzzz 2.0.0 lz4f/::Resultrust-analyzer cargo lzzzz 2.0.0 lz4f/error/Result#; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 4 | fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, |
| 5 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#, Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#}, |
| 6 | }; |
| 7 | |
| 8 | /// The [`BufRead`]-based streaming compressor. |
| 9 | /// |
| 10 | /// # Example |
| 11 | /// |
| 12 | /// ``` |
| 13 | /// # use std::env; |
| 14 | /// # use std::path::Path; |
| 15 | /// # use lzzzz::{Error, Result}; |
| 16 | /// # use assert_fs::prelude::*; |
| 17 | /// # let tmp_dir = assert_fs::TempDir::new().unwrap().into_persistent(); |
| 18 | /// # env::set_current_dir(tmp_dir.path()).unwrap(); |
| 19 | /// # |
| 20 | /// # tmp_dir.child("foo.txt").write_str("Hello").unwrap(); |
| 21 | /// # |
| 22 | /// use lzzzz::lz4f::BufReadCompressor; |
| 23 | /// use std::{ |
| 24 | /// fs::File, |
| 25 | /// io::{prelude::*, BufReader}, |
| 26 | /// }; |
| 27 | /// |
| 28 | /// let mut f = File::open("foo.txt")?; |
| 29 | /// let mut b = BufReader::new(f); |
| 30 | /// let mut r = BufReadCompressor::new(&mut b, Default::default())?; |
| 31 | /// |
| 32 | /// let mut buf = Vec::new(); |
| 33 | /// r.read_to_end(&mut buf)?; |
| 34 | /// # Ok::<(), std::io::Error>(()) |
| 35 | /// ``` |
| 36 | /// |
| 37 | /// [`BufRead`]: https://doc.rust-lang.org/std/io/trait.BufRead.html |
| 38 | pub struct BufReadCompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#<R: BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#> { |
| 39 | pub(superrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/) innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#inner.: R, |
| 40 | pub(superrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/) comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#comp.: Compressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#, |
| 41 | consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#consumed.: usize, |
| 42 | } |
| 43 | |
| 44 | impl<R: BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#> BufReadCompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#<R> { |
| 45 | /// Creates a new `BufReadCompressor<R>`. |
| 46 | pub fn newrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/impl#[`BufReadCompressor<R>`]new().(reader: R, prefs: Preferencesrust-analyzer cargo lzzzz 2.0.0 lz4f/preferences/Preferences#) -> Resultrust-analyzer cargo lzzzz 2.0.0 lz4f/error/Result#<Selfrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/impl#[`BufReadCompressor<R>`]> { |
| 47 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/impl#[`BufReadCompressor<R>`] { |
| 48 | innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#inner.: reader, |
| 49 | comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#comp.: Compressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#::newrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]new().(prefs, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 50 | consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#consumed.: 0, |
| 51 | }) |
| 52 | } |
| 53 | |
| 54 | /// Creates a new `BufReadCompressor<R>` with a dictionary. |
| 55 | pub fn with_dictrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/impl#[`BufReadCompressor<R>`]with_dict().(reader: R, prefs: Preferencesrust-analyzer cargo lzzzz 2.0.0 lz4f/preferences/Preferences#, dict: Dictionaryrust-analyzer cargo lzzzz 2.0.0 lz4f/dictionary/Dictionary#) -> Resultrust-analyzer cargo lzzzz 2.0.0 lz4f/error/Result#<Selfrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/impl#[`BufReadCompressor<R>`]> { |
| 56 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/impl#[`BufReadCompressor<R>`] { |
| 57 | innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#inner.: reader, |
| 58 | comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#comp.: Compressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#::newrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]new().(prefs, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(dict))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 59 | consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#consumed.: 0, |
| 60 | }) |
| 61 | } |
| 62 | |
| 63 | /// Returns ownership of the reader. |
| 64 | pub fn into_innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/impl#[`BufReadCompressor<R>`]into_inner().(self) -> R { |
| 65 | self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#inner. |
| 66 | } |
| 67 | |
| 68 | /// Returns a mutable reference to the reader. |
| 69 | pub fn get_mutrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/impl#[`BufReadCompressor<R>`]get_mut().(&mut self) -> &mut R { |
| 70 | &mut self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#inner. |
| 71 | } |
| 72 | |
| 73 | /// Returns a shared reference to the reader. |
| 74 | pub fn get_refrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/impl#[`BufReadCompressor<R>`]get_ref().(&self) -> &R { |
| 75 | &self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#inner. |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | impl<R> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for BufReadCompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#<R> |
| 80 | where |
| 81 | R: BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead# + fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, |
| 82 | { |
| 83 | fn fmtrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/impl#[`BufReadCompressor<R>`][Debug]fmt().(&self, fmt: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 84 | fmt.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("BufReadCompressor") |
| 85 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("reader", &self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#inner.) |
| 86 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("prefs", &self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#comp..prefsrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]prefs().()) |
| 87 | .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().() |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | impl<R: BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#> Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# for BufReadCompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#<R> { |
| 92 | fn readrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/impl#[`BufReadCompressor<R>`][Read]read().(&mut self, buf: &mut [u8]) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> { |
| 93 | let consumed = { |
| 94 | let inner_buf = self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#inner..fill_bufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#fill_buf().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 95 | if inner_buf.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 96 | self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#comp..endrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]end().(false)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 97 | if self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#comp..bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]buf().().is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 98 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0); |
| 99 | } |
| 100 | 0 |
| 101 | } else { |
| 102 | self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#comp..updaterust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]update().(inner_buf, false)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 103 | inner_buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() |
| 104 | } |
| 105 | }; |
| 106 | self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#inner..consumerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#consume().(consumed); |
| 107 | |
| 108 | let len = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#comp..bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]buf().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().self.consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#consumed.); |
| 109 | buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#len]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()..copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(&self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#comp..bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]buf().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().self.consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#consumed...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/index/impl#[`[T]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#len]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/index/impl#[`[T]`][`Index<I>`]index().); |
| 110 | self.consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#consumed. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().len; |
| 111 | if self.consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#consumed. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#comp..bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]buf().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 112 | self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#comp..clear_bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]clear_buf().(); |
| 113 | self.consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#consumed. = 0; |
| 114 | } |
| 115 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(len) |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | impl<R: BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#> BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead# for BufReadCompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#<R> { |
| 120 | fn fill_bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/impl#[`BufReadCompressor<R>`][BufRead]fill_buf().(&mut self) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<&[u8]> { |
| 121 | let _ = self.readrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/impl#[`BufReadCompressor<R>`][Read]read().(&mut [])?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 122 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(&self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#comp..bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]buf().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().self.consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#consumed...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) |
| 123 | } |
| 124 | |
| 125 | fn consumerust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/impl#[`BufReadCompressor<R>`][BufRead]consume().(&mut self, amt: usize) { |
| 126 | self.consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#consumed. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().amt; |
| 127 | if self.consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#consumed. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#comp..bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]buf().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 128 | self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#comp..clear_bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]clear_buf().(); |
| 129 | self.consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/BufReadCompressor#consumed. = 0; |
| 130 | } |
| 131 | } |
| 132 | } |