read_tag/
read_tag.rs

1use multitag::Tag;
2use std::env::args;
3use std::fs::File;
4use std::io::Cursor;
5use std::io::Read;
6use std::path::PathBuf;
7
8fn main() {
9    let path = PathBuf::from(args().nth(1).unwrap());
10
11    // Option 1: read from path
12    let tag = Tag::read_from_path(&path).unwrap();
13    println!("{:#?}", tag.title());
14
15    // Option 2: read from reader
16    let mut f = File::open(&path).unwrap();
17
18    let mut data = Vec::new();
19    f.read_to_end(&mut data).unwrap();
20
21    let cursor = Cursor::new(data);
22    // You can also just pass in f instead of creating a cursor since Files are Read + Seek
23    let extension = path.extension().unwrap().to_str().unwrap();
24    let tag = Tag::read_from(extension, cursor).unwrap();
25    println!("{:#?}", tag.title());
26}