headers

package
v0.0.0-...-eed3b00 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: MIT, MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxInOutStreams is the maximum allowed stream inputs/outputs into/out
	// of a coder.
	MaxInOutStreams = 4

	// MaxPropertyDataSize is the size in bytes supported for coder property data.
	MaxPropertyDataSize = 128

	// MaxCodersInFolder is the maximum number of coders allowed to be
	// specified in a folder.
	MaxCodersInFolder = 4

	// MaxPackedStreamsInFolder is the maximum number of packed streams allowed
	// to be in a folder.
	MaxPackedStreamsInFolder = 4
)
View Source
const (
	// SignatureHeaderSize SignatureHeader size is the size of the signature header.
	SignatureHeaderSize = 32

	// MaxHeaderSize is the maximum header size.
	MaxHeaderSize = int64(1 << 62) // 4 exbibyte
)
View Source
const MaxFolderCount = 1 << 30

MaxFolderCount count

View Source
const MaxNumber = 0x7FFFFFFF

MaxNumber max

Variables

View Source
var (
	// ErrInvalidStreamCount is the error returned when the input/output stream
	// count for a coder is <= 0 || > MaxInOutStreams.
	ErrInvalidStreamCount = errors.New("invalid in/out stream count")

	// ErrInvalidPropertyDataSize is the error returned when the property data
	// size is <= 0 || > MaxInOutStreams.
	ErrInvalidPropertyDataSize = errors.New("invalid property data size")

	// ErrInvalidCoderInFolderCount is the error returned when the number of
	// coders in a folder is <= 0 || > MaxCodersInFolder.
	ErrInvalidCoderInFolderCount = errors.New("invalid coder in folder count")

	// ErrInvalidPackedStreamsCount is the error returned when the number of
	// packed streams exceeds MaxPackedStreamsInFolder
	ErrInvalidPackedStreamsCount = errors.New("invalid packed streams count")
)
View Source
var (
	// MagicBytes is the magic bytes used in the 7z signature.
	MagicBytes = [6]byte{0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C}

	// ErrInvalidSignatureHeader is returned when signature header is invalid.
	ErrInvalidSignatureHeader = errors.New("invalid signature header")
)
View Source
var (
	// ErrUnexpectedPropertyID is returned when we read a property id that was
	// either unexpected, or we don't support.
	ErrUnexpectedPropertyID = errors.New("unexpected property id")

	// ErrAdditionalStreamsNotImplemented is returned for archives using
	// additional streams. These were apparently used in older versions of 7zip.
	ErrAdditionalStreamsNotImplemented = errors.New("additional streams are not implemented")

	// ErrArchivePropertiesNotImplemented is returned if archive properties
	// structure is found. So far, this hasn't been used in any verison of 7zip.
	ErrArchivePropertiesNotImplemented = errors.New("archive properties are not implemented")

	// ErrChecksumMismatch is returned when a CRC check fails.
	ErrChecksumMismatch = errors.New("checksum mismatch")

	// ErrPackInfoCRCsNotImplemented is returned if a CRC property id is
	// encountered whilst reading packinfo.
	ErrPackInfoCRCsNotImplemented = errors.New("packinfo crcs are not implemented")

	// ErrInvalidNumber is returned when a number read exceeds 0x7FFFFFFF
	ErrInvalidNumber = errors.New("invalid number")
)
View Source
var ErrInvalidCountExceeded = errors.New("invalid folder count")

ErrInvalidCountExceeded is returned when the folder count is < 0 || > MaxFolderCount

View Source
var ErrInvalidFileCount = errors.New("invalid file count")

ErrInvalidFileCount is returned when the file count read from the stream exceeds the caller supplied maxFileCount.

Functions

func ReadAttributeVector

func ReadAttributeVector(r io.Reader, numFiles int) ([]uint32, error)

ReadAttributeVector reads a vector of uint32s.

func ReadBoolVector

func ReadBoolVector(r io.Reader, length int) ([]bool, int, error)

ReadBoolVector reads a vector of boolean values.

func ReadByte

func ReadByte(r io.Reader) (byte, error)

ReadByte reads a single byte.

func ReadByteExpect

func ReadByteExpect(r io.Reader, val byte) error

ReadByteExpect reads a byte to be expected, errors if unexpected.

func ReadDateTimeVector

func ReadDateTimeVector(r io.Reader, numFiles int) ([]time.Time, error)

ReadDateTimeVector reads a vector of datetime values.

func ReadDigests

func ReadDigests(r io.Reader, length int) ([]uint32, error)

ReadDigests reads an array of uint32 CRCs.

func ReadNumber

func ReadNumber(r io.Reader) (uint64, error)

ReadNumber reads a 7z encoded uint64.

func ReadNumberInt

func ReadNumberInt(r io.Reader) (int, error)

ReadNumberInt is the same as ReadNumber, but cast to int.

func ReadNumberVector

func ReadNumberVector(r io.Reader, numFiles int) ([]*int64, error)

ReadNumberVector returns a vector of 7z encoded int64s.

func ReadOptionalBoolVector

func ReadOptionalBoolVector(r io.Reader, length int) ([]bool, int, error)

ReadOptionalBoolVector reads a vector of boolean values if they're available, otherwise it returns an array of booleans all being true.

func ReadPackedStreamsForHeaders

func ReadPackedStreamsForHeaders(r *io.LimitedReader) (header *Header, encodedHeader *StreamsInfo, err error)

ReadPackedStreamsForHeaders reads either a header or encoded header structure.

func ReadUint32

func ReadUint32(r io.Reader) (uint32, error)

ReadUint32 reads a uint32.

func ReadUint64

func ReadUint64(r io.Reader) (uint64, error)

ReadUint64 reads a uint64.

Types

type BindPairsInfo

type BindPairsInfo struct {
	InIndex  int
	OutIndex int
}

BindPairsInfo is a structure that binds the in and out indexes of a codec.

func ReadBindPairsInfo

func ReadBindPairsInfo(r io.Reader) (*BindPairsInfo, error)

ReadBindPairsInfo reads a bindpairs info structure.

type CoderInfo

type CoderInfo struct {
	CodecID       uint32
	Properties    []byte
	NumInStreams  int
	NumOutStreams int
}

CoderInfo is a structure holding information about a codec.

func ReadCoderInfo

func ReadCoderInfo(r io.Reader) (*CoderInfo, error)

ReadCoderInfo reads a coder info structure.

type FileInfo

type FileInfo struct {
	Name   string
	Attrib uint32

	IsEmptyStream bool
	IsEmptyFile   bool

	// Flag indicating a file should be removed upon extraction.
	IsAntiFile bool

	CreatedAt  time.Time
	AccessedAt time.Time
	ModifiedAt time.Time
}

FileInfo is a structure containing the information of an archived file.

func ReadFilesInfo

func ReadFilesInfo(r io.Reader, maxFileCount int) ([]*FileInfo, error)

ReadFilesInfo reads the files info structure.

type Folder

type Folder struct {
	CoderInfo     []*CoderInfo
	BindPairsInfo []*BindPairsInfo
	PackedIndices []int
	UnpackSizes   []uint64
	UnpackCRC     uint32
}

Folder is a structure containing information on how a solid block was constructed.

func ReadFolder

func ReadFolder(r io.Reader) (*Folder, error)

ReadFolder reads a folder structure.

func (*Folder) FindBindPairForInStream

func (f *Folder) FindBindPairForInStream(inStreamIndex int) int

FindBindPairForInStream returns the index of a bindpair by an in index.

func (*Folder) FindBindPairForOutStream

func (f *Folder) FindBindPairForOutStream(outStreamIndex int) int

FindBindPairForOutStream returns the index of a bindpair by an out index.

func (*Folder) NumInStreamsTotal

func (f *Folder) NumInStreamsTotal() int

NumInStreamsTotal is the sum of inputs required by all codecs.

func (*Folder) NumOutStreamsTotal

func (f *Folder) NumOutStreamsTotal() int

NumOutStreamsTotal is the sum of outputs required by all codecs.

func (*Folder) UnpackSize

func (f *Folder) UnpackSize() uint64

UnpackSize returns the final unpacked size of the folder.

type Header struct {
	MainStreamsInfo *StreamsInfo
	FilesInfo       []*FileInfo
}

Header is structure containing file and stream information.

func ReadHeader

func ReadHeader(r *io.LimitedReader) (*Header, error)

ReadHeader reads a header structure.

type PackInfo

type PackInfo struct {
	PackPos   uint64
	PackSizes []uint64
}

PackInfo contains the pack stream sizes of the folders.

func ReadPackInfo

func ReadPackInfo(r io.Reader) (*PackInfo, error)

ReadPackInfo reads a pack info structure.

type SignatureHeader

type SignatureHeader struct {
	Signature [6]byte

	ArchiveVersion struct {
		Major byte
		Minor byte
	}

	StartHeaderCRC uint32

	StartHeader struct {
		NextHeaderOffset int64
		NextHeaderSize   int64
		NextHeaderCRC    uint32
	}
}

SignatureHeader is the structure found at the top of 7z files.

func ReadSignatureHeader

func ReadSignatureHeader(r io.Reader) (*SignatureHeader, error)

ReadSignatureHeader reads the signature header.

type StreamsInfo

type StreamsInfo struct {
	PackInfo       *PackInfo
	UnpackInfo     *UnpackInfo
	SubStreamsInfo *SubStreamsInfo
}

StreamsInfo is a top-level structure of the 7z format.

func ReadStreamsInfo

func ReadStreamsInfo(r io.Reader) (*StreamsInfo, error)

ReadStreamsInfo reads the streams info structure.

type SubStreamsInfo

type SubStreamsInfo struct {
	NumUnpackStreamsInFolders []int
	UnpackSizes               []uint64
	Digests                   []uint32
}

SubStreamsInfo is a structure found within the StreamsInfo structure.

func ReadSubStreamsInfo

func ReadSubStreamsInfo(r io.Reader, unpackInfo *UnpackInfo) (*SubStreamsInfo, error)

ReadSubStreamsInfo reads the substreams info structure.

type UnpackInfo

type UnpackInfo struct {
	Folders []*Folder
}

UnpackInfo is a structure containing folders.

func ReadUnpackInfo

func ReadUnpackInfo(r io.Reader) (*UnpackInfo, error)

ReadUnpackInfo reads unpack info structures.

Jump to

Keyboard shortcuts

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