pub struct RadFileWriter<W: Write + Seek> { /* private fields */ }Expand description
A writer for a complete RAD file.
Constructed via RadFileWriter::new, which immediately writes the prelude
schema and file-level tag values and records the byte offset of the
num_chunks field for later backpatching.
Use RadFileWriter::write_chunk or RadFileWriter::write_chunk_bytes to
append chunks, then RadFileWriter::finalize to backpatch and flush.
Implementations§
Source§impl<W: Write + Seek> RadFileWriter<W>
impl<W: Write + Seek> RadFileWriter<W>
Sourcepub fn new(
writer: W,
prelude: &RadPrelude,
file_tag_values: &TagMap,
) -> Result<Self>
pub fn new( writer: W, prelude: &RadPrelude, file_tag_values: &TagMap, ) -> Result<Self>
Create a new RadFileWriter.
Writes the prelude schema (header + three tag-section descriptions) and
the file-level tag values to writer, then records the byte offset of
the num_chunks field so it can be backpatched in Self::finalize.
Sourcepub fn backpatch_file_tag_value(
&mut self,
name: &str,
value: &TagValue,
) -> Result<()>
pub fn backpatch_file_tag_value( &mut self, name: &str, value: &TagValue, ) -> Result<()>
Overwrite a previously-written file-tag value in place. The new value
must serialize to exactly the same number of bytes as the placeholder
written by Self::new (true for fixed-length arrays / fixed-width
scalars). Intended for values that are only known after the chunks have
streamed — e.g. a fragment-length distribution or abundance estimates
computed during the pass. Seeks are absolute, so this composes with the
num_chunks backpatch in Self::finalize; call it before finalize.
Sourcepub fn write_chunk<R: MappedRecord>(
&mut self,
chunk: &Chunk<R>,
ctx: &R::ParsingContext,
) -> Result<()>
pub fn write_chunk<R: MappedRecord>( &mut self, chunk: &Chunk<R>, ctx: &R::ParsingContext, ) -> Result<()>
Write a fully-typed Chunk to the file.
Internally delegates to Chunk::write, which uses seeking to backpatch
the per-chunk nbytes field.
Sourcepub fn write_chunk_bytes(&mut self, bytes: &[u8]) -> Result<()>
pub fn write_chunk_bytes(&mut self, bytes: &[u8]) -> Result<()>
Append raw chunk bytes produced by [ChunkBuf::into_bytes].
The bytes must already contain the complete chunk header (nbytes + nrec)
followed by all record bytes. This is the low-overhead path for multi-threaded
writing where worker threads build chunks in local [ChunkBuf]s.
Sourcepub fn finalize(self) -> Result<W>
pub fn finalize(self) -> Result<W>
Backpatch the num_chunks field in the header, flush the writer, and
return the inner W.
This must be called after all chunks have been written. Any outstanding
Arc clones of the inner writer (e.g. held by a ConcurrentChunkWriter)
must be dropped before calling this.