From 2d69c2798b1a39d39f2f85445eef54d8b0128170 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 14:16:02 +0000 Subject: [PATCH] Read native preview members from shared archive handles --- crates/figcraft-format/src/lib.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/figcraft-format/src/lib.rs b/crates/figcraft-format/src/lib.rs index 299dc1959..05536c01b 100644 --- a/crates/figcraft-format/src/lib.rs +++ b/crates/figcraft-format/src/lib.rs @@ -275,14 +275,22 @@ pub fn read_preview_thumbnail(reader: R) -> Re /// retain the separate limits used by the app's recent-file preview. pub fn read_preview_archive(reader: R) -> Result { let mut archive = SeekArchive::open(reader, u64::MAX).map_err(|error| FormatError::Corrupt(error.to_string()))?; + Ok(read_preview_archive_from(&mut archive)) +} + +/// Read bounded native preview members from an already-open shared archive reader. +/// +/// This lets callers preserve fallback handling for other ZIP formats without implementing ZIP +/// member access themselves. +pub fn read_preview_archive_from(archive: &mut impl NativeArchive) -> PreviewArchive { let has_document = archive.contains("document.json"); - let thumbnail_png = archive.read("thumbnail.png", MAX_PREVIEW_THUMBNAIL_BYTES).ok().flatten(); + let thumbnail_png = archive.read_member("thumbnail.png", MAX_PREVIEW_THUMBNAIL_BYTES).ok().flatten(); let document = if has_document { - archive.read("document.json", MAX_PREVIEW_DOCUMENT_BYTES).ok().flatten().and_then(|bytes| read_preview_document(&bytes).ok()) + archive.read_member("document.json", MAX_PREVIEW_DOCUMENT_BYTES).ok().flatten().and_then(|bytes| read_preview_document(&bytes).ok()) } else { None }; - Ok(PreviewArchive { has_document, thumbnail_png, document }) + PreviewArchive { has_document, thumbnail_png, document } } pub fn check_version(h: &Header) -> Result<(), NewerVersion> {