pub struct Probe<R: Read> { /* private fields */ }Expand description
A format agnostic reader
This provides a way to determine the FileType of a reader, for when a concrete
type is not known.
Usage
When reading from a path, the FileType will be inferred from the path, rather than the
open file.
use lofty::FileType;
let probe = Probe::open("tests/files/assets/minimal/full_test.mp3")?;
// Inferred from the `mp3` extension
assert_eq!(probe.file_type(), Some(FileType::MP3));When a path isn’t available, or is unreliable, content-based detection is also possible.
use lofty::FileType;
// Our same path probe with a guessed file type
let probe = Probe::open("tests/files/assets/minimal/full_test.mp3")?.guess_file_type()?;
// Inferred from the file's content
assert_eq!(probe.file_type(), Some(FileType::MP3));Or with another reader
use lofty::FileType;
use std::io::Cursor;
static MAC_HEADER: &[u8; 3] = b"MAC";
let probe = Probe::new(Cursor::new(MAC_HEADER)).guess_file_type()?;
// Inferred from the MAC header
assert_eq!(probe.file_type(), Some(FileType::APE));Implementations
sourceimpl<R: Read> Probe<R>
impl<R: Read> Probe<R>
sourcepub fn with_file_type(reader: R, file_type: FileType) -> Self
pub fn with_file_type(reader: R, file_type: FileType) -> Self
Create a new Probe with a specified FileType
sourcepub fn set_file_type(&mut self, file_type: FileType)
pub fn set_file_type(&mut self, file_type: FileType)
Set the FileType with which to read the file
sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Extract the reader
sourceimpl Probe<BufReader<File>>
impl Probe<BufReader<File>>
sourcepub fn open<P>(path: P) -> Result<Self> where
P: AsRef<Path>,
pub fn open<P>(path: P) -> Result<Self> where
P: AsRef<Path>,
Opens a file for reading
This will initially guess the FileType from the path, but
this can be overwritten with Probe::guess_file_type or Probe::set_file_type
Errors
pathdoes not exist
sourceimpl<R: Read + Seek> Probe<R>
impl<R: Read + Seek> Probe<R>
sourcepub fn guess_file_type(self) -> Result<Self>
pub fn guess_file_type(self) -> Result<Self>
Attempts to get the FileType based on the data in the reader
On success, the file type will be replaced
Errors
All errors that occur within this function are std::io::Error.
If an error does occur, there is likely an issue with the provided
reader, and the entire Probe should be discarded.
sourcepub fn read(self, read_properties: bool) -> Result<TaggedFile>
pub fn read(self, read_properties: bool) -> Result<TaggedFile>
Attempts to extract a TaggedFile from the reader
If read_properties is false, the properties will be zeroed out.
Errors
- No file type
- This expects the file type to have been set already, either with
Probe::guess_file_typeorProbe::set_file_type. When reading from paths, this is not necessary.
- This expects the file type to have been set already, either with
- The reader contains invalid data
Auto Trait Implementations
impl<R> RefUnwindSafe for Probe<R> where
R: RefUnwindSafe,
impl<R> Send for Probe<R> where
R: Send,
impl<R> Sync for Probe<R> where
R: Sync,
impl<R> Unpin for Probe<R> where
R: Unpin,
impl<R> UnwindSafe for Probe<R> where
R: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more