| 1 | //! Streaming LZ4F compressors. |
| 2 | mod bufreadrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/; |
| 3 | mod readrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/read/; |
| 4 | mod writerust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/; |
| 5 | |
| 6 | 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#; |
| 7 | |
| 8 | pub use bufreadrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/bufread/::*; |
| 9 | pub use readrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/read/::*; |
| 10 | pub use writerust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/::*; |
| 11 | |
| 12 | use craterust-analyzer cargo lzzzz 2.0.0 crate/::lz4frust-analyzer cargo lzzzz 2.0.0 lz4f/::{ |
| 13 | apirust-analyzer cargo lzzzz 2.0.0 lz4f/api/::{CompressionContextrust-analyzer cargo lzzzz 2.0.0 lz4f/api/CompressionContext#, LZ4F_HEADER_SIZE_MAXrust-analyzer cargo lzzzz 2.0.0 lz4f/api/LZ4F_HEADER_SIZE_MAX.}, |
| 14 | Dictionaryrust-analyzer cargo lzzzz 2.0.0 lz4f/dictionary/Dictionary#, Preferencesrust-analyzer cargo lzzzz 2.0.0 lz4f/preferences/Preferences#, |
| 15 | }; |
| 16 | |
| 17 | pub(craterust-analyzer cargo lzzzz 2.0.0 crate/) struct Compressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor# { |
| 18 | ctxrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#ctx.: CompressionContextrust-analyzer cargo lzzzz 2.0.0 lz4f/api/CompressionContext#, |
| 19 | prefsrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#prefs.: Preferencesrust-analyzer cargo lzzzz 2.0.0 lz4f/preferences/Preferences#, |
| 20 | staterust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#state.: Staterust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/State#, |
| 21 | bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, |
| 22 | } |
| 23 | |
| 24 | impl Compressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor# { |
| 25 | pub fn newrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]new().(prefs: Preferencesrust-analyzer cargo lzzzz 2.0.0 lz4f/preferences/Preferences#, dict: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<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/impl#[Compressor]> { |
| 26 | 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/impl#[Compressor] { |
| 27 | ctxrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#ctx.: CompressionContextrust-analyzer cargo lzzzz 2.0.0 lz4f/api/CompressionContext#::newrust-analyzer cargo lzzzz 2.0.0 lz4f/api/impl#[CompressionContext]new().(dict)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 28 | prefsrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#prefs., |
| 29 | staterust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#state.: Staterust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/State#::Createdrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/State#Created#, |
| 30 | bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer.: 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().(LZ4F_HEADER_SIZE_MAXrust-analyzer cargo lzzzz 2.0.0 lz4f/api/LZ4F_HEADER_SIZE_MAX.), |
| 31 | }) |
| 32 | } |
| 33 | |
| 34 | pub fn prefsrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]prefs().(&self) -> &Preferencesrust-analyzer cargo lzzzz 2.0.0 lz4f/preferences/Preferences# { |
| 35 | &self.prefsrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#prefs. |
| 36 | } |
| 37 | |
| 38 | fn beginrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]begin().(&mut self) -> Resultrust-analyzer cargo lzzzz 2.0.0 lz4f/error/Result#<()> { |
| 39 | if let Staterust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/State#::Createdrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/State#Created# = self.staterust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#state. { |
| 40 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 41 | self.staterust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#state. = Staterust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/State#::Activerust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/State#Active#; |
| 42 | let len = self.ctxrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#ctx..beginrust-analyzer cargo lzzzz 2.0.0 lz4f/api/impl#[CompressionContext]begin().( |
| 43 | self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..as_mut_ptrrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_mut_ptr().(), |
| 44 | self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]capacity().(), |
| 45 | &self.prefsrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#prefs., |
| 46 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 47 | #[allow(unsafe_code)] |
| 48 | unsafe { |
| 49 | self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..set_lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]set_len().(len); |
| 50 | } |
| 51 | } |
| 52 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 53 | } |
| 54 | |
| 55 | pub fn updaterust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]update().(&mut self, src: &[u8], stable_src: bool) -> Resultrust-analyzer cargo lzzzz 2.0.0 lz4f/error/Result#<()> { |
| 56 | self.beginrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]begin().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 57 | let ext_len = CompressionContextrust-analyzer cargo lzzzz 2.0.0 lz4f/api/CompressionContext#::compress_boundrust-analyzer cargo lzzzz 2.0.0 lz4f/api/impl#[CompressionContext]compress_bound().(src.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), &self.prefsrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#prefs.); |
| 58 | self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..reserverust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]reserve().(ext_len); |
| 59 | let offset = self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 60 | #[allow(unsafe_code)] |
| 61 | unsafe { |
| 62 | let len = self.ctxrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#ctx..updaterust-analyzer cargo lzzzz 2.0.0 lz4f/api/impl#[CompressionContext]update().( |
| 63 | self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..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().(offset), |
| 64 | self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..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().offset, |
| 65 | src, |
| 66 | stable_src, |
| 67 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 68 | self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..set_lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]set_len().(offset 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().len); |
| 69 | if 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 { |
| 70 | self.flushrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]flush().(stable_src) |
| 71 | } else { |
| 72 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | pub fn flushrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]flush().(&mut self, stable_src: bool) -> Resultrust-analyzer cargo lzzzz 2.0.0 lz4f/error/Result#<()> { |
| 78 | self.beginrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]begin().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 79 | let ext_len = CompressionContextrust-analyzer cargo lzzzz 2.0.0 lz4f/api/CompressionContext#::compress_boundrust-analyzer cargo lzzzz 2.0.0 lz4f/api/impl#[CompressionContext]compress_bound().(0, &self.prefsrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#prefs.); |
| 80 | self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..reserverust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]reserve().(ext_len); |
| 81 | let offset = self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 82 | #[allow(unsafe_code)] |
| 83 | unsafe { |
| 84 | let len = self.ctxrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#ctx..flushrust-analyzer cargo lzzzz 2.0.0 lz4f/api/impl#[CompressionContext]flush().( |
| 85 | self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..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().(offset), |
| 86 | self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..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().offset, |
| 87 | stable_src, |
| 88 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 89 | self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..set_lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]set_len().(offset 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().len); |
| 90 | } |
| 91 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 92 | } |
| 93 | |
| 94 | pub fn endrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]end().(&mut self, stable_src: bool) -> Resultrust-analyzer cargo lzzzz 2.0.0 lz4f/error/Result#<()> { |
| 95 | self.beginrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]begin().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 96 | if let Staterust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/State#::Activerust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/State#Active# = self.staterust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#state. { |
| 97 | self.staterust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#state. = Staterust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/State#::Finishedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/State#Finished#; |
| 98 | let ext_len = CompressionContextrust-analyzer cargo lzzzz 2.0.0 lz4f/api/CompressionContext#::compress_boundrust-analyzer cargo lzzzz 2.0.0 lz4f/api/impl#[CompressionContext]compress_bound().(0, &self.prefsrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#prefs.); |
| 99 | self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..reserverust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]reserve().(ext_len); |
| 100 | let offset = self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 101 | #[allow(unsafe_code)] |
| 102 | unsafe { |
| 103 | let len = self.ctxrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#ctx..endrust-analyzer cargo lzzzz 2.0.0 lz4f/api/impl#[CompressionContext]end().( |
| 104 | self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..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().(offset), |
| 105 | self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..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().offset, |
| 106 | stable_src, |
| 107 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 108 | self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..set_lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]set_len().(offset 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().len); |
| 109 | } |
| 110 | } |
| 111 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 112 | } |
| 113 | |
| 114 | pub fn bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]buf().(&self) -> &[u8] { |
| 115 | &self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer. |
| 116 | } |
| 117 | |
| 118 | pub fn clear_bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]clear_buf().(&mut self) { |
| 119 | self.bufferrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#buffer..clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().(); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | pub(craterust-analyzer cargo lzzzz 2.0.0 crate/) enum Staterust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/State# { |
| 124 | Createdrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/State#Created#, |
| 125 | Activerust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/State#Active#, |
| 126 | Finishedrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/State#Finished#, |
| 127 | } |