Crate exaf_rs

Source
Expand description

The exaf_rs crate implements the EXtensible Archiver Format and is intended to be used in compressing and archiving files. It offers an alternative to the well-known zip and 7-zip formats, with extensibility in mind. The running time of this reference implementation is similar to that of GNU tar with Zstandard compression, and the resulting file size is very similar.

§Examples

To create an archive, use the Writer to add files, directories, and symbolic links. It also can add an entire directory tree in one call.

use exaf_rs::writer::Writer;

let output = File::create("archive.exa").expect("create file");
let mut writer = Writer::new(output).expect("new writer");
writer.add_dir_all("important-docs").expect("add dir all");

// You must call finish() in order to flush everything to the output.
writer.finish().expect("finish");

The code to list the entries of an archive might look like this (this example assumes that the archive is not encrypted):

let mut reader = exaf_rs::reader::Entries::new("archive.exa").expect("new entries");
for result in reader {
    match result {
        Ok(entry) => println!("{}", entry.name()),
        Err(err) => println!("error: {}", err),
    }
}

To extract everything within the archive, which may be encrypted, use the Reader like so:

let mut reader = exaf_rs::reader::from_file("archive.exa").expect("from file");
if reader.is_encrypted() && passwd.is_none() {
    println!("Archive is encrypted, please provide a password.");
} else {
    if let Some(password) = passwd {
        reader.enable_encryption(password).expect("enable crypto");
    }
    let path = std::env::current_dir().expect("no env?");
    reader.extract_all(&path).expect("extract all");
}

A more complete example of creating and extracting archives can be found in the src/main.rs file in the source repository.

Modules§

reader
Read an archive, decrypting and decompressing as needed.
writer
Create compressed archives to contain files, directories, and symbolic links.

Structs§

Entry
Represents a file, directory, or symbolic link within an archive.
KeyDerivationParams
Parameters to be provided to the key derivation function. These are fairly common to most such functions.

Enums§

Encryption
Algorithm for encrypting the archive data.
Error
This type represents all possible errors that can occur within this crate.
KeyDerivation
Algorithm for deriving a key from a passphrase.
Kind
The type of an entry that has content, such as a file or symbolic link.

Functions§

content_size
Return the size in bytes of the content block at which point a Writer will create a new manifest and content pair.