v2

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package v2 reads TA: Kingdoms HPI archives (version 0x00020000). Unlike the Total Annihilation v1 format, the directory and name blocks live at arbitrary offsets near the tail of the file, each optionally wrapped in a single SQSH chunk, and file payloads are stored without the v1 XOR cipher.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

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

Reader reads a TA: Kingdoms (v2) HPI archive.

A Reader is not safe for concurrent use: every read seeks the shared file handle, so callers serving an archive to multiple goroutines must serialize access.

func Open

func Open(path string) (*Reader, error)

Open opens a v2 HPI archive for reading.

func (*Reader) Close

func (r *Reader) Close() error

Close closes the underlying file.

func (*Reader) Find

func (r *Reader) Find(path string) *common.Entry

Find locates an entry by path.

func (*Reader) Header

func (r *Reader) Header() *common.Header

Header returns the archive header. Only Marker and Version are populated for v2 archives; the v1-style directory fields are zero.

func (*Reader) List

func (r *Reader) List() []string

List returns the full paths of every file in the archive.

func (*Reader) Open

func (r *Reader) Open(path string) (io.ReadCloser, error)

Open opens a file from the archive by path.

func (*Reader) OpenEntry

func (r *Reader) OpenEntry(entry *common.Entry) (io.ReadCloser, error)

OpenEntry opens a file entry for reading.

func (*Reader) Root

func (r *Reader) Root() *common.Entry

Root returns the root directory entry.

func (*Reader) Version

func (r *Reader) Version() uint32

Version reports the on-disk HPI version (always VersionV2).

func (*Reader) Walk

func (r *Reader) Walk(fn func(*common.Entry) error) error

Walk traverses every entry in the archive.

type Writer

type Writer struct {
	CompressionLevel  int   // zlib level (0–9); 0 means default
	CompressionMethod uint8 // common.CompressionNone or common.CompressionZLib (default)
	// contains filtered or unexported fields
}

Writer builds a TA: Kingdoms (v2) HPI archive. Unlike v1 there is no XOR cipher; each file is stored either raw or as a single zlib-compressed SQSH chunk, and the directory and name blocks are written uncompressed.

func CreateWriter

func CreateWriter(path string) (*Writer, error)

CreateWriter creates a new v2 HPI archive at the given path, defaulting to zlib compression.

func (*Writer) AddDirectory

func (w *Writer) AddDirectory(archivePath, dirPath string) error

AddDirectory recursively adds every file under dirPath, rooted at archivePath inside the archive.

func (*Writer) AddFile

func (w *Writer) AddFile(archivePath, filePath string) error

AddFile reads a file from disk and adds it to the archive.

func (*Writer) AddFileFromBytes

func (w *Writer) AddFileFromBytes(archivePath string, data []byte) error

AddFileFromBytes adds a file from an in-memory byte slice.

func (*Writer) Close

func (w *Writer) Close() error

Close finalises the archive and closes the underlying file.

type WriterEntry

type WriterEntry struct {
	Path string
	Data []byte
}

WriterEntry holds a file's metadata and payload for writing into an archive.

Jump to

Keyboard shortcuts

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