CBDF Specification: Resources Section

Version 1.1 (Phase II)

Document: 05-Resources-Section • Date: 2026-07-13

1. Overview

The Resources section stores binary data (images, custom fonts, audio, video, embedded sub-documents) referenced by Image Definitions and the Text section. It sits after Text and before Logic, enabling abortable downloads.

In Phase II the Resources slot is always present in the document skeleton (may be zero-length). Payload is embedded in the same body object as Styles/Text for QMail file_type=1.

No Compression

The Resources section is NEVER re-compressed by CBDF (media codecs are already compressed).

Structure (packed — no RS, no count field):

[Length: 4 bytes LE]
repeat until length exhausted:
  [Resource ID:1][Type:1][Data Length:4 LE][Raw Data:N]

2. Resource Record Format

Records are packed end-to-end. There is no RS separator between resources (RS is reserved for table rows in Text).

FieldSizeDescription
Resource ID1 byteUnique ID within the document (0-255)
Resource Type1 byteFormat/media type (see table below)
Data Length4 bytes LESize of raw data in bytes
Raw DataN bytesThe binary content

Overhead per resource: 6 bytes. Parser walks until ResourcesLen is exhausted.

Resource IDs

  • Must be unique within the document.
  • Range 0-255 (1 byte).
  • Referenced by IMAGE (0x16) commands in the Text section and by Image Definition records in the Styles section.
  • ID assignment is at the document author's discretion (no required ordering).

Resource Types

IDTypeDescription
0image/pngPNG image
1image/jpegJPEG image
2image/webpWebP image
3image/svgSVG vector image (may be compressed)
4fontCustom font file (WOFF2, TTF, etc.)
5audioAudio clip (format TBD)
6videoVideo clip (format TBD)
7cbdfEmbedded CBDF sub-document (for iframes)
8-255reservedFuture media types

3. Resource Referencing

Resources are referenced in two places:

A. Image Definitions (Styles section, sub-table 6J): The Image Definition record includes a Resource ID field (byte 1) that points to the resource containing the image data.

B. Text section (IMAGE command 0x16): [IMAGE image_def_index] inserts the image at the current text position. The index references an Image Definition in the Styles section, which in turn contains the Resource ID for the binary data.

The indirection chain is:

IMAGE [image_def_index] -> Image Definition -> Resource ID -> binary data

Design Note

IMAGE always references an Image Definition, never a Resource ID directly. This ensures the renderer always has access to the display properties (width, height, fit mode, alignment, border) stored in the Image Definition, even when the resource binary data is unavailable.

4. Missing Resource Behavior

When a resource is unavailable (section not downloaded, or resource stripped by a server/filter), the renderer must handle it gracefully:

  • A. Image Definitions include Width and Height fields: the renderer can display a placeholder box of the correct size.
  • B. Client choice:
    • Show a placeholder box (outlined rectangle, broken-image icon)
    • Reflow text as if the image doesn't exist
    • Show a "download" button for the user to request the resource
  • C. Server stripping: A server (spam filter, bandwidth limiter) may remove specific resources by deleting their records. Because resources are referenced by ID (not positional index), removing a resource does NOT invalidate references to other resources.

5. Resource Section Layout

Complete section (packed records — no count field, no RS separators):

[Length: 4 bytes LE]               -- total bytes of section content
[ResID:1][Type:1][Len:4 LE][Data:N]   -- Resource record
[ResID:1][Type:1][Len:4 LE][Data:N]   -- Resource record
...                                 -- repeat until Length is exhausted

Empty section (no resources):

[0x00 0x00 0x00 0x00]      -- Length: 0 bytes (the slot is still present)

Single image example (a 1024-byte JPEG with ID=1):

[0x06 0x04 0x00 0x00]      -- Length: 1030 bytes (6-byte header + 1024 data), LE
[0x01]                      -- Resource ID: 1
[0x01]                      -- Type: image/jpeg
[0x00 0x04 0x00 0x00]      -- Data length: 1024 bytes, LE
[... 1024 bytes of JPEG data ...]

6. Size Limits

  • No overall size limit on the Resources section.
  • Individual resource data length: up to 4 GB (4-byte LE uint32).
  • Maximum 256 resources per document (the 1-byte Resource ID space; there is no count field — records repeat until the section length is exhausted). Documents needing more than 256 resources can use the ESC extended command mechanism (Phase III) for 2-byte resource IDs.

7. Abortable Download Behavior

The Resources section is deliberately placed LAST (before Logic) so that clients can implement "abortable downloads":

  1. Client begins downloading the CBDF document.
  2. Meta section arrives first (small, fast).
  3. Styles + Text arrive next (may be compressed).
  4. Client renders the text with image placeholders.
  5. Client displays the rendered content to the user.
  6. If the user doesn't need images (e.g., text-only mode, low bandwidth): client closes the connection. Resources never download.
  7. If images are desired: client continues reading the Resources section. Images fill in progressively as each resource record is parsed.

Analogy

This is functionally equivalent to how modern web browsers show text before images load, but at the protocol level rather than requiring HTTP range requests or chunked encoding.