resource

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 25 Imported by: ? modules, 0 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.

Documentation

Index

Constants

View Source
const (
	CatalogFile    = "catalog.bin"
	CatalogVersion = 2
	BasePackage    = "base"
	ContentIDSize  = 16
)
View Source
const (
	Extension     = ".dat"
	FormatVersion = 5
)

Variables

View Source
var (
	ErrPackageNotLoaded = errors.New("resource package is not loaded")
	ErrPackageInUse     = errors.New("resource package is in use")
	ErrRequiredPackage  = errors.New("required resource package cannot be unloaded")
)

Functions

func Default

func Default() (fs.FS, string, bool)

func LoadDefaultPackage

func LoadDefaultPackage(name string) error

func MarshalCatalog

func MarshalCatalog(catalog Catalog) ([]byte, error)

MarshalCatalog encodes a validated catalog into Onix's compact binary format.

func MountDefaultPackage

func MountDefaultPackage(name string, data []byte) error

func OpenDirectory

func OpenDirectory(root string) fs.FS

OpenDirectory returns the filesystem rooted at root. It matches os.DirFS for every fs.FS operation and additionally serves OpenBlob.

func SetDefault

func SetDefault(source fs.FS, root string) error

func SetDefaultProject

func SetDefaultProject(source fs.FS, root string) error

SetDefaultProject mounts project-relative packaged files at their source project root.

func Size

func Size(name string) (float64, float64, error)

Size returns an image's logical dimensions from the configured resource source without decoding its pixel data. The source is opened through the engine resource layer, so packaged and directory-backed projects behave the same way.

func Sub

func Sub(source fs.FS, dir string) (fs.FS, error)

Sub returns the subtree of source rooted at dir without dropping OpenBlob. A source that serves mapped blobs keeps serving them, so packaged builds and authoring directories resolve resources through the same path.

func ValidPackageName

func ValidPackageName(name string) bool

Types

type AssetInfo

type AssetInfo struct {
	Path      string
	Size      int64
	Checksum  uint32
	ContentID ContentID
}

AssetInfo is the catalog-owned metadata for one logical resource. Assets in each package are strictly sorted by Path and line up with the package index.

type Blob

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

Blob is a pinned, immutable view of one encoded resource. Bytes may return a direct package view; callers must not mutate it. Close releases the package pin and invalidates all views obtained from the Blob.

func NewMemoryBlob

func NewMemoryBlob(name string, data []byte) *Blob

NewMemoryBlob takes ownership of data and returns an already verified Blob.

func (*Blob) Bytes

func (b *Blob) Bytes() ([]byte, error)

func (*Blob) Close

func (b *Blob) Close() error

func (*Blob) ContentID

func (b *Blob) ContentID() ContentID

func (*Blob) Info

func (b *Blob) Info() AssetInfo

func (*Blob) Open

func (b *Blob) Open() (io.ReadSeekCloser, error)

func (*Blob) ReadAll

func (b *Blob) ReadAll() ([]byte, error)

ReadAll returns an owned copy of the resource. Unlike Bytes, the result may be mutated and remains valid after Close.

func (*Blob) ReleaseResidentPages

func (b *Blob) ReleaseResidentPages() error

ReleaseResidentPages lets a mapped package discard fully covered file pages after a resource has been decoded. The bytes remain available on next access.

func (*Blob) Size

func (b *Blob) Size() int64

func (*Blob) Validate

func (b *Blob) Validate() error

func (*Blob) View

func (b *Blob) View() ([]byte, bool)

View returns the resource bytes without copying when the backing store can expose them directly. Callers must not mutate the result and must keep the Blob open for as long as they use it. The boolean reports whether a direct view exists; otherwise callers fall back to Bytes or ReadAll.

type Catalog

type Catalog struct {
	Packages []PackageInfo
	Version  int
}

func ParseCatalog

func ParseCatalog(data []byte) (Catalog, error)

ParseCatalog decodes an ONIXCAT2 resource catalog.

func (Catalog) Validate

func (c Catalog) Validate() error

type ContentID

type ContentID [ContentIDSize]byte

ContentID identifies identical encoded resource contents independently of their logical paths. It is the first 128 bits of SHA-256.

type Manager

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

func DefaultManager

func DefaultManager() (*Manager, bool)

func NewManager

func NewManager(catalog Catalog, loader PackageLoader) (*Manager, error)

func NewMemoryManager

func NewMemoryManager(catalogData []byte, packages map[string][]byte) (*Manager, error)

NewMemoryManager takes ownership of every package byte slice in packages. The slices must not be mutated for the lifetime of the Manager.

func OpenManager

func OpenManager(directory string) (*Manager, error)

func (*Manager) Catalog

func (m *Manager) Catalog() Catalog

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) Load

func (m *Manager) Load(name string) error

func (*Manager) LoadContext

func (m *Manager) LoadContext(ctx context.Context, name string) error

func (*Manager) LoadRequired

func (m *Manager) LoadRequired() error

func (*Manager) LoadRequiredContext

func (m *Manager) LoadRequiredContext(ctx context.Context) error

func (*Manager) Loaded

func (m *Manager) Loaded(name string) bool

func (*Manager) MountBytes

func (m *Manager) MountBytes(name string, data []byte) error

MountBytes takes ownership of data and mounts it without copying. The caller must not mutate data after this method is called.

func (*Manager) MountBytesContext

func (m *Manager) MountBytesContext(ctx context.Context, name string, data []byte) error

func (*Manager) Open

func (m *Manager) Open(name string) (fs.File, error)

func (*Manager) OpenBlob

func (m *Manager) OpenBlob(name string) (*Blob, error)

func (*Manager) ReadDir

func (m *Manager) ReadDir(name string) ([]fs.DirEntry, error)

func (*Manager) ReadFile

func (m *Manager) ReadFile(name string) ([]byte, error)

func (*Manager) Stat

func (m *Manager) Stat(name string) (fs.FileInfo, error)

func (*Manager) Statistics

func (m *Manager) Statistics() ManagerStatistics

func (*Manager) Unload

func (m *Manager) Unload(name string) error

type ManagerStatistics

type ManagerStatistics struct {
	LoadedPackages         int
	ResidentPackageBytes   int64
	PinnedBlobs            int
	PinnedBytes            int64
	PackageLoads           uint64
	PackageUnloads         uint64
	BlobAcquires           uint64
	PackageLoadNanoseconds uint64
}

type PackInput

type PackInput struct {
	Path   string
	Source string
	Data   []byte
}

PackInput names either an in-memory blob or a file-backed blob. Source is empty for in-memory data. Callers retain ownership until Pack returns.

func BytesInput

func BytesInput(path string, data []byte) PackInput

func FileInput

func FileInput(path, source string) PackInput

type PackProgress

type PackProgress struct {
	Path      string
	Writing   bool
	Active    bool
	Completed int
	Total     int
}

PackProgress reports actual input inspection and writing work. Completed and Total include both passes, including deduplicated files. Active identifies the event before a potentially long operation; it clears on completion.

type PackResult

type PackResult struct {
	Assets []AssetInfo
	Stats  PackStats
}

func Pack

func Pack(writer io.Writer, inputs []PackInput) (PackResult, error)

Pack writes the current indexed package format. It hashes file-backed inputs in a first pass, then streams only canonical blobs into the package.

func PackWithProgress

func PackWithProgress(writer io.Writer, inputs []PackInput, progress func(PackProgress)) (PackResult, error)

PackWithProgress writes a package and reports each resource before and after its work, without retaining its contents or adding another input traversal.

type PackStats

type PackStats struct {
	Files             int
	RawBytes          int64
	PackedBytes       int64
	Stored            int
	Deduplicated      int
	DeduplicatedBytes int64
}

PackStats describes the uncompressed resource blobs written to a package. Stored counts non-alias entries; aliases are counted in Deduplicated.

type PackageInfo

type PackageInfo struct {
	Name         string
	File         string
	Dependencies []string
	Assets       []AssetInfo
	Size         int64
	SHA256       [sha256.Size]byte
	Required     bool
}

type PackageLoader

type PackageLoader func(context.Context, PackageInfo) (PackageSource, error)

PackageLoader opens one package. It runs without the Manager mutex held and must honor cancellation whenever its backing transport supports it.

type PackageNotLoadedError

type PackageNotLoadedError struct {
	Package string
	Path    string
}

func (*PackageNotLoadedError) Error

func (e *PackageNotLoadedError) Error() string

func (*PackageNotLoadedError) Unwrap

func (e *PackageNotLoadedError) Unwrap() error

type PackageSource

type PackageSource struct {
	ReaderAt io.ReaderAt
	Closer   io.Closer
	Size     int64
}

type Preparation

type Preparation[T any] struct {
	// contains filtered or unexported fields
}

Preparation transfers one CPU result to its caller. Load must not access ECS or render devices. Wake may be called by the worker and must be thread-safe.

func BeginPreparation

func BeginPreparation[T any](load func(context.Context) (T, error), discard func(T), wake func()) *Preparation[T]

func (*Preparation[T]) Cancel

func (p *Preparation[T]) Cancel()

Cancel does not wait for I/O. An unpublished CPU result is released by its owner; results already transferred by Take must be released by the caller.

func (*Preparation[T]) Finish

func (p *Preparation[T]) Finish(err error)

Finish records the render-thread outcome after Take.

func (*Preparation[T]) State

func (p *Preparation[T]) State() PreparationState

func (*Preparation[T]) Take

func (p *Preparation[T]) Take() (T, bool, error)

Take transfers the CPU result once, without waiting for unfinished work. The caller owns its cleanup and all subsequent GPU operations.

func (*Preparation[T]) WaitCPU

func (p *Preparation[T]) WaitCPU(ctx context.Context) error

WaitCPU is for callers explicitly choosing synchronous preparation.

type PreparationState

type PreparationState uint8

PreparationState separates background CPU work from render-thread upload.

const (
	PreparingCPU PreparationState = iota
	CPUReady
	PreparingGPU
	PreparationReady
	PreparationFailed
	PreparationCancelled
)

type Reader

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

func NewReader

func NewReader(source io.ReaderAt, size int64, assets []AssetInfo) (*Reader, error)

func (*Reader) Close

func (r *Reader) Close() error

func (*Reader) Open

func (r *Reader) Open(name string) (iofs.File, error)

func (*Reader) OpenBlob

func (r *Reader) OpenBlob(name string) (*Blob, error)

func (*Reader) ReadDir

func (r *Reader) ReadDir(name string) ([]iofs.DirEntry, error)

func (*Reader) ReadFile

func (r *Reader) ReadFile(name string) ([]byte, error)

func (*Reader) Stat

func (r *Reader) Stat(name string) (iofs.FileInfo, error)

Jump to

Keyboard shortcuts

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