Skip to main content

Crate zexc

Crate zexc 

Source
Expand description

§ZEX — original high-speed secure compressor

Pure-Rust native compression algorithm and .zex container.

Author: Ali Zain <alizain@zainiumdynamics.tech>
Website: https://zainiumdynamics.tech
License: GPL-3.0-only (GNU General Public License version 3 only — not “or later”). Full text: project root LICENSE.

§Not a wrapper

ZEX is not “LZ4 + Zstd glued together”. Match finding, block format, and entropy (optional) are an original design. LZ4/Zstd sources were studied only for engineering ideas (hash tables, acceleration, levels).

§Goals

GoalHow
FastHash-table matcher + adaptive skip on incompressible data
SecureSafe Rust, hard size caps, match bounds checks, CRC32 default
SimpleOne algorithm; profiles only tune search depth

§Profiles (CompressionMode)

  • Turbo — max speed (shallow search)
  • Balanced — default
  • Max — deeper search + optional literal Huffman

§Quick start

use zexc::{compress, decompress, CompressOptions, CompressionMode};

let src = b"Hello ZEX! Hello ZEX! Hello ZEX!";
let opts = CompressOptions::default().mode(CompressionMode::Balanced).level(3);
let compressed = compress(src, &opts).unwrap();
let restored = decompress(&compressed).unwrap();
assert_eq!(src.as_slice(), restored.as_slice());

§Streaming

use std::io::{Cursor, Read, Write};
use zexc::{StreamEncoder, StreamDecoder, CompressOptions};

let mut sink = Vec::new();
{
    let mut enc = StreamEncoder::new(&mut sink, CompressOptions::default());
    enc.write_all(b"stream me").unwrap();
    enc.finish().unwrap();
}
let mut out = Vec::new();
StreamDecoder::new(Cursor::new(&sink)).read_to_end(&mut out).unwrap();
assert_eq!(out, b"stream me");

Full docs: docs/ARCHITECTURE.md, docs/FORMAT.md, docs/API.md.

§no_std

With default-features = false (dropping the default-on std feature), this crate builds #![no_std] + alloc, exposing the core compress/decompress path (compress/decompress, Encoder, Decoder) for embedding in freestanding environments — see zainix-kernel/libzainix/src/ firmware.rs’s ZexDecompressor for a real consumer. Everything that inherently needs an OS (file-based streaming via StreamEncoder/ StreamDecoder, the archive/seekable/cli modules, parallel compression via rayon) stays behind the std feature, which is on by default — existing host users see no change.

Re-exports§

pub use archive::ARCHIVE_MAGIC;
pub use archive::ARCHIVE_VERSION;
pub use archive::ArchiveEntry;
pub use archive::ArchiveListItem;
pub use archive::create_archive;
pub use archive::create_from_paths;
pub use archive::extract_archive;
pub use archive::extract_to_dir;
pub use archive::is_archive;
pub use archive::list_archive;
pub use core::cover::CoverParams;
pub use core::cover::train_cover;
pub use core::decoder::Decoder;
pub use core::decoder::DecompressOptions;
pub use core::decoder::decompress;
pub use core::decoder::decompress_with_options;
pub use core::dictionary::Dictionary;
pub use core::encoder::CompressOptions;
pub use core::encoder::Encoder;
pub use core::encoder::compress;
pub use core::encoder::compress_with_dict;
pub use core::frame::FrameInfo;
pub use core::frame::FrameReader;
pub use core::stream::StreamDecoder;
pub use core::stream::StreamEncoder;
pub use format::block::BlockHeader;
pub use format::block::BlockType;
pub use format::header::CompressionMode;
pub use format::header::HeaderFlags;
pub use format::header::MAGIC;
pub use format::header::VERSION;
pub use format::header::ZexHeader;
pub use seekable::SEEK_MAGIC;
pub use seekable::SEEK_VERSION;
pub use seekable::SeekEntry;
pub use seekable::SeekTable;
pub use seekable::compress_seekable;
pub use seekable::compress_seekable_writer;
pub use seekable::decompress_range;
pub use seekable::decompress_seekable;
pub use seekable::read_seek_table;
pub use utils::security::SecurityPolicy;
pub use crypto::EncryptionKey;

Modules§

algorithms
ZEX compression backends — one native algorithm.
archive
Multi-file .zexa archive format.
cli
Command-line interface definitions.
core
Core encode / decode / frame / streaming orchestration.
crypto
Optional AEAD encryption for .zex frames.
ffi
C ABI for embedding ZEX in other languages.
format
.zex binary format: header + blocks + optional trailer.
seekable
Seekable multi-frame ZEX files with a trailing index.
utils
Shared utilities: CRC32, bit packing, Huffman, security, SIMD.

Enums§

Error
Library-level error type.

Constants§

ZEX_VERSION
Crate version string.

Type Aliases§

Result
Convenient Result alias for this crate.