files

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Img = "image"
	// Application is provide because the type from the document's mimetype
	// is defined as application, not document. Both are supported.
	Application = "application"
	Doc         = "document"
	Text        = "text"
)

Variables

This section is empty.

Functions

func SupportedFileTypes

func SupportedFileTypes() map[string]string

SupportedFileTypes returns a map with the underlying file type, given a sub-type.

func TypeAndSupType

func TypeAndSupType(mimetype string) (string, string, error)

TypeAndSupType returns a the type and the sub-type of a given mimetype. e.g. image/png type: image subtype: png

Types

type Document

type Document interface {
	DocumentType() string
}

Document interface is the one that defines what a document is in this context. It's responsible to return kind of the underlying document.

type DocumentFactory

type DocumentFactory struct {
	// contains filtered or unexported fields
}

DocumentFactory implements the FileFactory interface.

func NewDocumentFactory

func NewDocumentFactory(filename string) *DocumentFactory

func (*DocumentFactory) NewFile

func (d *DocumentFactory) NewFile(f string) (File, error)

NewFile method returns an object that implements the File interface, given a document format as input. If not supported, it will error out.

type File

type File interface {
	SupportedFormats() map[string][]string
	SupportedMIMETypes() map[string][]string
	ConvertTo(string, string, io.Reader) (io.Reader, error)
}

File interface is the main interface of the package, that defines what a file is in this context. It's moslty responsible to say other entitites what formats it can be converted to and provides a method to convert the current file given a target format, if supported. SupportedMIMETypes was added to tell between how we see files, categorized by extension, and how they are registered as MIME types. e.g. Kind of document: Microsoft Word (OpenXML) Extension: docx MIME Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document

type FileFactory

type FileFactory interface {
	NewFile(string) (File, error)
}

FileFactory interface is responsible for defining how a FileFactory behaves. It defines a NewFile method that returns an entity that implements the File interface.

func BuildFactory

func BuildFactory(f string, filename string) (FileFactory, error)

BuildFactory is a function responsible to return a FileFactory, given a supported and valid file type, otherwise, it will error out.

type Image

type Image interface {
	ImageType() string
}

Image interface is the one that defines what an images is in this context. It's responsible to return kind of the underlying image.

type ImageFactory

type ImageFactory struct{}

ImageFactory implements the FileFactory interface.

func (*ImageFactory) NewFile

func (i *ImageFactory) NewFile(f string) (File, error)

NewFile method returns an object that implements the File interface, given an image format as input. If not supported, it will error out.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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