rev_lines icon indicating copy to clipboard operation
rev_lines copied to clipboard

[Q] Can this lib solve this use case?

Open NightMachinery opened this issue 4 years ago • 0 comments

https://users.rust-lang.org/t/count-trailing-zero-bytes-of-a-binary-file/42503/2

use std::env;
use std::fs;

fn main() {
    let filename = env::args().nth(1).unwrap();
    let buffer = fs::read(filename).unwrap();
    let count = buffer.iter().rev().take_while(|b| **b == 0).count();
    println!("{}", count);
}

There are no new lines as the file is binary.

NightMachinery avatar May 12 '20 20:05 NightMachinery