Skip to main content

Archive

Struct Archive 

Source
pub struct Archive {
    pub collection: Option<Collection>,
    pub collection_name: Option<String>,
    pub recordings: Vec<RecordingRef>,
    pub archive_path: Option<String>,
    /* private fields */
}
Expand description

An opened .sigmf archive: a tar file of recordings and an optional collection.

Metadata members are indexed and parsed when the archive is loaded; dataset members are read lazily on request. Each recording::RecordingRef carries the SHA-512 digest of its metadata member, which is re-checked whenever the metadata is read back from the archive.

An archive created with Default has no archive_path; in that case recordings are resolved as <name>.sigmf-meta and <name>.sigmf-data files in the current working directory.

§Examples

let archive = sigmf::Archive::load("recordings.sigmf")?;
for recording in archive.get_recordings() {
    let metadata = archive.get_meta_from_recording(&recording)?;
    println!("{}: {}", recording.get_name(), metadata.global().datatype);
}

Fields§

§collection: Option<Collection>

The archive’s .sigmf-collection object, if it has one.

§collection_name: Option<String>

Name (file stem) of the collection member, e.g. "collection" for collection.sigmf-collection.

§recordings: Vec<RecordingRef>

References to the recordings in the archive, in member order.

§archive_path: Option<String>

Filesystem path of the .sigmf tar file backing this archive.

Implementations§

Source§

impl Archive

Source

pub fn validate_collection_references(&self) -> Option<ValidationReport>

Checks that the archive’s collection streams resolve to its recordings.

Each core:streams entry is matched by name against the archive’s recordings. A missing recording yields an unresolved-recording-reference warning (making the status ValidationStatus::NotChecked); a recording whose metadata hash differs (case-insensitively) from the reference yields a collection-reference-digest-mismatch error.

Returns None if the archive has no collection.

Source§

impl Archive

Source

pub fn new(path: String) -> Self

Creates an empty archive handle pointing at path without reading it.

Use Archive::load to open and index an existing archive.

Source

pub fn load(path: &str) -> Result<Self, SigmfError>

Opens and indexes a .sigmf tar archive.

All .sigmf-meta members are parsed and at most one top-level .sigmf-collection member is accepted. Equivalent to ArchiveWriter::load.

§Errors

Returns an error if path does not end in .sigmf, cannot be read, is not a valid tar file, contains unsafe or duplicate member paths, non-regular members, invalid metadata, oversized (> 1 MB) metadata, or no recordings.

Source

pub fn save(&self, save_path: &str) -> Result<(), SigmfError>

Writes a new .sigmf archive at save_path containing only this archive’s current recordings.

Members are copied from the source archive at archive_path. Metadata and dataset members of recordings that were removed (for example by retain_recordings_with_minimum_frames) are dropped, other members are preserved, and the collection is replaced when collection is set. The destination must not already exist.

§Errors

Returns an error if the source path is unset, the destination exists, a referenced member is missing, or a metadata digest no longer matches its recording::RecordingRef.

Source

pub fn retain_recordings_with_minimum_frames( &mut self, minimum_frames: Integer, ) -> Result<(), SigmfError>

Removes recordings whose datasets hold fewer than minimum_frames frames.

Frame counts are derived from member sizes, core:num_channels, core:datatype, NCD core:header_bytes, and core:trailing_bytes without reading sample data. Metadata-only recordings count as zero frames.

§Errors

Returns an error if metadata cannot be read or a dataset layout is inconsistent with its size. On error the recordings are left unchanged.

Source

pub fn set_recordings(&mut self, recordings: Vec<RecordingRef>)

Replaces the list of recording references.

Source

pub fn set_collection(&mut self, collection: Collection)

Sets the collection, naming it collection if no name is set yet.

Source

pub fn set_collection_member( &mut self, name: impl Into<String>, collection: Collection, ) -> Result<(), SigmfError>

Sets the collection along with its archive member name (file stem).

§Errors

Returns SigmfError::InvalidMetadata if name is not a safe, top-level member name.

Source

pub fn set_path(&mut self, path: &str)

Sets the path of the backing .sigmf file.

Source

pub fn add_recording(&mut self, recording: RecordingRef)

Appends a recording reference.

Source

pub fn add_collection(&mut self, collection: Collection)

Sets the collection; alias for Archive::set_collection.

Source

pub fn get_recordings(&self) -> Vec<RecordingRef>

Returns a copy of the recording references.

Source

pub fn get_collection(&self) -> Option<Collection>

Returns a copy of the collection, if any.

Source

pub fn get_path(&self) -> Option<String>

Returns the path of the backing .sigmf file, if set.

Source

pub fn get_names(&self) -> Vec<String>

Returns the name of every recording, in order.

A recording’s name is its member path without the .sigmf-meta extension, e.g. "dir/burst" for dir/burst.sigmf-meta.

Source

pub fn get_recording_from_name(&self, name: &str) -> Option<RecordingRef>

Finds a recording reference by name.

Source

pub fn get_meta_from_recording( &self, recording: &RecordingRef, ) -> Result<Metadata, SigmfError>

Returns the parsed metadata for recording.

Metadata parsed at load time is reused when its digest still matches; otherwise the member is re-read and its SHA-512 digest is checked against RecordingRef::get_hash.

§Errors

Returns SigmfError::HashMismatch if the digest differs, SigmfError::NotFound if the member is missing, or a parse error.

Source

pub fn get_meta_from_name(&self, name: &str) -> Result<Metadata, SigmfError>

Returns the parsed metadata for the recording called name.

§Errors

Returns SigmfError::NotFound if no recording has that name, or any error from Archive::get_meta_from_recording.

Source

pub fn get_samples_from_recording( &self, recording: &RecordingRef, ) -> Result<Vec<SampleValue>, SigmfError>

Reads and decodes every sample of recording into memory.

See Archive::get_samples_from_name.

Source

pub fn get_samples_from_name( &self, name: &str, ) -> Result<Vec<SampleValue>, SigmfError>

Reads and decodes every sample of the recording called name into memory.

Samples are returned frame by frame, interleaved across core:num_channels. The whole dataset member is decoded as plain samples, so use recording_file::Recording for NCD datasets or for streaming large recordings.

§Errors

Returns SigmfError::NoDataset for metadata-only recordings, or an error if the dataset cannot be read or does not hold whole frames.

Trait Implementations§

Source§

impl Debug for Archive

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Archive

Source§

fn default() -> Self

Returns the “default value” for a type. 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