| 1 | use 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/, 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#}; |
| 2 | |
| 3 | use craterust-analyzer cargo gix-features 0.48.0 crate/::zlibrust-analyzer cargo gix-features 0.48.0 zlib/::{Decompressrust-analyzer cargo gix-features 0.48.0 zlib/Decompress#, FlushDecompressrust-analyzer cargo gix-features 0.48.0 zlib/FlushDecompress#, Statusrust-analyzer cargo gix-features 0.48.0 zlib/Status#}; |
| 4 | |
| 5 | /// Read bytes from `rd` and decompress them using `state` into a pre-allocated fitting buffer `dst`, returning the amount of bytes written. |
| 6 | pub fn readrust-analyzer cargo gix-features 0.48.0 zlib/stream/inflate/read().(rd: &mut impl BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#, state: &mut Decompressrust-analyzer cargo gix-features 0.48.0 zlib/Decompress#, mut dst: &mut [u8]) -> 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> { |
| 7 | let mut total_written = 0; |
| 8 | loop { |
| 9 | let (written, consumed, ret, eof); |
| 10 | { |
| 11 | let input = rd.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().; |
| 12 | eof = input.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().(); |
| 13 | let before_out = state.total_outrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress]total_out().(); |
| 14 | let before_in = state.total_inrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress]total_in().(); |
| 15 | let flush = if eof { |
| 16 | FlushDecompressrust-analyzer cargo gix-features 0.48.0 zlib/FlushDecompress#::Finishrust-analyzer cargo gix-features 0.48.0 zlib/FlushDecompress#Finish# |
| 17 | } else { |
| 18 | FlushDecompressrust-analyzer cargo gix-features 0.48.0 zlib/FlushDecompress#::Nonerust-analyzer cargo gix-features 0.48.0 zlib/FlushDecompress#None# |
| 19 | }; |
| 20 | ret = state.decompressrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress]decompress().(input, dst, flush); |
| 21 | written = (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; |
| 22 | total_written 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().written; |
| 23 | dst = &mut dst[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().written..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/IndexMut#index_mut().; |
| 24 | consumed = (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; |
| 25 | } |
| 26 | rd.consumerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#consume().(consumed); |
| 27 | |
| 28 | match ret { |
| 29 | // The stream has officially ended, nothing more to do here. |
| 30 | 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#) => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(total_written), |
| 31 | // Either input our output are depleted even though the stream is not depleted yet. |
| 32 | 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# | Statusrust-analyzer cargo gix-features 0.48.0 zlib/Status#::BufErrorrust-analyzer cargo gix-features 0.48.0 zlib/Status#BufError#) if eof || dst.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(total_written), |
| 33 | // Some progress was made in both the input and the output, it must continue to reach the end. |
| 34 | 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# | Statusrust-analyzer cargo gix-features 0.48.0 zlib/Status#::BufErrorrust-analyzer cargo gix-features 0.48.0 zlib/Status#BufError#) if consumed rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0 || written rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0 => continue, |
| 35 | // A strange state, where zlib makes no progress but isn't done either. Call it out. |
| 36 | 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# | Statusrust-analyzer cargo gix-features 0.48.0 zlib/Status#::BufErrorrust-analyzer cargo gix-features 0.48.0 zlib/Status#BufError#) => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!("Definitely a bug somewhere"), |
| 37 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(..) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(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#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#, "corrupt deflate stream")), |
| 38 | } |
| 39 | } |
| 40 | } |