The basic building block of a RIFF file is called a chunk. Using C syntax, a chunk can be defined as follows:
typedef unsigned long ULONG; typedef unsigned char BYTE; typedef ULONG FOURCC; /* Four-character code */ typedef FOURCC CKID; /* Four-character-code chunk identifier */ typedef ULONG CKSIZE; /* 32-bit unsigned size value */ typedef struct { /* Chunk structure */ CKID ckID; /* Chunk type identifier */ CKSIZE ckSize; /* Chunk size field (size of ckData) */ BYTE ckData[ckSize]; /* Chunk data */ } CK;
A FOURCC is represented as a sequence of one to four ASCII alphanumeric characters, padded on the right with blank characters (ASCII character value 32) as required, with 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 three parts of the chunk are described in the following table:
Part
We can represent a chunk with the following notation (in this example, the ckSize and pad byte are implicit):
<ckID> ( <ckData> )
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>.