imagefiles

package
v2.23.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: GPL-3.0 Imports: 12 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

Overview

Package imagefiles stores user-supplied images as files in a folder of Core's data directory: deck covers and the images set on games by hand.

Index

Constants

View Source
const (
	// MaxBytes is the largest image a store keeps.
	MaxBytes = 10 << 20
)

Variables

View Source
var (
	// ErrNotImage reports bytes that are not a supported image.
	ErrNotImage = errors.New("not a JPEG, PNG, GIF or WebP image")
	// ErrTooLarge reports an image over MaxBytes.
	ErrTooLarge = errors.New("image is larger than 10 MiB")
	// ErrNotFound reports an image file that is not stored.
	ErrNotFound = errors.New("image not found")
)

Functions

func ContentType

func ContentType(data []byte) (string, error)

ContentType reports the image type of data, or ErrNotImage.

Types

type Store

type Store struct {
	FS  afero.Fs
	Dir string
}

Store keeps images in one folder. A file is named after a caller's prefix and its content, so a new image never overwrites one a row still names, and files no row names are pruned.

func (*Store) Holds

func (s *Store) Holds(path string) bool

Holds reports whether path names a file in the store, whether or not the file is still there.

func (*Store) Path

func (s *Store) Path(name string) (string, error)

Path returns the full path of a stored image, or ErrNotFound when it is not stored. Any other error is a folder that could not be checked, not a missing image.

func (*Store) Prune

func (s *Store) Prune(keep map[string]struct{}, now time.Time)

Prune removes files not in keep. Files written in the last few minutes stay, since the row that names one may not be stored yet.

func (*Store) Read

func (s *Store) Read(name string) ([]byte, error)

Read returns a stored image's bytes, or ErrNotFound.

func (*Store) Save

func (s *Store) Save(prefix string, data []byte) (string, error)

Save stores an image and returns the file name to keep.

Jump to

Keyboard shortcuts

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