Library for working with Electron's ASAR archive files.
pip install asar
- pack and extract asar.
from pathlib import Path from asar import create_archive, extract_archive create_archive(Path("src"), Path("app.asar")) extract_archive(Path("app.asar"), Path("dst"))
- with unpack expression
then we got:
create_archive(Path("src"), Path("app.asar"), unpack="*.exe")
. ├── app.asar └── app.asar.unpacked └── f2.exe
- list files of asar
then we got:
from pathlib import Path from asar import AsarArchive with AsarArchive(Path("app.asar"), mode="r") as archive: print(archive.list())
[Path('assets'), Path('assets/icon.png'), ...]
- read one file from asar by random access
then we got:
from pathlib import Path from asar import AsarArchive with AsarArchive(Path("app.asar"), mode="r") as archive: print(archive.read(Path("f1.txt"), follow_link=True))
b'Hello, Asar'
- create an asar from another asar, without extracting to filesystem.
then we got app.new.asar, extract it:
import io from pathlib import Path from asar import AsarArchive with AsarArchive(Path("app.asar"), mode="r") as reader, AsarArchive(Path("app.new.asar"), "w") as writer: writer.pack_other_asar(reader) writer.pack_file(path_in=Path("assets/added1.txt"), file_path=Path("added.txt")) writer.pack_stream(path_in=Path("assets/added2.txt"), file_reader=io.BytesIO(b"some text"))
app_new_asar_extract ├── assets │ ├── added1.txt │ ├── added2.txt │ └── ... other files from app.asar └── ... other files from app.asar