riff-chunks
riff-chunks reads and writes Resource Interchange File Format containers. It supports RIFF and RIFX files, plus read access to RF64 and BW64 files.
The borrowed reader walks a byte slice without allocating or copying payloads. The streaming reader accepts owned standard readers and custom readers passed as &mut R. Wrap a reader in Seekable to skip unread payloads with seeks. The writer patches chunk, list, and file sizes when each scope closes.
The crate has no dependencies. Disable the default std feature to use the borrowed reader in a no_std program.
Borrowed input
use ;
let bytes = b"RIFF\x10\x00\x00\x00TESTdata\x04\x00\x00\x00abcd";
let file = parse?;
let chunk = file.chunks.find?.unwrap;
assert_eq!;
# Ok::
Chunk::children descends into one LIST level. The caller chooses which lists to enter, so finding an unrelated top-level chunk does not inspect nested payloads.
Streaming input
use ;
use ;
let bytes = b"RIFF\x10\x00\x00\x00TESTdata\x04\x00\x00\x00abcd";
let mut reader = new?;
let header = reader.next?.unwrap;
assert_eq!;
let mut payload = ;
reader.payload.read_exact?;
assert_eq!;
# Ok::
ChunkReader::next skips unread bytes from the previous chunk. A plain reader discards them through a 4 KiB stack buffer. Seekable<R> moves over them with Seek.
Writing
use ;
use Cursor;
let cursor = new;
let mut writer = new?;
writer.chunk?;
let bytes = writer.finish?.into_inner;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
# Ok::
RF64 and BW64 writing returns Unsupported(Feature::Rf64Write) before writing bytes. Their 64-bit sizes require a ds64 layout that this release reads and exposes through Riff::ds64 and ChunkReader::ds64.
Input limits
The readers cap list nesting at 32 levels. Size arithmetic uses checked u64 operations. Streaming payload reads stay within the declared chunk size, and read_payload requires a caller-owned buffer large enough for the remaining bytes.
The file header's declared size is available through Header::size. Readers walk to the real input boundary because files produced by streaming tools may leave that field stale. Writers calculate and patch the field.
License
MIT