Skip to main content

FileCommandMimeDetector

Struct FileCommandMimeDetector 

Source
pub struct FileCommandMimeDetector<'a> { /* private fields */ }
Expand description

MIME detector backed by file --mime-type --brief.

Implementations§

Source§

impl FileCommandMimeDetector<'static>

Source

pub fn new() -> Self

Creates a detector using the embedded repository for filename guesses.

§Returns

File command detector.

Source

pub fn from_mime_config(config: MimeConfig) -> Self

Creates a detector using the embedded repository and explicit config.

§Parameters
  • config: MIME detector configuration.
§Returns

File command detector.

Source§

impl<'a> FileCommandMimeDetector<'a>

Source

pub const COMMAND: &'static str = "file"

System command executable name.

Source

pub const MIME_TYPE_ARG: &'static str = "--mime-type"

Argument enabling MIME type output.

Source

pub const BRIEF_ARG: &'static str = "--brief"

Argument enabling concise output.

Source

pub fn with_repository(repository: &'a MimeRepository) -> Self

Creates a detector using an explicit repository for filename guesses.

§Parameters
  • repository: Repository used for filename detection.
§Returns

File command detector borrowing repository.

Source

pub fn with_repository_and_runner( repository: &'a MimeRepository, command_runner: CommandRunner, ) -> Self

Creates a detector using an explicit repository and command runner.

§Parameters
  • repository: Repository used for filename detection.
  • command_runner: Runner used for all file command executions.
§Returns

File command detector borrowing repository and owning the supplied runner.

Source

pub fn with_repository_runner_and_config( repository: &'a MimeRepository, command_runner: CommandRunner, config: MimeConfig, ) -> Self

Creates a detector using an explicit repository, runner, and config.

§Parameters
  • repository: Repository used for filename detection.
  • command_runner: Runner used for all file command executions.
  • config: MIME detector configuration.
§Returns

File command detector borrowing repository and owning the supplied runner.

Source

pub fn core(&self) -> &MimeDetectorCore

Gets the shared detector core.

§Returns

Shared detector core.

Source

pub fn core_mut(&mut self) -> &mut MimeDetectorCore

Gets mutable shared detector core.

§Returns

Mutable shared detector core.

Source

pub fn repository(&self) -> &'a MimeRepository

Gets the repository used for filename detection.

§Returns

Repository reference.

Source

pub fn command_runner(&self) -> &CommandRunner

Gets the command runner used by this detector.

§Returns

Runner used for file command executions.

Source

pub fn set_command_runner(&mut self, command_runner: CommandRunner)

Replaces the command runner used by this detector.

§Parameters
  • command_runner: New runner configuration.
Source

pub fn with_command_runner(self, command_runner: CommandRunner) -> Self

Replaces the command runner and returns the updated detector.

§Parameters
  • command_runner: New runner configuration.
§Returns

The updated detector.

Source

pub fn detect_file_by_content(&self, file: &Path) -> MimeResult<Option<String>>

Detects content from a local file using the file command only.

§Parameters
  • file: Local file path to inspect.
§Returns

MIME type name, or None.

§Errors

Returns MimeError::Command when the command cannot be executed.

Source

pub fn detect_file( &self, file: &Path, policy: MimeDetectionPolicy, ) -> MimeResult<Option<String>>

Detects a local file from filename and content.

§Parameters
  • file: Local file path.
  • policy: Strategy for resolving filename and content results.
§Returns

Selected MIME type name, or None.

§Errors

Returns MimeError::Command when command execution fails.

Source

pub fn detect_reader( &self, reader: &mut dyn ReadSeek, filename: Option<&str>, policy: MimeDetectionPolicy, ) -> MimeResult<Option<String>>

Detects a seekable reader by staging its prefix to a temporary file.

§Parameters
  • reader: Reader to inspect. The original position is restored.
  • filename: Optional filename.
  • policy: Strategy for resolving filename and content results.
§Returns

Selected MIME type name, or None.

§Errors

Returns MimeError::Io when stream operations fail.

Source

pub fn is_available() -> bool

Checks whether the file command is available.

Availability is checked by executing file --mime-type --brief . with a quiet command runner. This only validates that the command can be started successfully in the current process environment; it does not guarantee that every future file path can be inspected.

§Returns

true when the command can be executed.

Trait Implementations§

Source§

impl<'a> Clone for FileCommandMimeDetector<'a>

Source§

fn clone(&self) -> FileCommandMimeDetector<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for FileCommandMimeDetector<'a>

Source§

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

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

impl Default for FileCommandMimeDetector<'static>

Source§

fn default() -> Self

Creates a detector using the embedded repository.

Source§

impl<'a> FileBasedMimeDetector for FileCommandMimeDetector<'a>

Source§

fn core(&self) -> &MimeDetectorCore

Gets the shared detector core.

Source§

fn max_test_bytes(&self) -> usize

Gets the maximum content prefix length from the repository.

Source§

fn guess_from_filename(&self, filename: &str) -> Vec<String>

Guesses MIME type names from filename rules.

Source§

fn guess_from_local_file(&self, file: &Path) -> MimeResult<Vec<String>>

Guesses MIME type names from a local file using the file command.

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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, D> IntoConfigDefault<T> for D
where D: IntoValueDefault<T>,

Source§

fn into_config_default(self) -> T

Converts this fallback value into T.
Source§

impl<T> IntoValueDefault<T> for T

Source§

fn into_value_default(self) -> T

Converts this argument into the default value.
Source§

impl<T> MimeDetector for T

Source§

fn detect_by_filename(&self, filename: &str) -> Option<String>

Detects a MIME type from filename candidates.

Source§

fn detect_by_content(&self, content: &[u8]) -> Option<String>

Detects a MIME type from content candidates.

Source§

fn detect( &self, content: &[u8], filename: Option<&str>, policy: MimeDetectionPolicy, ) -> Option<String>

Detects a MIME type from content bytes and an optional filename.

Source§

fn detect_reader( &self, reader: &mut dyn ReadSeek, filename: Option<&str>, policy: MimeDetectionPolicy, ) -> Result<Option<String>, MimeError>

Detects a MIME type from a seekable reader.

Source§

fn detect_file( &self, file: &Path, policy: MimeDetectionPolicy, ) -> Result<Option<String>, MimeError>

Detects a MIME type from a local file.

Source§

impl<T> MimeDetectorBackend for T

Source§

fn core(&self) -> &MimeDetectorCore

Gets the shared detector core.

Source§

fn max_test_bytes(&self) -> usize

Gets the maximum content prefix length needed by this detector.

Source§

fn guess_from_filename(&self, filename: &str) -> Vec<String>

Guesses MIME type names from filename rules.

Source§

fn guess_from_content(&self, content: &[u8]) -> Result<Vec<String>, MimeError>

Guesses MIME type names from content bytes.

Source§

fn guess_from_reader( &self, reader: &mut dyn ReadSeek, ) -> Result<(Vec<String>, Vec<u8>), MimeError>

Delegates reader inspection to the stream-based hook.

Source§

fn guess_from_file( &self, file: &Path, ) -> Result<(Vec<String>, Vec<u8>), MimeError>

Delegates local-file inspection to the stream-based hook.

Source§

impl<T> StreamBasedMimeDetector for T

Source§

fn core(&self) -> &MimeDetectorCore

Gets the shared detector core.

Source§

fn max_test_bytes(&self) -> usize

Gets the maximum content prefix length needed by this detector.

Source§

fn guess_from_filename(&self, filename: &str) -> Vec<String>

Guesses MIME type names from filename rules.

Source§

fn guess_from_content_bytes( &self, content: &[u8], ) -> Result<Vec<String>, MimeError>

Stages content to a temporary local file before inspection.

Source§

fn guess_from_file_stream( &self, file: &Path, ) -> Result<(Vec<String>, Vec<u8>), MimeError>

Delegates local-file inspection to the file-based hook.

Source§

fn guess_from_reader_stream( &self, reader: &mut dyn ReadSeek, ) -> MimeResult<(Vec<String>, Vec<u8>)>

Guesses MIME type names from a seekable reader. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.