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>
impl<W: Write + Sized> OdcBuilder<W>
Sourcepub fn default_mode_file(&mut self, mode: u32)
pub fn default_mode_file(&mut self, mode: u32)
Set the default file mode to use for files.
Sourcepub fn default_mode_directory(&mut self, mode: u32)
pub fn default_mode_directory(&mut self, mode: u32)
Set the default file mode to use for directories.
Sourcepub fn default_user_id(&mut self, uid: u32)
pub fn default_user_id(&mut self, uid: u32)
Set the default user ID (UID).
Sourcepub fn default_group_id(&mut self, gid: u32)
pub fn default_group_id(&mut self, gid: u32)
Set the default group ID (GID).
Sourcepub fn default_mtime(&mut self, mtime: DateTime<Utc>)
pub fn default_mtime(&mut self, mtime: DateTime<Utc>)
Set the default modified time.
Sourcepub fn auto_write_dirs(&mut self, value: bool)
pub fn auto_write_dirs(&mut self, value: bool)
Set the behavior for auto writing directory entries.
Sourcepub fn next_header(&mut self) -> OdcHeader
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.
Sourcepub fn append_header_with_data(
&mut self,
header: OdcHeader,
data: impl AsRef<[u8]>,
) -> CpioResult<u64>
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.
Sourcepub fn append_header_with_reader(
&mut self,
header: OdcHeader,
reader: &mut impl Read,
) -> CpioResult<u64>
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.
Sourcepub fn append_file_from_data(
&mut self,
archive_path: impl ToString,
data: impl AsRef<[u8]>,
mode: u32,
) -> CpioResult<u64>
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.
Sourcepub fn append_file_from_path(
&mut self,
archive_path: impl ToString,
path: impl AsRef<Path>,
) -> CpioResult<u64>
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.
Sourcepub fn append_file_manifest(
&mut self,
manifest: &FileManifest,
) -> CpioResult<u64>
pub fn append_file_manifest( &mut self, manifest: &FileManifest, ) -> CpioResult<u64>
Append a FileManifest to the archive.
Sourcepub fn finish(&mut self) -> CpioResult<u64>
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.
Sourcepub fn into_inner(self) -> CpioResult<W>
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.