Skip to main content

Crate djvu_iff

Crate djvu_iff 

Source
Expand description

IFF (Interchange File Format) container parser for DjVu files.

This module provides two APIs:

  1. New spec-based parser (parse_form) — zero-copy, borrowing slices from the input byte buffer. Written from the sndjvu.org specification.

  2. Legacy API (parse, Chunk, DjvuFile) — the original tree-based parser kept for internal backward compatibility while the rewrite is in progress.

§DjVu IFF layout

[4] magic   = "AT&T"
[4] id      = "FORM"
[4] length  (big-endian u32, covers form_type + all chunks)
[4] form_type = "DJVU" | "DJVM" | "BM44" | "PM44"
... chunks

Each inner chunk:

[4] id
[4] length  (big-endian u32)
[n] data    (padded to even number of bytes if length is odd)

Re-exports§

pub use LegacyError as Error;

Structs§

DjvuFile
A parsed DjVu document (the root FORM chunk).
Form
The top-level FORM structure parsed by the spec-based parser.
IffChunk
A parsed IFF chunk from the new spec-based parser: a 4-byte identifier plus a zero-copy slice into the original byte buffer.

Enums§

Chunk
A parsed IFF chunk — either a FORM container or a leaf data chunk.
EmitPart
One child for partial_emit: a parsed Chunk to re-frame, a verbatim byte slice copied as-is, or a nested FORM container framed from its body.
IffError
Errors that can occur while parsing the IFF container.
LegacyError
Original error type used by the legacy implementation.

Constants§

MAGIC
The 4-byte magic that prefixes every on-disk DjVu IFF stream.

Functions§

emit
Serialise a DjvuFile (legacy parser) back into the on-disk IFF byte stream, including the leading “AT&T” magic.
emitted_size
Number of bytes emit writes for chunk: the 8-byte header, the payload, and any word-alignment pad byte.
parse
Parse a DjVu file from raw bytes (legacy tree-based parser).
parse_form
Parse a DjVu IFF byte stream into a Form.
parse_form_body
Parse a sequence of IFF chunks from a FORM body (the bytes after the 4-byte form type), returning zero-copy IffChunk slices.
partial_emit
Emit a complete DjVu file (AT&T magic + one root FORM) whose children are a mix of re-framed chunks and verbatim original slices.
partial_emit_with_offsets
Like partial_emit, but also returns the absolute file-byte offset of each part within the returned buffer: offsets[i] is the index at which parts[i]’s framing begins, measured from the start of the leading AT&T magic.

Type Aliases§

ChunkId
A 4-byte chunk identifier (e.g., b“FORM“, b“INFO“, b“Sjbz“).