#archive #electron #applications #parser #read-write #integrity #check

bin+lib asar

A crate to read and write asar archives, often used by Electron apps

3 releases (breaking)

0.3.0 Nov 24, 2023
0.2.0 Jan 11, 2023
0.1.0 Jul 30, 2022
0.0.0 Jan 5, 2021

#228 in Compression

Download history 41/week @ 2024-07-22 16/week @ 2024-07-29 18/week @ 2024-08-05 4/week @ 2024-08-12 10/week @ 2024-08-26 21/week @ 2024-09-16 28/week @ 2024-09-23 13/week @ 2024-09-30 9/week @ 2024-10-07 21/week @ 2024-10-14 3/week @ 2024-10-21 2/week @ 2024-10-28 28/week @ 2024-11-04

55 downloads per month
Used in 2 crates

Apache-2.0 OR MIT

55KB
1K SLoC

asar

This crate allows for the parsing, reading, and writing of asar archives, often seen in Electron-based applications.

Examples

Listing the contents of an asar archive

use asar::{AsarReader, Header, Result};
use std::fs;

fn main() -> Result<()> {
	let asar_file = fs::read("archive.asar")?;
	let asar = AsarReader::new(&asar_file)?;

	println!("There are {} files in archive.asar", asar.files().len());
	for path in asar.files().keys() {
		println!("{}", path.display());
	}
	Ok(())
}

Reading a file from an asar archive

use asar::{AsarReader, Header, Result};
use std::{fs, path::PathBuf};

fn main() -> Result<()> {
	let asar_file = fs::read("archive.asar")?;
	let asar = AsarReader::new(&asar_file)?;

	let path = PathBuf::from("hello.txt");
	let file = asar.files().get(&path).unwrap();
	let contents = std::str::from_utf8(file.data()).unwrap();
	assert_eq!(contents, "Hello, World!");
	Ok(())
}

Writing a file to an asar archive

use asar::{AsarWriter, Result};
use std::fs::File;

fn main() -> Result<()> {
	let mut asar = AsarWriter::new();
	asar.write_file("hello.txt", b"Hello, World!", false)?;
	asar.finalize(File::create("archive.asar")?)?;
	Ok(())
}

Features

  • integrity: Enable integrity checks/calculation.
  • check-integrity-on-read: Enable integrity checks when reading an archive, failing if any integrity check fails.
  • write - Enable writing an asar archive. Enabled by default, also enables integrity.

License

asar is licensed under either the MIT license or the Apache License 2.0, at the choice of the user.

License: Apache-2.0 OR MIT

Amendment

I, @Absolucy, fully give permission for any of my code (including the entirety of this project, asar-rs), anywhere, no matter the license, to be used to train machine learning models intended to be used for general-purpose programming or code analysis.

Dependencies

~10–20MB
~274K SLoC