Debian Codegraph @

src/lz4f/stream/decomp/bufread.rs

raw symbols SCIP
1 use superrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/::Decompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/Decompressor#;
2 use craterust-analyzer cargo lzzzz 2.0.0 crate/::lz4frust-analyzer cargo lzzzz 2.0.0 lz4f/::{FrameInforust-analyzer cargo lzzzz 2.0.0 lz4f/frame_info/FrameInfo#, 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 borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#,
5 fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/,
6 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#},
7 };
8
9 /// The [`BufRead`]-based streaming decompressor.
10 ///
11 /// # Example
12 ///
13 /// ```
14 /// # use std::env;
15 /// # use std::path::Path;
16 /// # use lzzzz::{Error, Result};
17 /// # use assert_fs::prelude::*;
18 /// # let tmp_dir = assert_fs::TempDir::new().unwrap().into_persistent();
19 /// # env::set_current_dir(tmp_dir.path()).unwrap();
20 /// #
21 /// # let mut buf = Vec::new();
22 /// # lzzzz::lz4f::compress_to_vec(b"Hello world!", &mut buf, &Default::default())?;
23 /// # tmp_dir.child("foo.lz4").write_binary(&buf).unwrap();
24 /// #
25 /// use lzzzz::lz4f::BufReadDecompressor;
26 /// use std::{
27 /// fs::File,
28 /// io::{prelude::*, BufReader},
29 /// };
30 ///
31 /// let mut f = File::open("foo.lz4")?;
32 /// let mut b = BufReader::new(f);
33 /// let mut r = BufReadDecompressor::new(&mut b)?;
34 ///
35 /// let mut buf = Vec::new();
36 /// r.read_to_end(&mut buf)?;
37 /// # Ok::<(), std::io::Error>(())
38 /// ```
39 ///
40 /// [`BufRead`]: https://doc.rust-lang.org/std/io/trait.BufRead.html
41 pub struct BufReadDecompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#<'a, R: BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#> {
42 pub(superrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/) innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#inner.: R,
43 decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#decomp.: Decompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/Decompressor#<'a>,
44 consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#consumed.: usize,
45 }
46
47 impl<'a, R: BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#> BufReadDecompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#<'a, R> {
48 /// Creates a new `BufReadDecompressor<R>`.
49 pub fn newrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/impl#[`BufReadDecompressor<'a, R>`]new().(reader: R) -> Resultrust-analyzer cargo lzzzz 2.0.0 lz4f/error/Result#<Selfrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/impl#[`BufReadDecompressor<'a, R>`]> {
50 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/impl#[`BufReadDecompressor<'a, R>`] {
51 innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#inner.: reader,
52 decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#decomp.: Decompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/Decompressor#::newrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/impl#[`Decompressor<'a>`]new().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
53 consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#consumed.: 0,
54 })
55 }
56
57 /// Sets the dictionary.
58 pub fn set_dictrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/impl#[`BufReadDecompressor<'a, R>`]set_dict().<D>(&mut self, dict: D)
59 where
60 D: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, [u8]>>,
61 {
62 self.decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#decomp..set_dictrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/impl#[`Decompressor<'a>`]set_dict().(dict);
63 }
64
65 /// Reads the frame header and returns `FrameInfo`.
66 ///
67 /// Calling this function before any `Read` or `BufRead` operations
68 /// does not consume the frame body.
69 pub fn read_frame_inforust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/impl#[`BufReadDecompressor<'a, R>`]read_frame_info().(&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#<FrameInforust-analyzer cargo lzzzz 2.0.0 lz4f/frame_info/FrameInfo#> {
70 loop {
71 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(frame) = self.decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#decomp..frame_inforust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/impl#[`Decompressor<'a>`]frame_info().() {
72 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(frame);
73 }
74 self.decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#decomp..decode_header_onlyrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/impl#[`Decompressor<'a>`]decode_header_only().(true);
75 let _ = self.readrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/impl#[`BufReadDecompressor<'_, R>`][Read]read().(&mut [])?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
76 self.decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#decomp..decode_header_onlyrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/impl#[`Decompressor<'a>`]decode_header_only().(false);
77 }
78 }
79
80 /// Returns ownership of the reader.
81 pub fn into_innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/impl#[`BufReadDecompressor<'a, R>`]into_inner().(self) -> R {
82 self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#inner.
83 }
84
85 /// Returns a mutable reference to the reader.
86 pub fn get_mutrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/impl#[`BufReadDecompressor<'a, R>`]get_mut().(&mut self) -> &mut R {
87 &mut self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#inner.
88 }
89
90 /// Returns a shared reference to the reader.
91 pub fn get_refrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/impl#[`BufReadDecompressor<'a, R>`]get_ref().(&self) -> &R {
92 &self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#inner.
93 }
94 }
95
96 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 BufReadDecompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#<'_, R>
97 where
98 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#,
99 {
100 fn fmtrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/impl#[`BufReadDecompressor<'_, 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# {
101 fmt.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("BufReadDecompressor")
102 .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/decomp/bufread/BufReadDecompressor#inner.)
103 .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().()
104 }
105 }
106
107 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 BufReadDecompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#<'_, R> {
108 fn readrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/impl#[`BufReadDecompressor<'_, 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> {
109 loop {
110 let inner_buf = self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#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().;
111 let consumed = self.decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#decomp..decompressrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/impl#[`Decompressor<'a>`]decompress().(inner_buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
112 self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#inner..consumerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#consume().(consumed);
113 if consumed rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
114 break;
115 }
116 }
117
118 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.decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#decomp..bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/impl#[`Decompressor<'a>`]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/decomp/bufread/BufReadDecompressor#consumed.);
119 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.decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#decomp..bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/impl#[`Decompressor<'a>`]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/decomp/bufread/BufReadDecompressor#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().);
120 self.consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#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;
121 if self.consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#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.decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#decomp..bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/impl#[`Decompressor<'a>`]buf().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() {
122 self.decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#decomp..clear_bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/impl#[`Decompressor<'a>`]clear_buf().();
123 self.consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#consumed. = 0;
124 }
125 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(len)
126 }
127 }
128
129 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 BufReadDecompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#<'_, R> {
130 fn fill_bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/impl#[`BufReadDecompressor<'_, 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]> {
131 let _ = self.readrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/impl#[`BufReadDecompressor<'_, R>`][Read]read().(&mut [])?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
132 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(&self.decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#decomp..bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/impl#[`Decompressor<'a>`]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/decomp/bufread/BufReadDecompressor#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().)
133 }
134
135 fn consumerust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/impl#[`BufReadDecompressor<'_, R>`][BufRead]consume().(&mut self, amt: usize) {
136 self.consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#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;
137 if self.consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#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.decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#decomp..bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/impl#[`Decompressor<'a>`]buf().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() {
138 self.decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#decomp..clear_bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/impl#[`Decompressor<'a>`]clear_buf().();
139 self.consumedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/bufread/BufReadDecompressor#consumed. = 0;
140 }
141 }
142 }