pub enum ArtifactPreview {
Text {
text: String,
truncated: bool,
source_bytes: u64,
},
Json {
value: Value,
source_bytes: u64,
},
Image {
format: String,
width: u32,
height: u32,
thumb_width: u32,
thumb_height: u32,
pixels_ppm_hex: String,
},
Audio {
format: String,
duration_ms: u64,
sample_rate: u32,
channels: u16,
frames: u64,
peaks: Vec<u16>,
},
Empty {
reason: String,
},
}Expand description
What a read derived from the bytes — the RegistryDiff precedent
applied to media: computed on read, never stored. A stored preview
would be a second, divergent account of the same bytes; derivation
keeps one source of truth, and a kind that cannot be derived answers
ArtifactPreview::Empty — an honest empty, not a placeholder.
The derivations are deliberately dependency-free, which bounds what they cover, stated per kind:
file/data: a bounded UTF-8 window (ArtifactPreview::Text), or the parsed document when the whole payload fits the window and is JSON (ArtifactPreview::Json). Binary bytes are not text — they answerEmpty.image: a real downscaled thumbnail (ArtifactPreview::Image) for the formats decodable without a codec dependency — uncompressed BMP (24/32-bitBI_RGB) and binary PNM (P6/P5). Compressed formats (PNG, JPEG, GIF, …) answerEmpty: a codec dependency is the measured-need seam the design’s preview question reserves, not something to half-parse.audio: waveform metadata (ArtifactPreview::Audio) for RIFF/WAVE PCM (8/16-bit) — duration, rate, channels, and a bounded peak envelope. Anything else answersEmpty.
Variants§
Text
A bounded UTF-8 window over the source bytes.
Fields
Json
The parsed JSON document (only when it fits the window whole — a
preview is bounded, so a larger document degrades to Text,
never to a partial parse).
Image
A downscaled thumbnail, re-encoded as a binary PPM (P6) and
carried hex-encoded (the repo’s dependency-free byte-on-JSON
codec — the commit path’s bytes_hex convention).
Fields
Audio
Waveform metadata for RIFF/WAVE PCM: the envelope an operator glances at, derived — the audio bytes themselves are never re-encoded.
Fields
peaks: Vec<u16>The peak envelope: PREVIEW_WAVEFORM_BUCKETS buckets, each
the loudest absolute sample in its window on the 16-bit scale
(0..=65535), max across channels.
Empty
The honest empty answer: this media kind (or these bytes, under the dependency-free derivations above) yields no preview. Carries the reason so the answer is attributable, never a placeholder.