Debian Codegraph @

tests/compress_test.rs

raw symbols SCIP
1 // Copyright (c) 2023 Harry [Majored] [[email protected]]
2 // MIT License (https://github.com/Majored/rs-async-zip/blob/main/LICENSE)
3
4 use async_ziprust-analyzer cargo async_zip 0.0.18 crate/::{Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#, ZipEntryBuilderrust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#, ZipStringrust-analyzer cargo async_zip 0.0.18 string/ZipString#};
5 use futures_literust-analyzer cargo futures-lite 2.1.0 crate/::AsyncWriteExtrust-analyzer cargo futures-lite 2.1.0 io/AsyncWriteExt#;
6
7 mod commonrust-analyzer cargo async_zip 0.0.18 common/;
8
9 #[cfg(feature = "zstd")]
10 #[tokiorust-analyzer cargo tokio 1.25.0 crate/::testrust-analyzer cargo tokio-macros 1.8.0 test:]
11 async fn zip_zstd_in_outrust-analyzer cargo async_zip 0.0.18 zip_zstd_in_out().() {
12 let zip_data = commonrust-analyzer cargo async_zip 0.0.18 common/::compress_to_memrust-analyzer cargo async_zip 0.0.18 common/compress_to_mem().(Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#::Zstdrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Zstd#).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().;
13 commonrust-analyzer cargo async_zip 0.0.18 common/::check_decompress_memrust-analyzer cargo async_zip 0.0.18 common/check_decompress_mem().(zip_data).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().
14 }
15
16 #[cfg(feature = "deflate")]
17 #[tokiorust-analyzer cargo tokio 1.25.0 crate/::testrust-analyzer cargo tokio-macros 1.8.0 test:]
18 async fn zip_decompress_in_outrust-analyzer cargo async_zip 0.0.18 zip_decompress_in_out().() {
19 let zip_data = commonrust-analyzer cargo async_zip 0.0.18 common/::compress_to_memrust-analyzer cargo async_zip 0.0.18 common/compress_to_mem().(Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#::Deflaterust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Deflate#).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().;
20 commonrust-analyzer cargo async_zip 0.0.18 common/::check_decompress_memrust-analyzer cargo async_zip 0.0.18 common/check_decompress_mem().(zip_data).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().
21 }
22
23 #[tokiorust-analyzer cargo tokio 1.25.0 crate/::testrust-analyzer cargo tokio-macros 1.8.0 test:]
24 async fn zip_store_in_outrust-analyzer cargo async_zip 0.0.18 zip_store_in_out().() {
25 let zip_data = commonrust-analyzer cargo async_zip 0.0.18 common/::compress_to_memrust-analyzer cargo async_zip 0.0.18 common/compress_to_mem().(Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#::Storedrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Stored#).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().;
26 commonrust-analyzer cargo async_zip 0.0.18 common/::check_decompress_memrust-analyzer cargo async_zip 0.0.18 common/check_decompress_mem().(zip_data).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().
27 }
28
29 #[tokiorust-analyzer cargo tokio 1.25.0 crate/::testrust-analyzer cargo tokio-macros 1.8.0 test:]
30 async fn zip_utf8_extra_in_out_streamrust-analyzer cargo async_zip 0.0.18 zip_utf8_extra_in_out_stream().() {
31 let mut zip_bytes = 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().(10_000);
32
33 {
34 // writing
35 let content = "Test".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().();
36 let mut writer = async_ziprust-analyzer cargo async_zip 0.0.18 crate/::baserust-analyzer cargo async_zip 0.0.18 base/::writerust-analyzer cargo async_zip 0.0.18 base/write/::ZipFileWriterrust-analyzer cargo async_zip 0.0.18 base/write/ZipFileWriter#::newrust-analyzer cargo async_zip 0.0.18 base/write/impl#[`ZipFileWriter<W>`]new().(&mut zip_bytes);
37 let filename =
38 ZipStringrust-analyzer cargo async_zip 0.0.18 string/ZipString#::new_with_alternativerust-analyzer cargo async_zip 0.0.18 string/impl#[ZipString]new_with_alternative().("\u{4E2D}\u{6587}.txt".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), b"\xD6\xD0\xCe\xC4.txt".to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().());
39 let opts = ZipEntryBuilderrust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#::newrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder]new().(filename, Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#::Storedrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Stored#);
40
41 let mut entry_writer = writer.write_entry_streamrust-analyzer cargo async_zip 0.0.18 base/write/impl#[`ZipFileWriter<W>`]write_entry_stream().(opts).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
42 entry_writer.write_allrust-analyzer cargo futures-lite 2.1.0 io/AsyncWriteExt#write_all().(content).rust-analyzer cargo futures-lite 2.1.0 io/impl#[`WriteAllFuture<'_, W>`][Future]poll().awaitrust-analyzer cargo futures-lite 2.1.0 io/impl#[`WriteAllFuture<'_, W>`][Future]poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
43 entry_writer.closerust-analyzer cargo async_zip 0.0.18 base/write/entry_stream/impl#[`EntryStreamWriter<'b, W>`]close().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
44
45 writer.closerust-analyzer cargo async_zip 0.0.18 base/write/impl#[`ZipFileWriter<W>`]close().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
46 }
47
48 {
49 // reading
50 let zip = async_ziprust-analyzer cargo async_zip 0.0.18 crate/::baserust-analyzer cargo async_zip 0.0.18 base/::readrust-analyzer cargo async_zip 0.0.18 base/read/::memrust-analyzer cargo async_zip 0.0.18 base/read/mem/::ZipFileReaderrust-analyzer cargo async_zip 0.0.18 base/read/mem/ZipFileReader#::newrust-analyzer cargo async_zip 0.0.18 base/read/mem/impl#[ZipFileReader]new().(zip_bytes).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
51 let zip_entries: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = zip.filerust-analyzer cargo async_zip 0.0.18 base/read/mem/impl#[ZipFileReader]file().().entriesrust-analyzer cargo async_zip 0.0.18 file/impl#[ZipFile]entries().().to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().();
52 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(zip_entries.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1);
53 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(zip_entries[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..filenamerust-analyzer cargo async_zip 0.0.18 entry/impl#[ZipEntry]filename().().as_strrust-analyzer cargo async_zip 0.0.18 string/impl#[ZipString]as_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "\u{4E2D}\u{6587}.txt");
54 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(zip_entries[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..filenamerust-analyzer cargo async_zip 0.0.18 entry/impl#[ZipEntry]filename().().alternativerust-analyzer cargo async_zip 0.0.18 string/impl#[ZipString]alternative().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(b"\xD6\xD0\xCe\xC4.txt".as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`AsRef<[T]>`]as_ref().()));
55 }
56 }
57
58 #[tokiorust-analyzer cargo tokio 1.25.0 crate/::testrust-analyzer cargo tokio-macros 1.8.0 test:]
59 async fn zip_utf8_extra_in_out_wholerust-analyzer cargo async_zip 0.0.18 zip_utf8_extra_in_out_whole().() {
60 let mut zip_bytes = 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().(10_000);
61
62 {
63 // writing
64 let content = "Test".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().();
65 let mut writer = async_ziprust-analyzer cargo async_zip 0.0.18 crate/::baserust-analyzer cargo async_zip 0.0.18 base/::writerust-analyzer cargo async_zip 0.0.18 base/write/::ZipFileWriterrust-analyzer cargo async_zip 0.0.18 base/write/ZipFileWriter#::newrust-analyzer cargo async_zip 0.0.18 base/write/impl#[`ZipFileWriter<W>`]new().(&mut zip_bytes);
66 let filename =
67 ZipStringrust-analyzer cargo async_zip 0.0.18 string/ZipString#::new_with_alternativerust-analyzer cargo async_zip 0.0.18 string/impl#[ZipString]new_with_alternative().("\u{4E2D}\u{6587}.txt".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), b"\xD6\xD0\xCe\xC4.txt".to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().());
68 let opts = ZipEntryBuilderrust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#::newrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder]new().(filename, Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#::Storedrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#Stored#);
69 writer.write_entry_wholerust-analyzer cargo async_zip 0.0.18 base/write/impl#[`ZipFileWriter<W>`]write_entry_whole().(opts, content).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
70 writer.closerust-analyzer cargo async_zip 0.0.18 base/write/impl#[`ZipFileWriter<W>`]close().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
71 }
72
73 {
74 // reading
75 let zip = async_ziprust-analyzer cargo async_zip 0.0.18 crate/::baserust-analyzer cargo async_zip 0.0.18 base/::readrust-analyzer cargo async_zip 0.0.18 base/read/::memrust-analyzer cargo async_zip 0.0.18 base/read/mem/::ZipFileReaderrust-analyzer cargo async_zip 0.0.18 base/read/mem/ZipFileReader#::newrust-analyzer cargo async_zip 0.0.18 base/read/mem/impl#[ZipFileReader]new().(zip_bytes).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
76 let zip_entries: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = zip.filerust-analyzer cargo async_zip 0.0.18 base/read/mem/impl#[ZipFileReader]file().().entriesrust-analyzer cargo async_zip 0.0.18 file/impl#[ZipFile]entries().().to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().();
77 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(zip_entries.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1);
78 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(zip_entries[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..filenamerust-analyzer cargo async_zip 0.0.18 entry/impl#[ZipEntry]filename().().as_strrust-analyzer cargo async_zip 0.0.18 string/impl#[ZipString]as_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "\u{4E2D}\u{6587}.txt");
79 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(zip_entries[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..filenamerust-analyzer cargo async_zip 0.0.18 entry/impl#[ZipEntry]filename().().alternativerust-analyzer cargo async_zip 0.0.18 string/impl#[ZipString]alternative().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(b"\xD6\xD0\xCe\xC4.txt".as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`AsRef<[T]>`]as_ref().()));
80 }
81 }