pub struct FileCommandMimeDetector<'a> { /* private fields */ }Expand description
MIME detector backed by file --mime-type --brief.
Implementations§
Source§impl FileCommandMimeDetector<'static>
impl FileCommandMimeDetector<'static>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a detector using the embedded repository for filename guesses.
§Returns
File command detector.
Sourcepub fn from_mime_config(config: MimeConfig) -> Self
pub fn from_mime_config(config: MimeConfig) -> Self
Source§impl<'a> FileCommandMimeDetector<'a>
impl<'a> FileCommandMimeDetector<'a>
Sourcepub const MIME_TYPE_ARG: &'static str = "--mime-type"
pub const MIME_TYPE_ARG: &'static str = "--mime-type"
Argument enabling MIME type output.
Sourcepub fn with_repository(repository: &'a MimeRepository) -> Self
pub fn with_repository(repository: &'a MimeRepository) -> Self
Sourcepub fn with_repository_and_runner(
repository: &'a MimeRepository,
command_runner: CommandRunner,
) -> Self
pub fn with_repository_and_runner( repository: &'a MimeRepository, command_runner: CommandRunner, ) -> Self
Sourcepub fn with_repository_runner_and_config(
repository: &'a MimeRepository,
command_runner: CommandRunner,
config: MimeConfig,
) -> Self
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 allfilecommand executions.config: MIME detector configuration.
§Returns
File command detector borrowing repository and owning the supplied
runner.
Sourcepub fn core(&self) -> &MimeDetectorCore
pub fn core(&self) -> &MimeDetectorCore
Sourcepub fn core_mut(&mut self) -> &mut MimeDetectorCore
pub fn core_mut(&mut self) -> &mut MimeDetectorCore
Sourcepub fn repository(&self) -> &'a MimeRepository
pub fn repository(&self) -> &'a MimeRepository
Sourcepub fn command_runner(&self) -> &CommandRunner
pub fn command_runner(&self) -> &CommandRunner
Sourcepub fn set_command_runner(&mut self, command_runner: CommandRunner)
pub fn set_command_runner(&mut self, command_runner: CommandRunner)
Replaces the command runner used by this detector.
§Parameters
command_runner: New runner configuration.
Sourcepub fn with_command_runner(self, command_runner: CommandRunner) -> Self
pub fn with_command_runner(self, command_runner: CommandRunner) -> Self
Sourcepub fn detect_file_by_content(&self, file: &Path) -> MimeResult<Option<String>>
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.
Sourcepub fn detect_file(
&self,
file: &Path,
policy: MimeDetectionPolicy,
) -> MimeResult<Option<String>>
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.
Sourcepub fn detect_reader(
&self,
reader: &mut dyn ReadSeek,
filename: Option<&str>,
policy: MimeDetectionPolicy,
) -> MimeResult<Option<String>>
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.
Sourcepub fn is_available() -> bool
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>
impl<'a> Clone for FileCommandMimeDetector<'a>
Source§fn clone(&self) -> FileCommandMimeDetector<'a>
fn clone(&self) -> FileCommandMimeDetector<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Debug for FileCommandMimeDetector<'a>
impl<'a> Debug for FileCommandMimeDetector<'a>
Source§impl Default for FileCommandMimeDetector<'static>
impl Default for FileCommandMimeDetector<'static>
Source§impl<'a> FileBasedMimeDetector for FileCommandMimeDetector<'a>
impl<'a> FileBasedMimeDetector for FileCommandMimeDetector<'a>
Source§fn core(&self) -> &MimeDetectorCore
fn core(&self) -> &MimeDetectorCore
Gets the shared detector core.
Source§fn max_test_bytes(&self) -> usize
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>
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>>
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§
impl<'a> Freeze for FileCommandMimeDetector<'a>
impl<'a> !RefUnwindSafe for FileCommandMimeDetector<'a>
impl<'a> Send for FileCommandMimeDetector<'a>
impl<'a> Sync for FileCommandMimeDetector<'a>
impl<'a> Unpin for FileCommandMimeDetector<'a>
impl<'a> UnsafeUnpin for FileCommandMimeDetector<'a>
impl<'a> !UnwindSafe for FileCommandMimeDetector<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, D> IntoConfigDefault<T> for Dwhere
D: IntoValueDefault<T>,
impl<T, D> IntoConfigDefault<T> for Dwhere
D: IntoValueDefault<T>,
Source§fn into_config_default(self) -> T
fn into_config_default(self) -> T
T.Source§impl<T> IntoValueDefault<T> for T
impl<T> IntoValueDefault<T> for T
Source§fn into_value_default(self) -> T
fn into_value_default(self) -> T
Source§impl<T> MimeDetector for Twhere
T: MimeDetectorBackend,
impl<T> MimeDetector for Twhere
T: MimeDetectorBackend,
Source§fn detect_by_filename(&self, filename: &str) -> Option<String>
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>
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>
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>
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>
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 Twhere
T: StreamBasedMimeDetector,
impl<T> MimeDetectorBackend for Twhere
T: StreamBasedMimeDetector,
Source§fn core(&self) -> &MimeDetectorCore
fn core(&self) -> &MimeDetectorCore
Gets the shared detector core.
Source§fn max_test_bytes(&self) -> usize
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>
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>
fn guess_from_content(&self, content: &[u8]) -> Result<Vec<String>, MimeError>
Guesses MIME type names from content bytes.
Source§impl<T> StreamBasedMimeDetector for Twhere
T: FileBasedMimeDetector,
impl<T> StreamBasedMimeDetector for Twhere
T: FileBasedMimeDetector,
Source§fn core(&self) -> &MimeDetectorCore
fn core(&self) -> &MimeDetectorCore
Gets the shared detector core.
Source§fn max_test_bytes(&self) -> usize
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>
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>
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>
fn guess_from_file_stream( &self, file: &Path, ) -> Result<(Vec<String>, Vec<u8>), MimeError>
Delegates local-file inspection to the file-based hook.