| 1 | use zlib_rsrust-analyzer cargo zlib-rs 0.6.3 crate/::InflateErrorrust-analyzer cargo zlib-rs 0.6.3 stable/InflateError#; |
| 2 | |
| 3 | /// A type to hold all state needed for decompressing a ZLIB encoded stream. |
| 4 | pub struct Decompressrust-analyzer cargo gix-features 0.48.0 zlib/Decompress#(zlib_rsrust-analyzer cargo zlib-rs 0.6.3 crate/::Inflaterust-analyzer cargo zlib-rs 0.6.3 stable/Inflate#); |
| 5 | |
| 6 | impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for Decompressrust-analyzer cargo gix-features 0.48.0 zlib/Decompress# { |
| 7 | fn defaultrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress][Default]default().() -> Selfrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress][Default] { |
| 8 | Selfrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress][Default]::newrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress]new().() |
| 9 | } |
| 10 | } |
| 11 | |
| 12 | impl Decompressrust-analyzer cargo gix-features 0.48.0 zlib/Decompress# { |
| 13 | /// The amount of bytes consumed from the input so far. |
| 14 | pub fn total_inrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress]total_in().(&self) -> u64 { |
| 15 | self.0rust-analyzer cargo gix-features 0.48.0 zlib/Decompress#0..total_inrust-analyzer cargo zlib-rs 0.6.3 stable/impl#[Inflate]total_in().() |
| 16 | } |
| 17 | |
| 18 | /// The amount of decompressed bytes that have been written to the output thus far. |
| 19 | pub fn total_outrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress]total_out().(&self) -> u64 { |
| 20 | self.0rust-analyzer cargo gix-features 0.48.0 zlib/Decompress#0..total_outrust-analyzer cargo zlib-rs 0.6.3 stable/impl#[Inflate]total_out().() |
| 21 | } |
| 22 | |
| 23 | /// Create a new instance. Note that it allocates in various ways and thus should be re-used. |
| 24 | pub fn newrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress]new().() -> Selfrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress] { |
| 25 | let config = zlib_rsrust-analyzer cargo zlib-rs 0.6.3 crate/::InflateConfigrust-analyzer cargo zlib-rs 0.6.3 inflate/InflateConfig#::defaultrust-analyzer cargo zlib-rs 0.6.3 inflate/impl#[InflateConfig][Default]default().(); |
| 26 | let header = true; |
| 27 | let inner = zlib_rsrust-analyzer cargo zlib-rs 0.6.3 crate/::Inflaterust-analyzer cargo zlib-rs 0.6.3 stable/Inflate#::newrust-analyzer cargo zlib-rs 0.6.3 stable/impl#[Inflate]new().(header, config.window_bitsrust-analyzer cargo zlib-rs 0.6.3 inflate/InflateConfig#window_bits. as u8); |
| 28 | Selfrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress](inner) |
| 29 | } |
| 30 | |
| 31 | /// Reset the state to allow handling a new stream. |
| 32 | pub fn resetrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress]reset().(&mut self) { |
| 33 | self.0rust-analyzer cargo gix-features 0.48.0 zlib/Decompress#0..resetrust-analyzer cargo zlib-rs 0.6.3 stable/impl#[Inflate]reset().(true); |
| 34 | } |
| 35 | |
| 36 | /// Decompress `input` and write all decompressed bytes into `output`, with `flush` defining some details about this. |
| 37 | pub fn decompressrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress]decompress().( |
| 38 | &mut self, |
| 39 | input: &[u8], |
| 40 | output: &mut [u8], |
| 41 | flush: FlushDecompressrust-analyzer cargo gix-features 0.48.0 zlib/FlushDecompress#, |
| 42 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Statusrust-analyzer cargo gix-features 0.48.0 zlib/Status#, DecompressErrorrust-analyzer cargo gix-features 0.48.0 zlib/DecompressError#> { |
| 43 | let inflate_flush = match flush { |
| 44 | FlushDecompressrust-analyzer cargo gix-features 0.48.0 zlib/FlushDecompress#::Nonerust-analyzer cargo gix-features 0.48.0 zlib/FlushDecompress#None# => zlib_rsrust-analyzer cargo zlib-rs 0.6.3 crate/::InflateFlushrust-analyzer cargo zlib-rs 0.6.3 InflateFlush#::NoFlushrust-analyzer cargo zlib-rs 0.6.3 InflateFlush#NoFlush#, |
| 45 | FlushDecompressrust-analyzer cargo gix-features 0.48.0 zlib/FlushDecompress#::Syncrust-analyzer cargo gix-features 0.48.0 zlib/FlushDecompress#Sync# => zlib_rsrust-analyzer cargo zlib-rs 0.6.3 crate/::InflateFlushrust-analyzer cargo zlib-rs 0.6.3 InflateFlush#::SyncFlushrust-analyzer cargo zlib-rs 0.6.3 InflateFlush#SyncFlush#, |
| 46 | FlushDecompressrust-analyzer cargo gix-features 0.48.0 zlib/FlushDecompress#::Finishrust-analyzer cargo gix-features 0.48.0 zlib/FlushDecompress#Finish# => zlib_rsrust-analyzer cargo zlib-rs 0.6.3 crate/::InflateFlushrust-analyzer cargo zlib-rs 0.6.3 InflateFlush#::Finishrust-analyzer cargo zlib-rs 0.6.3 InflateFlush#Finish#, |
| 47 | }; |
| 48 | |
| 49 | let status = self.0rust-analyzer cargo gix-features 0.48.0 zlib/Decompress#0..decompressrust-analyzer cargo zlib-rs 0.6.3 stable/impl#[Inflate]decompress().(input, output, inflate_flush)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 50 | match status { |
| 51 | zlib_rsrust-analyzer cargo zlib-rs 0.6.3 crate/::Statusrust-analyzer cargo zlib-rs 0.6.3 stable/Status#::Okrust-analyzer cargo zlib-rs 0.6.3 stable/Status#Ok# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Statusrust-analyzer cargo gix-features 0.48.0 zlib/Status#::Okrust-analyzer cargo gix-features 0.48.0 zlib/Status#Ok#), |
| 52 | zlib_rsrust-analyzer cargo zlib-rs 0.6.3 crate/::Statusrust-analyzer cargo zlib-rs 0.6.3 stable/Status#::BufErrorrust-analyzer cargo zlib-rs 0.6.3 stable/Status#BufError# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Statusrust-analyzer cargo gix-features 0.48.0 zlib/Status#::BufErrorrust-analyzer cargo gix-features 0.48.0 zlib/Status#BufError#), |
| 53 | zlib_rsrust-analyzer cargo zlib-rs 0.6.3 crate/::Statusrust-analyzer cargo zlib-rs 0.6.3 stable/Status#::StreamEndrust-analyzer cargo zlib-rs 0.6.3 stable/Status#StreamEnd# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Statusrust-analyzer cargo gix-features 0.48.0 zlib/Status#::StreamEndrust-analyzer cargo gix-features 0.48.0 zlib/Status#StreamEnd#), |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /// The error produced by [`Decompress::decompress()`]. |
| 59 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, thiserrorrust-analyzer cargo thiserror 2.0.18 crate/::Errorrust-analyzer cargo thiserror-impl 2.0.18 Error:)] |
| 60 | #[allow(missing_docs)] |
| 61 | pub enum DecompressErrorrust-analyzer cargo gix-features 0.48.0 zlib/DecompressError# { |
| 62 | #[errorrust-analyzer cargo thiserror-impl 2.0.18 error:("stream error")] |
| 63 | StreamErrorrust-analyzer cargo gix-features 0.48.0 zlib/DecompressError#StreamError#, |
| 64 | #[errorrust-analyzer cargo thiserror-impl 2.0.18 error:("Not enough memory")] |
| 65 | InsufficientMemoryrust-analyzer cargo gix-features 0.48.0 zlib/DecompressError#InsufficientMemory#, |
| 66 | #[errorrust-analyzer cargo thiserror-impl 2.0.18 error:("Invalid input data")] |
| 67 | DataErrorrust-analyzer cargo gix-features 0.48.0 zlib/DecompressError#DataError#, |
| 68 | #[errorrust-analyzer cargo thiserror-impl 2.0.18 error:("Decompressing this input requires a dictionary")] |
| 69 | NeedDictrust-analyzer cargo gix-features 0.48.0 zlib/DecompressError#NeedDict#, |
| 70 | } |
| 71 | |
| 72 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<zlib_rsrust-analyzer cargo zlib-rs 0.6.3 crate/::InflateErrorrust-analyzer cargo zlib-rs 0.6.3 stable/InflateError#> for DecompressErrorrust-analyzer cargo gix-features 0.48.0 zlib/DecompressError# { |
| 73 | fn fromrust-analyzer cargo gix-features 0.48.0 zlib/impl#[DecompressError][`From<InflateError>`]from().(value: InflateErrorrust-analyzer cargo zlib-rs 0.6.3 stable/InflateError#) -> Selfrust-analyzer cargo gix-features 0.48.0 zlib/impl#[DecompressError][`From<InflateError>`] { |
| 74 | match value { |
| 75 | InflateErrorrust-analyzer cargo zlib-rs 0.6.3 stable/InflateError#::NeedDictrust-analyzer cargo zlib-rs 0.6.3 stable/InflateError#NeedDict# { .. } => DecompressErrorrust-analyzer cargo gix-features 0.48.0 zlib/DecompressError#::NeedDictrust-analyzer cargo gix-features 0.48.0 zlib/DecompressError#NeedDict#, |
| 76 | InflateErrorrust-analyzer cargo zlib-rs 0.6.3 stable/InflateError#::StreamErrorrust-analyzer cargo zlib-rs 0.6.3 stable/InflateError#StreamError# => DecompressErrorrust-analyzer cargo gix-features 0.48.0 zlib/DecompressError#::StreamErrorrust-analyzer cargo gix-features 0.48.0 zlib/DecompressError#StreamError#, |
| 77 | InflateErrorrust-analyzer cargo zlib-rs 0.6.3 stable/InflateError#::DataErrorrust-analyzer cargo zlib-rs 0.6.3 stable/InflateError#DataError# => DecompressErrorrust-analyzer cargo gix-features 0.48.0 zlib/DecompressError#::DataErrorrust-analyzer cargo gix-features 0.48.0 zlib/DecompressError#DataError#, |
| 78 | InflateErrorrust-analyzer cargo zlib-rs 0.6.3 stable/InflateError#::MemErrorrust-analyzer cargo zlib-rs 0.6.3 stable/InflateError#MemError# => DecompressErrorrust-analyzer cargo gix-features 0.48.0 zlib/DecompressError#::InsufficientMemoryrust-analyzer cargo gix-features 0.48.0 zlib/DecompressError#InsufficientMemory#, |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /// The status returned by [`Decompress::decompress()`]. |
| 84 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 85 | pub enum Statusrust-analyzer cargo gix-features 0.48.0 zlib/Status# { |
| 86 | /// The decompress operation went well. Not to be confused with `StreamEnd`, so one can continue |
| 87 | /// the decompression. |
| 88 | Okrust-analyzer cargo gix-features 0.48.0 zlib/Status#Ok#, |
| 89 | /// An error occurred when decompression. |
| 90 | BufErrorrust-analyzer cargo gix-features 0.48.0 zlib/Status#BufError#, |
| 91 | /// The stream was fully decompressed. |
| 92 | StreamEndrust-analyzer cargo gix-features 0.48.0 zlib/Status#StreamEnd#, |
| 93 | } |
| 94 | |
| 95 | /// Values which indicate the form of flushing to be used when |
| 96 | /// decompressing in-memory data. |
| 97 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 98 | #[non_exhaustive] |
| 99 | #[allow(clippy::unnecessary_cast)] |
| 100 | pub enum FlushDecompressrust-analyzer cargo gix-features 0.48.0 zlib/FlushDecompress# { |
| 101 | /// A typical parameter for passing to compression/decompression functions, |
| 102 | /// this indicates that the underlying stream to decide how much data to |
| 103 | /// accumulate before producing output in order to maximize compression. |
| 104 | Nonerust-analyzer cargo gix-features 0.48.0 zlib/FlushDecompress#None# = 0, |
| 105 | |
| 106 | /// All pending output is flushed to the output buffer and the output is |
| 107 | /// aligned on a byte boundary so that the decompressor can get all input |
| 108 | /// data available so far. |
| 109 | /// |
| 110 | /// Flushing may degrade compression for some compression algorithms and so |
| 111 | /// it should only be used when necessary. This will complete the current |
| 112 | /// deflate block and follow it with an empty stored block. |
| 113 | Syncrust-analyzer cargo gix-features 0.48.0 zlib/FlushDecompress#Sync# = 2, |
| 114 | |
| 115 | /// Pending input is processed and pending output is flushed. |
| 116 | /// |
| 117 | /// The return value may indicate that the stream is not yet done and more |
| 118 | /// data has yet to be processed. |
| 119 | Finishrust-analyzer cargo gix-features 0.48.0 zlib/FlushDecompress#Finish# = 4, |
| 120 | } |
| 121 | |
| 122 | /// non-streaming interfaces for decompression |
| 123 | pub mod inflaterust-analyzer cargo gix-features 0.48.0 zlib/inflate/ { |
| 124 | /// The error returned by various [Inflate methods][super::Inflate] |
| 125 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, thiserrorrust-analyzer cargo thiserror 2.0.18 crate/::Errorrust-analyzer cargo thiserror-impl 2.0.18 Error:)] |
| 126 | #[allow(missing_docs)] |
| 127 | pub enum Errorrust-analyzer cargo gix-features 0.48.0 zlib/inflate/Error# { |
| 128 | #[errorrust-analyzer cargo thiserror-impl 2.0.18 error:("Could not write all bytes when decompressing content")] |
| 129 | WriteInflatedrust-analyzer cargo gix-features 0.48.0 zlib/inflate/Error#WriteInflated#(#[from] 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/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#), |
| 130 | #[errorrust-analyzer cargo thiserror-impl 2.0.18 error:("Could not decode zip stream, status was '{0}'")] |
| 131 | Inflaterust-analyzer cargo gix-features 0.48.0 zlib/inflate/Error#Inflate#(#[from] superrust-analyzer cargo gix-features 0.48.0 zlib/::DecompressErrorrust-analyzer cargo gix-features 0.48.0 zlib/DecompressError#), |
| 132 | #[errorrust-analyzer cargo thiserror-impl 2.0.18 error:("The zlib status indicated an error, status was '{0:?}'")] |
| 133 | Statusrust-analyzer cargo gix-features 0.48.0 zlib/inflate/Error#Status#(superrust-analyzer cargo gix-features 0.48.0 zlib/::Statusrust-analyzer cargo gix-features 0.48.0 zlib/Status#), |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | /// Decompress a few bytes of a zlib stream without allocation |
| 138 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 139 | pub struct Inflaterust-analyzer cargo gix-features 0.48.0 zlib/Inflate# { |
| 140 | /// The actual decompressor doing all the work. |
| 141 | pub staterust-analyzer cargo gix-features 0.48.0 zlib/Inflate#state.: Decompressrust-analyzer cargo gix-features 0.48.0 zlib/Decompress#, |
| 142 | } |
| 143 | |
| 144 | impl Inflaterust-analyzer cargo gix-features 0.48.0 zlib/Inflate# { |
| 145 | /// Run the decompressor exactly once. Cannot be run multiple times |
| 146 | pub fn oncerust-analyzer cargo gix-features 0.48.0 zlib/impl#[Inflate]once().(&mut self, input: &[u8], out: &mut [u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(Statusrust-analyzer cargo gix-features 0.48.0 zlib/Status#, usize, usize), inflaterust-analyzer cargo gix-features 0.48.0 zlib/inflate/::Errorrust-analyzer cargo gix-features 0.48.0 zlib/inflate/Error#> { |
| 147 | let before_in = self.staterust-analyzer cargo gix-features 0.48.0 zlib/Inflate#state..total_inrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress]total_in().(); |
| 148 | let before_out = self.staterust-analyzer cargo gix-features 0.48.0 zlib/Inflate#state..total_outrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress]total_out().(); |
| 149 | let status = self.staterust-analyzer cargo gix-features 0.48.0 zlib/Inflate#state..decompressrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress]decompress().(input, out, FlushDecompressrust-analyzer cargo gix-features 0.48.0 zlib/FlushDecompress#::Nonerust-analyzer cargo gix-features 0.48.0 zlib/FlushDecompress#None#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 150 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(( |
| 151 | status, |
| 152 | (self.staterust-analyzer cargo gix-features 0.48.0 zlib/Inflate#state..total_inrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress]total_in().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().before_in) as usize, |
| 153 | (self.staterust-analyzer cargo gix-features 0.48.0 zlib/Inflate#state..total_outrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress]total_out().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().before_out) as usize, |
| 154 | )) |
| 155 | } |
| 156 | |
| 157 | /// Ready this instance for decoding another data stream. |
| 158 | pub fn resetrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Inflate]reset().(&mut self) { |
| 159 | self.staterust-analyzer cargo gix-features 0.48.0 zlib/Inflate#state..resetrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress]reset().(); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | /// |
| 164 | pub mod streamrust-analyzer cargo gix-features 0.48.0 zlib/stream/; |