media

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TypeField is the name of the field that contains the type of the media
	TypeField = "Type"

	// DefaultType is the name used by default to identify a media type.
	// It is usually used in case media cannot be identified (either missing
	// or incorrect value)
	DefaultType = "media"
)
View Source
const (
	// DefaultMimetype is the fallback content type to identify file. The
	// handler that supports DefaultMimetype, if any, is also the default
	// handler should no handler be registered for a given Type or Mimetype.
	DefaultMimetype = "application/octet-stream"
)

Variables

View Source
var (
	// ErrNoMetadataFound reports an error when no Metadata found
	ErrNoMetadataFound = errors.New("media: no metadata found")
)
View Source
var (
	// ErrUnknownMediaType error is raise if submitted file is of unknown media
	// type, that is to say that no corresponding media handler is found.
	ErrUnknownMediaType = fmt.Errorf("media handler: unknown file type")
)

Functions

func Check added in v0.7.0

func Check(mdata Metadata, f File) (map[string]string, error)

Check reviews a media metadata and content to capture possible quality issues. Quality issues are organised by Metadata Field using "Content" as the special field name for issues about the media.File content itself.

func IsOfType added in v0.3.3

func IsOfType(mdata Metadata, typ string) bool

IsOfType checks whether the media is of the given type. IsOfType considers media's type of the form "family/sub-family" and checks if the provided type name is either the complete type, only the family of the sub-family.

func RegisterHandler

func RegisterHandler(mh Handler)

RegisterHandler registers a new media handler. It does not check if the handler is already registered.

func TypeOf added in v0.3.3

func TypeOf(mdata Metadata) string

TypeOf returns the media's type corresponding to the TypeField attribute value. If no information exists for TypeField attribute or if it is not of the appropriate type, it feedbacks DefaultType

func WalkContent added in v0.7.0

func WalkContent(f File, walkFn WalkFunc) error

WalkContent walks the media.File content, calling for each media.File sub-set the provided WalkFunc.

Types

type File

type File interface {
	io.Reader
	io.ReaderAt
	io.Seeker
}

File represents a media file

type Handler

type Handler interface {
	// Type provides the name of the handler. An handler's name is mainly used
	// to identify a media type and adopt customized behavior based on a media
	// type.
	Type() string

	// Mimetype provides the mimetype that the handler can manage.
	Mimetype() string

	// ReadMetadata retrieves the metadata from a given file.
	ReadMetadata(File) (Metadata, error)

	// FetchMetadata retrieves the metadata from an external source (usually an
	// internet data base) that corresponds to the provided known data.
	FetchMetadata(Metadata) ([]Metadata, error)

	// Check reviews a media's metadata and content to capture possible quality
	// issues.  Quality issues are organised by Metadata Field using "Content"
	// as the special field name for issues about the media.File content
	// itself.
	Check(Metadata, File) (map[string]string, error)

	// WalkContent walks the media.File content, calling for each
	// media.File sub-set the provided WalkFunc.
	WalkContent(File, WalkFunc) error
}

Handler represents a media handler.

type Handlers

type Handlers []Handler

Handlers represent the list of known media handlers.

func (Handlers) ForMetadata added in v0.4.0

func (h Handlers) ForMetadata(mdata Metadata) (Handler, error)

ForMetadata retrieves the handler corresponding to the provided metadata. Should no registered handler be found, the handler for DefaultType is returned if it exists.

ErrUnknownMediaType is returned if no handler is found.

func (Handlers) ForMimetype

func (h Handlers) ForMimetype(mtype string) (Handler, error)

ForMimetype retrieves the handler corresponding to the provided mimetype. Should no registered handler be found, the handler for DefaultType is returned if it exists.

ErrUnknownMediaType is returned if no handler is found.

func (Handlers) ForReader

func (h Handlers) ForReader(f io.Reader) (Handler, error)

ForReader retrieves the handler based on the reader guessed content type. Should no registered handler be found, the handler for DefaultType is returned if it exists.

ErrUnknownMediaType is returned if no handler is found.

func (Handlers) ForType

func (h Handlers) ForType(typ string) (Handler, error)

ForType retrieves the handler corresponding to the provided type. Should no registered handler be found, the handler for DefaultType is returned if it exists.

ErrUnknownMediaType is returned if no handler is found.

type Metadata

type Metadata = map[string]interface{}

Metadata represents a set of media's metadata, it is essentially a set of (key, value).

func FetchMetadata

func FetchMetadata(mdata Metadata) ([]Metadata, error)

FetchMetadata retrieves the metadata from an external source (usually an internet data base) that corresponds to the provided known data.

func ReadMetadata added in v0.4.0

func ReadMetadata(f File) (Metadata, error)

ReadMetadata reads metadata from the provided File and setup the proper media Type if not done by the corresponding Handler.

func ReadMetadataFromFile added in v0.4.0

func ReadMetadataFromFile(path string) (Metadata, error)

ReadMetadataFromFile reads metadata from the provided file name.

type WalkFunc added in v0.7.0

type WalkFunc func(string, io.Reader, error) error

WalkFunc is the type of the function called by WalkContent.

Directories

Path Synopsis
sanitizer
Package sanitizer provides functions for sanitizing HTML text.
Package sanitizer provides functions for sanitizing HTML text.

Jump to

Keyboard shortcuts

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