Skip to main content

compression/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![allow(
3    clippy::doc_markdown,
4    clippy::missing_const_for_fn,
5    clippy::missing_errors_doc,
6    clippy::module_name_repetitions,
7    clippy::must_use_candidate,
8    clippy::use_self
9)]
10#![doc = include_str!("../README.md")]
11
12#[cfg(not(target_os = "macos"))]
13compile_error!("compression only supports macOS");
14
15mod aa_archive_stream;
16mod aa_byte_stream;
17mod aa_entry_stream;
18mod aa_field_key;
19mod aa_header;
20mod compression_decode;
21mod compression_encode;
22mod compression_stream;
23mod error;
24mod ffi;
25#[cfg(feature = "raw-ffi")]
26pub mod raw_ffi;
27pub(crate) mod util;
28
29pub use aa_archive_stream::ArchiveStream;
30pub use aa_byte_stream::{
31    ArchiveCompressionAlgorithm, ArchiveFlags, ByteStream, DEFAULT_FILE_MODE, OPEN_CREATE,
32    OPEN_READ_ONLY, OPEN_READ_WRITE, OPEN_TRUNCATE, OPEN_WRITE_ONLY,
33};
34pub use aa_entry_stream::{EntryAttributes, EntryMessage, PathList};
35pub use aa_field_key::{FieldKey, FieldKeySet};
36pub use aa_header::{
37    BlobDescription, EntryType, FieldType, HashFunction, HashValue, Header, HeaderFieldValue,
38    Timespec,
39};
40pub use compression_decode::{
41    compression_decode_buffer, compression_decode_scratch_buffer_size, decompress,
42};
43pub use compression_encode::{
44    compress, compression_encode_buffer, compression_encode_scratch_buffer_size,
45};
46pub use compression_stream::{CompressionStream, Decoder, Encoder, StreamOperation};
47pub use error::{CompressionError, Result};
48
49#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
50pub enum Algorithm {
51    Lz4,
52    Zlib,
53    Lzma,
54    Lz4Raw,
55    Brotli,
56    Lzfse,
57    Lzbitmap,
58}
59
60impl Algorithm {
61    pub const ALL: [Self; 5] = [Self::Lz4, Self::Zlib, Self::Lzma, Self::Brotli, Self::Lzfse];
62    pub const BUFFER_ALL: [Self; 7] = [
63        Self::Lz4,
64        Self::Zlib,
65        Self::Lzma,
66        Self::Lz4Raw,
67        Self::Brotli,
68        Self::Lzfse,
69        Self::Lzbitmap,
70    ];
71
72    pub const fn supports_streams(self) -> bool {
73        !matches!(self, Self::Lz4Raw | Self::Lzbitmap)
74    }
75
76    pub(crate) const fn as_raw(self) -> u32 {
77        match self {
78            Self::Lz4 => 0x100,
79            Self::Zlib => 0x205,
80            Self::Lzma => 0x306,
81            Self::Lz4Raw => 0x101,
82            Self::Brotli => 0xB02,
83            Self::Lzfse => 0x801,
84            Self::Lzbitmap => 0x702,
85        }
86    }
87}