pub enum Buffer {
InMemory(Vec<u8>),
Spilled {
writer: BufWriter<NamedTempFile>,
len: u64,
},
}Expand description
The buffered input. Transitions from in-memory to spilled as data accumulates.
Variants§
InMemory(Vec<u8>)
In-memory accumulation (small inputs).
Spilled
Spilled-to-tempfile accumulation (large inputs).
Fields
writer: BufWriter<NamedTempFile>Implementations§
Source§impl Buffer
impl Buffer
Sourcepub fn drain_reader<R: Read>(
&mut self,
reader: R,
threshold: usize,
spill_dir: &Path,
) -> Result<()>
pub fn drain_reader<R: Read>( &mut self, reader: R, threshold: usize, spill_dir: &Path, ) -> Result<()>
Drain the entire reader into this buffer, transitioning to the
spilled variant when the accumulated size would exceed threshold.
spill_dir is the directory in which the spill tempfile is created
when the transition triggers. Caller MUST pass the target file’s
parent directory (HINT-002).
On the binary path (feature cli), the loop polls the process-wide
cancellation flag between chunks; if a signal was delivered, the
drain returns io::ErrorKind::Interrupted so the in-progress
tempfile is dropped via the normal Drop chain before exit.
Sourcepub fn append(
&mut self,
bytes: &[u8],
threshold: usize,
spill_dir: &Path,
) -> Result<()>
pub fn append( &mut self, bytes: &[u8], threshold: usize, spill_dir: &Path, ) -> Result<()>
Append a slice of bytes, transitioning to spilled storage if doing so
would push the buffer past threshold.
Sourcepub fn transition_to_spilled(&mut self, spill_dir: &Path) -> Result<()>
pub fn transition_to_spilled(&mut self, spill_dir: &Path) -> Result<()>
Promote an InMemory buffer to a Spilled one, flushing the existing
bytes into the new tempfile. No-op if already spilled.