zx0decompress

Crates.iozx0decompress
lib.rszx0decompress
version0.1.2
sourcesrc
created_at2023-05-26 11:42:12.169305
updated_at2023-05-27 09:14:45.573896
descriptionDecompress files in the ZX0 compression format commonly used on 8 bit platforms
homepage
repositoryhttps://github.com/vilcans/zx0decompress
max_upload_size
id874956
size191,566
Martin Vilcans (vilcans)

documentation

README

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

Commit count: 29

cargo fmt