media

package
v0.1.0-preview.28 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package media defines bounded media preparation and storage-neutral blob interfaces. Applications retain authorization, references, lifecycle, and presentation policy.

Index

Constants

View Source
const (
	KindImage      = "image"
	KindAttachment = "attachment"
)

Variables

View Source
var (
	ErrInvalidMedia = errors.New("media: invalid media")
	ErrTooLarge     = errors.New("media: upload exceeds its size limit")
	ErrNotFound     = errors.New("media: object not found")
)

Functions

func Extension

func Extension(mediaType string) string

func ValidKey

func ValidKey(value string) bool

Types

type Limits

type Limits struct {
	MaxBytes  int64
	MaxWidth  int
	MaxHeight int
	MaxPixels int64
}

type Object

type Object struct {
	Key       string
	Size      int64
	MediaType string
	CreatedAt time.Time
}

type Prepared

type Prepared struct {
	Digest       [32]byte
	Data         []byte
	MediaType    string
	Kind         string
	OriginalName string
	Width        int
	Height       int
}

Prepared is a sanitized, bounded object ready for durable storage. Raster images are decoded and re-encoded so source metadata and unparsed trailing bytes are not retained. PDFs are attachments and are never inline media.

func Prepare

func Prepare(reader io.Reader, originalName string, limits Limits) (Prepared, error)

Prepare reads at most the configured bound and accepts JPEG, PNG, GIF, or a PDF attachment. Animated images are deliberately flattened to the decoded first frame. The returned byte slice is owned by the caller.

func (Prepared) Key

func (prepared Prepared) Key() string

type Store

type Store interface {
	Put(context.Context, Prepared) (Object, error)
	Open(context.Context, string) (io.ReadCloser, Object, error)
	Delete(context.Context, string) error
}

Jump to

Keyboard shortcuts

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