| 1 | use craterust-analyzer cargo lzzzz 2.0.0 crate/::lz4frust-analyzer cargo lzzzz 2.0.0 lz4f/::{Decompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/Decompressor#, FrameInforust-analyzer cargo lzzzz 2.0.0 lz4f/frame_info/FrameInfo#, Resultrust-analyzer cargo lzzzz 2.0.0 lz4f/error/Result#}; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{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#, fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#}; |
| 3 | |
| 4 | /// The [`Write`]-based streaming decompressor. |
| 5 | /// |
| 6 | /// # Example |
| 7 | /// |
| 8 | /// ``` |
| 9 | /// # use std::env; |
| 10 | /// # use std::path::Path; |
| 11 | /// # use lzzzz::{Error, Result}; |
| 12 | /// # use assert_fs::prelude::*; |
| 13 | /// # let tmp_dir = assert_fs::TempDir::new().unwrap().into_persistent(); |
| 14 | /// # env::set_current_dir(tmp_dir.path()).unwrap(); |
| 15 | /// use lzzzz::lz4f::{compress_to_vec, WriteDecompressor}; |
| 16 | /// use std::{fs::File, io::prelude::*}; |
| 17 | /// |
| 18 | /// let mut f = File::create("foo.txt")?; |
| 19 | /// let mut w = WriteDecompressor::new(&mut f)?; |
| 20 | /// |
| 21 | /// let mut buf = Vec::new(); |
| 22 | /// compress_to_vec(b"Hello world!", &mut buf, &Default::default())?; |
| 23 | /// |
| 24 | /// w.write_all(&buf)?; |
| 25 | /// # Ok::<(), std::io::Error>(()) |
| 26 | /// ``` |
| 27 | /// |
| 28 | /// [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html |
| 29 | pub struct WriteDecompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#<'a, W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> { |
| 30 | innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#inner.: W, |
| 31 | decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#decomp.: Decompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/Decompressor#<'a>, |
| 32 | } |
| 33 | |
| 34 | impl<'a, W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> WriteDecompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#<'a, W> { |
| 35 | /// Creates a new `WriteDecompressor<W>`. |
| 36 | pub fn newrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/impl#[`WriteDecompressor<'a, W>`]new().(writer: W) -> Resultrust-analyzer cargo lzzzz 2.0.0 lz4f/error/Result#<Selfrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/impl#[`WriteDecompressor<'a, W>`]> { |
| 37 | 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/write/impl#[`WriteDecompressor<'a, W>`] { |
| 38 | innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#inner.: writer, |
| 39 | decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#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()., |
| 40 | }) |
| 41 | } |
| 42 | |
| 43 | /// Sets the dictionary. |
| 44 | pub fn set_dictrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/impl#[`WriteDecompressor<'a, W>`]set_dict().<D>(&mut self, dict: D) |
| 45 | where |
| 46 | 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]>>, |
| 47 | { |
| 48 | self.decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#decomp..set_dictrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/impl#[`Decompressor<'a>`]set_dict().(dict); |
| 49 | } |
| 50 | |
| 51 | /// Returns `FrameInfo` if the frame header is already decoded. |
| 52 | /// Otherwise, returns `None`. |
| 53 | pub fn frame_inforust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/impl#[`WriteDecompressor<'a, W>`]frame_info().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<FrameInforust-analyzer cargo lzzzz 2.0.0 lz4f/frame_info/FrameInfo#> { |
| 54 | self.decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#decomp..frame_inforust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/impl#[`Decompressor<'a>`]frame_info().() |
| 55 | } |
| 56 | |
| 57 | /// Sets the 'header-only' mode. |
| 58 | /// |
| 59 | /// When the 'header-only' mode is enabled, the decompressor doesn't |
| 60 | /// consume the frame body and `write()` always returns `Ok(0)` |
| 61 | /// if the frame header is already decoded. |
| 62 | pub fn decode_header_onlyrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/impl#[`WriteDecompressor<'a, W>`]decode_header_only().(&mut self, flag: bool) { |
| 63 | self.decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#decomp..decode_header_onlyrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/impl#[`Decompressor<'a>`]decode_header_only().(flag); |
| 64 | } |
| 65 | |
| 66 | /// Returns a mutable reference to the writer. |
| 67 | pub fn get_mutrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/impl#[`WriteDecompressor<'a, W>`]get_mut().(&mut self) -> &mut W { |
| 68 | &mut self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#inner. |
| 69 | } |
| 70 | |
| 71 | /// Returns a shared reference to the writer. |
| 72 | pub fn get_refrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/impl#[`WriteDecompressor<'a, W>`]get_ref().(&self) -> &W { |
| 73 | &self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#inner. |
| 74 | } |
| 75 | |
| 76 | /// Returns ownership of the writer. |
| 77 | pub fn into_innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/impl#[`WriteDecompressor<'a, W>`]into_inner().(self) -> W { |
| 78 | self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#inner. |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | impl<W> 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 WriteDecompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#<'_, W> |
| 83 | where |
| 84 | W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# + 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#, |
| 85 | { |
| 86 | fn fmtrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/impl#[`WriteDecompressor<'_, W>`][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# { |
| 87 | fmt.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("WriteDecompressor") |
| 88 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("writer", &self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#inner.) |
| 89 | .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().() |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# for WriteDecompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#<'_, W> { |
| 94 | fn writerust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/impl#[`WriteDecompressor<'_, W>`][Write]write().(&mut self, buf: &[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> { |
| 95 | let report = self.decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#decomp..decompressrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/impl#[`Decompressor<'a>`]decompress().(buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 96 | self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#inner..write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(self.decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#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 result/impl#[`Result<T, E>`][Try]branch().; |
| 97 | self.decomprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#decomp..clear_bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/impl#[`Decompressor<'a>`]clear_buf().(); |
| 98 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(report) |
| 99 | } |
| 100 | |
| 101 | fn flushrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/impl#[`WriteDecompressor<'_, W>`][Write]flush().(&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#<()> { |
| 102 | self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/decomp/write/WriteDecompressor#inner..flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#flush().() |
| 103 | } |
| 104 | } |