#archive #file-format #electron #writer #asar #tokio #reader

hive-asar

Asynchronous parser and writer for Electron's asar archive format

6 releases (3 breaking)

0.4.0 Jul 19, 2022
0.3.2 Jul 5, 2022
0.3.1 Jun 22, 2022
0.2.0 Jun 20, 2022
0.1.1 Jun 8, 2022

#2245 in Parser implementations

33 downloads per month
Used in abel

MIT license

35KB
834 lines

hive-asar

Rust Crates.io Docs License

Asynchronous parser and writer for Electron's asar archive format.

Requires Tokio 1.x 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)
  • executable (not planned, it is up to you whether use it or not)

Examples

Reading

use hive_asar::{Archive, FileArchive};
use tokio::io::AsyncReadExt;

#[tokio::main]
async fn main() -> tokio::io::Result<()> {
  // Parses an asar archive from a file
  let mut file_archive = Archive::new_from_file("path/to/archive.asar").await?;

  // Gets the file, retrieving its metadata and reading the entire content
  let mut file = file_archive.read("path/to/file.txt").await?;
  let size = file.metadata().size;
  let mut buf = Vec::with_capacity(size as _);
  file.read_to_end(&mut buf).await?;

  Ok(())
}

Writing

use hive_asar::{Writer, pack_dir};
use tokio::io::AsyncReadExt;
use tokio::fs::File;

#[tokio::main]
async fn main() -> tokio::io::Result<()> {
  let mut writer = Writer::new();

  // You can manually add all of the file one by one
  writer.add_sized("foo.txt", File::open("folder/foo.txt").await?).await?;
  writer.add_sized("bar.toml", File::open("folder/bar.toml").await?).await?;
  writer.add_sized("baaz.rs", File::open("folder/baaz.rs").await?).await?;
  writer.write(File::create("dest.asar").await?).await?;

  // Or use `pack_dir` to pack a directory's content conveniently
  pack_dir("folder", &mut File::create("dest.asar").await?).await?;

  Ok(())
}

Features

  • fs: (enabled by default) File system support, e.g. Archive::extract and pack_dir.
  • integrity: (enabled by default) Enables SHA256 hash support in header. Uses sha2 crate.

License

hive-asar is licensed under the MIT License.

Dependencies

~2.9–9.5MB
~91K SLoC