formats

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package formats defines the canonical format registry used for routing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustID

func MustID(path string) string

MustID returns the canonical format ID for a file path. Returns "" if the format cannot be determined.

Types

type Category

type Category string

Category classifies a format by its broad media type.

const (
	CategoryDocument Category = "document"
	CategoryMarkup   Category = "markup"
	CategoryData     Category = "data"
	CategoryImage    Category = "image"
	CategoryAudio    Category = "audio"
	CategoryVideo    Category = "video"
	CategoryTextArt  Category = "text-art"
	CategoryArchive  Category = "archive"
)

type Format

type Format struct {
	ID         string // canonical id: "md", "docx", "mp4"
	Category   Category
	Extensions []string // includes leading dot: ".md", ".markdown"
	MimeTypes  []string
	Text       bool // true for text-based formats (safe to pipe via stdin)
}

Format describes a single file format.

func All

func All() []Format

All returns all registered formats.

func AllByCategory

func AllByCategory(c Category) []Format

AllByCategory returns formats filtered by category.

func ByExtension

func ByExtension(ext string) *Format

ID returns the canonical format id for the given extension (without dot). Returns empty string if not found.

func ByID

func ByID(id string) *Format

ByID returns the Format for the given canonical id.

func DetectFile

func DetectFile(path string) (*Format, error)

DetectFile detects the format of a file by magic bytes then extension.

func DetectReader

func DetectReader(name string, r io.Reader) (*Format, error)

DetectReader detects the format from a reader (reads first 512 bytes). For generic text/plain MIME type, extension-based detection takes priority because many text-based formats (md, rst, toml, yaml, etc.) share the same MIME.

Jump to

Keyboard shortcuts

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