Function file_is_text

Source
pub fn file_is_text<P: AsRef<Path>>(path: P) -> Result<bool>
Expand description

Determine if a file contains text or binary data.

This function reads the first 1KB of a file to determine if it contains text or binary data, using a similar algorithm to the file command.

§Arguments

  • path - Path to the file to analyze

§Returns

true if the file appears to contain text, false if binary.

§Errors

Returns an error if the file cannot be opened or read.

§Examples

use file_identify::file_is_text;

assert!(file_is_text(&text_path).unwrap());

assert!(!file_is_text(&binary_path).unwrap());