Struct asar::writer::AsarWriter

source ·
pub struct AsarWriter { /* private fields */ }

Implementations§

source§

impl AsarWriter

source

pub fn new() -> Self

Creates a new AsarWriter, with an empty buffer and the default HashAlgorithm

source

pub fn new_with_algorithm(hasher: HashAlgorithm) -> Self

Creates a new AsarWriter, with an empty buffer and the given HashAlgorithm

Currently useless, as only one HashAlgorithmHashAlgorithm::Sha256 — is supported

source

pub fn add_from_reader(&mut self, reader: &AsarReader<'_>) -> Result<()>

Adds all the files from an AsarReader to the AsarWriter.

Example
use asar::{AsarReader, AsarWriter, Header};

let reader = AsarReader::new(&asar_file, None)?;
let mut writer = AsarWriter::new();
writer.add_from_reader(&reader)?;
source

pub fn write_file( &mut self, path: impl AsRef<Path>, bytes: impl AsRef<[u8]>, executable: bool ) -> Result<()>

Write a file to the archive. This appends the contents to the buffer, adds the file to the header, and updates the offset.

Errors
Example
use asar::AsarWriter;

let mut writer = AsarWriter::new();
writer.write_file("bad news.txt", b"Nothing travels faster than the speed of light with the possible exception of bad news, which obeys its own special laws.", false)?;
source

pub fn finalize<FinalWriter>(self, final_writer: FinalWriter) -> Result<usize>
where FinalWriter: Write,

Finalizes the archive, writing the Header and the files to the writer.

The buffer is also flushed before returning.

Returns the amount of bytes written.

Errors
  • If writing fails, an std::io::Error is returned.
  • This can panic if an invalid path (such as one containing . or ..) was added to the archive.
Example
use asar::AsarWriter;
use std::fs::File;

let mut writer = AsarWriter::new();
writer.write_file("bad news.txt", b"Nothing travels faster than the speed of light with the possible exception of bad news, which obeys its own special laws.", false)?;
writer.write_file("advice.txt", b"Don't Panic.", false)?;
writer.write_file("truth.txt", b"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move.", false)?;
let mut file = File::create("archive.asar")?;
writer.finalize(&mut file)?;

Trait Implementations§

source§

impl Default for AsarWriter

source§

fn default() -> Self

Creates a new AsarWriter, with an empty buffer and the default HashAlgorithm

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

§

type Output = T

Should always be Self
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.