Go to file
Milan Nikolic 7a3539ca72
Build binary for linux/arm64
2024-04-23 09:49:10 +02:00
.github/workflows Update actions 2023-10-16 05:18:55 +02:00
cmd/unarr add version info for goreleaser 2020-09-19 13:24:24 -06:00
testdata Test subdir 2023-06-02 09:09:38 +02:00
unarrc Fix build for MACOS/__APPLE__ 2024-04-23 09:42:27 +02:00
.gitignore fixes for Windows 2022-01-13 20:18:00 -05:00
.goreleaser.yml Build binary for linux/arm64 2024-04-23 09:49:10 +02:00
LICENSE Bundle C sources 2017-03-12 20:05:17 +01:00
README.md Remove build.sh 2023-06-02 09:22:37 +02:00
go.mod Update actions 2023-10-16 05:10:37 +02:00
unarr.go Replace deprecated functions 2023-06-02 08:53:39 +02:00
unarr_test.go Test subdir 2023-06-02 09:09:38 +02:00

README.md

go-unarr

Build Status GoDoc Go Report Card

Golang bindings for the unarr library from sumatrapdf.

unarr is a decompression library and CLI for RAR, TAR, ZIP and 7z archives.

GoDoc

See https://pkg.go.dev/github.com/gen2brain/go-unarr

Install CLI

go install github.com/gen2brain/go-unarr/cmd/unarr@latest

Example

unarr ./example.7z ./example/

Build

For one-off builds:

go build -o ./unarr ./cmd/unarr/*.go

For multi-platform cross-compile builds:

goreleaser --snapshot --skip-publish --rm-dist

Library Examples

Install Library

go get -v github.com/gen2brain/go-unarr

Open archive

a, err := unarr.NewArchive("test.7z")
if err != nil {
    panic(err)
}
defer a.Close()

Read first entry from archive

err := a.Entry()
if err != nil {
    panic(err)
}

data, err := a.ReadAll()
if err != nil {
    panic(err)
}

List contents of archive

list, err := a.List()
if err != nil {
    panic(err)
}

Read known filename from archive

err := a.EntryFor("filename.txt")
if err != nil {
    panic(err)
}

data, err := a.ReadAll()
if err != nil {
    panic(err)
}

Read first 8 bytes of the entry

err := a.Entry()
if err != nil {
    panic(err)
}

data := make([]byte, 8)

n, err := a.Read(data)
if err != nil {
    panic(err)
}

Read all entries from archive

for {
    err := a.Entry()
    if err != nil {
        if err == io.EOF {
            break
        } else {
            panic(err)
        }
    }

    data, err := a.ReadAll()
    if err != nil {
        panic(err)
    }
}

Extract contents of archive to destination path

_, err := a.Extract("/tmp/path")
if err != nil {
    panic(err)
}