MemoryReader

Struct MemoryReader 

Source
pub struct MemoryReader { /* private fields */ }
Expand description

Memory reader.

This implementation keeps the entire PAKS file in memory.

Implementations§

Source§

impl MemoryReader

Source

pub fn from_bytes(bytes: &[u8], key: &Key) -> Result<MemoryReader, ErrorKind>

Parses the bytes as the PAKS file format for reading.

§Notes

The reader has specific alignment requirements for the buffer. For this reason the entire byte array will be copied to an internal buffer.

§Errors
Source

pub fn from_blocks( blocks: Vec<Block>, key: &Key, ) -> Result<MemoryReader, Vec<Block>>

Parses the blocks as the PAKS file format for reading.

Examples found in repository?
examples/readme1.rs (line 26)
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().to_string());
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}
Source§

impl MemoryReader

Source

pub fn read(&self, path: &[u8], key: &Key) -> Result<Vec<u8>, ErrorKind>

Reads the contents of a file from the PAKS archive.

Examples found in repository?
examples/readme1.rs (line 29)
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().to_string());
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}
Source

pub fn read_to_string( &self, path: &[u8], key: &Key, ) -> Result<String, ErrorKind>

Reads the contents of a file from the PAKS archive into a string.

Source

pub fn read_section( &self, section: &Section, key: &Key, ) -> Result<Vec<Block>, ErrorKind>

Decrypts and authenticates the section.

The key is not required to be the same as used to open the PAKS file.

§Errors
Source

pub fn read_data( &self, desc: &Descriptor, key: &Key, ) -> Result<Vec<u8>, ErrorKind>

Decrypts the contents of the given file descriptor.

See read_section for more information.

Source

pub fn read_data_into( &self, desc: &Descriptor, key: &Key, byte_offset: usize, dest: &mut [u8], ) -> Result<(), ErrorKind>

Decrypts the contents of the given file descriptor into the dest buffer.

See read_section for more information.

Methods from Deref<Target = Directory>§

Source

pub fn is_empty(&self) -> bool

Returns if there are no files or directories.

Source

pub fn len(&self) -> usize

Returns the number of Descriptors in the directory.

Source

pub fn find_desc(&self, path: &[u8]) -> Option<&Descriptor>

Finds a descriptor by its path.

Source

pub fn find_file(&self, path: &[u8]) -> Option<&Descriptor>

Finds a file descriptor by its path.

Source

pub fn get_children(&self, path: &[u8]) -> Option<&[Descriptor]>

Gets the child descriptors of the directory at the given path.

Source

pub fn display(&self) -> impl '_ + Display

Returns a displayable directory.

Examples found in repository?
examples/readme1.rs (line 20)
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().to_string());
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}
Source

pub fn fsck(&self, high_mark: u32, log: &mut dyn Write) -> bool

File system consistency check.

Checks the directory for errors, returns false if there’s any inconsistencies. Detailed information can be found in the log.

The high mark is the highest block index that a file section is allowed.

Trait Implementations§

Source§

impl Deref for MemoryReader

Source§

type Target = Directory

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Directory

Dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.