The basic building block of a RIFF file is called a chunk, which, defined using C syntax, looks like the following:
typedef unsigned long DWORD;
typedef unsigned char BYTE;
typedef DWORD FOURCC; // Four-character code
typedef struct {
FOURCC ckID;
DWORD ckSize; // the size of field <ckData>
BYTE ckData[ckSize]; // the actual data of the chunk
} CK;
Four-character codes (FOURCCs) are used extensively in RIFF files; they identify the sections of data contained in the file. A four-character code has the following characteristics:
A 32-bit quantity represented as a sequence of one to four ASCII alphanumeric characters
Padded on the right with blank characters (ASCII character value 32)
Contains no embedded blanks.
For example, the four-character code “FOO” is stored as a sequence of four bytes (`F' `O' `O' ` ') in ascending addresses. For quick comparisons, a four-character code may also be treated as a 32-bit number.
The chunk fields are as follows:
Part | Description |
ckID | Chunk ID. This four-character code identifies the representation of the chunk data. A program reading a RIFF file can skip over any chunk whose chunk ID it doesn't recognize; it skips the number of bytes specified by the ckSize field plus the pad byte, if present. |
ckSize | Chunk size. This is a 32-bit unsigned value identifying the size of ckData. This size value includes does not include the size of the ckID or ckSize fields or the pad byte at the end of the ckData field. |
ckData | Chunk data. This is binary data of fixed or variable size. The start of ckData is word-aligned with the start of the RIFF file. If the size of the chunk is an odd number of bytes, a pad byte with value zero is written after ckData. Word aligning is done to improve access speed (for chunks resident in memory) and for compatibility with EA IFF. The ckSize value does not include the pad byte. |
Two types of chunks, the “LIST” and “RIFF” chunks, may contain nested chunks, or subchunks. These special chunk types are discussed later in this document. All other chunk types store a single element of binary data in ckData.
Chunks are represented using the following notation (in this example, the ckSize field and pad byte are implicit):
<ckID> ( <ckData> )
For example, a chunk with chunk ID “FOO” might be represented as follows:
FOO ( <foo-Data> )
It's common to refer to chunks by their chunk ID; the chunk shown above would be called a “FOO” chunk.