romloader

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: GPL-3.0 Imports: 13 Imported by: 5 modules, 9 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

eblitui-romloader

A shared ROM loading utility for eblitui UIs. Handles loading ROM files from raw files and compressed archives (ZIP, 7z, gzip/tar.gz, RAR).

Valid ROM extensions are passed by the caller rather than being hardcoded. Extensions come from SystemInfo.Extensions at the call site.

Usage

import "github.com/user-none/eblitui/romloader"

// Load a ROM, searching archives for files matching the given extensions
data, filename, err := romloader.Load(path, []string{".sms"})

The Load function auto-detects archive formats via magic bytes and extracts the first file whose extension matches the provided list. For non-archive files, the file is read directly if its extension matches.

Public API

// Load reads a ROM from a file path. It auto-detects compressed
// archives via magic bytes and extracts the first file matching
// one of the given extensions.
//
// Returns the ROM data, the filename (basename only), and any error.
func Load(path string, extensions []string) ([]byte, string, error)
Errors
var ErrNoROMFile         // no ROM file found in archive
var ErrUnsupportedFormat // unrecognized file format
var ErrFileTooLarge      // file exceeds 8MB safety limit

Supported Formats

Detection uses magic bytes first (reliable), then falls back to file extension.

Format Magic bytes Extensions
ZIP PK\x03\x04 .zip
7z 7z\xBC\xAF\x27\x1C .7z
GZIP/TAR \x1F\x8B .gz, .tgz, .tar.gz
RAR Rar! .rar
Raw ROM (none) Caller-provided

For archives, the loader searches for the first file whose extension matches one of the provided ROM extensions (case-insensitive). Directories and non-matching files are skipped.

For plain gzip files (not tar.gz), the decompressed content is returned directly since the file is not a multi-file archive.

Dependencies

  • github.com/bodgit/sevenzip - 7z archive support
  • github.com/nwaples/rardecode/v2 - RAR archive support

ZIP and gzip support use Go's standard library.

Testing

go test ./...

Used By

  • eblitui-standalone (ROM loading for desktop UI)
  • eblitui-ios (ROM loading for iOS app)

Not used by eblitui-libretro (the frontend provides ROM data directly).

Documentation

Overview

Package romloader handles loading ROM files from various sources, including compressed archives (ZIP, 7z, gzip, tar.gz, RAR).

Index

Constants

This section is empty.

Variables

View Source
var ErrFileTooLarge = errors.New("file exceeds maximum size limit")

ErrFileTooLarge is returned when extracted content exceeds size limit

View Source
var ErrNoFile = errors.New("no matching file found in archive")

ErrNoFile is returned when no matching file is found in an archive

View Source
var ErrUnsupportedFormat = errors.New("unsupported file format")

ErrUnsupportedFormat is returned for unrecognized file formats

Functions

func Load

func Load(path string, extensions []string) ([]byte, string, error)

Load reads a ROM from a file path. It auto-detects compressed archives via magic bytes and extracts the first file matching one of the given extensions. For raw (non-archive) files, the extension must match or the file is loaded as-is if no archive format is detected.

Returns the ROM data, the filename (basename only, useful for display), and any error.

func LoadBIOS added in v0.2.0

func LoadBIOS(path string) ([]byte, error)

LoadBIOS reads a BIOS file from the given path, supporting the same archive formats as Load (ZIP, 7z, gzip/tar, RAR). Unlike Load, it does not require the contained file to have a specific extension - the first non-directory file in an archive is returned.

Types

type Disc added in v0.3.0

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

Disc is a streaming reader over a CHD disc image. It owns the open file handle and decodes hunks on demand, so the whole image is never read into memory. Its method set uses only stdlib types so it satisfies a disc-reader interface structurally without a shared type.

func OpenDisc added in v0.3.0

func OpenDisc(path string) (*Disc, error)

OpenDisc opens a CHD disc image for streaming. The file handle is held open for on-demand hunk reads until Close is called.

func (*Disc) Close added in v0.3.0

func (d *Disc) Close() error

Close releases the CHD decoder and the underlying file handle.

func (*Disc) NumTracks added in v0.3.0

func (d *Disc) NumTracks() int

NumTracks returns the number of tracks on the disc.

func (*Disc) ReadSector added in v0.3.0

func (d *Disc) ReadSector(lba int) ([]byte, error)

ReadSector returns the raw 2352-byte sector at the given LBA.

func (*Disc) Track added in v0.3.0

func (d *Disc) Track(i int) (number int, typ string, frames int, pregap int, startLBA int, control uint8)

Track returns the TOC fields for track index i in [0, NumTracks).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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