Skip to content

Commit

Permalink
jpeg: Add example that lists segments in file
Browse files Browse the repository at this point in the history
  • Loading branch information
sophie-h committed Aug 16, 2024
1 parent 15e7d72 commit 26a0575
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions gufo-jpeg/examples/jpeg-dump.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use gufo_jpeg::Jpeg;

fn main() {
let path = std::env::args()
.nth(1)
.expect("First agument must be a file path.");
let data = std::fs::read(path).unwrap();
let jpeg = Jpeg::new(&data);

for segment in jpeg.segments() {
let data_init = segment
.data()
.iter()
.take(50)
.take_while(|x| **x != b'\0')
.filter(|x| x.is_ascii_graphic())
.cloned()
.collect::<Vec<_>>();
let s = String::from_utf8_lossy(&data_init);

println!("{:x?}: {s}", segment.marker());
}
}

0 comments on commit 26a0575

Please sign in to comment.