README

go-unarr

TravisCI Build Status AppVeyor 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 get github.com/gen2brain/go-unarr/cmd/unarr
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

See build.sh for gcc toolchain information and for manual cross-platform build instructions.

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)
}

Documentation

Overview

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

    Index

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    This section is empty.

    Types

    type Archive

    type Archive struct {
    	// contains filtered or unexported fields
    }

      Archive represents unarr archive

      func NewArchive

      func NewArchive(path string) (a *Archive, err error)

        NewArchive returns new unarr Archive

        func NewArchiveFromMemory

        func NewArchiveFromMemory(b []byte) (a *Archive, err error)

          NewArchiveFromMemory returns new unarr Archive from byte slice

          func NewArchiveFromReader

          func NewArchiveFromReader(r io.Reader) (a *Archive, err error)

            NewArchiveFromReader returns new unarr Archive from io.Reader

            func (*Archive) Close

            func (a *Archive) Close() (err error)

              Close closes the underlying unarr archive

              func (*Archive) Entry

              func (a *Archive) Entry() error

                Entry reads the next archive entry.

                io.EOF is returned when there is no more to be read from the archive.

                func (*Archive) EntryAt

                func (a *Archive) EntryAt(off int64) error

                  EntryAt reads the archive entry at the given offset

                  func (*Archive) EntryFor

                  func (a *Archive) EntryFor(name string) error

                    EntryFor reads the (first) archive entry associated with the given name

                    func (*Archive) Extract

                    func (a *Archive) Extract(path string) (contents []string, err error)

                      Extract extracts archive to destination path

                      func (*Archive) List

                      func (a *Archive) List() (contents []string, err error)

                        List lists the contents of archive

                        func (*Archive) ModTime

                        func (a *Archive) ModTime() time.Time

                          ModTime returns the stored modification time of the current entry

                          func (*Archive) Name

                          func (a *Archive) Name() string

                            Name returns the name of the current entry

                            func (*Archive) Offset

                            func (a *Archive) Offset() int64

                              Offset returns the stream offset of the current entry, for use with EntryAt

                              func (*Archive) Read

                              func (a *Archive) Read(b []byte) (n int, err error)

                                Read tries to read 'b' bytes into buffer, advancing the read offset pointer.

                                Returns the actual number of bytes read.

                                func (*Archive) ReadAll

                                func (a *Archive) ReadAll() ([]byte, error)

                                  ReadAll reads current entry and returns data

                                  func (*Archive) Seek

                                  func (a *Archive) Seek(offset int64, whence int) (int64, error)

                                    Seek moves the read offset pointer interpreted according to whence.

                                    Returns the new offset.

                                    func (*Archive) Size

                                    func (a *Archive) Size() int

                                      Size returns the total size of uncompressed data of the current entry

                                      Directories

                                      Path Synopsis
                                      cmd