sleep_parser/file_type.rs
1/// Type of file.
2///
3/// `signatures`, `bitfield` and `tree` are the three SLEEP files. There are two
4///additional files, `key`, and `data`, which do not contain SLEEP file headers
5///and store plain serialized data for easy access. `key` stores the public key
6///that is described by the `signatures` file, and `data` stores the raw chunk
7///data that the `tree` file contains the hashes and metadata.
8#[derive(Debug, PartialEq)]
9pub enum FileType {
10 /// The bitfield describes which pieces of data you have, and which nodes in
11 /// the tree file have been written. This file exists as an index of the tree
12 /// and data to quickly figure out which pieces of data you have or are
13 /// missing. This file can be regenerated if you delete it, so it is
14 /// considered a materialized index.
15 BitField,
16 /// A SLEEP formatted 32 byte header with data entries being 64 byte
17 /// signatures.
18 Signatures,
19 /// A SLEEP formatted 32 byte header with data entries representing a
20 /// serialized Merkle tree based on the data in the data storage layer. All
21 /// the fixed size nodes written in in-order tree notation. The header
22 /// algorithm string for `tree` files is `BLAKE2b`. The entry size is 40
23 /// bytes.
24 Tree,
25}
26
27impl FileType {
28 /// Returns true if the file is `BitField`
29 #[inline]
30 pub fn is_bitfield(&self) -> bool {
31 *self == FileType::BitField
32 }
33
34 /// Returns true if the file is `Signatures`
35 #[inline]
36 pub fn is_signatures(&self) -> bool {
37 *self == FileType::Signatures
38 }
39
40 /// Returns true if the file is `Tree`
41 #[inline]
42 pub fn is_tree(&self) -> bool {
43 *self == FileType::Tree
44 }
45}