1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// Copyright 2026 Adobe. All rights reserved.
// This file is licensed to you under the Apache License,
// Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
// or the MIT license (http://opensource.org/licenses/MIT),
// at your option.
// Unless required by applicable law or agreed to in writing,
// this software is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
// implied. See the LICENSE-MIT and LICENSE-APACHE files for the
// specific language governing permissions and limitations under
// each license.
//! A portable, dynamically extensible container model for media assets.
//!
//! `asset-io` provides one abstract model for reading, inspecting and updating a
//! wide variety of image, audio, video and document formats, including JPEG, PNG,
//! ISO BMFF (HEIF, AVIF, MP4), RIFF (WebP, WAV, AVI), TIFF, SVG and PDF. Applications
//! work with common structures and metadata items rather than format-specific
//! parsers and writers.
//!
//! Container support is dynamically extensible: applications register built-in
//! or third-party handlers with [`HandlerRegistry`] at runtime. Handler authors
//! use [`container_api`] to add formats without changing the client API.
//!
//! The core is portable and independent of any async runtime. The same handler
//! implementation runs with blocking streams, async adapters or caller-driven
//! I/O. It is designed for high performance: updates stream the output in a single
//! pass with bounded buffers, copying unchanged media without loading the whole
//! asset into memory. [`Sink`]s observe tagged bytes during reads and writes,
//! allowing callers to hash output without a second pass.
//!
//! Used by [c2pa-rs](https://github.com/contentauth/c2pa-rs) for media-container
//! access, `asset-io` separates container mechanics from manifest interpretation,
//! hashing and signing.
//!
//! A [`Structure`] describes a file as an ordered tiling of [`Segment`]s, each
//! split into header, payload and trailer, plus [`Item`]s: logical units such as
//! XMP, JUMBF, EXIF or an embedded file, assembled from [`Extent`]s. It carries
//! geometry only: no data, and no hashing or signing rules. Callers decide what
//! each byte range means.
//!
//! # Glossary
//!
//! - **Asset**: a complete byte stream. Assets are recursive: an asset can contain
//! embedded assets. The [`Asset`] type pairs one with its parsed structure.
//! - **Structure**: the parsed description of an asset ([`Structure`]): its
//! segments, items and sub-assets, and the handler that parsed it. It is
//! geometry only and holds no bytes, so its reads take the stream as an
//! argument; an [`Asset`] holds the stream for them. A planned structure
//! ([`Structure::plan`]) describes an output before it is written.
//! - **Container**: a structural family (ISO BMFF, JPEG, RIFF). **Format**: a media
//! type within one (HEIC and MP4 are both ISO BMFF).
//! - **Handler**: implements a container's specifications
//! ([`ContainerHandler`](container_api::ContainerHandler)).
//! - **Range**: an offset and a length ([`ByteRange`]).
//! - **Segment**: a unit of the asset's tiling. Segments are ordered, do not
//! overlap and cover every byte; a segment is what a writer copies, replaces or
//! moves. Its [`SegmentKind`] gives its dominant purpose: `Preamble` (the leading
//! bytes that identify the format; "signature" is avoided, as C2PA uses it for
//! cryptographic signatures), `Metadata`, `MediaData` (coded media of any type)
//! or `Other`. Items, not segment kinds, say what bytes belong to.
//! - **Role**: within a segment, framing ([`Role::Header`], [`Role::Trailer`])
//! versus content ([`Role::Payload`]). "Header" always means framing.
//! - **Region**: a segment, a role and a range: the view a hasher takes
//! ([`Region`]).
//! - **Element**: a native unit of the container (box, chunk, marker segment, PDF
//! object, IFD). [`Structure::elements`] is the finest tiling by elements.
//! - **Node**: an element and its position in the container's tree
//! ([`Node`], [`Structure::walk`]).
//! - **Item**: a logical unit the format defines, with an [`ItemKind`] (the
//! specification that defines it), an [`ItemCategory`] derived from the kind
//! (metadata or asset) and an [`Encoding`] (its serialization).
//! - **Transfer encoding**: how the bytes a container stores for an item wrap its
//! content, such as SVG's base64, a PDF `FlateDecode` (zlib) stream or a HEIF
//! `content_encoding` ([`TransferEncoding`], [`Item::transfer`]). It is distinct
//! from the [`Encoding`], which is the serialization of the content itself. The
//! core always identifies it; decoders are optional features (`flate`,
//! `brotli`). [`Structure::read_item`] returns the
//! stored bytes (what a hash covers); [`Structure::read_content`] the content.
//! - **Extent**: one contiguous run of an item's bytes. An item may be
//! multi-extent; "fragment" is reserved for fragmented ISO BMFF.
//! - **Identifiers**: native names, kept exactly: FourCCs, markers, UUIDs, JUMBF
//! types, URIs, media types and container labels ([`Name`],
//! [`Item::native_type`], [`Item::native_id`]).
//! - **Relation**: a reference from one item to another that keeps its native type
//! (HEIF `thmb`, `auxl`, `cdsc`, `dimg`); [`RelationKind`] gives common names.
//! - **Sub-asset**: a contiguous, top-level embedded asset, such as each image of a
//! Multi-Picture Format file ([`SubAsset`]).
//! - **Embedded asset**: an item the format declares to be a file of a media type
//! ([`ItemKind::EmbeddedAsset`]). Items whose bytes the format does not type are
//! [`ItemKind::Other`]; [`Structure::scan_embedded`] also finds those that turn out
//! to be files.
//!
//! # Layering
//!
//! 1. Account for every byte: segments always tile the asset.
//! 2. Expose the structure the format's own specifications define, including
//! companion specifications (EXIF/TIFF, MPF, JPEG XT, the HEIF item model), and
//! preserve native identifiers.
//! 3. Never interpret content that is portable across formats (C2PA manifests, XMP
//! schemas, IPTC vocabularies). That belongs to optional higher-level helpers
//! built on this API. Where such content is placed in each container is
//! container knowledge, and is here.
//!
//! # Design principles
//!
//! - **Container agnostic**: one API for every format. Format knowledge lives in a
//! [`ContainerHandler`](container_api::ContainerHandler); callers never test
//! which format they have.
//! - **Streaming**: a file is parsed and written in one pass, in bounded memory.
//! - **Safe on hostile input**: every length is checked, resources are capped,
//! and errors are returned rather than guessed around.
//! - **Pluggable**: [`HandlerRegistry`] finds handlers by format string or by
//! content, and callers can register their own.
//!
//! # Containers and features
//!
//! Each built-in container is a Cargo feature (`jpeg`, `png`, `bmff`, `riff`,
//! `svg`, `pdf`, `tiff`, `c2pa`, or `all-formats`) and a module under
//! [`containers`]. No container is enabled by default.
//! [`HandlerRegistry::builtin`] holds the handlers of the enabled features, and
//! handlers from other crates are registered at runtime. Without any container
//! feature, the crate is the API a handler crate builds on, and nothing more.
//!
//! # API namespaces
//!
//! The root exposes the client model, [`HandlerRegistry`], [`Asset`],
//! [`Structure`], [`Updates`] and [`Sink`], including C2PA geometry and exact
//! patching. Handler authors use [`container_api`] for handler traits, builders,
//! metadata-update decisions and container utilities. Built-in factories and
//! typed options remain under [`containers`].
//!
//! Advanced clients use [`plan`] for declarative write plans, [`execute`] for
//! caller-driven execution, [`io`] for async reads and [`task`] for read requests
//! and blocking or caller-driven task execution. The `*_async`, planning and
//! task methods on [`Structure`] still compose these APIs; no runtime is required.
//! [`HandlerRegistry::handler`] and [`HandlerRegistry::handlers`] retain handler
//! lookup and composition, including custom use of
//! [`ContainerHandler::compose`](container_api::ContainerHandler::compose).
//!
//! # Example
//!
//! ```no_run
//! use asset_io::{Asset, ItemKind, NullSink, Updates};
//!
//! # fn main() -> asset_io::Result<()> {
//! // Enable the `jpeg` feature for this example.
//! let asset = Asset::open(std::fs::File::open("image.jpg")?, None)?;
//!
//! // Read a metadata item, which may have extents in several segments.
//! if let Some(jumbf) = asset.item(ItemKind::Jumbf)? {
//! let bytes = asset.read_item(jumbf)?;
//! println!("JUMBF: {} bytes", bytes.len());
//! }
//!
//! // Write a copy with changes. Every output byte also goes to a sink, tagged
//! // with its segment and role, so it can be hashed without a second pass.
//! let mut out = std::fs::File::create("out.jpg")?;
//! let updates = Updates::new()
//! .set_xmp(b"<x:xmpmeta/>".to_vec())
//! .remove_jumbf();
//! asset.write(&mut out, &updates, &mut NullSink)?;
//! # Ok(())
//! # }
//! ```
//!
//! [`Asset`] holds the source; [`Structure`] is the I/O-free description it
//! wraps, whose methods take the source as an argument. Async and caller-driven
//! code uses [`Structure::parse_task`] and the `*_async` methods directly.
pub use Asset;
pub use ;
pub use ;
pub use C2paHash;
pub use ;
pub use MappedFile;
pub use ByteRange;
pub use HandlerRegistry;
pub use ;
pub use ;
pub use ;
pub use Thumbnail;
pub use ExifInfo;
pub use TransferEncoding;
pub use Updates;
pub use Node;
pub use MiniXmp;