1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::fs::File;
use std::{env};
use std::path::Path;
use std::io::{Write, BufReader, BufRead, Error,Read};
const CHUNKSIZE:usize= 8192;
pub fn is_binary_file(file_path :&str) -> Option<bool> {
let mut read_size =CHUNKSIZE;
let path = Path::new(&file_path);
let file_size =path.metadata().unwrap().len() as usize;
if read_size > file_size {
read_size =file_size;
}
let mut buffer=[0;CHUNKSIZE];
let mut _inputfile = File::open(&file_path).unwrap();
_inputfile.read(&mut buffer).unwrap();
let mut i=0;
while(i<read_size){
if (buffer[i] ==0) {
return Some(true);
}
i=i+1;
}
Some(false)
}