1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use cuet::{parse_cue_points, WaveCursor};
use std::env::args;
use std::fs::File;
use std::io;

fn main() {
    let mut arguments = args();

    let wav_path = if let Some(path) = arguments.nth(1) {
        path
    } else {
        panic!("No argument for path");
    };

    let file = File::open(wav_path).unwrap();
    let reader = io::BufReader::new(file);
    let mut wave_cursor = WaveCursor::new(reader).unwrap();

    while let Some((tag, chunk)) = wave_cursor.read_next_chunk(None).unwrap() {
        let tag_s = tag.iter().map(|&b| b as char).collect::<String>();
        println!(
            "Found \"{}\" chunk that's {} bytes long",
            tag_s,
            chunk.len()
        );

        if tag == *b"LIST" {
            let ltype = &chunk[..4];
            let ltype_s = ltype.iter().map(|&b| b as char).collect::<String>();
            println!("\tLIST type = \"{}\"", ltype_s);

            if ltype == *b"adtl" {
                let sctype = &chunk[4..8];
                let sctype_s =
                    sctype.iter().map(|&b| b as char).collect::<String>();
                println!("\tSub-chunk type = \"{}\"", sctype_s);
            }
        }
    }
}