Skip to main content

ArchiveWriter

Struct ArchiveWriter 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn build(&mut self) -> Result<Archive, SigmfError>

Finalizes the tar file, publishes it at the destination path, and returns the loaded Archive.

§Errors

Returns an error if the writer was already built, the written archive does not load (for example, it has no recordings), or the destination was created by someone else in the meantime.

Source

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

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more