Skip to main content

SplitdirfdstreamWriter

Struct SplitdirfdstreamWriter 

Source
pub struct SplitdirfdstreamWriter<W> { /* private fields */ }
Expand description

Writer for building a splitdirfdstream.

Encodes inline data and dirfd-relative file references into the splitdirfdstream binary format.

§Example

use composefs_splitdirfdstream::SplitdirfdstreamWriter;

let mut buffer = Vec::new();
let mut writer = SplitdirfdstreamWriter::new(&mut buffer);
writer.write_metadata(b"hello").unwrap();
writer.write_file_backed_data(0, 42, b"objects/abc123").unwrap();
let _buf = writer.finish().unwrap();

Implementations§

Source§

impl<W: Write> SplitdirfdstreamWriter<W>

Source

pub fn new(writer: W) -> Self

Create a new writer wrapping writer.

Source

pub fn write_metadata(&mut self, data: &[u8]) -> Result<()>

Write an inline chunk containing data.

Empty slices are silently ignored (no bytes are written).

§Errors

Returns Error::InlineTooLarge if data.len() exceeds MAX_INLINE_CHUNK_SIZE, or propagates I/O errors from the underlying writer.

Source

pub fn write_inline_data(&mut self, data: &[u8]) -> Result<()>

Write an InlineData chunk carrying data bytes of file content transported inline.

Unlike write_metadata, a zero-length slice IS written (a zero-byte non-world-readable file must still round-trip).

§Errors

Returns Error::InlineTooLarge if data.len() exceeds MAX_INLINE_CHUNK_SIZE, or propagates I/O errors from the underlying writer.

Source

pub fn write_file_backed_data( &mut self, dirfd_index: u32, length: u64, filename: &[u8], ) -> Result<()>

Write a FileBackedData chunk referencing a file by dirfd index and relative filename.

The consumer will open filename beneath dirfds[dirfd_index] and read exactly length bytes from offset 0.

filename is validated by validate_filename before writing.

§Errors

Returns any Error produced by validate_filename, or propagates I/O errors from the underlying writer.

Source

pub fn finish(self) -> Result<W>

Consume the writer and return the underlying Write impl.

Trait Implementations§

Source§

impl<W: Debug> Debug for SplitdirfdstreamWriter<W>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.