Struct asar::reader::AsarReader

source ·
pub struct AsarReader<'a> { /* private fields */ }
Expand description

An AsarReader is a struct that takes an asar Header and its offset, and reads the files specified in the header from the given byte buffer.

The lifetime of the AsarReader is tied to the lifetime of the byte buffer that it reads from.

If the check-integrity-on-read feature is enabled, then the AsarReader will check file integrity when reading an archive, and error out if any integrity check fails.

Example

use asar::{AsarReader, Header, Result};
use std::fs;

fn main() -> Result<()> {
	let asar_file = fs::read("archive.asar")?;
	let reader = AsarReader::new(&asar_file, None)?;

	println!("There are {} files in archive.asar", reader.files().len());
	Ok(())
}

Implementations§

source§

impl<'a> AsarReader<'a>

source

pub fn new( data: &'a [u8], asar_path: impl Into<Option<PathBuf>> ) -> Result<Self>

Parse and read an asar archive from a byte buffer.

If you care about unpacked files, pass a asar_path containing the path to the asar archive.

Example
use asar::{AsarReader, Header};
use std::{fs, path::PathBuf};

let asar_file = fs::read("archive.asar")?;
let asar = AsarReader::new(&asar_file, PathBuf::from("./archive.asar"))?;
source

pub fn new_from_header( header: Header, offset: usize, data: &'a [u8], asar_path: impl Into<Option<PathBuf>> ) -> Result<Self>

Read an asar archive from a byte buffer, using the given header and offset.

If you care about unpacked files, pass a asar_path containing the path to the asar archive.

Example
use asar::{AsarReader, Header};
use std::fs;

let asar_file = fs::read("archive.asar")?;
let (header, offset) = Header::read(&mut &asar_file[..])?;
let asar = AsarReader::new_from_header(header, offset, &asar_file, None)?;
source

pub const fn files(&self) -> &BTreeMap<PathBuf, AsarFile<'a>>

Gets all files in the asar.

Example
use asar::AsarReader;

for (path, file_info) in asar.files() {
	println!("file {}", path.display());
	println!("\t{} bytes", file_info.data().len());
	println!(
		"\thash: {}",
		hex::encode(file_info.integrity().unwrap().hash())
	);
}
source

pub const fn directories(&self) -> &BTreeMap<PathBuf, Vec<PathBuf>>

Gets all directories in the asar.

Example
use asar::AsarReader;

for (path, contents) in asar.directories() {
	println!("dir {}", path.display());
	for file in contents {
		println!("\tfile {}", file.display());
	}
}

Gets all symbolic links in the asar.

Example
use asar::AsarReader;

for (path, link) in asar.symlinks() {
	println!("file {}", path.display());
	println!("\tlink {}", link.display());
}
source

pub fn read(&self, path: &Path) -> Option<&AsarFile<'_>>

Gets information about a file.

Example
use asar::AsarReader;
use std::path::Path;

let file_info = asar.read(Path::new("hello.txt")).unwrap();
println!("hello.txt is {} bytes", file_info.data().len());
source

pub fn read_dir(&self, path: &Path) -> Option<&[PathBuf]>

Gets the contents of a directory.

Example
use asar::AsarReader;
use std::path::Path;

let contents = asar.read_dir(Path::new("dir a/dir b")).unwrap();
for file in contents {
	println!("file {}", file.display());
}

Trait Implementations§

source§

impl<'a> Clone for AsarReader<'a>

source§

fn clone(&self) -> AsarReader<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for AsarReader<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> PartialEq for AsarReader<'a>

source§

fn eq(&self, other: &AsarReader<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> StructuralPartialEq for AsarReader<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for AsarReader<'a>

§

impl<'a> Send for AsarReader<'a>

§

impl<'a> Sync for AsarReader<'a>

§

impl<'a> Unpin for AsarReader<'a>

§

impl<'a> UnwindSafe for AsarReader<'a>

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<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.