-
-
Save BurntSushi/37cf13595516acda9bd45e5003be4ea9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate walkdir; | |
use walkdir::WalkDir; | |
use std::fs::File; | |
use std::io::Read; | |
fn main() { | |
let nul = 0; | |
let mut bytes_count: i32; | |
for entry in WalkDir::new("./").into_iter().filter_map(|e| e.ok()) { | |
if entry.file_type().is_file() { | |
let mut file = File::open(entry.path()).unwrap(); | |
bytes_count = 0; | |
let mut s: Vec<u8> = Vec::with_capacity(file.metadata().unwrap().len() as usize); | |
file.read_to_end(&mut s).unwrap(); | |
for b in s.into_iter() { | |
if b == nul { | |
println!("{} bytes={} binary file", entry.path().display(), bytes_count); | |
break | |
} | |
bytes_count += 1; | |
} | |
println!("{} bytes={}", entry.path().display(), bytes_count) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment