sevenzip

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2020 License: BSD-3-Clause Imports: 27 Imported by: 65

README

Build Status Coverage Status Go Report Card GoDoc

sevenzip

A very rough attempt at a reader for 7-zip archives inspired by archive/zip.

Current status:

  • Pure Go, no external libraries or binaries needed.
  • Handles uncompressed headers, (7za a -mhc=off test.7z ...).
  • Handles compressed headers, (7za a -mhc=on test.7z ...).
  • Handles password-protected versions of both of the above (7za a -mhc=on|off -mhe=on -ppassword test.7z ...).
  • Handles archives split into multiple volumes.
  • Validates CRC values as it parses the file.
  • Supports Bzip2, Deflate, Copy, LZMA and LZMA2 methods.

More examples of 7-zip archives are needed to test all of the different combinations/algorithms possible.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDecompressor

func RegisterDecompressor(method []byte, dcomp Decompressor)

RegisterDecompressor allows custom decompressors for a specified method ID.

Types

type Decompressor

type Decompressor func([]byte, uint64, ...io.ReadCloser) (io.ReadCloser, error)

Decompressor describes the function signature that decompression/decryption methods must implement to return a new instance of themselves. They are passed any property bytes, the size of the stream and a varying number of, but nearly always one, io.ReadCloser providing the stream of bytes. Blame (currently unimplemented) BCJ2 for that one.

type File

type File struct {
	FileHeader
	// contains filtered or unexported fields
}

func (*File) Open

func (f *File) Open() (io.ReadCloser, error)

Open returns an io.ReadCloser that provides access to the File's contents. Multiple files may be read concurrently.

type FileHeader

type FileHeader struct {
	Name             string
	Created          time.Time
	Accessed         time.Time
	Modified         time.Time
	Attributes       uint32
	CRC32            uint32
	UncompressedSize uint64
}

FileHeader describes a file within a 7-zip file.

func (*FileHeader) FileInfo

func (h *FileHeader) FileInfo() os.FileInfo

FileInfo returns an os.FileInfo for the FileHeader.

func (*FileHeader) Mode

func (h *FileHeader) Mode() (mode os.FileMode)

Mode returns the permission and mode bits for the FileHeader.

type ReadCloser

type ReadCloser struct {
	Reader
	// contains filtered or unexported fields
}

func OpenReader

func OpenReader(name string) (*ReadCloser, error)

OpenReader will open the 7-zip file specified by name and return a ReadCloser. If name has a ".001" suffix it is assumed there are multiple volumes and each sequential volume will be opened.

Example
r, err := OpenReader(filepath.Join("testdata", "multi.7z.001"))
if err != nil {
	panic(err)
}
defer r.Close()

for _, file := range r.File {
	fmt.Println(file.Name)
}
Output:

01
02
03
04
05
06
07
08
09
10

func OpenReaderWithPassword

func OpenReaderWithPassword(name, password string) (*ReadCloser, error)

OpenReaderWithPassword will open the 7-zip file specified by name using password as the basis of the decryption key and return a ReadCloser. If name has a ".001" suffix it is assumed there are multiple volumes and each sequential volume will be opened.

func (*ReadCloser) Close

func (rc *ReadCloser) Close() error

Close closes the 7-zip file or volumes, rendering them unusable for I/O.

type Reader

type Reader struct {
	File []*File
	// contains filtered or unexported fields
}

func NewReader

func NewReader(r io.ReaderAt, size int64) (*Reader, error)

NewReader returns a new Reader reading from r, which is assumed to have the given size in bytes.

func NewReaderWithPassword

func NewReaderWithPassword(r io.ReaderAt, size int64, password string) (*Reader, error)

NewReaderWithPassword returns a new Reader reading from r using password as the basis of the decryption key, which is assumed to have the given size in bytes.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL