1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
//! # zesven
//!
//! A pure-Rust library for reading and writing 7z archives.
//!
//! This crate provides a safe, efficient, and fully-featured implementation of
//! the 7z archive format with support for multiple compression methods, AES-256
//! encryption, solid archives, and streaming decompression.
//!
//! ## Quick Start
//!
//! ### Extracting an Archive
//!
//! ```rust,no_run
//! use zesven::{Archive, ExtractOptions, Result};
//! use std::io::Cursor;
//!
//! fn main() -> Result<()> {
//! // Open from a file path
//! let mut archive = Archive::open_path("archive.7z")?;
//!
//! // List entries
//! for entry in archive.entries() {
//! println!("{}: {} bytes", entry.path.as_str(), entry.size);
//! }
//!
//! // Extract all entries to a directory
//! archive.extract("./output", (), &ExtractOptions::default())?;
//! Ok(())
//! }
//! ```
//!
//! ### Creating an Archive
//!
//! ```rust,no_run
//! use zesven::{Writer, WriteOptions, ArchivePath, Result};
//!
//! fn main() -> Result<()> {
//! // Create a new archive
//! let mut writer = Writer::create_path("new.7z")?;
//!
//! // Add files from disk
//! writer.add_path("file.txt", ArchivePath::new("file.txt")?)?;
//!
//! // Add data from memory
//! writer.add_bytes(ArchivePath::new("hello.txt")?, b"Hello, World!")?;
//!
//! // Finish and get statistics
//! let result = writer.finish()?;
//! println!("Wrote {} entries ({:.1}% compression)",
//! result.entries_written,
//! result.space_savings() * 100.0);
//! Ok(())
//! }
//! ```
//!
//! ### Extracting Password-Protected Archives
//!
//! ```rust,ignore
//! # #[cfg(feature = "aes")]
//! use zesven::{Archive, ExtractOptions, Password, Result};
//!
//! # #[cfg(feature = "aes")]
//! fn main() -> Result<()> {
//! let mut archive = Archive::open_path_with_password(
//! "encrypted.7z",
//! Password::new("secret"),
//! )?;
//! archive.extract("./output", (), &ExtractOptions::default())?;
//! Ok(())
//! }
//! # #[cfg(not(feature = "aes"))]
//! # fn main() {}
//! ```
//!
//! ### Creating an Encrypted Archive
//!
//! ```rust,ignore
//! # #[cfg(feature = "aes")]
//! use zesven::{Writer, WriteOptions, ArchivePath, Password, Result};
//!
//! # #[cfg(feature = "aes")]
//! fn main() -> Result<()> {
//! let options = WriteOptions::new()
//! .password(Password::new("secret"))
//! .level(7)?;
//!
//! let mut writer = Writer::create_path("encrypted.7z")?
//! .options(options);
//!
//! writer.add_bytes(ArchivePath::new("secret.txt")?, b"Secret data")?;
//! writer.finish()?;
//! Ok(())
//! }
//! # #[cfg(not(feature = "aes"))]
//! # fn main() {}
//! ```
//!
//! ## Feature Flags
//!
//! | Feature | Default | Description |
//! |---------|---------|-------------|
//! | `lzma` | Yes | LZMA compression support |
//! | `lzma2` | Yes | LZMA2 compression support (includes `lzma`) |
//! | `deflate` | Yes | Deflate/zlib compression |
//! | `bzip2` | Yes | BZip2 compression |
//! | `ppmd` | Yes | PPMd compression |
//! | `aes` | Yes | AES-256 encryption for data and headers |
//! | `parallel` | Yes | Multi-threaded compression with Rayon |
//! | `lz4` | No | LZ4 compression support |
//! | `zstd` | No | Zstandard compression support |
//! | `brotli` | No | Brotli compression support |
//! | `fast-lzma2` | No | Fast LZMA2 encoder with radix match-finder |
//! | `regex` | No | Regex-based file filtering |
//! | `sysinfo` | No | System info for adaptive memory limits |
//! | `async` | No | Async/await API with Tokio integration |
//! | `wasm` | No | WebAssembly/browser support |
//! | `cli` | No | Command-line interface tool |
//!
//! ### Disabling Default Features
//!
//! To create a minimal build, disable default features:
//!
//! ```toml
//! [dependencies]
//! zesven = { version = "1.0", default-features = false, features = ["lzma2"] }
//! ```
//!
//! ## Async API
//!
//! Enable the `async` feature for Tokio-based async operations:
//!
//! ```rust,ignore
//! # #[cfg(feature = "async")]
//! use zesven::{AsyncArchive, AsyncExtractOptions, Result};
//!
//! # #[cfg(feature = "async")]
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! let mut archive = AsyncArchive::open_path("archive.7z").await?;
//! archive.extract("./output", (), &AsyncExtractOptions::default()).await?;
//! Ok(())
//! }
//! # #[cfg(not(feature = "async"))]
//! # fn main() {}
//! ```
//!
//! ## Streaming API
//!
//! For memory-efficient processing of large archives, use the streaming API:
//!
//! ```rust,ignore
//! use zesven::{StreamingArchive, StreamingConfig, Result};
//!
//! fn main() -> Result<()> {
//! let config = StreamingConfig::default()
//! .max_memory_buffer(64 * 1024 * 1024); // 64 MB limit
//!
//! // With default features (aes enabled), pass empty string for unencrypted archives
//! let archive = StreamingArchive::open_path_with_config("large.7z", "", config)?;
//!
//! for entry in archive.entries()? {
//! let entry = entry?;
//! println!("Processing: {}", entry.path().as_str());
//! }
//! Ok(())
//! }
//! ```
//!
//! ## Error Handling
//!
//! All operations return [`Result<T>`], which is an alias for
//! `std::result::Result<T, Error>`. The [`Error`] enum covers all possible
//! failure modes:
//!
//! ```rust,no_run
//! use zesven::{Archive, Error};
//!
//! fn open_archive(path: &str) -> zesven::Result<()> {
//! match Archive::open_path(path) {
//! Ok(archive) => {
//! println!("Opened archive with {} entries", archive.len());
//! Ok(())
//! }
//! Err(Error::Io(e)) => {
//! eprintln!("I/O error: {}", e);
//! Err(Error::Io(e))
//! }
//! Err(Error::InvalidFormat(msg)) => {
//! eprintln!("Not a valid 7z file: {}", msg);
//! Err(Error::InvalidFormat(msg))
//! }
//! Err(e @ Error::WrongPassword { .. }) => {
//! eprintln!("Incorrect password");
//! Err(e)
//! }
//! Err(e) => Err(e),
//! }
//! }
//! # fn main() {}
//! ```
//!
//! ## Safety and Resource Limits
//!
//! The library includes built-in protections against malicious archives:
//!
//! - **Path traversal protection**: Prevents extraction outside the destination
//! - **Resource limits**: Guards against zip bombs and excessive memory usage
//! - **CRC verification**: Validates data integrity during extraction
//!
//! ```rust,no_run
//! use zesven::{ExtractOptions, read::PathSafety};
//!
//! // Enable strict path validation (default)
//! let options = ExtractOptions::new()
//! .path_safety(PathSafety::Strict);
//! ```
//!
//! ## Platform Support
//!
//! | Platform | Status |
//! |----------|--------|
//! | Linux (x86_64, aarch64) | Full support |
//! | macOS (x86_64, aarch64) | Full support |
//! | Windows (x86_64) | Full support |
//! | WebAssembly | Via `wasm` feature |
//!
//! ## Minimum Supported Rust Version (MSRV)
//!
//! This crate requires **Rust 1.85** or later.
/// Default buffer size for read operations (8 KiB).
pub const READ_BUFFER_SIZE: usize = 8192;
// Async modules (requires "async" feature)
pub use ArchivePath;
pub use ;
pub use Timestamp;
pub use Password;
// Re-export reading API at crate root for convenience
pub use ;
// Re-export writing API at crate root for convenience
pub use ;
// Re-export volume API at crate root for convenience
pub use VolumeConfig;
// Re-export safety utilities
pub use ;
pub use ;
// Re-export streaming API
pub use ;
// Re-export stats API
pub use ;
// Re-export progress API
pub use ;
// Re-export edit API
pub use ;
// Re-export SFX API
pub use ;
// Re-export recovery API
pub use ;
// Re-export ownership API
pub use UnixOwnership;
// Re-export hard link API
pub use ;
// Re-export NTFS alternate data streams API
pub use ;
// Async API re-exports (requires "async" feature)
pub use ;
pub use AsyncArchive;
pub use AsyncWriter;
pub use ;
pub use ;
// Re-export CancellationToken for convenience
pub use CancellationToken;
// WASM/Browser support (requires "wasm" feature)
pub use ;