SplitStreamWriter

Struct SplitStreamWriter 

Source
pub struct SplitStreamWriter<ObjectId: FsVerityHashValue> {
    repo: Arc<Repository<ObjectId>>,
    stream_refs: UniqueVec<ObjectId>,
    object_refs: UniqueVec<ObjectId>,
    named_refs: BTreeMap<Box<str>, usize>,
    inline_buffer: Vec<u8>,
    total_size: u64,
    writer: Encoder<'static, Vec<u8>>,
    content_type: u64,
}
Expand description

Writer for creating split stream format files with inline content and external object references.

Fields§

§repo: Arc<Repository<ObjectId>>§stream_refs: UniqueVec<ObjectId>§object_refs: UniqueVec<ObjectId>§named_refs: BTreeMap<Box<str>, usize>§inline_buffer: Vec<u8>§total_size: u64§writer: Encoder<'static, Vec<u8>>§content_type: u64

Implementations§

Source§

impl<ObjectID: FsVerityHashValue> SplitStreamWriter<ObjectID>

Source

pub fn new(repo: &Arc<Repository<ObjectID>>, content_type: u64) -> Self

Create a new split stream writer.

Source

pub fn add_object_ref(&mut self, verity: &ObjectID) -> usize

Add an externally-referenced object.

This establishes a link to an object (ie: raw data file) from this stream. The link is given a unique index number, which is returned. Once assigned, this index won’t change. The same index can be used to find the linked object when reading the file back.

This is the primary mechanism by which splitstreams reference split external content.

You usually won’t need to call this yourself: if you want to add split external content to the stream, call .write_external() or ._write_external_async().

Source

pub fn lookup_object_ref(&self, verity: &ObjectID) -> Option<usize>

Find the index of a previously referenced object.

Finds the previously-assigned index for a linked object, or None if the object wasn’t previously linked.

Source

pub fn add_named_stream_ref(&mut self, name: &str, verity: &ObjectID)

Add an externally-referenced stream with the given name.

The name has no meaning beyond the scope of this file: it is meant to be used to link to associated data when reading the file back again. For example, for OCI config files, this might refer to a layer splitstream via its DiffId.

This establishes a link between the two splitstreams and is considered when performing garbage collection: the named stream will be kept alive by this stream.

Source

fn flush_inline(&mut self) -> Result<()>

Source

pub fn write_inline(&mut self, data: &[u8])

Write inline data to the stream.

Source

pub fn add_external_size(&mut self, size: u64)

Add to the total external size tracked by this writer.

This is used by SplitStreamBuilder when replaying external entries, since write_reference doesn’t track size on its own.

Source

pub fn write_reference(&mut self, id: ObjectID) -> Result<()>

Write a reference to an external object that has already been stored.

This is the common implementation for .write_external() and .write_external_async(), and is also used by SplitStreamBuilder when replaying resolved entries.

Note: This does NOT add to total_size - the caller must do that if needed.

Source

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

Write externally-split data to the stream.

The data is stored in the repository and a reference is written to the stream.

Source

pub async fn write_external_async(&mut self, data: Vec<u8>) -> Result<()>

Asynchronously write externally-split data to the stream.

The data is stored in the repository asynchronously and a reference is written to the stream. This method awaits the storage operation before returning.

Source

fn write_named_refs(named_refs: BTreeMap<Box<str>, usize>) -> Result<Vec<u8>>

Source

pub fn done(self) -> Result<ObjectID>

Finalizes the split stream and returns its object ID.

Flushes any remaining inline content, validates the SHA256 hash if provided, and stores the compressed stream in the repository.

Source

pub async fn done_async(self) -> Result<ObjectID>

Finalizes the split stream asynchronously.

This is an async-friendly version of done() that runs the final object storage on a blocking thread pool.

Returns the fs-verity object ID of the stored splitstream.

Trait Implementations§

Source§

impl<ObjectID: FsVerityHashValue> Debug for SplitStreamWriter<ObjectID>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<ObjectId> Freeze for SplitStreamWriter<ObjectId>

§

impl<ObjectId> RefUnwindSafe for SplitStreamWriter<ObjectId>
where ObjectId: RefUnwindSafe,

§

impl<ObjectId> Send for SplitStreamWriter<ObjectId>

§

impl<ObjectId> Sync for SplitStreamWriter<ObjectId>

§

impl<ObjectId> Unpin for SplitStreamWriter<ObjectId>

§

impl<ObjectId> !UnwindSafe for SplitStreamWriter<ObjectId>

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> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V