asar/
lib.rs

1// SPDX-License-Identifier: Apache-2.0 OR MIT
2#![cfg_attr(docsrs, feature(doc_auto_cfg))]
3#![forbid(unsafe_code)]
4#![warn(
5	clippy::perf,
6	clippy::complexity,
7	clippy::style,
8	clippy::correctness,
9	clippy::missing_const_for_fn
10)]
11#![allow(clippy::tabs_in_doc_comments, clippy::too_many_arguments)]
12
13//! This crate allows for the parsing, reading, and writing of [asar](https://github.com/electron/asar) archives,
14//! often seen in [Electron](https://www.electronjs.org/)-based applications.
15//!
16//! # Examples
17//!
18//! ## Listing the contents of an asar archive
19//! ```rust,no_run
20//! use asar::{AsarReader, Header, Result};
21//! use std::fs;
22//!
23//! fn main() -> Result<()> {
24//! 	let asar_file = fs::read("archive.asar")?;
25//! 	let asar = AsarReader::new(&asar_file, None)?;
26//!
27//! 	println!("There are {} files in archive.asar", asar.files().len());
28//! 	for path in asar.files().keys() {
29//! 		println!("{}", path.display());
30//! 	}
31//! 	Ok(())
32//! }
33//! ```
34//!
35//! ## Reading a file from an asar archive
36//! ```rust,no_run
37//! use asar::{AsarReader, Header, Result};
38//! use std::{fs, path::PathBuf};
39//!
40//! fn main() -> Result<()> {
41//! 	let asar_file = fs::read("archive.asar")?;
42//! 	let asar = AsarReader::new(&asar_file, None)?;
43//!
44//! 	let path = PathBuf::from("hello.txt");
45//! 	let file = asar.files().get(&path).unwrap();
46//! 	let contents = std::str::from_utf8(file.data()).unwrap();
47//! 	assert_eq!(contents, "Hello, World!");
48//! 	Ok(())
49//! }
50//! ```
51//!
52//! ## Writing a file to an asar archive
53//! ```rust,no_run
54//! use asar::{AsarWriter, Result};
55//! use std::fs::File;
56//!
57//! fn main() -> Result<()> {
58//! 	let mut asar = AsarWriter::new();
59//! 	asar.write_file("hello.txt", b"Hello, World!", false)?;
60//! 	asar.finalize(File::create("archive.asar")?)?;
61//! 	Ok(())
62//! }
63//! ```
64//!
65//! # Features
66//!
67//!  - `integrity`: Enable integrity checks/calculation.
68//!  - `check-integrity-on-read`: Enable integrity checks when reading an
69//!    archive, failing if any integrity check fails.
70//!  - `write` - Enable writing an asar archive. **Enabled by default**, also
71//!    enables `integrity`.
72//!
73//! # License
74//!
75//! `asar` is licensed under either the [MIT license](LICENSE-MIT) or the
76//! [Apache License 2.0](LICENSE-APACHE), at the choice of the user.
77
78/// Error handling for parsing, reading, and writing asar archives.
79pub mod error;
80/// Header parsing for asar archives.
81pub mod header;
82#[cfg(feature = "integrity")]
83pub mod integrity;
84/// Reading asar archives.
85pub mod reader;
86#[cfg(feature = "write")]
87/// Writing asar archives.
88pub mod writer;
89
90pub use error::{Error, Result};
91pub use header::{File, FileIntegrity, HashAlgorithm, Header};
92pub use reader::AsarReader;
93#[cfg(feature = "write")]
94pub use writer::AsarWriter;