3 releases
0.1.2 | May 27, 2023 |
---|---|
0.1.1 | May 27, 2023 |
0.1.0 | May 26, 2023 |
#363 in Compression
50 downloads per month
Used in zx0dec
105KB
215 lines
zx0decompress
A Rust library to decompress files compressed with Einar Saukas' ZX0 compression format.
Normally, you use the ZX0 format to save space on 8 bit platforms like the ZX Spectrum. You compress the data on a modern computer, and use a decompressor implemented in assembly language on the target platform.
For some use cases, like build tools and other utilities, it may still be useful to have a decompressor on your workstation. That's why I created this library.
I also implemented a command-line application called zx0dec
based on this library.
Usage
Add the crate to your project:
cargo add zx0decompress
Call zx0decompress::decompress
with any object that implements std::io::Read
.
You may also want to specify settings other than the default. For that, call zx0decompress::decompress_with_settings
.
Examples
Decompress from file into a Vec<u8>
:
let mut source = std::fs::File::open(filename)?;
let content = zx0decompress::decompress(&mut source)?;
Decompress from a byte slice into a Vec<u8>
:
let source = [
0x1fu8, 0x41, 0x42, 0x52, 0x41, 0x20, 0xf6, 0xab, 0x43, 0x44, 0xf5, 0xf2, 0x55, 0x58,
];
let result = decompress(&mut source.as_ref()).unwrap();
assert_eq!(&result, b"ABRA ABRACADABRA");
Testing
In lib/tests there are compressed files (compressed with zx0-rs) and their corresponding uncompressed files. A test case verifies that zx0decompress
decompresses correctly.
In the fuzz directory there are fuzz tests that can be run with cargo-fuzz:
cargo fuzz run fuzz_decompress
Links
Dependencies
~310–780KB
~18K SLoC