From a2c00337bc9bac1942ad835181ae09f8a66d524b Mon Sep 17 00:00:00 2001 From: 53hornet Date: Thu, 5 Aug 2021 11:09:04 -0400 Subject: init --- src/main.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main.rs (limited to 'src') diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..da0e599 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,37 @@ +use std::{env, fs::File, io::Read}; + +fn main() -> Result<(), Box> { + const CHUNK_SIZE: usize = 8; + + let filename = env::args().nth(1).unwrap_or_default(); + if filename.is_empty() { + eprintln!("error missing filename"); + return Ok(()); + } + + let mut file = File::open(&filename)?; + let mut chunk = Vec::with_capacity(CHUNK_SIZE); + let mut idx = 0; + + while { + chunk.clear(); + file.by_ref() + .take(CHUNK_SIZE as u64) + .read_to_end(&mut chunk)? + > 0 + } { + // write index + print!("{:010}: ", idx); + + // write hex + for byte in &chunk { + print!("{:02X} ", byte); + } + + // write ascii + println!("{}", String::from_utf8_lossy(&chunk).replace('\n', "⏎")); + idx += CHUNK_SIZE; + } + + Ok(()) +} -- cgit v1.2.3