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>
impl<'a> AsarReader<'a>
sourcepub fn new(
data: &'a [u8],
asar_path: impl Into<Option<PathBuf>>
) -> Result<Self>
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"))?;
sourcepub fn new_from_header(
header: Header,
offset: usize,
data: &'a [u8],
asar_path: impl Into<Option<PathBuf>>
) -> Result<Self>
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)?;
sourcepub const fn files(&self) -> &BTreeMap<PathBuf, AsarFile<'a>>
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())
);
}
sourcepub const fn directories(&self) -> &BTreeMap<PathBuf, Vec<PathBuf>>
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());
}
}
sourcepub const fn symlinks(&self) -> &BTreeMap<PathBuf, PathBuf>
pub const fn symlinks(&self) -> &BTreeMap<PathBuf, PathBuf>
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());
}
Trait Implementations§
source§impl<'a> Clone for AsarReader<'a>
impl<'a> Clone for AsarReader<'a>
source§fn clone(&self) -> AsarReader<'a>
fn clone(&self) -> AsarReader<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'a> Debug for AsarReader<'a>
impl<'a> Debug for AsarReader<'a>
source§impl<'a> PartialEq for AsarReader<'a>
impl<'a> PartialEq for AsarReader<'a>
source§fn eq(&self, other: &AsarReader<'a>) -> bool
fn eq(&self, other: &AsarReader<'a>) -> bool
self
and other
values to be equal, and is used
by ==
.