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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
use ;
use crateContentPath;
use crateExtractionContext;
use crateOwnedContentPtr;
/// Return value used by analyzers to steer the scan.
///
/// [`ContentAnalyzer::analyze`] returns a `NextAction` that tells the
/// scanner whether to continue this object, skip the rest of it, or
/// abort the entire scan. [`ContentExtractor`] and
/// [`ExtractionSession`] methods do not return this type: they yield
/// [`Option`] at each session step.
/// Metadata for a single entry produced by a [`ContentExtractor`].
///
/// An [`ExtractionSession`] advertises the next item it is about to
/// extract via this struct. The scanner uses it to apply
/// [`Filter`](crate::Filter) rules cheaply (path + size) before asking
/// the session to materialize the actual [`Content`].
/// A plugin that inspects a piece of content and records information.
///
/// Analyzers are the "read-only" half of the framework: they observe
/// content and write findings into the [`Context`]. Use
/// [`Context::local`] for per-object results and
/// [`Context::global`] for scan-wide aggregates. To run extractors
/// registered for a *different* type on a region of this object
/// (for example the byte offset of an embedded ZIP), call
/// [`Context::request_extract`]. Analyzers do not
/// produce child content themselves —
/// for that, use a [`ContentExtractor`].
///
/// Analyzers can be registered per [`ContentType`] via
/// [`ScannerBuilder::add_analyzer`](crate::ScannerBuilder::add_analyzer)
/// or as generic (all types) plugins via
/// [`ScannerBuilder::add_generic_analyzer`](crate::ScannerBuilder::add_generic_analyzer).
/// A plugin that turns a container into a stream of child [`Content`]
/// items.
///
/// Extractors are the "produce children" half of the framework. The
/// scanner calls [`create_session`](Self::create_session) once per
/// parent; the returned [`ExtractionSession`] then enumerates children
/// with [`advance`](ExtractionSession::advance) /
/// [`extract`](ExtractionSession::extract). Methods return [`Option`]
/// (or nothing, when the session is dropped) — they do **not** return
/// [`NextAction`] and cannot Skip or Exit on their own.
///
/// An extractor registered for type `T` runs in two situations:
///
/// - The current object was **identified as `T`**. The
/// [`ExtractionContext`] then covers the whole object
/// (`offset = 0`, `length = Some(content.size())`, `params = None`).
/// - An analyzer **requested** extraction of `T` from the current
/// object via [`Context::request_extract`]. The context then carries
/// the requested offset, length, and params. The parent does not
/// need to have been identified as `T`.
///
/// One extractor instance is shared by every object of its type, and
/// `create_session` can be re-entered while a previous session is
/// still live (nested containers). Keep configuration on the extractor
/// and put cursors, open archives, and the current [`Entry`] on the
/// session.
///
/// Register extractors via
/// [`ScannerBuilder::add_extractor`](crate::ScannerBuilder::add_extractor).
/// Multiple extractors for the same type run in registration order.
/// A live extraction of children from one parent [`Content`].
///
/// Produced by [`ContentExtractor::create_session`] and driven by the
/// scanner as a short loop:
///
/// 1. [`advance`](Self::advance) — move to the next child and return
/// a lightweight [`Entry`] (path / size / filter skip). `None`
/// ends the stream and the session is dropped.
/// 2. [`extract`](Self::extract) — materialize that child as a boxed
/// [`Content`]. The scanner then recursively scans it (subject to
/// `max_depth`). `None` skips just this entry; enumeration
/// continues with the next `advance`.
///
/// A child's [`NextAction::Skip`] does not end this session — the
/// scanner continues with the next `advance`. A child's
/// [`NextAction::Exit`] drops the session immediately as the scan
/// unwinds.
///
/// Keep one [`Entry`] as a field and overwrite `entry.path` in place
/// with [`ContentPath::set_from_str`](crate::ContentPath::set_from_str)
/// (synthetic names) or
/// [`ContentPath::set_from_os`](crate::ContentPath::set_from_os)
/// (real OS paths) so `advance` does not allocate a new path for
/// every child.
/// Fast, declarative way to identify a content type without running
/// custom code.
///
/// A [`ContentIdentifier`] can return one of these variants from
/// [`identify_method`](ContentIdentifier::identify_method) so the
/// scanner can build efficient matchers (tries, magic tables, etc.)
/// once and reuse them for every scanned object.
///
/// If none of the variants fit your identifier, return `None` from
/// `identify_method` and perform your own check inside
/// [`validate`](ContentIdentifier::validate).
///
/// Magic patterns ([`Magic`](Self::Magic),
/// [`MultipleMagic`](Self::MultipleMagic)) must be at most 16 bytes.
/// The scanner only feeds the matcher the first 16 bytes of content;
/// [`ScannerBuilder::build`](crate::ScannerBuilder::build) panics if a
/// registered magic is longer. To match bytes past that window, return
/// `None` from `identify_method` and call [`Content::read`] in
/// `validate`.
/// A plugin that classifies content into a [`ContentType`].
///
/// Identifiers pair a fast pre-filter ([`IdentifyMethod`]) with an
/// optional custom [`validate`](Self::validate) step. The scanner
/// first uses the pre-filter to narrow down candidate types and then
/// calls `validate` to accept or reject each candidate. Identifiers
/// that return `None` from [`identify_method`](Self::identify_method)
/// are tried afterwards, in registration order, via `validate` alone.
///
/// Register identifiers via
/// [`ScannerBuilder::add_identifier`](crate::ScannerBuilder::add_identifier).
/// Only one identifier is allowed per [`ContentType`].
/// [`ScannerBuilder::build`](crate::ScannerBuilder::build) panics if a
/// [`IdentifyMethod::Magic`] / [`IdentifyMethod::MultipleMagic`]
/// pattern is longer than 16 bytes.