Expand description
The .hprz container: a design and the files that go with it, such as flight logs, results
and photographs, in one zip archive (ADR-112).
The archive holds the design as its first entry, DESIGN_ENTRY, written exactly as a .hpr
file (to_json), so unzipping a container gives a .hpr any reader of the
format takes. Every other entry is an attachment, kept byte for byte under its name, in order.
Every entry is deflated and dated 1980-01-01, zip’s zero date, so with one build of this crate a
container’s bytes depend only on what it holds. (Another deflate implementation, chosen by a
program’s features, can compress the same files to other bytes, which read back the same.)
An attachment’s name is a relative path with / between folders, so an archive can’t place a
file outside the folder it is unpacked into (check_name). A container holds at most
MAX_UNPACKED_BYTES, unpacked. Reading is held to the same rules as writing, so a hostile
archive is refused with its reason rather than filling memory.
use hpr_format::DesignFile;
use hpr_format::container::{self, Entry, Hprz};
let bytes = include_bytes!("../../../validation/fixtures/ork/loft-demo/demo-stable.ork");
let design = DesignFile::from_ork(bytes)?.value;
let log = Entry::new("logs/first-flight.csv", b"time_s,altitude_m\n0,0\n".to_vec());
let hprz = Hprz::new(design, vec![log]);
let written = container::write(&hprz)?;
let read = container::read(&written)?;
assert_eq!(read.value, hprz);Structs§
- Entry
- A file in a container: its name, a relative path such as
logs/flight-1.csv, and its bytes. - Hprz
- A design and its attachments.
Constants§
- DESIGN_
ENTRY - The name of the design’s entry, the first in every container this crate writes.
- MAX_
PART_ BYTES - The longest part of an attachment’s name, between
/s, in bytes: what common file systems take for one file’s or folder’s name. - MAX_
UNPACKED_ BYTES - The most a container holds, unpacked, over all its entries, the design’s included: 256 MiB.
writerefuses more, andreaddecompresses no more.
Functions§
- check_
name - Whether
namecan name an attachment, and why not if it can’t. - read
- Reads a container, taking a design of an older version to the current one.
- read_
within - Reads a container, decompressing at most
max_unpacked_bytesout of it, and says which version its design was written in. - write
- The container’s bytes: the design as
DESIGN_ENTRY, then each attachment, in order.