archive

package
v0.0.0-...-2916d33 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package archive provides support for reading game files from archives. It supports ZIP, 7z, and RAR formats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectGameFile

func DetectGameFile(arc Archive) (string, error)

DetectGameFile finds the first game file in an archive. It scans the archive's file list and returns the path to the first file that has a recognized game extension.

func IsArchiveExtension

func IsArchiveExtension(ext string) bool

IsArchiveExtension checks if an extension is a supported archive format.

func IsArchivePath

func IsArchivePath(path string) bool

IsArchivePath checks if a path references an archive. This is a quick check that doesn't verify file existence.

func IsGameFile

func IsGameFile(filename string) bool

IsGameFile checks if a filename has a recognized game file extension. This only returns true for cartridge-based game extensions.

Types

type Archive

type Archive interface {
	// List returns all files in the archive.
	List() ([]FileInfo, error)

	// Open opens a file within the archive for reading.
	// Returns the reader, uncompressed size, and any error.
	Open(internalPath string) (io.ReadCloser, int64, error)

	// OpenReaderAt opens a file and returns an io.ReaderAt interface.
	// The file contents are buffered in memory to support random access.
	// The returned Closer must be called to release resources.
	OpenReaderAt(internalPath string) (io.ReaderAt, int64, io.Closer, error)

	// Close closes the archive.
	Close() error
}

Archive provides read access to files within an archive.

func Open

func Open(path string) (Archive, error)

Open opens an archive file based on its extension. Supported formats: .zip, .7z, .rar

type DiscNotSupportedError

type DiscNotSupportedError struct {
	Console string
}

DiscNotSupportedError indicates disc-based games in archives are not supported.

func (DiscNotSupportedError) Error

func (e DiscNotSupportedError) Error() string

type FileInfo

type FileInfo struct {
	Name string // Full path within archive
	Size int64  // Uncompressed size
}

FileInfo contains information about a file in an archive.

type FileNotFoundError

type FileNotFoundError struct {
	Archive      string
	InternalPath string
}

FileNotFoundError indicates a file was not found in the archive.

func (FileNotFoundError) Error

func (e FileNotFoundError) Error() string

type FormatError

type FormatError struct {
	Format string
	Reason string
}

FormatError indicates an unsupported or invalid archive format.

func (FormatError) Error

func (e FormatError) Error() string

type NoGameFilesError

type NoGameFilesError struct {
	Archive string
}

NoGameFilesError indicates no game files were found in the archive.

func (NoGameFilesError) Error

func (e NoGameFilesError) Error() string

type Path

type Path struct {
	ArchivePath  string // Path to the archive file
	InternalPath string // Path inside the archive (empty means auto-detect)
}

Path represents a parsed archive path with optional internal path.

func ParsePath

func ParsePath(path string) (*Path, error)

ParsePath parses a path that may reference a file inside an archive. It supports MiSTer-style paths like "/path/to/archive.zip/folder/game.gba".

Returns:

  • (*Path, nil) if the path contains an archive reference
  • (nil, nil) if the path is not an archive reference
  • (nil, error) if there was an error checking the path

type RARArchive

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

RARArchive provides access to files in a RAR archive.

func OpenRAR

func OpenRAR(path string) (*RARArchive, error)

OpenRAR opens a RAR archive for reading.

func (*RARArchive) Close

func (ra *RARArchive) Close() error

Close closes the RAR archive.

func (*RARArchive) List

func (ra *RARArchive) List() ([]FileInfo, error)

List returns all files in the RAR archive.

func (*RARArchive) Open

func (ra *RARArchive) Open(internalPath string) (io.ReadCloser, int64, error)

Open opens a file within the RAR archive. Note: RAR archives require sequential reading, so this seeks through the archive.

func (*RARArchive) OpenReaderAt

func (ra *RARArchive) OpenReaderAt(internalPath string) (io.ReaderAt, int64, io.Closer, error)

OpenReaderAt opens a file and returns an io.ReaderAt interface. The file contents are buffered in memory.

type SevenZipArchive

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

SevenZipArchive provides access to files in a 7z archive.

func OpenSevenZip

func OpenSevenZip(path string) (*SevenZipArchive, error)

OpenSevenZip opens a 7z archive for reading.

func (*SevenZipArchive) Close

func (sza *SevenZipArchive) Close() error

Close closes the 7z archive.

func (*SevenZipArchive) List

func (sza *SevenZipArchive) List() ([]FileInfo, error)

List returns all files in the 7z archive.

func (*SevenZipArchive) Open

func (sza *SevenZipArchive) Open(internalPath string) (io.ReadCloser, int64, error)

Open opens a file within the 7z archive.

func (*SevenZipArchive) OpenReaderAt

func (sza *SevenZipArchive) OpenReaderAt(internalPath string) (io.ReaderAt, int64, io.Closer, error)

OpenReaderAt opens a file and returns an io.ReaderAt interface. The file contents are buffered in memory.

type ZIPArchive

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

ZIPArchive provides access to files in a ZIP archive.

func OpenZIP

func OpenZIP(path string) (*ZIPArchive, error)

OpenZIP opens a ZIP archive for reading.

func (*ZIPArchive) Close

func (za *ZIPArchive) Close() error

Close closes the ZIP archive.

func (*ZIPArchive) List

func (za *ZIPArchive) List() ([]FileInfo, error)

List returns all files in the ZIP archive.

func (*ZIPArchive) Open

func (za *ZIPArchive) Open(internalPath string) (io.ReadCloser, int64, error)

Open opens a file within the ZIP archive.

func (*ZIPArchive) OpenReaderAt

func (za *ZIPArchive) OpenReaderAt(internalPath string) (io.ReaderAt, int64, io.Closer, error)

OpenReaderAt opens a file and returns an io.ReaderAt interface. The file contents are buffered in memory.

Jump to

Keyboard shortcuts

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