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: u64Implementations§
Source§impl<ObjectID: FsVerityHashValue> SplitStreamWriter<ObjectID>
impl<ObjectID: FsVerityHashValue> SplitStreamWriter<ObjectID>
Sourcepub fn new(repo: &Arc<Repository<ObjectID>>, content_type: u64) -> Self
pub fn new(repo: &Arc<Repository<ObjectID>>, content_type: u64) -> Self
Create a new split stream writer.
Sourcepub fn add_object_ref(&mut self, verity: &ObjectID) -> usize
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().
Sourcepub fn lookup_object_ref(&self, verity: &ObjectID) -> Option<usize>
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.
Sourcepub fn add_named_stream_ref(&mut self, name: &str, verity: &ObjectID)
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.
fn flush_inline(&mut self) -> Result<()>
Sourcepub fn write_inline(&mut self, data: &[u8])
pub fn write_inline(&mut self, data: &[u8])
Write inline data to the stream.
Sourcepub fn add_external_size(&mut self, size: u64)
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.
Sourcepub fn write_reference(&mut self, id: ObjectID) -> Result<()>
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.
Sourcepub fn write_external(&mut self, data: &[u8]) -> Result<()>
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.
Sourcepub async fn write_external_async(&mut self, data: Vec<u8>) -> Result<()>
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.
fn write_named_refs(named_refs: BTreeMap<Box<str>, usize>) -> Result<Vec<u8>>
Sourcepub fn done(self) -> Result<ObjectID>
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.
Sourcepub async fn done_async(self) -> Result<ObjectID>
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.