filesystem

package
v0.0.0-...-c627d9c Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2023 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ThumbSizeRegex = regexp.MustCompile(`^(\d+)x(\d+)(t|b|f)?$`)

Functions

This section is empty.

Types

type BytesReader

type BytesReader struct {
	Bytes []byte
}

BytesReader defines a FileReader from bytes content.

func (*BytesReader) Open

func (r *BytesReader) Open() (io.ReadSeekCloser, error)

Open implements the filesystem.FileReader interface.

type File

type File struct {
	Name         string
	OriginalName string
	Size         int64
	Reader       FileReader
}

File defines a single file io.ReadSeekCloser resource.

The file could be from a local path, multipipart/formdata header, etc.

func NewFileFromBytes

func NewFileFromBytes(b []byte, name string) (*File, error)

NewFileFromBytes creates a new File instance from the provided byte slice.

func NewFileFromMultipart

func NewFileFromMultipart(mh *multipart.FileHeader) (*File, error)

NewFileFromMultipart creates a new File instace from the provided multipart header.

func NewFileFromPath

func NewFileFromPath(path string) (*File, error)

NewFileFromPath creates a new File instance from the provided local file path.

type FileReader

type FileReader interface {
	Open() (io.ReadSeekCloser, error)
}

FileReader defines an interface for a file resource reader.

type MultipartReader

type MultipartReader struct {
	Header *multipart.FileHeader
}

MultipartReader defines a FileReader from multipart.FileHeader.

func (*MultipartReader) Open

func (r *MultipartReader) Open() (io.ReadSeekCloser, error)

Open implements the filesystem.FileReader interface.

type PathReader

type PathReader struct {
	Path string
}

PathReader defines a FileReader from a local file path.

func (*PathReader) Open

func (r *PathReader) Open() (io.ReadSeekCloser, error)

Open implements the filesystem.FileReader interface.

type System

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

func NewLocal

func NewLocal(dirPath string) (*System, error)

NewLocal initializes a new local filesystem instance.

NB! Make sure to call `Close()` after you are done working with it.

func NewS3

func NewS3(
	bucketName string,
	region string,
	endpoint string,
	accessKey string,
	secretKey string,
	s3ForcePathStyle bool,
) (*System, error)

NewS3 initializes an S3 filesystem instance.

NB! Make sure to call `Close()` after you are done working with it.

func (*System) Attributes

func (s *System) Attributes(fileKey string) (*blob.Attributes, error)

Attributes returns the attributes for the file with fileKey path.

func (*System) Close

func (s *System) Close() error

Close releases any resources used for the related filesystem.

func (*System) CreateThumb

func (s *System) CreateThumb(originalKey string, thumbKey, thumbSize string) error

CreateThumb creates a new thumb image for the file at originalKey location. The new thumb file is stored at thumbKey location.

thumbSize is in the format: - 0xH (eg. 0x100) - resize to H height preserving the aspect ratio - Wx0 (eg. 300x0) - resize to W width preserving the aspect ratio - WxH (eg. 300x100) - resize and crop to WxH viewbox (from center) - WxHt (eg. 300x100t) - resize and crop to WxH viewbox (from top) - WxHb (eg. 300x100b) - resize and crop to WxH viewbox (from bottom) - WxHf (eg. 300x100f) - fit inside a WxH viewbox (without cropping)

func (*System) Delete

func (s *System) Delete(fileKey string) error

Delete deletes stored file at fileKey location.

func (*System) DeletePrefix

func (s *System) DeletePrefix(prefix string) []error

DeletePrefix deletes everything starting with the specified prefix.

func (*System) Exists

func (s *System) Exists(fileKey string) (bool, error)

Exists checks if file with fileKey path exists or not.

func (*System) Serve

func (s *System) Serve(res http.ResponseWriter, req *http.Request, fileKey string, name string) error

Serve serves the file at fileKey location to an HTTP response.

func (*System) Upload

func (s *System) Upload(content []byte, fileKey string) error

Upload writes content into the fileKey location.

func (*System) UploadFile

func (s *System) UploadFile(file *File, fileKey string) error

UploadFile uploads the provided multipart file to the fileKey location.

func (*System) UploadMultipart

func (s *System) UploadMultipart(fh *multipart.FileHeader, fileKey string) error

UploadMultipart uploads the provided multipart file to the fileKey location.

Jump to

Keyboard shortcuts

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