Read and write Go library for Electron ASAR archives.
An ASAR file is an 8-byte Chromium pickle, a JSON index pickle, and concatenated
uncompressed file bytes. Open returns io.SectionReader values over packed files.
Pack and WriteArchive build the same layout, including shared offsets for
identical contents and SHA-256 integrity blocks. Hashes are not verified on read.
Unpacked entries (unpacked: true) live in a sibling {archive}.unpacked directory.
The reader records the flag; callers copy those files themselves.
Integration tests pack archives with @electron/asar 4.3.0 and read them back:
npm ci --prefix integration
go test -tags integration -race ./...package main
import (
"fmt"
"io"
"os"
"golift.io/asar"
)
func main() {
reader, err := asar.Open("app.asar")
if err != nil {
panic(err)
}
defer reader.Close()
for _, file := range reader.Files {
if !file.Packed() {
continue
}
src, err := file.Open()
if err != nil {
panic(err)
}
fmt.Println(file.Name, file.Size)
_, _ = io.Copy(os.Stdout, src)
}
}