hive-asar

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) - executable (not planned, it is up to you whether use it or not)

Examples

Reading

```rust 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 file_archive = FileArchive::new("path/to/archive.asar").await?;

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

// Or you can read from any async reader that implements // AsyncRead + AsyncSeek + Send + Sync + Unpin let mut archive = Archive::new(Cursor::new(include_bytes!("path/to/static/archive.asar"))).await?; let _file = archive.read("path/to/file.txt").await?; archive.extract("dest/folder/to/extract").await?;

Ok(()) } ```

Writing

```rust use hiveasar::{Writer, packdir}; 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.addsized("foo.txt", File::open("folder/foo.txt").await?).await?; writer.addsized("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", File::create("dest.asar").await?).await?;

Ok(()) } ```

Features

License

hive-asar is licensed under the MIT License.