Skip to main content

Module container

Module container 

Source
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. write refuses more, and read decompresses no more.

Functions§

check_name
Whether name can 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_bytes out 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.