cpio_archive::odc

Struct OdcBuilder

Source
pub struct OdcBuilder<W: Write + Sized> { /* private fields */ }
Expand description

Iteratively create a cpio archive using the Portable ASCII format.

cpio archives logically consist of 2-tuples of (file header, data), so data can be streamed by iteratively feeding new entries to write.

cpio archives contain a special file header denoting the end of the archive. This is emitted by calling Self::finish. So consumers should always call this method when done writing new files.

By default, missing parent directories are automatically emitted when writing files. Instances track which directories have been emitted. Upon encountering a file path in a directory that has not yet been emitted, a directory entry will be emitted. This behavior can be disabled by calling Self::auto_write_dirs.

Implementations§

Source§

impl<W: Write + Sized> OdcBuilder<W>

Source

pub fn new(writer: W) -> Self

Construct a new instance which will write data to a writer.

Source

pub fn default_mode_file(&mut self, mode: u32)

Set the default file mode to use for files.

Source

pub fn default_mode_directory(&mut self, mode: u32)

Set the default file mode to use for directories.

Source

pub fn default_user_id(&mut self, uid: u32)

Set the default user ID (UID).

Source

pub fn default_group_id(&mut self, gid: u32)

Set the default group ID (GID).

Source

pub fn default_mtime(&mut self, mtime: DateTime<Utc>)

Set the default modified time.

Source

pub fn auto_write_dirs(&mut self, value: bool)

Set the behavior for auto writing directory entries.

Source

pub fn next_header(&mut self) -> OdcHeader

Obtain a header record representing the next header in the archive.

The header has fields set to default values. Callers should likely update at least the name and possibly the file size and mode.

This will increment the inode sequence number when called.

Source

pub fn append_header_with_data( &mut self, header: OdcHeader, data: impl AsRef<[u8]>, ) -> CpioResult<u64>

Append a raw header and corresponding file data to the writer.

The writer and data are written as-is.

Only simple validation that the data length matches the length advertised in the header is performed.

Automatic directory emission is not processed in this mode.

Source

pub fn append_header_with_reader( &mut self, header: OdcHeader, reader: &mut impl Read, ) -> CpioResult<u64>

Append a raw header and corresponding data from a reader to the writer.

The header’s file size must match the length of data available in the reader or errors could occur. This method will copy all data available in the reader to the output stream. If the number of bytes written does not match what is reported by the header, the cpio archive stream is effectively corrupted and an error is returned.

Source

pub fn append_file_from_data( &mut self, archive_path: impl ToString, data: impl AsRef<[u8]>, mode: u32, ) -> CpioResult<u64>

Write a regular file to the cpio archive with provided file data and file mode.

Source

pub fn append_file_from_path( &mut self, archive_path: impl ToString, path: impl AsRef<Path>, ) -> CpioResult<u64>

Write a regular file to the cpio archive.

This takes the relative path in the archive and the filesystem path of the file to write. It resolves header metadata automatically given filesystem attributes. However, the UID, GID, and mtime defaults specified on this builder are used so archive construction is more deterministic.

Source

pub fn append_file_manifest( &mut self, manifest: &FileManifest, ) -> CpioResult<u64>

Append a FileManifest to the archive.

Source

pub fn finish(&mut self) -> CpioResult<u64>

Finish writing the archive.

This will emit a special header denoting the end of archive.

Failure to call this method will result in a malformed cpio archive. Readers may or may not handle the missing trailer correctly.

Source

pub fn into_inner(self) -> CpioResult<W>

Consume self and return the original writer this instance was constructed from.

This will automatically finish the archive if needed.

Auto Trait Implementations§

§

impl<W> Freeze for OdcBuilder<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for OdcBuilder<W>
where W: RefUnwindSafe,

§

impl<W> Send for OdcBuilder<W>
where W: Send,

§

impl<W> Sync for OdcBuilder<W>
where W: Sync,

§

impl<W> Unpin for OdcBuilder<W>
where W: Unpin,

§

impl<W> UnwindSafe for OdcBuilder<W>
where W: UnwindSafe,

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.