Skip to main content

RadFileWriter

Struct RadFileWriter 

Source
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>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<W> Freeze for RadFileWriter<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for RadFileWriter<W>
where W: RefUnwindSafe,

§

impl<W> Send for RadFileWriter<W>
where W: Send,

§

impl<W> Sync for RadFileWriter<W>
where W: Sync,

§

impl<W> Unpin for RadFileWriter<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for RadFileWriter<W>
where W: UnsafeUnpin,

§

impl<W> UnwindSafe for RadFileWriter<W>
where W: UnwindSafe,

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.