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
//! # mismall - Streaming Huffman Compression Library
//!
//! A sophisticated Rust library for file compression and decompression built around
//! canonical Huffman coding with streaming architecture. Designed to handle arbitrarily
//! large files with bounded memory usage and optional AES-256-GCM encryption.
//!
//! ## 🚀 Quick Start
//!
//! ### Basic Usage
//! ```rust
//! use mismall::{compress_file, decompress_file};
//!
//! // Note: These examples require existing files
//! // let result = compress_file("document.txt", None)?;
//! // println!("Compressed {} -> {} bytes", result.original_size, result.compressed_size);
//! //
//! // // Decompress a file
//! // let result = decompress_file("document.txt.small", None)?;
//! // println!("Decompressed {} bytes", result.original_size);
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ### Advanced Usage
//! ```rust
//! use mismall::compress::CompressionBuilder;
//!
//! // Note: This requires an existing file
//! // let result = CompressionBuilder::new("large_video.mp4")
//! // .with_password("secret123")
//! // .with_chunk_size(64 * 1024 * 1024) // 64MB chunks
//! // .with_progress_callback(|progress: &mismall::progress::ProgressInfo| {
//! // println!("Progress: {}%", progress.percentage);
//! // })
//! // .compress()?;
//! //
//! // println!("Compressed with {:.1}% ratio", result.compression_ratio);
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ### Archive Operations
//! ```rust
//! use mismall::archive::{ArchiveBuilder, ArchiveExtractor};
//!
//! // Create archive
//! ArchiveBuilder::new()
//! .add_file("doc1.pdf", b"PDF content")?
//! .add_file("image.jpg", b"JPG content")?
//! .with_password("archive_secret")
//! .build("backup.small")?;
//!
//! // Note: This requires an existing archive
//! // // Extract from archive
//! // ArchiveExtractor::new("backup.small")
//! // .with_password("archive_secret")
//! // .extract_all()?;
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ## Features
//!
//! - **Streaming Architecture**: Bounded memory usage (16MB default) with chunked I/O
//! - **AES-256-GCM Encryption**: Optional password-based encryption with authenticated data integrity
//! - **Archive Support**: Pack multiple files into single `.small` containers with metadata
//! - **Memory Efficient**: Uses temporary files for intermediate processing, never loads entire files into RAM
//! - **Raw-Store Heuristic**: Automatically stores uncompressed data if compression would expand file size
//! - **Configurable Chunk Sizes**: Users can adjust memory usage from 64KB to 1GB+
//!
//! ## Quick Start
//!
//! ```rust
//! use mismall::{compress_file, decompress_file};
//!
//! // Note: These examples require existing files
//! // let compressed = compress_file("document.txt", None)?;
//! // println!("File compressed successfully!");
//! //
//! // // Simple decompression
//! // let decompressed = decompress_file("document.txt.small", None)?;
//! // println!("File decompressed successfully!");
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ## Advanced Usage
//!
//! ```rust
//! use mismall::compress::CompressionBuilder;
//!
//! // Note: This requires an existing file
//! // let result = CompressionBuilder::new("large_video.mp4")
//! // .with_password("secret123")
//! // .with_chunk_size(64 * 1024 * 1024) // 64MB chunks
//! // .with_progress_callback(|progress: &mismall::progress::ProgressInfo| {
//! // println!("Progress: {}%", progress.percentage);
//! // })
//! // .compress()?;
//! //
//! // println!("Compressed {} bytes to {} bytes",
//! // result.original_size, result.compressed_size);
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ## Archive Operations
//!
//! ```rust
//! use mismall::archive::{ArchiveBuilder, ArchiveExtractor};
//!
//! // Create archive
//! ArchiveBuilder::new()
//! .add_file("doc1.pdf", b"PDF content")?
//! .add_file("image.jpg", b"JPG content")?
//! .with_password("archive_secret")
//! .build("backup.small")?;
//!
//! // Note: This requires an existing archive
//! // // Extract from archive
//! // ArchiveExtractor::new("backup.small")
//! // .with_password("archive_secret")
//! // .extract_file("doc1.pdf", "restored_doc.pdf")?;
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ## Streaming Utilities
//!
//! ```rust
//! use mismall::stream::{Compressor, Decompressor, stream_reader, stream_writer};
//! use std::fs::File;
//! use std::io::{Write, Read};
//!
//! // Note: This example shows the pattern but requires actual files
//! // // Streaming compression
//! // let output_file = File::create("data.txt.small")?;
//! // let mut compressor = stream_writer(output_file, "data.txt", None);
//! // compressor.write_all(b"Hello, ")?;
//! // compressor.write_all(b"world!")?;
//! // compressor.finish()?;
//! //
//! // // Streaming decompression
//! // let input_file = File::open("data.txt.small")?;
//! // let mut reader = stream_reader(input_file, None);
//! // let mut buffer = String::new();
//! // reader.read_to_string(&mut buffer)?;
//! // println!("Decompressed: {}", buffer);
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ## 🎯 Core APIs
//!
//! ### Simple API
//! - [`compress_file()`] - Compress a file with default settings
//! - [`decompress_file()`] - Decompress a file with default settings
//! - [`compress_stream()`] - Compress data streams with custom settings
//! - [`decompress_stream()`] - Decompress data streams with custom settings
//! - [`validate_chunk_size()`] - Validate memory usage parameters
//!
//! ### Builder API
//! - [`CompressionBuilder`] - Advanced compression with options
//! - [`DecompressionBuilder`] - Advanced decompression with options
//! - [`ArchiveBuilder`] - Create multi-file archives
//! - [`ArchiveExtractor`] - Extract from archives with options
//!
//! ### Streaming API
//! - [`stream_reader()`] - Read from compressed streams
//! - [`stream_writer()`] - Write to compressed streams
//! - [`Compressor`] - Stateful streaming compression
//! - [`Decompressor`] - Stateful streaming decompression
//!
//! ### Progress Tracking
//! - [`ProgressInfo`] - Progress information for long operations
//! - [`ProgressCallback`] - Callback type for progress updates
//! - [`ProcessingStage`] - Different stages of compression/decompression
//!
//! ## 📚 Module Organization
//!
//! ### [`compress`]
//! High-level compression functions and builder pattern for advanced options.
//!
//! ### [`decompress`]
//! High-level decompression functions and builder pattern for advanced options.
//!
//! ### [`archive`]
//! Multi-file archive operations including creation, extraction, and listing.
//!
//! ### [`stream`]
//! Low-level streaming utilities for custom I/O patterns.
//!
//! ### [`error`]
//! Comprehensive error hierarchy with context and suggestions.
//!
//! ### [`progress`]
//! Progress tracking utilities with callback support.
//!
//! ## 💾 Memory Management
//!
//! mismall is designed for **bounded memory usage** regardless of file size:
//!
//! | System Type | Recommended Chunk Size | Memory Usage |
//! |-------------|---------------------|--------------|
//! | Low (1GB) | 64KB | Minimal |
//! | Standard (8GB+) | 16MB (default) | Balanced |
//! | High (32GB+) | 1GB | Maximum |
//!
//! **Why this matters**: The streaming architecture processes files in chunks,
//! never loading entire files into memory. This enables compression of
//! multi-gigabyte files on resource-constrained systems.
//!
//! ## 🔒 Security Features
//!
//! - **AES-256-GCM** encryption with authenticated data integrity
//! - **Password-based key derivation** using PBKDF2 with random salt
//! - **Authentication tags** prevent tampering and verify data integrity
//! - **Optional encryption** -.compress without passwords for speed
//!
//! ## âš¡ Performance Characteristics
//!
//! - **Compression**: Huffman coding optimized for text and binary data
//! - **Raw-store heuristic**: Automatically skips compression for incompressible data
//! - **Chunked I/O**: Overlaps computation with I/O for better throughput
//! - **Zero-copy operations**: Minimizes memory allocations where possible
//!
//! ## Feature Flags
//!
//! - `compression` (default): Compression and decompression functionality
//! - `archives` (default): Multi-file archive operations
//! - `encryption` (default): AES-256-GCM encryption support
//! - `cli`: Command-line interface (enables all other features)
//!
//! ## Error Handling
//!
//! All library functions return `Result<T, MismallError>` where `MismallError` provides
//! detailed error information with context for troubleshooting.
//!
//! # License
//!
//! MIT - do whatever you want, just don't claim you wrote it.
// Re-export key types for convenience
pub use ;
// Re-export simple API functions
pub use ;
pub use ;
// Re-export archive API functions
pub use ;
pub use ;
// Re-export constants
pub use ;
pub use DEFAULT_CHUNK_SIZE;
// Re-export streaming utilities
pub use ;
// Async support (placeholder for future implementation)
// Note: async_stream module not implemented yet
// #[cfg(all(feature = "compression", feature = "async"))]
// pub mod async_stream;
// Legacy modules for CLI use
// Archive operations module
// Streaming utilities module