Interleaving
Not all physical packages natively support interleaving of the data streams of parts. The package implementer should use the mechanism described in this Open Packaging specification to allow interleaving when mapping to the physical package for layout scenarios that support streaming consumption. [S2.4]
The interleaving mechanism breaks the data stream of a part into pieces, which can be interleaved with pieces of other parts or with whole parts. Pieces are named using a unique mapping from the part name, defined in §9.1.3. This enables a consumer to join the pieces together in their original order, forming the data stream of the part.
The individual pieces of an interleaved part exist only in the physical package and are not addressable in the packaging model. A piece might be empty.
An individual part shall be stored either in an interleaved or non-interleaved fashion. The package implementer shall not mix interleaving and non-interleaving for an individual part. [M2.11] The format designer specifies whether that format might use interleaving. [O2.1]
The grammar for deriving piece names from a given part name is defined by the logical item name grammar as defined in §9.1.3.1. A suffix name is mandatory.
The package implementer should store pieces in their natural order for optimal efficiency. [S2.5] The package implementer might create a physical package containing interleaved parts and non-interleaved parts. [O2.6]
Example 9–8. ZIP archive contents
A ZIP archive might contain the following item names mapped to part pieces and whole parts:
spine.xml/[0].piece pages/page0.xml spine.xml/[1].piece pages/page1.xml spine.xml/[2].last.piece pages/page2.xml
Under certain scenarios, interleaved ordering can provide important performance benefits, as demonstrated in the following example.
Example 9–9. Performance benefits with interleaved ordering
The figure below contains two parts: a page part (markup/page.xml) describing the contents of a page, and an image part (images/picture.jpg) referring to an image that appears on the page.
With simple ordering, all of the bytes of the page part are delivered before the bytes of the image part. The figure below illustrates this scenario. The consumer is unable to display the image until it has received all of the page part and the image part. In some circumstances, such as small packages on a high-speed network, this may be acceptable. In others, having to read through all of markup/page.xml to get to the image results in unacceptable performance or places unreasonable memory demands on the consumer’s system.
With interleaved ordering, performance is improved by splitting the page part into pieces and inserting the image part immediately following the reference to the image. This allows the consumer to begin processing the image as soon as it encounters the reference.