pub struct ArchiveWriter { /* private fields */ }Expand description
Builds a new .sigmf archive.
Members are streamed into a hidden temporary file next to the destination,
which is only published at the destination path by ArchiveWriter::build.
An existing destination is never overwritten.
§Examples
use sigmf::{datatype::Datatype, global::Global, meta::Metadata, ArchiveWriter};
use std::str::FromStr;
let metadata = Metadata::new(Global::new("1.2.6", Datatype::from_str("ru8")?), vec![], vec![]);
let mut writer = ArchiveWriter::new(path)?;
writer.add("ramp", metadata, &[0, 1, 2, 3])?;
let archive = writer.build()?;
assert_eq!(archive.get_names(), ["ramp"]);Implementations§
Source§impl ArchiveWriter
impl ArchiveWriter
Sourcepub fn new(path: String) -> Result<Self, SigmfError>
pub fn new(path: String) -> Result<Self, SigmfError>
Starts a new archive that will be published at path.
§Errors
Returns an error if path does not end in .sigmf, already exists, or
a temporary file cannot be created in its directory.
Sourcepub fn add_meta(
&mut self,
filename: &str,
meta: Metadata,
) -> Result<(), SigmfError>
pub fn add_meta( &mut self, filename: &str, meta: Metadata, ) -> Result<(), SigmfError>
Appends <filename>.sigmf-meta without a dataset.
Use this for metadata-only recordings, or pair it with
ArchiveWriter::add_data. Prefer ArchiveWriter::add, which also
fills in core:sha512.
§Errors
Returns SigmfError::InvalidMetadata if filename is unsafe or
already used, or if the metadata fails
ValidationPolicy::Interoperability.
Sourcepub fn add_data(
&mut self,
filename: &str,
data: &[u8],
) -> Result<(), SigmfError>
pub fn add_data( &mut self, filename: &str, data: &[u8], ) -> Result<(), SigmfError>
Appends raw dataset bytes as <filename>.sigmf-data.
The bytes are written as-is; no digest is computed or checked.
§Errors
Returns SigmfError::InvalidMetadata if filename is unsafe or the
dataset member already exists.
Sourcepub fn add(
&mut self,
filename: &str,
meta: Metadata,
data: &[u8],
) -> Result<(), SigmfError>
pub fn add( &mut self, filename: &str, meta: Metadata, data: &[u8], ) -> Result<(), SigmfError>
Appends a recording: its metadata and its encoded dataset bytes.
core:sha512 is set to the SHA-512 digest of data. The dataset member
is <filename>.sigmf-data, or the file named by core:dataset (in the
same archive directory as the metadata) when that field is present.
§Errors
Returns SigmfError::HashMismatch if the metadata already declares a
different core:sha512, SigmfError::UnsupportedLayout for
metadata-only recordings, or any error from
ArchiveWriter::add_meta.
Sourcepub fn add_collection(
&mut self,
filename: &str,
collection: Collection,
) -> Result<(), SigmfError>
pub fn add_collection( &mut self, filename: &str, collection: Collection, ) -> Result<(), SigmfError>
Appends a top-level <filename>.sigmf-collection member.
Stream hashes in core:streams are updated to the digests of metadata
members already added to this writer, so add recordings first.
§Errors
Returns SigmfError::InvalidMetadata if filename is not a safe
top-level name or the collection fails validation.
Sourcepub fn build(&mut self) -> Result<Archive, SigmfError>
pub fn build(&mut self) -> Result<Archive, SigmfError>
Sourcepub fn load(path: &str) -> Result<Archive, SigmfError>
pub fn load(path: &str) -> Result<Archive, SigmfError>
Opens and indexes a .sigmf tar archive; see Archive::load.
Trait Implementations§
Source§impl Drop for ArchiveWriter
impl Drop for ArchiveWriter
Auto Trait Implementations§
impl Freeze for ArchiveWriter
impl RefUnwindSafe for ArchiveWriter
impl Send for ArchiveWriter
impl Sync for ArchiveWriter
impl Unpin for ArchiveWriter
impl UnsafeUnpin for ArchiveWriter
impl UnwindSafe for ArchiveWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more