#io #riff #format #reading #formatted #chunks #byte

longriff

This crate provides utilities for reading and writing LONGRIFF formatted files

1 stable release

1.0.0 Sep 15, 2024

#1027 in Parser implementations

Download history 158/week @ 2024-09-12 24/week @ 2024-09-19 11/week @ 2024-09-26 3/week @ 2024-10-03

196 downloads per month

MIT license

13KB
217 lines

longriff

Crate for doing IO on LONGRIFF-formatted files

This crate provides utility methods for reading and writing in the LONGRIFF format, which is RIFF but everywhere we use 4 bytes we use 8 bytes instead.

Forked from frabert/riff.

Examples

Reading chunks:

let mut file = File::open("somefile.longriff")?;
let chunk = longriff::Chunk::read(&mut file, 0)?;

for child in chunk.iter(&mut file) {
  println!(child.id());
}

Writing chunks:

// Some ids to use while creating chunks
let smpl_id: ChunkId = ChunkId { value: [0x73, 0x6D, 0x70, 0x6C, 0x20, 0x20, 0x20, 0x20] };
let test_id: ChunkId = ChunkId { value: [0x74, 0x65, 0x73, 0x74, 0x20, 0x20, 0x20, 0x20] };
let tst1_id: ChunkId = ChunkId { value: [0x74, 0x73, 0x74, 0x31, 0x20, 0x20, 0x20, 0x20] };
let tst2_id: ChunkId = ChunkId { value: [0x74, 0x73, 0x74, 0x32, 0x20, 0x20, 0x20, 0x20] };

let str1 = "hey this is a test".as_bytes().to_vec();
let str2 = "hey this is another test".as_bytes().to_vec();
let str3 = "final test".as_bytes().to_vec();

let contents = ChunkContents::Children(
  riff::RIFF_ID,
  smpl_id,
  vec![
    ChunkContents::Children(
      riff::LIST_ID,
      tst1_id,
      vec![
        ChunkContents::Data(test_id, str1),
        ChunkContents::Data(test_id, str2)
      ]),
    ChunkContents::Children(
      riff::LIST_ID,
      tst2_id,
      vec![
        ChunkContents::Data(test_id, str3)
      ]
    )
  ]);

let mut file = File::create("somefile.longriff")?;
contents.write(&mut file)?;

No runtime deps