metadata

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHandler

func AddHandler(re *regexp.Regexp, fn HandlerFunc, namespaces ...string)

Add a metadata handler for a given regular expression, along with the namespaces (e.g. "exif", "tiff") of metadata it can produce. A filter that requests a specific namespace (e.g. "tiff:Make") will only run handlers registered for that namespace.

func ContentType

func ContentType(r io.Reader) (string, map[string]string, error)

Type returns the MIME type of the given file, along with a map of any additional metadata that was extracted from the file. If the MIME type cannot be determined, an error is returned.

func ExtensionByType

func ExtensionByType(contentType string) string

ExtensionByType returns the preferred extension for contentType, falling back to the first registered extension if no preferred extension matches.

func FilterMetadata

func FilterMetadata(entries map[string]gomedia.Metadata, filter string) []gomedia.Metadata

FilterMetadata returns the entries whose key matches filter, which may be "namespace:" (match all entries in the namespace), "name" (match entries with this name in any namespace), "namespace:name" (match entries with this name in this namespace), or empty (match everything). Keys are matched case-insensitively. This is a helper for handlers that build up a map of "namespace:name"-keyed metadata and need to apply the filter passed to their HandlerFunc.

func GetMetadata

func GetMetadata(ctx context.Context, r io.Reader, contentType, filter string) ([]gomedia.Metadata, error)

GetMetadata runs every handler registered for contentType against r, concurrently, and returns the combined metadata from all of them. If filter names a specific namespace (e.g. "tiff:" or "tiff:Make"), only the handlers registered for that namespace are run. Metadata from handlers that succeed is always returned, even if other handlers for the same content type fail; a non-nil error is the joined errors from any failing handlers, and should be treated as a warning rather than a reason to discard the metadata that was returned alongside it. ctx is passed to every handler and checked before any work starts, but GetMetadata otherwise waits for all handlers to finish rather than returning early on cancellation, since metadata extraction isn't preemptible and this avoids leaking their goroutines.

Types

type HandlerFunc

type HandlerFunc func(context.Context, io.Reader, string) ([]gomedia.Metadata, error)

HandlerFunc is a function that can be used to extract metadata from a given reader. The context can be used to cancel or time out long-running extraction. If the third argument is a non-empty string, if should return a specific named metadata, namespace, or artwork. For example, "exif:" => return all EXIF metadata "DateTimeOriginal" => return any DateTimeOriginal tags "exif:DateTimeOriginal" => return the DateTimeOriginal EXIF tag "artwork:" => return all artwork metadata "artwork:thumbnail" => return the thumbnail artwork metadata

func GetHandlers

func GetHandlers(contentType string) []HandlerFunc

GetHandlers returns all handlers registered for a given content type, or nil if no handler is registered for that content type.

type NamedStream

type NamedStream interface {
	// Name returns the name (path) of the stream, which can be used to
	// determine the MIME type.
	Name() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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