Portable-Network-Archive-Specification

9. Chunk Ordering Rules

To allow new chunk types to be added to PNA, it is necessary to establish rules about the ordering requirements for all chunk types. Otherwise, a PNA editing program cannot know what to do when it encounters an unknown chunk.

We define a “PNA editor” as a program that modifies a PNA file and wishes to preserve as much as possible of the ancillary information in the file. Two examples of PNA editors are a program that adds or modifies text chunks, and a program that adds or modifies an entry to a PNA file. (Note: we strongly encourage programs handling PNA files to preserve ancillary information whenever possible.)

As an example of possible problems, consider a hypothetical new ancillary chunk type that is safe-to-copy and is required to appear after PHSF if PHSF is present. If our program to add a suggested PHSF does not recognize this new chunk, it may insert PHSF in the wrong place, namely after the new chunk. We could prevent such problems by requiring PNA editors to discard all unknown chunks, but that is a very unattractive solution. Instead, PNA requires ancillary chunks not to have ordering restrictions like this.

To prevent this type of problem while allowing for future extension, we put some constraints on both the behavior of PNA editors and the allowed ordering requirements for chunks.

9.1. Behavior of PNA editors

The rules for PNA editors are:

See also Chunk naming conventions.

9.2. Ordering of ancillary chunks

The ordering rules for an ancillary chunk type cannot be any stricter than this:

The actual ordering rules for any particular ancillary chunk type may be weaker. See for example the ordering rules for the standard ancillary chunk types (Summary of standard chunks).

Decoders must not assume more about the positioning of any ancillary chunk than is specified by the chunk ordering rules. In particular, it is never valid to assume that a specific ancillary chunk type occurs with any particular positioning relative to other ancillary chunks. (For example, it is unsafe to assume that your private ancillary chunk occurs immediately before AEND, FEND or SEND. Even if your application always writes it there, a PNA editor might have inserted some other ancillary chunk after it. But you can safely assume that your chunk will remain somewhere between AHED and AEND or FDAT and FEND or SDAT and SEND.)

9.3. Ordering of critical chunks

Critical chunks can have arbitrary ordering requirements, because PNA editors are required to give up if they encounter unknown critical chunks. For example, AHED has the special ordering rule that it must always appear first. A PNA editor, or indeed any PNA-writing program, must know and follow the ordering rules for any critical chunk type that it can emit.