web_static_pack_common/file.rs
1//! File represents single item of a Pack, accessible under specific path.
2
3use crate::cache_control::CacheControl;
4use rkyv::{Archive, Serialize};
5
6/// [File] represents an original file from filesystem with all fields
7/// precalculated. It contains `gzip` / `brotli` compressed content,
8/// precalculated http headers, like `content-type`, `ETag` and `cache-control`.
9///
10/// [File] is created in packing phase (once) to allow fast loading in loader
11/// without need to perform expensive computations (like calculating compressed
12/// forms) in runtime.
13#[derive(Archive, Serialize, Debug)]
14#[rkyv(archived = FileArchived)]
15#[rkyv(derive(Debug))]
16#[rkyv(attr(allow(missing_docs)))] // TODO: resolve with https://github.com/rkyv/rkyv/issues/561
17pub struct File {
18 /// Raw (not compressed) file contents.
19 pub content: Box<[u8]>,
20 /// Gzip compressed file contents, if provided, otherwise None.
21 pub content_gzip: Option<Box<[u8]>>,
22 /// Brotli compressed file contents, if provided, otherwise None.
23 pub content_brotli: Option<Box<[u8]>>,
24
25 /// `content-type` header contents for the file, eg. `text/html;
26 /// charset=utf-8` or `image/webp`.
27 pub content_type: String,
28 /// `ETag` header contents for the file, eg. checksum of `content`.
29 pub etag: String,
30 /// `cache-control` options for the file.
31 pub cache_control: CacheControl,
32}