pub mod error;
pub mod reader;
pub mod writer;
#[cfg(feature = "encryption")]
pub mod encryption;
#[cfg(feature = "async")]
pub mod async_writer;
#[cfg(feature = "async")]
pub mod async_reader;
#[cfg(feature = "async")]
pub mod parallel;
#[cfg(any(feature = "cloud-s3", feature = "cloud-gcs"))]
pub mod cloud;
pub use error::{Result, SZipError};
pub use reader::{StreamingZipReader, ZipEntry};
pub use writer::{CompressionMethod, StreamingZipWriter};
#[cfg(feature = "encryption")]
pub use encryption::AesStrength;
#[cfg(feature = "async")]
pub use async_writer::AsyncStreamingZipWriter;
#[cfg(feature = "async")]
pub use async_reader::{AsyncStreamingZipReader, GenericAsyncZipReader};
#[cfg(feature = "async")]
pub use parallel::{ParallelConfig, ParallelEntry};
#[cfg(test)]
mod tests {
use super::*;
use std::io::Cursor;
#[test]
fn test_basic_write_read_roundtrip() {
let buffer = Vec::new();
let cursor = Cursor::new(buffer);
let mut writer = StreamingZipWriter::from_writer(cursor).unwrap();
writer.start_entry("test1.txt").unwrap();
writer.write_data(b"Hello, World!").unwrap();
writer.start_entry("test2.txt").unwrap();
writer.write_data(b"Testing s-zip library").unwrap();
let cursor = writer.finish().unwrap();
let zip_bytes = cursor.into_inner();
assert!(!zip_bytes.is_empty(), "ZIP should not be empty");
assert_eq!(
&zip_bytes[0..4],
b"PK\x03\x04",
"Should start with ZIP signature"
);
}
#[test]
fn test_compression_method_to_zip_method() {
assert_eq!(CompressionMethod::Stored.to_zip_method(), 0);
assert_eq!(CompressionMethod::Deflate.to_zip_method(), 8);
#[cfg(feature = "zstd-support")]
assert_eq!(CompressionMethod::Zstd.to_zip_method(), 93);
}
#[test]
fn test_empty_entry_name() {
let buffer = Vec::new();
let cursor = Cursor::new(buffer);
let mut writer = StreamingZipWriter::from_writer(cursor).unwrap();
assert!(writer.start_entry("").is_ok());
}
#[test]
fn test_multiple_small_entries() {
let buffer = Vec::new();
let cursor = Cursor::new(buffer);
let mut writer = StreamingZipWriter::from_writer(cursor).unwrap();
for i in 0..10 {
let entry_name = format!("file_{}.txt", i);
let entry_data = format!("Content of file {}", i);
writer.start_entry(&entry_name).unwrap();
writer.write_data(entry_data.as_bytes()).unwrap();
}
let cursor = writer.finish().unwrap();
let zip_bytes = cursor.into_inner();
assert!(zip_bytes.len() > 100, "ZIP with 10 files should be larger");
}
#[test]
fn test_error_display() {
let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found");
let err = SZipError::from(io_err);
assert!(format!("{}", err).contains("I/O error"));
let invalid_err = SZipError::InvalidFormat("bad format".to_string());
assert!(format!("{}", invalid_err).contains("Invalid ZIP format"));
let not_found_err = SZipError::EntryNotFound("missing.txt".to_string());
assert!(format!("{}", not_found_err).contains("Entry not found"));
}
#[cfg(feature = "encryption")]
#[test]
fn test_aes_strength() {
assert_eq!(AesStrength::Aes256.salt_size(), 16);
assert_eq!(AesStrength::Aes256.key_size(), 32);
assert_eq!(AesStrength::Aes256.to_winzip_code(), 0x03);
}
}