| 1 | mod apirust-analyzer cargo lzzzz 2.0.0 lz4/stream/api/; |
| 2 | |
| 3 | use craterust-analyzer cargo lzzzz 2.0.0 crate/::{ |
| 4 | commonrust-analyzer cargo lzzzz 2.0.0 common/::{DEFAULT_BUF_SIZErust-analyzer cargo lzzzz 2.0.0 common/DEFAULT_BUF_SIZE., DICTIONARY_SIZErust-analyzer cargo lzzzz 2.0.0 common/DICTIONARY_SIZE.}, |
| 5 | lz4rust-analyzer cargo lzzzz 2.0.0 lz4/, Errorrust-analyzer cargo lzzzz 2.0.0 common/error/Error#, ErrorKindrust-analyzer cargo lzzzz 2.0.0 common/error/ErrorKind#, Resultrust-analyzer cargo lzzzz 2.0.0 common/error/Result#, |
| 6 | }; |
| 7 | use apirust-analyzer cargo lzzzz 2.0.0 lz4/stream/api/::{CompressionContextrust-analyzer cargo lzzzz 2.0.0 lz4/stream/api/CompressionContext#, DecompressionContextrust-analyzer cargo lzzzz 2.0.0 lz4/stream/api/DecompressionContext#}; |
| 8 | 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#, cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/, collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::LinkedListrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/linked_list/LinkedList#, pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/::Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#}; |
| 9 | |
| 10 | /// Streaming LZ4 compressor. |
| 11 | /// |
| 12 | /// # Example |
| 13 | /// |
| 14 | /// ``` |
| 15 | /// use lzzzz::lz4; |
| 16 | /// |
| 17 | /// let data = b"The quick brown fox jumps over the lazy dog."; |
| 18 | /// let mut buf = [0u8; 256]; |
| 19 | /// |
| 20 | /// // The slice should have enough capacity. |
| 21 | /// assert!(buf.len() >= lz4::max_compressed_size(data.len())); |
| 22 | /// |
| 23 | /// let mut comp = lz4::Compressor::new()?; |
| 24 | /// let len = comp.next(data, &mut buf, lz4::ACC_LEVEL_DEFAULT)?; |
| 25 | /// let compressed = &buf[..len]; |
| 26 | /// |
| 27 | /// # let mut buf = [0u8; 256]; |
| 28 | /// # let len = lz4::decompress(compressed, &mut buf[..data.len()])?; |
| 29 | /// # assert_eq!(&buf[..len], &data[..]); |
| 30 | /// # Ok::<(), std::io::Error>(()) |
| 31 | /// ``` |
| 32 | pub struct Compressorrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#<'a> { |
| 33 | ctxrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#ctx.: CompressionContextrust-analyzer cargo lzzzz 2.0.0 lz4/stream/api/CompressionContext#, |
| 34 | dictrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#dict.: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, [u8]>>, |
| 35 | safe_bufrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#safe_buf.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, |
| 36 | } |
| 37 | |
| 38 | impl<'a> Compressorrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#<'a> { |
| 39 | /// Creates a new `Compressor`. |
| 40 | pub fn newrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`]new().() -> Resultrust-analyzer cargo lzzzz 2.0.0 common/error/Result#<Selfrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`]> { |
| 41 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`] { |
| 42 | ctxrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#ctx.: CompressionContextrust-analyzer cargo lzzzz 2.0.0 lz4/stream/api/CompressionContext#::newrust-analyzer cargo lzzzz 2.0.0 lz4/stream/api/impl#[CompressionContext]new().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 43 | dictrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#dict.: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`]new().(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(&[])), |
| 44 | safe_bufrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#safe_buf.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(), |
| 45 | }) |
| 46 | } |
| 47 | |
| 48 | /// Creates a new `Compressor` with a dictionary. |
| 49 | pub fn with_dictrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`]with_dict().<D>(dict: D) -> Resultrust-analyzer cargo lzzzz 2.0.0 common/error/Result#<Selfrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`]> |
| 50 | where |
| 51 | 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]>>, |
| 52 | { |
| 53 | let mut comp = Selfrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`] { |
| 54 | dictrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#dict.: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`]new().(dict.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()), |
| 55 | ..Selfrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`]::newrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`]new().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 56 | }; |
| 57 | comp.ctxrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#ctx..load_dictrust-analyzer cargo lzzzz 2.0.0 lz4/stream/api/impl#[CompressionContext]load_dict().(&comp.dictrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#dict.); |
| 58 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(comp) |
| 59 | } |
| 60 | |
| 61 | /// Creates a new `Compressor` with a dictionary. |
| 62 | /// This variant which consumes more initialization time to better reference the dictionary, |
| 63 | /// resulting in slightly improved compression ratios at expense of time. |
| 64 | pub fn with_dict_slowrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`]with_dict_slow().<D>(dict: D) -> Resultrust-analyzer cargo lzzzz 2.0.0 common/error/Result#<Selfrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`]> |
| 65 | where |
| 66 | 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]>>, |
| 67 | { |
| 68 | let mut comp = Selfrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`] { |
| 69 | dictrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#dict.: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`]new().(dict.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()), |
| 70 | ..Selfrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`]::newrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`]new().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 71 | }; |
| 72 | comp.ctxrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#ctx..load_dict_slowrust-analyzer cargo lzzzz 2.0.0 lz4/stream/api/impl#[CompressionContext]load_dict_slow().(&comp.dictrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#dict.); |
| 73 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(comp) |
| 74 | } |
| 75 | |
| 76 | /// Performs LZ4 streaming compression. |
| 77 | /// |
| 78 | /// Returns the number of bytes written into the destination buffer. |
| 79 | pub fn nextrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`]next().(&mut self, src: &[u8], dst: &mut [u8], acc: i32) -> Resultrust-analyzer cargo lzzzz 2.0.0 common/error/Result#<usize> { |
| 80 | self.next_to_ptrrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`]next_to_ptr().(src, dst.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_mut_ptr().(), dst.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), acc) |
| 81 | } |
| 82 | |
| 83 | fn next_to_ptrrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`]next_to_ptr().(&mut self, src: &[u8], dst: *mut u8, dst_len: usize, acc: i32) -> Resultrust-analyzer cargo lzzzz 2.0.0 common/error/Result#<usize> { |
| 84 | let is_empty = src.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() && dst_len 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; |
| 85 | let dst_len = self.ctxrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#ctx..nextrust-analyzer cargo lzzzz 2.0.0 lz4/stream/api/impl#[CompressionContext]next().(src, dst, dst_len, acc); |
| 86 | |
| 87 | self.save_dictrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`]save_dict().(); |
| 88 | |
| 89 | if dst_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 90 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(dst_len) |
| 91 | } else if is_empty { |
| 92 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0) |
| 93 | } else { |
| 94 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo lzzzz 2.0.0 common/error/Error#::newrust-analyzer cargo lzzzz 2.0.0 common/error/impl#[Error]new().(ErrorKindrust-analyzer cargo lzzzz 2.0.0 common/error/ErrorKind#::CompressionFailedrust-analyzer cargo lzzzz 2.0.0 common/error/ErrorKind#CompressionFailed#)) |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | /// Appends compressed data to `Vec<u8>`. |
| 99 | /// |
| 100 | /// Returns the number of bytes appended to the given `Vec<u8>`. |
| 101 | pub fn next_to_vecrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`]next_to_vec().(&mut self, src: &[u8], dst: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, acc: i32) -> Resultrust-analyzer cargo lzzzz 2.0.0 common/error/Result#<usize> { |
| 102 | let orig_len = dst.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 103 | dst.reserverust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]reserve().(lz4rust-analyzer cargo lzzzz 2.0.0 lz4/::max_compressed_sizerust-analyzer cargo lzzzz 2.0.0 lz4/block/max_compressed_size().(src.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().())); |
| 104 | #[allow(unsafe_code)] |
| 105 | unsafe { |
| 106 | let result = self.next_to_ptrrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`]next_to_ptr().( |
| 107 | src, |
| 108 | dst.as_mut_ptrrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_mut_ptr().().addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]add().(orig_len), |
| 109 | dst.capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]capacity().() 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().orig_len, |
| 110 | acc, |
| 111 | ); |
| 112 | dst.set_lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]set_len().(orig_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<&usize>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<&usize>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<&usize>`]add().result.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]as_ref().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(&0)); |
| 113 | result |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | fn save_dictrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`]save_dict().(&mut self) { |
| 118 | self.safe_bufrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#safe_buf..resizerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]resize().(DICTIONARY_SIZErust-analyzer cargo lzzzz 2.0.0 common/DICTIONARY_SIZE., 0); |
| 119 | self.ctxrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#ctx..save_dictrust-analyzer cargo lzzzz 2.0.0 lz4/stream/api/impl#[CompressionContext]save_dict().(&mut self.safe_bufrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#safe_buf.); |
| 120 | } |
| 121 | |
| 122 | /// Attaches a dictionary stream for efficient dictionary reuse. |
| 123 | /// |
| 124 | /// This allows efficient re-use of a static dictionary multiple times by referencing |
| 125 | /// the dictionary stream in-place rather than copying it. |
| 126 | /// |
| 127 | /// # Arguments |
| 128 | /// |
| 129 | /// * `dict_stream` - The dictionary stream to attach, or None to unset any existing dictionary |
| 130 | /// |
| 131 | /// # Notes |
| 132 | /// |
| 133 | /// - The dictionary stream must have been prepared using `with_dict()` or `with_dict_slow()` |
| 134 | /// - The dictionary will only remain attached through the first compression call |
| 135 | /// - The dictionary stream (and its source buffer) must remain valid through the compression session |
| 136 | /// |
| 137 | /// # Example |
| 138 | /// |
| 139 | /// ``` |
| 140 | /// use lzzzz::lz4; |
| 141 | /// |
| 142 | /// let dict_data = b"some dictionary data"; |
| 143 | /// let data = b"data to compress"; |
| 144 | /// |
| 145 | /// // Create dictionary stream |
| 146 | /// let mut dict_comp = lz4::Compressor::with_dict(dict_data)?; |
| 147 | /// |
| 148 | /// // Create working stream and attach dictionary |
| 149 | /// let mut comp = lz4::Compressor::new()?; |
| 150 | /// comp.attach_dict(Some(&mut dict_comp)); |
| 151 | /// |
| 152 | /// // Compress data using the attached dictionary |
| 153 | /// let mut buf = [0u8; 256]; |
| 154 | /// let len = comp.next(data, &mut buf, lz4::ACC_LEVEL_DEFAULT)?; |
| 155 | /// # Ok::<(), std::io::Error>(()) |
| 156 | /// ``` |
| 157 | pub fn attach_dictrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Compressor<'a>`]attach_dict().(&mut self, dict_stream: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&mut Compressorrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#<'a>>) { |
| 158 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(dict) = dict_stream { |
| 159 | self.ctxrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#ctx..attach_dictrust-analyzer cargo lzzzz 2.0.0 lz4/stream/api/impl#[CompressionContext]attach_dict().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&mut dict.ctxrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#ctx.)); |
| 160 | } else { |
| 161 | self.ctxrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Compressor#ctx..attach_dictrust-analyzer cargo lzzzz 2.0.0 lz4/stream/api/impl#[CompressionContext]attach_dict().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /// Streaming LZ4 decompressor. |
| 167 | /// |
| 168 | /// # Example |
| 169 | /// |
| 170 | /// ``` |
| 171 | /// use lzzzz::lz4; |
| 172 | /// |
| 173 | /// const ORIGINAL_SIZE: usize = 44; |
| 174 | /// const COMPRESSED_DATA: &str = |
| 175 | /// "8B1UaGUgcXVpY2sgYnJvd24gZm94IGp1bXBzIG92ZXIgdGhlIGxhenkgZG9nLg=="; |
| 176 | /// |
| 177 | /// let data = base64::decode(COMPRESSED_DATA).unwrap(); |
| 178 | /// |
| 179 | /// let mut decomp = lz4::Decompressor::new()?; |
| 180 | /// let result = decomp.next(&data[..], ORIGINAL_SIZE)?; |
| 181 | /// |
| 182 | /// assert_eq!(result, &b"The quick brown fox jumps over the lazy dog."[..]); |
| 183 | /// # Ok::<(), std::io::Error>(()) |
| 184 | /// ``` |
| 185 | pub struct Decompressorrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#<'a> { |
| 186 | ctxrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#ctx.: DecompressionContextrust-analyzer cargo lzzzz 2.0.0 lz4/stream/api/DecompressionContext#, |
| 187 | cacherust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#cache.: LinkedListrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/linked_list/LinkedList#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>, |
| 188 | cache_lenrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#cache_len.: usize, |
| 189 | last_lenrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#last_len.: usize, |
| 190 | dictrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#dict.: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, [u8]>>, |
| 191 | } |
| 192 | |
| 193 | impl<'a> Decompressorrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#<'a> { |
| 194 | /// Creates a new `Decompressor`. |
| 195 | pub fn newrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Decompressor<'a>`]new().() -> Resultrust-analyzer cargo lzzzz 2.0.0 common/error/Result#<Selfrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Decompressor<'a>`]> { |
| 196 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Decompressor<'a>`] { |
| 197 | ctxrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#ctx.: DecompressionContextrust-analyzer cargo lzzzz 2.0.0 lz4/stream/api/DecompressionContext#::newrust-analyzer cargo lzzzz 2.0.0 lz4/stream/api/impl#[DecompressionContext]new().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 198 | cacherust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#cache.: LinkedListrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/linked_list/LinkedList#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/linked_list/impl#[`LinkedList<T>`]new().(), |
| 199 | cache_lenrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#cache_len.: 0, |
| 200 | last_lenrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#last_len.: 0, |
| 201 | dictrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#dict.: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`]new().(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(&[])), |
| 202 | }) |
| 203 | } |
| 204 | |
| 205 | /// Creates a new `Decompressor` with a dictionary. |
| 206 | pub fn with_dictrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Decompressor<'a>`]with_dict().<D>(dict: D) -> Resultrust-analyzer cargo lzzzz 2.0.0 common/error/Result#<Selfrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Decompressor<'a>`]> |
| 207 | where |
| 208 | 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]>>, |
| 209 | { |
| 210 | let mut decomp = Selfrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Decompressor<'a>`] { |
| 211 | dictrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#dict.: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`]new().(dict.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()), |
| 212 | ..Selfrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Decompressor<'a>`]::newrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Decompressor<'a>`]new().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 213 | }; |
| 214 | decomp.ctxrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#ctx..resetrust-analyzer cargo lzzzz 2.0.0 lz4/stream/api/impl#[DecompressionContext]reset().(&decomp.dictrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#dict.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 215 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(decomp) |
| 216 | } |
| 217 | |
| 218 | /// Decompresses an LZ4 block. |
| 219 | pub fn nextrust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Decompressor<'a>`]next().(&mut self, src: &[u8], original_size: usize) -> Resultrust-analyzer cargo lzzzz 2.0.0 common/error/Result#<&[u8]> { |
| 220 | if self |
| 221 | .cacherust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#cache. |
| 222 | .backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/linked_list/impl#[`LinkedList<T, A>`]back().() |
| 223 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|v| v.capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]capacity().() 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().v.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()) |
| 224 | .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]filter().(|n| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().n 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().original_size) |
| 225 | .is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() |
| 226 | { |
| 227 | self.cacherust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#cache..push_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/linked_list/impl#[`LinkedList<T, A>`]push_back().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().( |
| 228 | original_size, |
| 229 | DEFAULT_BUF_SIZErust-analyzer cargo lzzzz 2.0.0 common/DEFAULT_BUF_SIZE., |
| 230 | ))); |
| 231 | } |
| 232 | |
| 233 | let back = self.cacherust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#cache..back_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/linked_list/impl#[`LinkedList<T, A>`]back_mut().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 234 | let orig_len = back.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 235 | |
| 236 | #[allow(unsafe_code)] |
| 237 | unsafe { |
| 238 | let dst_len = self.ctxrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#ctx..decompressrust-analyzer cargo lzzzz 2.0.0 lz4/stream/api/impl#[DecompressionContext]decompress().( |
| 239 | src, |
| 240 | back.as_mut_ptrrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_mut_ptr().().addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]add().(orig_len), |
| 241 | back.capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]capacity().() 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().orig_len, |
| 242 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 243 | back.set_lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]set_len().(orig_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().dst_len); |
| 244 | self.cache_lenrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#cache_len. 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().dst_len; |
| 245 | } |
| 246 | self.last_lenrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#last_len. = original_size; |
| 247 | |
| 248 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(len) = self |
| 249 | .cacherust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#cache. |
| 250 | .frontrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/linked_list/impl#[`LinkedList<T, A>`]front().() |
| 251 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().) |
| 252 | .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]filter().(|n| self.cache_lenrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#cache_len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<&usize>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<&usize>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<&usize>`]sub().n 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().DICTIONARY_SIZErust-analyzer cargo lzzzz 2.0.0 common/DICTIONARY_SIZE.) |
| 253 | { |
| 254 | self.cacherust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#cache..pop_frontrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/linked_list/impl#[`LinkedList<T, A>`]pop_front().(); |
| 255 | self.cache_lenrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#cache_len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().len; |
| 256 | } |
| 257 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.datarust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Decompressor<'a>`]data().()) |
| 258 | } |
| 259 | |
| 260 | fn datarust-analyzer cargo lzzzz 2.0.0 lz4/stream/impl#[`Decompressor<'a>`]data().(&self) -> &[u8] { |
| 261 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(back) = self.cacherust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#cache..backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/linked_list/impl#[`LinkedList<T, A>`]back().() { |
| 262 | let offset = back.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]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.last_lenrust-analyzer cargo lzzzz 2.0.0 lz4/stream/Decompressor#last_len.; |
| 263 | &back[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().offset..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(). |
| 264 | } else { |
| 265 | &[] |
| 266 | } |
| 267 | } |
| 268 | } |