romloader

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

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 ErrNoROMFile = errors.New("no ROM file found in archive")

ErrNoROMFile is returned when no ROM 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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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