mediaserver

package module
v0.10.16 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 17 Imported by: 4

README

Media Server 🌇

GoDoc Version Build Status Go Report Card Codecov

Image Resizing and Transcoding

First Pass at a pure Go media server that manages uploads to your web application. Automatically converts between GIF, JPG, PNG, and WEBP file types, and resizes images via a URL-based API.

Pull Requests Welcome

This library is a work in progress, and will benefit from your experience reports, use cases, and contributions. If you have an idea for making Rosetta better, send in a pull request. We're all in this together! 🌇

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileSpec

type FileSpec struct {
	Filename  string
	Extension string
	Width     int
	Height    int
	MimeType  string
}

FileSpec represents all the parameters available for requesting a file. This can be generated directly from a URL.

func NewFileSpec

func NewFileSpec(file *url.URL, defaultType string) FileSpec

NewFileSpec reads a URL and returns a fully populated FileSpec

func (*FileSpec) CacheDir

func (ms *FileSpec) CacheDir() string

CacheDir returns the name of the directory within the cache where versions of this file will be stored.

func (*FileSpec) CacheFilename

func (ms *FileSpec) CacheFilename() string

CacheFilename returns the filename to be used when retrieving this from the FileSpec cache.

func (*FileSpec) CacheHeight

func (ms *FileSpec) CacheHeight() int

CacheHeight returns the height of the file to save in the cache

func (*FileSpec) CachePath

func (ms *FileSpec) CachePath() string

CachePath returns the complete path (within the cache directory) to the file requested by this FileSpec

func (*FileSpec) CacheWidth

func (ms *FileSpec) CacheWidth() int

CacheWidth returns the width of the file to save in the cache

func (*FileSpec) MimeCategory

func (ms *FileSpec) MimeCategory() string

MimeCategory returns the first half of the mime type

func (*FileSpec) Resize

func (ms *FileSpec) Resize() bool

Resize returns TRUE if the FileSpec is requesting that the file be resized.

type MediaServer

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

MediaServer manages files on a filesystem and performs image processing when requested.

func New

func New(original afero.Fs, cache afero.Fs) MediaServer

New returns a fully initialized MediaServer

func (MediaServer) Delete

func (ms MediaServer) Delete(filename string) error

Delete completely removes a file from the MediaServer along with any cached files.

func (MediaServer) FileSpec

func (ms MediaServer) FileSpec(file *url.URL, defaultType string) FileSpec

FileSpec returns a new FileSpec for the provided URL

func (MediaServer) Get

func (ms MediaServer) Get(filespec FileSpec, destination io.Writer) error

Get locates the file, processes it if necessary, and returns it to the caller.

func (MediaServer) Process

func (ms MediaServer) Process(file afero.File, filespec FileSpec) (io.Reader, error)

Process decodes an image file and applies all of the processing steps requested in the FileSpec

func (MediaServer) Put

func (ms MediaServer) Put(filename string, file io.Reader) (int, int, error)

Put adds a new file into the MediaServer.

Jump to

Keyboard shortcuts

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