rardecode

package module
v2.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2025 License: BSD-2-Clause Imports: 24 Imported by: 36

README

rardecode

GoDoc Go Report Card

A go package for reading RAR archives.

Documentation

Index

Constants

View Source
const (
	HostOSUnknown = 0
	HostOSMSDOS   = 1
	HostOSOS2     = 2
	HostOSWindows = 3
	HostOSUnix    = 4
	HostOSMacOS   = 5
	HostOSBeOS    = 6
)

FileHeader HostOS types

View Source
const (
	DefaultMaxDictionarySize = 4 << 30 // default max dictionary size of 4GB
)

Variables

View Source
var (
	ErrCorruptBlockHeader    = errors.New("rardecode: corrupt block header")
	ErrCorruptFileHeader     = errors.New("rardecode: corrupt file header")
	ErrBadHeaderCRC          = errors.New("rardecode: bad header crc")
	ErrUnknownDecoder        = errors.New("rardecode: unknown decoder version")
	ErrDecoderOutOfData      = errors.New("rardecode: decoder expected more data than is in packed file")
	ErrArchiveEncrypted      = errors.New("rardecode: archive encrypted, password required")
	ErrArchivedFileEncrypted = errors.New("rardecode: archived files encrypted, password required")
	ErrMultiVolume           = errors.New("rardecode: multi-volume archive continues in next file")
)
View Source
var (
	ErrBadPassword          = errors.New("rardecode: incorrect password")
	ErrCorruptEncryptData   = errors.New("rardecode: corrupt encryption data")
	ErrUnknownEncryptMethod = errors.New("rardecode: unknown encryption method")
	ErrPlatformIntSize      = errors.New("rardecode: platform integer size too small")
	ErrDictionaryTooLarge   = errors.New("rardecode: decode dictionary too large")
	ErrBadVolumeNumber      = errors.New("rardecode: bad volume number")
	ErrNoArchiveBlock       = errors.New("rardecode: missing archive block")
)
View Source
var (
	ErrNoSig        = errors.New("rardecode: RAR signature not found")
	ErrNegativeRead = errors.New("rardecode: negative read from Reader")
)
View Source
var (
	ErrUnknownFilter       = errors.New("rardecode: unknown V5 filter")
	ErrCorruptDecodeHeader = errors.New("rardecode: corrupt decode header")
)
View Source
var (
	ErrTooManyFilters   = errors.New("rardecode: too many filters")
	ErrInvalidFilter    = errors.New("rardecode: invalid filter")
	ErrMultipleDecoders = errors.New("rardecode: multiple decoders in a single archive not supported")
)
View Source
var (
	ErrHuffDecodeFailed   = errors.New("rardecode: huffman decode failed")
	ErrInvalidLengthTable = errors.New("rardecode: invalid huffman code length table")
)
View Source
var (
	ErrShortFile        = errors.New("rardecode: decoded file too short")
	ErrInvalidFileBlock = errors.New("rardecode: invalid file block")
	ErrUnexpectedArcEnd = errors.New("rardecode: unexpected end of archive")
	ErrBadFileChecksum  = errors.New("rardecode: bad file checksum")
	ErrSolidOpen        = errors.New("rardecode: solid files don't support Open")
	ErrUnknownVersion   = errors.New("rardecode: unknown archive version")
)
View Source
var (
	ErrVerMismatch      = errors.New("rardecode: volume version mistmatch")
	ErrArchiveNameEmpty = errors.New("rardecode: archive name empty")
	ErrFileNameRequired = errors.New("rardecode: filename required for multi volume archive")
	ErrInvalidHeaderOff = errors.New("rardecode: invalid filed header offset")
)
View Source
var (
	ErrCorruptPPM = errors.New("rardecode: corrupt ppm data")
)
View Source
var (
	ErrInvalidVMInstruction = errors.New("rardecode: invalid vm instruction")
)
View Source
var (
	ErrUnsupportedDecoder = errors.New("rardecode: unsupported decoder version")
)

Functions

func OpenFSCheck added in v2.2.0

func OpenFSCheck(o *options)

OpenFSCheck flags the archive files to be checked on Open or List.

func SkipCheck added in v2.2.0

func SkipCheck(o *options)

SkipCheck sets archive files checksum not to be checked.

Types

type File

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

File represents a file in a RAR archive

func List

func List(name string, opts ...Option) ([]*File, error)

List returns a list of File's in the RAR archive specified by name.

func (*File) Open

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

Open returns an io.ReadCloser that provides access to the File's contents. Open is not supported on Solid File's as their contents depend on the decoding of the preceding files in the archive. Use OpenReader and Next to access Solid file contents instead.

type FileHeader

type FileHeader struct {
	Name             string    // file name using '/' as the directory separator
	IsDir            bool      // is a directory
	Solid            bool      // is a solid file
	Encrypted        bool      // file contents are encrypted
	HeaderEncrypted  bool      // file header is encrypted
	HostOS           byte      // Host OS the archive was created on
	Attributes       int64     // Host OS specific file attributes
	PackedSize       int64     // packed file size (or first block if the file spans volumes)
	UnPackedSize     int64     // unpacked file size
	UnKnownSize      bool      // unpacked file size is not known
	ModificationTime time.Time // modification time (non-zero if set)
	CreationTime     time.Time // creation time (non-zero if set)
	AccessTime       time.Time // access time (non-zero if set)
	Version          int       // file version
}

FileHeader represents a single file in a RAR archive.

func (*FileHeader) Mode

func (f *FileHeader) Mode() fs.FileMode

Mode returns an fs.FileMode for the file, calculated from the Attributes field.

type Option

type Option func(*options)

An Option is used for optional archive extraction settings.

func BufferSize

func BufferSize(size int) Option

BufferSize sets the size of the bufio.Reader used in reading the archive.

func FileSystem

func FileSystem(fs fs.FS) Option

FileSystem sets the fs.FS to be used for opening archive volumes.

func MaxDictionarySize added in v2.2.0

func MaxDictionarySize(size int64) Option

MaxDictionarySize sets the maximum size in bytes of the dictionary used in decoding a file. Any attempt to decode a file with a larger size will return an error. The default size if not set is DefaultMaxDictionarySize. Any size above 64GB will be ignored. Any size below 256kB will prevent any file from being decoded.

func Password

func Password(pass string) Option

Password sets the password to use for decrypting archives.

type RarFS added in v2.2.0

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

RarFS implements the fs.FS interface for accessing files in a rar archive.

func OpenFS added in v2.2.0

func OpenFS(name string, opts ...Option) (*RarFS, error)

func (*RarFS) Open added in v2.2.0

func (rfs *RarFS) Open(name string) (fs.File, error)

Open opens the named file.

func (*RarFS) ReadDir added in v2.2.0

func (rfs *RarFS) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir reads the named directory and returns a list of directory entries sorted by filename.

func (*RarFS) ReadFile added in v2.2.0

func (rfs *RarFS) ReadFile(name string) ([]byte, error)

ReadFile reads the named file from the file system fs and returns its contents.

func (*RarFS) Stat added in v2.2.0

func (rfs *RarFS) Stat(name string) (fs.FileInfo, error)

Stat returns a FileInfo describing the named file from the filesystem.

func (*RarFS) Sub added in v2.2.0

func (rfs *RarFS) Sub(dir string) (fs.FS, error)

Sub returns an FS corresponding to the subtree rooted at fsys's dir.

type ReadCloser

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

ReadCloser is a Reader that allows closing of the rar archive.

func OpenReader

func OpenReader(name string, opts ...Option) (*ReadCloser, error)

OpenReader opens a RAR archive specified by the name and returns a ReadCloser.

func (*ReadCloser) Close

func (rc *ReadCloser) Close() error

Close closes the rar file.

func (*ReadCloser) Volumes added in v2.2.0

func (rc *ReadCloser) Volumes() []string

Volumes returns the volume filenames that have been used in decoding the archive up to this point. This will include the current open volume if the archive is still being processed.

type Reader

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

Reader provides sequential access to files in a RAR archive.

func NewReader

func NewReader(r io.Reader, opts ...Option) (*Reader, error)

NewReader creates a Reader reading from r. NewReader only supports single volume archives. Multi-volume archives must use OpenReader.

func (*Reader) Next

func (r *Reader) Next() (*FileHeader, error)

Next advances to the next file in the archive.

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

func (*Reader) ReadByte added in v2.2.0

func (r *Reader) ReadByte() (byte, error)

func (*Reader) WriteTo

func (r *Reader) WriteTo(w io.Writer) (int64, error)

Jump to

Keyboard shortcuts

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