Skip to main content

Module archive

Module archive 

Source
Expand description

Zip archives of a flight’s files, as flyers share them: a Blue Raven’s high-rate and low-rate files with the app’s summary, or a folder of everything a flight left behind.

An archive isn’t a log. unpack takes its files out, in memory, and each is then read as a file on its own (import::read); an archive inside an archive is one of its files like any other, and is not opened. Nothing is written anywhere, so a file’s name is kept as the archive gives it, folders and all, and is only a label.

An archive comes from someone else, so what comes out of it is bounded: at most MAX_UNPACKED_BYTES of decompressed bytes, counted as they come out rather than as the archive states them. (The zip reader’s own record of the archive’s directory, a few times the directory’s size, is on top.) Two files of one name, which the zip reader would silently keep one of, are refused. A file is read with only the methods zip archives use for flight logs, stored and deflated; an encrypted file, another method or a damaged file is refused with its reason. The zip format is PKWARE’s APPNOTE.TXT, version 6.3.10.

use std::io::{Cursor, Write};

use hpr_flightdata::archive;

// An invented archive of one PerfectFlite export.
let mut zip = zip::ZipWriter::new(Cursor::new(Vec::new()));
zip.start_file("flight/export.csv", zip::write::SimpleFileOptions::default())?;
zip.write_all(b"Time,Altitude,Velocity\n0.00,0,0\n0.05,1,8\n0.10,3,30\n")?;
let bytes = zip.finish()?.into_inner();

let members = archive::unpack(&bytes)?;
assert_eq!(members[0].name, "flight/export.csv");
let log = hpr_flightdata::import::read(&members[0].bytes)?;
assert_eq!(log.time_s.len(), 3);

Structs§

Member
One file taken out of an archive.

Constants§

MAX_UNPACKED_BYTES
The most bytes unpack takes out of one archive, 256 MiB (268 MB): about eight times the largest of the project’s sample archives, which unpacks to 32 MB, and the limit the .hprz design container holds to.

Functions§

is_archive
Whether the bytes open as a zip archive does: a local file header, or the end of an empty archive’s central directory (APPNOTE.TXT 4.3.7, 4.3.16).
unpack
The files in a zip archive, in its central directory’s order, folders’ own entries left out; unpack_within with MAX_UNPACKED_BYTES.
unpack_within
The files in a zip archive, decompressing at most max_unpacked_bytes out of it.