Struct Writer

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

A basic SquashFS writer.

This provides a simple interface for writing archives. The user calls open, add to add each node, and finish to finish writing. This is intended for writing archives that are generated by code or otherwise not reflected by files in a file system – if you want to archive a tree of files from disk, TreeProcessor handles directory tracking so that you don’t have to do it yourself.

Each node must be written before its parent, and an error will be raised if this invariant is not maintained – however, this is not detected until finish is called.

let writer = Writer::open("archive.sfs")?;
let mut ids = HashMap::new();
for i in 0..5 {
    let mut content = format!("This is the content of file {}.txt.", i).as_bytes();
    let source = Source::defaults(SourceData::File(Box::new(content)));
    let id = writer.add(source)?;
    ids.insert(OsString::from(format!("{}.txt", i)), id);
}
writer.add(Source::defaults(SourceData::Dir(Box::new(ids.into_iter()))))?;
writer.finish()?;

Implementations§

Source§

impl Writer

Source

pub fn open<T: AsRef<Path>>(path: T) -> Result<Self>

Open a new output file for writing.

If the file exists, it will be overwritten.

Source

pub fn add(&mut self, source: Source) -> Result<u32>

Add the provided Source to the archive.

This writes file data and xattrs to the archive directly, while storing directory tree information to write when finish is called.

The returned value is the inode number of the added Source. If the file is to be added to a directory (that is, almost always), this number needs to be stored so that it can be provided when the directory is added. In the current implementation, inode numbers start at 1 for the first file and count steadily upward, but this behavior may change without warning.

Source

pub fn finish(&mut self) -> Result<()>

Finish writing the archive and flush all contents to disk.

It is an error to call add after this has been run.

Trait Implementations§

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, 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.
Source§

impl<T> Erased for T