mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 23:24:24 +00:00
The package layer of DeckCraft's native format, moved from storytold/deckcraft crates/format at 0d5c0b85 (lib.rs, finite.rs): the mimetype and legacy SlideCraft type, sniffing, the presentation.json envelope (generic over the app's presentation), the NaN-safe JSON writer (Finite), the reader that patches null numbers in older files, member names and compression choice, and the bounded, budget-charged member reads with the format's limits. The presentation model, repair, media and chart-part mapping, and outline/RTF stay in DeckCraft. Writes go through craft-zip's deterministic writer; the consumer's golden test shows the package bytes are unchanged. Part of #778.
craft-deckcraft-format
The DeckCraft .deckcraft package. A file is a ZIP that holds, in this order:
mimetype, stored:application/vnd.storyteller.deckcraft+zip. Files from before the SlideCraft rename carry the legacy type, andsniffaccepts both.presentation.json, deflated:{"format":"deckcraft","version":1,"generator":…,"presentation":…}. It is compact JSON, and non-finite numbers are written as0(Finite).media/<id>andchart-parts/<index>binary members. A member whose content type is already compressed (JPEG, PNG, video, MP3/MP4 audio, anythingzip) is stored, and any other member is deflated.
The presentation is a type parameter: DeckCraft owns the model, decides which media and chart parts become members, and repairs a loaded deck. This crate owns the bytes:
write(presentation, generator, members)writes the package withcraft-zip's deterministic writer.Package::open_manifest(bytes, max)reads and checks the manifest. A file with nopresentation.jsonor a differentformatisNotOurs.parse_manifestreads files written beforeFinite, where serde_json saved NaN asnull, as 0 within fixed patch and re-parse budgets.Package::read_maxrefuses a member that declares more than its limit and stops one that inflates past it.read_chargedcharges a shared budget for every byte it inflates, including the bytes of a read that then fails its CRC.Budgetand theMAX_*constants are the format's limits: 2 GiB per member, 4 GiB of media and chart parts, 100,000 items and a 256 MiB manifest.
There is no unsafe and no panics, and it builds for wasm32-unknown-unknown.