| 1 | # async_zip |
| 2 | [](https://crates.io/crates/async_zip) |
| 3 | [](https://crates.io/crates/async_zip) |
| 4 | [](https://docs.rs/async_zip/) |
| 5 | [](https://github.com/Majored/rs-async-zip/actions?query=branch%3Amain) |
| 6 | [](https://github.com/Majored/rs-async-zip/blob/main/LICENSE) |
| 7 | |
| 8 | An asynchronous ZIP archive reading/writing crate. |
| 9 | |
| 10 | ## Features |
| 11 | - A base implementation atop `futures`'s IO traits. |
| 12 | - An extended implementation atop `tokio`'s IO traits. |
| 13 | - Support for Stored, Deflate, bzip2, LZMA, zstd, and xz compression methods. |
| 14 | - Various different reading approaches (seek, stream, filesystem, in-memory buffer, etc). |
| 15 | - Support for writing complete data (u8 slices) or streams using data descriptors. |
| 16 | - Initial support for ZIP64 reading and writing. |
| 17 | - Aims for reasonable [specification](https://github.com/Majored/rs-async-zip/blob/main/SPECIFICATION.md) compliance. |
| 18 | |
| 19 | ## Installation & Basic Usage |
| 20 | |
| 21 | ```toml |
| 22 | [dependencies] |
| 23 | async_zip = { version = "0.0.17", features = ["full"] } |
| 24 | ``` |
| 25 | |
| 26 | A (soon to be) extensive list of [examples](https://github.com/Majored/rs-async-zip/tree/main/examples) can be found under the `/examples` directory. |
| 27 | |
| 28 | ### Feature Flags |
| 29 | - `full` - Enables all below features. |
| 30 | - `full-wasm` - Enables all below features that are compatible with WASM. |
| 31 | - `chrono` - Enables support for parsing dates via `chrono`. |
| 32 | - `tokio` - Enables support for the `tokio` implementation module. |
| 33 | - `tokio-fs` - Enables support for the `tokio::fs` reading module. |
| 34 | - `deflate` - Enables support for the Deflate compression method. |
| 35 | - `bzip2` - Enables support for the bzip2 compression method. |
| 36 | - `lzma` - Enables support for the LZMA compression method. |
| 37 | - `zstd` - Enables support for the zstd compression method. |
| 38 | - `xz` - Enables support for the xz compression method. |
| 39 | |
| 40 | ### Reading |
| 41 | ```rust |
| 42 | use tokio::{io::BufReader, fs::File}; |
| 43 | use async_zip::tokio::read::seek::ZipFileReader; |
| 44 | ... |
| 45 | |
| 46 | let mut file = BufReader::new(File::open("./Archive.zip").await?); |
| 47 | let mut zip = ZipFileReader::with_tokio(&mut file).await?; |
| 48 | |
| 49 | let mut string = String::new(); |
| 50 | let mut reader = zip.reader_with_entry(0).await?; |
| 51 | reader.read_to_string_checked(&mut string).await?; |
| 52 | |
| 53 | println!("{}", string); |
| 54 | ``` |
| 55 | |
| 56 | ### Writing |
| 57 | ```rust |
| 58 | use async_zip::tokio::write::ZipFileWriter; |
| 59 | use async_zip::{Compression, ZipEntryBuilder}; |
| 60 | use tokio::fs::File; |
| 61 | ... |
| 62 | |
| 63 | let mut file = File::create("foo.zip").await?; |
| 64 | let mut writer = ZipFileWriter::with_tokio(&mut file); |
| 65 | |
| 66 | let data = b"This is an example file."; |
| 67 | let builder = ZipEntryBuilder::new("bar.txt".into(), Compression::Deflate); |
| 68 | |
| 69 | writer.write_entry_whole(builder, data).await?; |
| 70 | writer.close().await?; |
| 71 | ``` |
| 72 | |
| 73 | ## Contributions |
| 74 | Whilst I will be continuing to maintain this crate myself, reasonable specification compliance is a huge undertaking for a single individual. As such, contributions will always be encouraged and appreciated. |
| 75 | |
| 76 | No contribution guidelines exist but additions should be developed with readability in mind, with appropriate comments, and make use of `rustfmt`. |
| 77 | |
| 78 | ## Issues & Support |
| 79 | Whether you're wanting to report a bug you've come across during use of this crate or are seeking general help/assistance, please utilise the [issues tracker](https://github.com/Majored/rs-async-zip/issues) and provide as much detail as possible (eg. recreation steps). |
| 80 | |
| 81 | I try to respond to issues within a reasonable timeframe. |