RRiffMeadow
Workflows

Coding workflows · RIFF chunk boundary walking

03
Built around your work

A concrete starting point

Walk up to 128 chunks in a RIFF WAVE byte sequence of 12–1048576 bytes with an exact declared size. Test unknown chunks and odd-length padding, rejecting truncated headers or payloads without decoding audio.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

RIFF chunk boundary walking

A concrete starting point
def riff_chunks(wire):
    if type(wire) is not bytes or not 12 <= len(wire) <= 1048576:
        raise ValueError("riff.input")
    if wire[:4] != b"RIFF" or wire[8:12] != b"WAVE" or int.from_bytes(wire[4:8], "little")+8 != len(wire):
        raise ValueError("riff.header")
    chunks, pos = [], 12
    while pos < len(wire):
        if len(chunks) == 128 or pos+8 > len(wire):
            raise ValueError("riff.chunk")
        tag = wire[pos:pos+4]
        size = int.from_bytes(wire[pos+4:pos+8], "little")
        start, stop = pos+8, pos+8+size
        next_pos = stop+(size & 1)
        if next_pos > len(wire):
            raise ValueError("riff.truncated")
        chunks.append((tag, wire[start:stop]))
        pos = next_pos
    return chunks

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗