hive_asar/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2
3//! Asynchronous parser and writer for Electron's asar archive format.
4//!
5//! Requires Tokio runtime.
6//!
7//! Currently supported:
8//! - Parse archive from file or async reader
9//! - Pack archive from multiple readers, or conveniently from a folder.
10//!
11//! Currently not supported:
12//! - Write and check integrity (planned)
13//! - Unpacked files (planned)
14//! - [`FileMetadata::executable`](header::FileMetadata::executable) (not
15//!   planned, it is up to you whether use it or not)
16
17pub mod header;
18
19mod archive;
20mod writer;
21
22pub use archive::{check_asar_format, Archive, Duplicable, File, LocalDuplicable};
23pub use writer::Writer;
24
25cfg_fs! {
26  mod extract;
27
28  pub use archive::DuplicableFile;
29  pub use writer::{pack_dir, pack_dir_into_writer};
30
31  cfg_stream! {
32    pub use writer::pack_dir_into_stream;
33  }
34}
35
36cfg_integrity! {
37  const BLOCK_SIZE: u32 = 4_194_304;
38}
39
40fn split_path(path: &str) -> Vec<&str> {
41  path
42    .split('/')
43    .filter(|x| !x.is_empty() && *x != ".")
44    .fold(Vec::new(), |mut result, segment| {
45      if segment == ".." {
46        result.pop();
47      } else {
48        result.push(segment);
49      }
50      result
51    })
52}
53
54mod private {
55  pub trait Sealed {}
56  impl<T> Sealed for T {}
57}
58
59#[macro_export]
60#[doc(hidden)]
61macro_rules! cfg_fs {
62  ($($item:item)*) => {
63    $(
64      #[cfg(feature = "fs")]
65      #[cfg_attr(docsrs, doc(cfg(feature = "fs")))]
66      $item
67    )*
68  }
69}
70
71#[macro_export]
72#[doc(hidden)]
73macro_rules! cfg_integrity {
74  ($($item:item)*) => {
75    $(
76      #[cfg(feature = "integrity")]
77      #[cfg_attr(docsrs, doc(cfg(feature = "integrity")))]
78      $item
79    )*
80  }
81}
82
83#[macro_export]
84#[doc(hidden)]
85macro_rules! cfg_stream {
86  ($($item:item)*) => {
87    $(
88      #[cfg(feature = "stream")]
89      #[cfg_attr(docsrs, doc(cfg(feature = "stream")))]
90      $item
91    )*
92  }
93}