Skip to main content

eazip/
lib.rs

1//! An simple yet flexible zip library.
2//!
3//! This crate provides tools to read and write ZIP archives. It aims at being
4//! nice to use for developpers, which includes a good and flexible API,
5//! readable source code and clean maintenance.
6//!
7//! Given how loose the ZIP spec is about what is a valid ZIP file and the
8//! history of security issues around them, this crate also aims at being robust
9//! and secure against malicious input. It might therefore may reject some
10//! "technically valid" ZIP files. If your ZIP file does not validate but you
11//! think it should, feel free to file an issue.
12//!
13//! See [`ArchiveReader`] for reading archives and [`ArchiveWriter`] for creating ones.
14//!
15//! # Cargo features
16//!
17//! - `std`: mandatory feature for forward-compatibility.
18//! - `deflate`: enable deflate compression and decompression.
19//! - `zstd`: enable zstd compression and decompression.
20//! - `parallel`: enable parallel ZIP file extraction.
21//!
22//! # Example
23//!
24//! ```no_run
25//! use std::io;
26//!
27//! // Open a ZIP archive from a file path
28//! let mut archive = eazip::ArchiveReader::open("example.zip")?;
29//!
30//! // Print some metadata for every entry in the archive
31//! for entry in archive.entries() {
32//!     println!("File \"{}\" of type {:?} and compressed size {}", entry.name(), entry.file_type, entry.compressed_size);
33//! }
34//!
35//! // Print the content of the file "hello.txt"
36//! let mut hello = archive.get_by_name("hello.txt").ok_or(io::ErrorKind::NotFound)?;
37//! let content = io::read_to_string(hello.read()?)?;
38//!
39//! println!("Content of hello.txt: {content}");
40//! # Ok::<(), io::Error>(())
41//! ```
42
43#![cfg_attr(docsrs, feature(doc_cfg))]
44#![warn(missing_debug_implementations)]
45#![no_std]
46#![cfg_attr(not(feature = "std"), feature(alloc_io))]
47
48extern crate alloc;
49#[cfg(feature = "std")]
50extern crate std;
51
52#[cfg(not(feature = "std"))]
53use alloc::io;
54#[cfg(feature = "std")]
55use std::io;
56
57mod compression;
58pub mod read;
59mod types;
60mod utils;
61pub mod write;
62
63pub use compression::{CompressionMethod, Compressor, Decompressor};
64pub use read::{Archive, ArchiveReader};
65pub use utils::{FileType, Timestamp};
66pub use write::ArchiveWriter;