| 1 | mod deflate_streamrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/ { |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 3 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, |
| 4 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#}, |
| 5 | }; |
| 6 | |
| 7 | use bstrrust-analyzer cargo bstr 1.12.1 crate/::ByteSlicerust-analyzer cargo bstr 1.12.1 ext_slice/ByteSlice#; |
| 8 | |
| 9 | use craterust-analyzer cargo gix-features 0.48.0 crate/::zlibrust-analyzer cargo gix-features 0.48.0 zlib/::streamrust-analyzer cargo gix-features 0.48.0 zlib/stream/::deflaterust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/; |
| 10 | 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#; |
| 11 | |
| 12 | /// Provide streaming decompression using the `std::io::Read` trait. |
| 13 | /// If `std::io::BufReader` is used, an allocation for the input buffer will be performed. |
| 14 | struct InflateReaderrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/InflateReader#<R> { |
| 15 | innerrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/InflateReader#inner.: R, |
| 16 | decompressorrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/InflateReader#decompressor.: Decompressrust-analyzer cargo gix-features 0.48.0 zlib/Decompress#, |
| 17 | } |
| 18 | |
| 19 | impl<R> InflateReaderrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/InflateReader#<R> |
| 20 | where |
| 21 | R: 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#, |
| 22 | { |
| 23 | pub fn from_readrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/impl#[`InflateReader<R>`]from_read().(read: R) -> InflateReaderrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/InflateReader#<R> { |
| 24 | InflateReaderrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/InflateReader# { |
| 25 | decompressorrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/InflateReader#decompressor.: Decompressrust-analyzer cargo gix-features 0.48.0 zlib/Decompress#::newrust-analyzer cargo gix-features 0.48.0 zlib/impl#[Decompress]new().(), |
| 26 | innerrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/InflateReader#inner.: read, |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | impl<R> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# for InflateReaderrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/InflateReader#<R> |
| 32 | where |
| 33 | R: 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#, |
| 34 | { |
| 35 | fn readrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/impl#[`InflateReader<R>`][Read]read().(&mut self, into: &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> { |
| 36 | craterust-analyzer cargo gix-features 0.48.0 crate/::zlibrust-analyzer cargo gix-features 0.48.0 zlib/::streamrust-analyzer cargo gix-features 0.48.0 zlib/stream/::inflaterust-analyzer cargo gix-features 0.48.0 zlib/stream/inflate/::readrust-analyzer cargo gix-features 0.48.0 zlib/stream/inflate/read().(&mut self.innerrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/InflateReader#inner., &mut self.decompressorrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/InflateReader#decompressor., into) |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 41 | fn small_file_decompressrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/small_file_decompress().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> { |
| 42 | fn fixture_pathrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/fixture_path().(path: &str) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf# { |
| 43 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<&T>`]from().("tests/fixtures").joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(path) |
| 44 | } |
| 45 | let r = InflateReaderrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/InflateReader#::from_readrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/impl#[`InflateReader<R>`]from_read().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/impl#[`BufReader<R>`]new().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]open().(fixture_pathrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/fixture_path().( |
| 46 | "objects/37/d4e6c5c48ba0d245164c4e10d5f41140cab980", |
| 47 | ))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)); |
| 48 | #[allow(clippy::unbuffered_bytes)] |
| 49 | let mut bytes = r.bytesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#bytes().(); |
| 50 | let content = bytes.by_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#by_ref().().takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(16).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>, _>>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 51 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(content.as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().().as_bstrrust-analyzer cargo bstr 1.12.1 ext_slice/ByteSlice#as_bstr().(), b"blob 9\0hi there\n".as_bstrrust-analyzer cargo bstr 1.12.1 ext_slice/ByteSlice#as_bstr().()); |
| 52 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(bytes.nextrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/impl#[`Bytes<R>`][Iterator]next().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()); |
| 53 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 54 | } |
| 55 | |
| 56 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 57 | fn all_at_oncerust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/all_at_once().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> { |
| 58 | let mut w = deflaterust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/::Writerust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/Write#::newrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/impls/impl#[`deflate::Write<W>`]new().(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().()); |
| 59 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(w.writerust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/impls/impl#[`deflate::Write<W>`][Write]write().(b"hello")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., 5); |
| 60 | w.flushrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/impls/impl#[`deflate::Write<W>`][Write]flush().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 61 | |
| 62 | let out = w.innerrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/Write#inner.; |
| 63 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(out.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() == 12 || out.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() == 13); |
| 64 | |
| 65 | assert_deflate_bufferrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/assert_deflate_buffer().(out, b"hello") |
| 66 | } |
| 67 | |
| 68 | fn assert_deflate_bufferrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/assert_deflate_buffer().(out: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, expected: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> { |
| 69 | let mut actual = 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().(); |
| 70 | InflateReaderrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/InflateReader#::from_readrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/impl#[`InflateReader<R>`]from_read().(out.as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().()).read_to_endrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_to_end().(&mut actual)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 71 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual, expected); |
| 72 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 73 | } |
| 74 | |
| 75 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 76 | fn big_file_small_writesrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/big_file_small_writes().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> { |
| 77 | let mut w = deflaterust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/::Writerust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/Write#::newrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/impls/impl#[`deflate::Write<W>`]new().(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().()); |
| 78 | let bytes = include_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/include_bytes!!( |
| 79 | "../../../../../gix-odb/tests/fixtures/objects/pack/pack-11fdfa9e156ab73caae3b6da867192221f2089c2.pack" |
| 80 | ); |
| 81 | for chunk in bytes.chunksrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks().(2) { |
| 82 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(w.writerust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/impls/impl#[`deflate::Write<W>`][Write]write().(chunk)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., chunk.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()); |
| 83 | } |
| 84 | w.flushrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/impls/impl#[`deflate::Write<W>`][Write]flush().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 85 | |
| 86 | assert_deflate_bufferrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/assert_deflate_buffer().(w.innerrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/Write#inner., bytes) |
| 87 | } |
| 88 | |
| 89 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 90 | fn big_file_a_few_big_writesrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/big_file_a_few_big_writes().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> { |
| 91 | let mut w = deflaterust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/::Writerust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/Write#::newrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/impls/impl#[`deflate::Write<W>`]new().(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().()); |
| 92 | let bytes = include_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/include_bytes!!( |
| 93 | "../../../../../gix-odb/tests/fixtures/objects/pack/pack-11fdfa9e156ab73caae3b6da867192221f2089c2.pack" |
| 94 | ); |
| 95 | for chunk in bytes.chunksrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks().(4096 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().9) { |
| 96 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(w.writerust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/impls/impl#[`deflate::Write<W>`][Write]write().(chunk)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., chunk.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()); |
| 97 | } |
| 98 | w.flushrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/impls/impl#[`deflate::Write<W>`][Write]flush().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 99 | |
| 100 | assert_deflate_bufferrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/tests/deflate_stream/assert_deflate_buffer().(w.innerrust-analyzer cargo gix-features 0.48.0 zlib/stream/deflate/Write#inner., bytes) |
| 101 | } |
| 102 | } |