1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#![cfg_attr(docsrs, feature(doc_cfg))]

//! Asynchronous parser and writer for Electron's asar archive format.
//!
//! Requires Tokio runtime.
//!
//! Currently supported:
//! - Parse archive from file or async reader
//! - Pack archive from multiple readers, or conveniently from a folder.
//!
//! Currently not supported:
//! - Write and check integrity (planned)
//! - Unpacked files (planned)
//! - [`FileMetadata::executable`](header::FileMetadata::executable) (not
//!   planned, it is up to you whether use it or not)

pub mod header;

mod archive;
mod writer;

pub use archive::{check_asar_format, Archive, Duplicable, File, LocalDuplicable};
pub use writer::Writer;

cfg_fs! {
  mod extract;

  pub use archive::DuplicableFile;
  pub use writer::pack_dir;
}

const BLOCK_SIZE: u32 = 4_194_304;

fn split_path(path: &str) -> Vec<&str> {
  path
    .split('/')
    .filter(|x| !x.is_empty() && *x != ".")
    .fold(Vec::new(), |mut result, segment| {
      if segment == ".." {
        result.pop();
      } else {
        result.push(segment);
      }
      result
    })
}

mod private {
  pub trait Sealed {}
  impl<T> Sealed for T {}
}

#[macro_export]
#[doc(hidden)]
macro_rules! cfg_fs {
  ($($item:item)*) => {
    $(
      #[cfg(feature = "fs")]
      #[cfg_attr(docsrs, doc(cfg(feature = "fs")))]
      $item
    )*
  }
}

#[macro_export]
#[doc(hidden)]
macro_rules! cfg_integrity {
  ($($item:item)*) => {
    $(
      #[cfg(feature = "integrity")]
      #[cfg_attr(docsrs, doc(cfg(feature = "integrity")))]
      $item
    )*
  }
}