Riff は汎用性の高いコンテナフォーマットである。Melon books の電子書籍データなどに使われている。

展開するためにはRust の riff クレートを使う方法がある。解析

// riff = "1.0.1"
 
use std::io;
use std::fs::File;
use std::env;
use std::io::Write;
use std::io::Read;
use std::io::Seek;
use std::fs;
 
fn print_bytes(bytes: &Vec<u8>) {
    for row in bytes.chunks(16) {
        for b in row {
            print!("{:02x} ", b);
        }
        for b in row {
            if 32 <= *b && *b <= 127 {
                print!("{}", *b as char);
            }
            else {
                print!(".");
            }
        }
        println!();
    }
}
 
fn main() -> io::Result<()> {
    let args: Vec<_> = env::args().collect();
    let name = args.get(1).expect("no file specified");
    println!("reading {}", name);
    let mut file = File::open(name)?;
    let chunk = riff::Chunk::read(&mut file, 0)?;
    let children: Vec<_> = chunk.iter(&mut file).collect();
    for child in children {
        println!("{}", child.id());
        let bytes = child.read_contents(&mut file);
        if let Ok(bytes) = bytes {
            //print_bytes(&bytes);
            std::fs::write(&format!("{}_{}.dat", name, child.id()), bytes);
        }
        else {
            eprintln!("could not read contents");
        }
    }
    Ok(())
}

Usage:

cargo single run riff.rs <file>

"上"のページ: ファイルフォーマット