Chunks

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: