readme1/
readme1.rs

1
2// This file contains 65 bytes filled with `0xCF`.
3const DATA: &[u8] = &[0xCF; 65];
4
5fn main() {
6	let ref key = [13, 42];
7
8	// Create the editor object to create PAKS files in memory.
9	let mut edit = paks::MemoryEditor::new();
10
11	// Let's create a file `foo` under a directory `sub`.
12	// If a file already exists by this name it will be overwritten.
13	edit.create_file(b"sub/foo", DATA, key);
14
15	// When done the editor object can be finalized and returns the encrypted PAKS file as a `Vec<Block>`.
16	// It also returns the unencrypted directory for final inspection if desired.
17	let (paks, dir) = edit.finish(key);
18
19	// Print the directory.
20	print!("The directory:\n\n```\n{}```\n\n", dir.display());
21
22	// Print the PAKS file itself.
23	print!("The RAW data:\n\n```\n{:x?}\n```\n", paks);
24
25	// Create the reader object to inspect PAKS files in memory.
26	let read = paks::MemoryReader::from_blocks(paks, key).unwrap();
27
28	// Find the file created earlier and read its data into a `Vec<u8>`.
29	let data = read.read(b"sub/foo", key).unwrap();
30
31	// Check that it still matches the expected data.
32	assert_eq!(DATA, &data[..]);
33}