pub struct DataFile<T> { /* private fields */ }Expand description
Data file (MMR) wrapper around an append-only file.
Implementations§
Source§impl<T> DataFile<T>
impl<T> DataFile<T>
Sourcepub fn open<P>(
path: P,
size_info: SizeInfo,
version: ProtocolVersion,
) -> Result<DataFile<T>>
pub fn open<P>( path: P, size_info: SizeInfo, version: ProtocolVersion, ) -> Result<DataFile<T>>
Open (or create) a file at the provided path on disk.
Sourcepub fn append(&mut self, data: &T) -> Result<u64>
pub fn append(&mut self, data: &T) -> Result<u64>
Append an element to the file. Will not be written to disk until flush() is subsequently called. Alternatively discard() may be called to discard any pending changes.
Sourcepub fn extend_from_slice(&mut self, data: &[T]) -> Result<u64>
pub fn extend_from_slice(&mut self, data: &[T]) -> Result<u64>
Append a slice of multiple elements to the file. Will not be written to disk until flush() is subsequently called. Alternatively discard() may be called to discard any pending changes.
Sourcepub fn read(&self, position: u64) -> Option<T>
pub fn read(&self, position: u64) -> Option<T>
Read an element from the file by position. Assumes we have already “shifted” the position to account for pruned data. Note: PMMR API is 1-indexed, but backend storage is 0-indexed.
Makes no assumptions about the size of the elements in bytes. Elements can be of variable size (handled internally in the append-only file impl).
Sourcepub fn write_tmp_pruned(&self, prune_pos: &[u64]) -> Result<()>
pub fn write_tmp_pruned(&self, prune_pos: &[u64]) -> Result<()>
Write the file out to disk, pruning removed elements.
Sourcepub fn replace_with_tmp(&mut self) -> Result<()>
pub fn replace_with_tmp(&mut self) -> Result<()>
Replace with file at tmp path. Rebuild and initialize from new file.