Crate vach

Source
Expand description

GitHub last commit

A simple archive format, in Pure Rust.

Β§πŸ”« Cargo Features

  • archive: Enables the Archive loader.
  • builder: Enables the Archive builder.
  • multithreaded: dump processes leaves in parallel, number of threads can be set manually using num_threads.
  • compression: Pulls snap, lz4_flex and brotli as dependencies and enables compression.
  • crypto: Enables encryption and authentication by pulling the ed25519_dalek and aes_gcm crates
  • default: Enables the archive and builder features.
  • all: Enables all the above features.

Β§πŸ€„ Show me some code dang it!

use std::{io::Cursor, fs::File};
use vach::prelude::*;

// collect leaves in a vector, or static buffer
let mut leaves = [
	// Leaf::new(File::open("background.wav").unwrap(), "ambient"),
	Leaf::new([12, 23, 34, 45, 56, 67, 78, 90, 69].as_slice(), "ftstep").compress(CompressMode::Always),
	Leaf::new(b"Hello, Cassandra!".as_slice(), "hello")
];

// let mut target = File::create("sounds.vach")?;
let mut target = Cursor::new(Vec::new());

let config = BuilderConfig::default();
let bytes_written = dump(&mut target, &mut leaves, &config, None).unwrap();

// roundtrip
let mut archive = Archive::new(target).unwrap();
let resource = archive.fetch_mut("ftstep").unwrap();

assert_eq!(resource.data.as_ref(), [12, 23, 34, 45, 56, 67, 78, 90, 69].as_slice());

ModulesΒ§

archivearchive
Archive Reading logic and data-structures, Archive, Resource
builderbuilder
Archive Creation logic and data structures, dump, Leaf and BuilderConfig
cryptocrypto
Import keypairs and signatures from here, mirrors from ed25519_dalek
crypto_utilscrypto
Some utility functions to keep you happy
prelude
Consolidated crate imports.

ConstantsΒ§

MAGIC
Magic Sequence used by vach: β€œVfACH”
MAX_ID_LENGTH
Maximum size for any ID, ie u16::MAX
PUBLIC_KEY_LENGTH
Size of a public key
SECRET_KEY_LENGTH
Size of a secret key
SIGNATURE_LENGTH
Size of a signature
VERSION
Current vach spec version. increments by ten with every spec change