Resource Package
About 741 words
The resource package filename.uink.extra is an ordinary ZIP file that stores the images, SVGs, PDFs, audio and video referenced by Media. It is only a container for resources: the position, size, order and undo information of resources are all recorded in the Media blocks of the main file, and the ZIP has no extra index.
Levels
Readers need to read the resource package from Standard (images) up; Core and Basic readers may ignore it completely.
Files
lesson.uink MessagePack main file
lesson.uink.extra ZIP resource package, optional
images
diagram.png
documents
handout.pdf
- EXTRA-1 The resource package has the same name as the main file with an additional
.extraextension, and is placed in the same directory. - EXTRA-2 The resource package may be absent. The main file is always the authoritative source of the content; when the resource package is missing, strokes and shapes must be displayed as usual.
Resource paths
- EXTRA-3
Media.pathis a relative path under the ZIP root, separated by/, and normalized to Unicode NFC before writing. - EXTRA-4 A path must not start with
/, and must not be a URI, a drive-letter path or any other absolute path; it must not contain\, NUL, control characters, empty path segments,.or... - EXTRA-5 ZIP entry names use the same normalization rules. When entry names are duplicated after normalization, the resources involved are all treated as unavailable; a reader must not pick one of them and continue.
Safe reading
The resource package may come from an untrusted source.
- EXTRA-6 Readers must not extract the resource package directly into the working directory.
- EXTRA-7 Before reading any entry, allocating buffers or starting a decoder, check the resource budget first: at least the number of entries, the size of a single entry, the total uncompressed size and the compression ratio. The specific values are up to the app.
- EXTRA-8 Keep accumulating the actual usage while decompressing and decoding as a stream; readers must not rely solely on the sizes declared in the ZIP. Stop immediately when any budget is exceeded, and treat that resource as missing.
- EXTRA-9 SVG must be treated as a static image: disable scripts, event handlers, external network resources, external file references and any other executable content; if it cannot be safely downgraded, do not display the resource.
- EXTRA-10 When the
mimeTypeis unknown, clearly disagrees with the result of content sniffing, or the decoder rejects the content, the resource is treated as unavailable.
Missing resources
- EXTRA-11 When the resource package does not exist, an entry does not exist or a resource is unavailable, the reader keeps the position and order of the Media and indicates that the resource is missing; whether to draw a placeholder box is up to the app. An error in one resource must not affect other content.
Commit order
During a full save, the main file and the resource package are replaced in order, so that at any moment the old main file can still find the resources it needs.
lesson.uinkResource packagelesson.uink.extraTemp files- 0Start savingEXTRA-12The old main file references A and B; after this save it references B and C.
- Main file
- OldReferences A, B
- Resource package
- AB
- Temp files
- None
- 1Prepare a temporary packageEXTRA-13It holds the union of both versions' references, A, B and C, and is verified once written.
- Main file
- OldReferences A, B
- Resource package
- AB
- Temp files
- PackageABC
- 2Write a temporary main fileEXTRA-14Write and verify the new main file, but do not replace the old one yet.
- Main file
- OldReferences A, B
- Resource package
- AB
- Temp files
- PackageABCMain fileNew
- 3Replace the packageEXTRA-15The package is replaced with the union first; A and B, needed by the old main file, are all still there.
- Main file
- OldReferences A, B
- Resource package
- ABC
- Temp files
- Main fileNew
- 4Atomically replace the main fileEXTRA-15The main file is replaced last; B and C, needed by the new main file, are already in the package.
- Main file
- NewReferences B, C
- Resource package
- ABC
- Temp files
- None
- 5Clean upEXTRA-16Only after the main file is replaced is the no-longer-referenced A deleted; this can be done later.
- Main file
- NewReferences B, C
- Resource package
ABC- Temp files
- None
- EXTRA-12 Determine the set of resources the new main file will reference.
- EXTRA-13 Generate a temporary resource package containing the union of the resources referenced by the old main file and the new main file, and verify it.
- EXTRA-14 Generate and verify the temporary main file, but do not use it to replace the existing main file yet.
- EXTRA-15 First replace the target resource package with the temporary resource package, and atomically replace the main file last.
- EXTRA-16 Only after the main file has been replaced successfully may entries that are no longer referenced, or the whole resource package, be deleted; extra resources left behind by a crash may be cleaned up later.
- EXTRA-17 When the content of a resource at the same path changes, a writer should use a new path (for example by including a content digest in the file name), so that the old main file does not read the new content before the replacement is complete.