#file-format #audio-video #file-io #chunks #reading #wave #formatted

riff

This crate provides utilities for reading and writing RIFF formatted files

5 releases (3 stable)

2.0.0 Jun 15, 2023
1.0.1 Jul 29, 2020
1.0.0 Apr 26, 2020
0.1.1 Jul 3, 2018
0.1.0 Jul 3, 2018

#18 in Multimedia

Download history 61366/week @ 2024-08-10 55913/week @ 2024-08-17 32885/week @ 2024-08-24 32846/week @ 2024-08-31 37807/week @ 2024-09-07 43398/week @ 2024-09-14 41972/week @ 2024-09-21 46583/week @ 2024-09-28 43960/week @ 2024-10-05 34100/week @ 2024-10-12 45197/week @ 2024-10-19 47252/week @ 2024-10-26 55503/week @ 2024-11-02 43893/week @ 2024-11-09 61226/week @ 2024-11-16 53664/week @ 2024-11-23

223,826 downloads per month
Used in 51 crates (5 directly)

MIT license

12KB
217 lines

riff

Crate for doing IO on RIFF-formatted files

This crate provides utility methods for reading and writing formats such as Microsoft Wave, Audio Video Interleave or Downloadable Sounds.

Examples

Reading chunks:

let mut file = File::open("somefile.wav")?;
let chunk = riff::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] };
let test_id: ChunkId = ChunkId { value: [0x74, 0x65, 0x73, 0x74] };
let tst1_id: ChunkId = ChunkId { value: [0x74, 0x73, 0x74, 0x31] };
let tst2_id: ChunkId = ChunkId { value: [0x74, 0x73, 0x74, 0x32] };

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.riff")?;
contents.write(&mut file)?;

No runtime deps