Struct File

Source
pub struct File { /* private fields */ }
Expand description

An .sdf file.

The file is mostly a simple wrapper around an fwifc_file handle, but we do a bit of extra smarts (or dumbs) to help other users.

  • We ensure that we reindex the file only once, regardless of the number of times that reindex has been called.

Implementations§

Source§

impl File

Source

pub fn open<T: Into<Vec<u8>>>(path: T) -> Result<File>

Opens an .sdf data file.

§Examples
use sdf::file::File;
let file = File::open("data/110630_174316.sdf").unwrap();
Source

pub fn reindex(&mut self) -> Result<()>

(Re-)Creates the index file.

The index file is required for navigating the file. This is a blocking operation and may take some time. The index file is placed in the same directory as the data file.

§Examples
use sdf::file::File;
let mut file = File::open("data/110630_174316.sdf").unwrap();
file.reindex().unwrap();
Source

pub fn remove_index(&self) -> Result<()>

Remove this file’s index from the filesystem.

§Examples
use sdf::file::File;
let mut file = File::open("data/110630_174316.sdf").unwrap();
file.reindex().unwrap();
file.remove_index().unwrap();
Source

pub fn set_sosbl_mode(&mut self, mode: SosblMode) -> Result<()>

Sets the mode timestamp of the start of the sample block.

§Examples
use sdf::file::{File, SosblMode};
let mut file = File::open("data/110630_174316.sdf").unwrap();
file.set_sosbl_mode(SosblMode::Relative).unwrap();
file.set_sosbl_mode(SosblMode::Absolute).unwrap();
Source

pub fn info(&mut self) -> Result<FileInfo>

Gets information about the file.

§Examples
use sdf::file::File;
let mut file = File::open("data/110630_174316.sdf").unwrap();
let file_info = file.info();
Source

pub fn calibration(&mut self, kind: CalibrationTableKind) -> Result<Calibration>

Gets the calibration info for the file.

We manually copy all of the calibration info into new vectors because we can’t really trust the memory behind the fwifc call.

§Examples
use sdf::file::{File, CalibrationTableKind, Channel};
let mut file = File::open("data/110630_174316.sdf").unwrap();
let calibration = file.calibration(CalibrationTableKind::Amplitude(Channel::High)).unwrap();
Source

pub fn read(&mut self) -> Result<Record>

Reads a sample data record from the file.

§Panics

Panics if the underlying sdfifc library returns a record with two blocks with the same channel. We assume that this can’t happen, and so we panic (rather than returning an error) to indicate that this is a very exceptional case.

§Examples
use sdf::file::File;
let mut file = File::open("data/110630_174316.sdf").unwrap();
file.reindex().unwrap();
let record = file.read().unwrap();
Source

pub fn seek(&mut self, index: u32) -> Result<()>

Seeks to a record index in the file.

§Examples

Seeks to the first record.

use sdf::file::File;
let mut file = File::open("data/110630_174316.sdf").unwrap();
file.reindex().unwrap();
file.seek(1).unwrap();

Seeks to the end of the file.

use std::u32;
use sdf::file::File;
let mut file = File::open("data/110630_174316.sdf").unwrap();
file.reindex().unwrap();
file.seek(u32::MAX).unwrap();
Source

pub fn seek_time(&mut self, time: f64) -> Result<()>

Seeks to an internal timestamp, in seconds.

§Examples
use sdf::file::File;
let mut file = File::open("data/110630_174316.sdf").unwrap();
file.reindex().unwrap();
file.seek_time(1.0).unwrap();
Source

pub fn seek_time_external(&mut self, time: f64) -> Result<()>

Seeks to an external time in seconds.

Either day or week seconds. This requires GPS-synchronized data.

§Examples
use sdf::file::File;
let mut file = File::open("data/110630_174316.sdf").unwrap();
file.reindex().unwrap();
file.seek_time_external(1.0).unwrap();
Source

pub fn tell(&mut self) -> Result<u32>

Returns the index of the next record to be read.

§Examples
use sdf::file::File;
let mut file = File::open("data/110630_174316.sdf").unwrap();
file.reindex().unwrap();
assert_eq!(1, file.tell().unwrap());
file.read().unwrap();
assert_eq!(2, file.tell().unwrap());
Source

pub fn indexed(&self) -> bool

Returns true if this file is indexed.

§Examples
use sdf::file::File;
let file = File::open("data/110630_174316.sdf").unwrap();
file.indexed();

Trait Implementations§

Source§

impl Debug for File

Source§

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

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

impl Drop for File

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl IntoIterator for File

Source§

type Item = Record

The type of the elements being iterated over.
Source§

type IntoIter = FileIterator

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl Freeze for File

§

impl RefUnwindSafe for File

§

impl !Send for File

§

impl !Sync for File

§

impl Unpin for File

§

impl UnwindSafe for File

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.