Documentation
¶
Index ¶
- type FileSpec
- func (filespec *FileSpec) AspectRatio() float64
- func (filespec *FileSpec) CacheHeight() int
- func (filespec *FileSpec) CacheWidth() int
- func (filespec *FileSpec) DownloadFilename() string
- func (filespec *FileSpec) MimeCategory() string
- func (filespec *FileSpec) MimeType() string
- func (filespec *FileSpec) OriginalMimeCategory() string
- func (filespec *FileSpec) OriginalMimeType() string
- func (filespec *FileSpec) ProcessedDir() string
- func (filespec *FileSpec) ProcessedFilename() string
- func (filespec *FileSpec) ProcessedPath() string
- func (filespec *FileSpec) Resize() bool
- func (filespec *FileSpec) WorkingFilename() string
- type MediaServer
- func (ms MediaServer) Delete(filename string) error
- func (ms MediaServer) Process(filespec FileSpec, output io.Writer) error
- func (ms MediaServer) Put(filename string, file io.Reader) error
- func (ms MediaServer) Serve(responseWriter http.ResponseWriter, request *http.Request, filespec FileSpec) error
- type WorkingDirectory
- func (wd *WorkingDirectory) Close()
- func (wd *WorkingDirectory) Exists(name string) bool
- func (wd *WorkingDirectory) Open(name string) (*os.File, error)
- func (wd *WorkingDirectory) Remove(name string)
- func (wd *WorkingDirectory) RemoveAll()
- func (wd *WorkingDirectory) Write(name string, reader io.Reader) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileSpec ¶
type FileSpec struct { Filename string // Original filename OriginalExtension string // Original file extension Extension string // File extension including a dot (.mp3) Width int // For images and videos, the requested width Height int // For images and videos, the requested height Bitrate int // For audio and videos, the audio bitrage Metadata mapof.String // Metadata to add to the outbound file Cache bool // If TRUE, then allow caching }
FileSpec represents all the parameters available for requesting a file. This can be generated directly from a URL.
func (*FileSpec) AspectRatio ¶ added in v0.11.0
func (*FileSpec) CacheHeight ¶
CacheHeight returns the height of the file to save in the cache
func (*FileSpec) CacheWidth ¶
CacheWidth returns the width of the file to save in the cache
func (*FileSpec) DownloadFilename ¶ added in v0.14.0
DownloadFilename returns the name that should be used when downloading the file.
func (*FileSpec) MimeCategory ¶
MimeCategory returns the first half of the mime type
func (*FileSpec) OriginalMimeCategory ¶ added in v0.13.0
func (*FileSpec) OriginalMimeType ¶ added in v0.13.0
func (*FileSpec) ProcessedDir ¶ added in v0.15.0
ProcessedDir returns the name of the directory within the cache where versions of this file will be stored.
func (*FileSpec) ProcessedFilename ¶ added in v0.15.0
ProcessedFilename returns the filename to be used when retrieving this from the FileSpec cache.
func (*FileSpec) ProcessedPath ¶ added in v0.15.0
ProcessedPath returns the complete path (within the cache directory) to the file requested by this FileSpec
func (*FileSpec) Resize ¶
Resize returns TRUE if the FileSpec is requesting that the file be resized.
func (*FileSpec) WorkingFilename ¶ added in v0.15.0
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, processed afero.Fs, working *WorkingDirectory) 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) Process ¶
func (ms MediaServer) Process(filespec FileSpec, output io.Writer) 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) error
Put adds a new file into the MediaServer.
func (MediaServer) Serve ¶ added in v0.15.0
func (ms MediaServer) Serve(responseWriter http.ResponseWriter, request *http.Request, filespec FileSpec) error
Serve locates the file, processes it if necessary, and returns it to the caller. If the filespec.Cache is set to FALSE, then file will be processed and returned. If the filespec.Cache is set to TRUE, then the processed file will retrieved from the cache (if possible) and the processed file will be stored in the cache.
type WorkingDirectory ¶ added in v0.15.0
type WorkingDirectory struct {
// contains filtered or unexported fields
}
WorkingDirectory manages files added and removed to the working directory.
func NewWorkingDirectory ¶ added in v0.15.0
func NewWorkingDirectory(folder string, ttl time.Duration, capacity int) WorkingDirectory
NewWorkingDirectory returns a fully initialized WorkingDirectory object
func (*WorkingDirectory) Close ¶ added in v0.15.0
func (wd *WorkingDirectory) Close()
Close shuts down the working directory, all background processes, and deletes all files from the filesystem
func (*WorkingDirectory) Exists ¶ added in v0.15.0
func (wd *WorkingDirectory) Exists(name string) bool
Exists returns TRUE if the file exists in the working directory
func (*WorkingDirectory) Open ¶ added in v0.15.0
func (wd *WorkingDirectory) Open(name string) (*os.File, error)
Get loads the file from the working directory and resets the TTL. It is the caller's responsibility to close the file when finished.
func (*WorkingDirectory) Remove ¶ added in v0.15.0
func (wd *WorkingDirectory) Remove(name string)
Remove deletes a file from the working directory This should trigger the onDelete event for the file.
func (*WorkingDirectory) RemoveAll ¶ added in v0.15.0
func (wd *WorkingDirectory) RemoveAll()
RemoveAll deletes all files from the working directory This should trigger the onDelete event for each file.