https://github.com/gen2brain/go-unarr
Go bindings for unarr (decompression library for RAR, TAR, ZIP and 7z archives)
https://github.com/gen2brain/go-unarr
7z-archives 7zip decompression-library golang golang-library rar rar-format tar
Last synced: 5 days ago
JSON representation
Go bindings for unarr (decompression library for RAR, TAR, ZIP and 7z archives)
- Host: GitHub
- URL: https://github.com/gen2brain/go-unarr
- Owner: gen2brain
- License: zlib
- Created: 2015-11-01T09:38:37.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-10-22T17:24:48.000Z (6 months ago)
- Last Synced: 2025-03-31T23:33:43.345Z (12 days ago)
- Topics: 7z-archives, 7zip, decompression-library, golang, golang-library, rar, rar-format, tar
- Language: Go
- Homepage:
- Size: 911 KB
- Stars: 290
- Watchers: 9
- Forks: 46
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - go-unarr - Decompression library for RAR, TAR, ZIP and 7z archives. (Miscellaneous / Uncategorized)
- zero-alloc-awesome-go - go-unarr - Decompression library for RAR, TAR, ZIP and 7z archives. (Miscellaneous / Uncategorized)
- awesome-go - go-unarr - Go bindings for unarr (decompression library for RAR, TAR, ZIP and 7z archives) - ★ 44 (Miscellaneous)
- awesome-go-extra - go-unarr - 11-01T09:38:37Z|2022-08-25T12:40:39Z| (Microsoft Office / Uncategorized)
- awesome-go-zh - go-unarr
README
# go-unarr
[](https://github.com/gen2brain/go-unarr/actions)
[](https://godoc.org/github.com/gen2brain/go-unarr)
[](https://goreportcard.com/report/github.com/gen2brain/go-unarr)> Golang bindings for the [unarr](https://github.com/selmf/unarr) library from sumatrapdf.
`unarr` is a decompression library and CLI for RAR, TAR, ZIP and 7z archives.
## GoDoc
See
## Build tags
* `extlib` - use external libunarr library
* `pkgconfig` - enable pkg-config (used with `extlib`)
* `static` - use static library (used with `pkgconfig`)## Install CLI
```bash
go install github.com/gen2brain/go-unarr/cmd/unarr@latest
```#### Example
```bash
unarr ./example.7z ./example/
```#### Build
For one-off builds:
```bash
go build -o ./unarr ./cmd/unarr/*.go
```For multi-platform cross-compile builds:
```bash
goreleaser --snapshot --skip-publish --rm-dist
```## Library Examples
#### Install Library
```bash
go get -v github.com/gen2brain/go-unarr
```#### Open archive
```go
a, err := unarr.NewArchive("test.7z")
if err != nil {
panic(err)
}
defer a.Close()
```#### Read first entry from archive
```go
err := a.Entry()
if err != nil {
panic(err)
}data, err := a.ReadAll()
if err != nil {
panic(err)
}
```#### List contents of archive
```go
list, err := a.List()
if err != nil {
panic(err)
}
```#### Read known filename from archive
```go
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
```go
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
```go
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
```go
_, err := a.Extract("/tmp/path")
if err != nil {
panic(err)
}
```