Struct asar::writer::AsarWriter
source · pub struct AsarWriter { /* private fields */ }
Implementations§
source§impl AsarWriter
impl AsarWriter
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new AsarWriter
, with an empty buffer and the default
HashAlgorithm
sourcepub fn new_with_algorithm(hasher: HashAlgorithm) -> Self
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 HashAlgorithm
—
HashAlgorithm::Sha256
— is supported
sourcepub fn add_from_reader(&mut self, reader: &AsarReader<'_>) -> Result<()>
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)?;
sourcepub fn write_file(
&mut self,
path: impl AsRef<Path>,
bytes: impl AsRef<[u8]>,
executable: bool
) -> Result<()>
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
- If the file already exists in the archive, returns an
Error::FileAlreadyWritten
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)?;
pub fn write_symlink( &mut self, path: impl AsRef<Path>, link: impl AsRef<Path> ) -> Result<()>
sourcepub fn finalize<FinalWriter>(self, final_writer: FinalWriter) -> Result<usize>where
FinalWriter: Write,
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
impl Default for AsarWriter
source§fn default() -> Self
fn default() -> Self
Creates a new AsarWriter
, with an empty buffer and the default
HashAlgorithm
Auto Trait Implementations§
impl RefUnwindSafe for AsarWriter
impl Send for AsarWriter
impl Sync for AsarWriter
impl Unpin for AsarWriter
impl UnwindSafe for AsarWriter
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more