file

package
v0.0.0-...-d841f61 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

* Package file contains operations with files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFile

func CopyFile(src, dest string) (resErr error)

CopyFile copies file from src to dest.

func GetHashPath

func GetHashPath() string

GetHashPath returns hash path to store file.

func IsImage

func IsImage(mediaType, filename string) bool

IsImage returns true if mediaType is valid mime type and mime type represents image. If mediaType is invalid mime type, mime type is defined by filename.

func MoveFile

func MoveFile(src, dest string) error

MoveFile moves file from src to dest.

Types

type EtagEncoder

type EtagEncoder interface {
	Encode([]byte) (string, error)
}

EtagEncoder is used to generate etag based on file content.

func NewEtagEncoder

func NewEtagEncoder() EtagEncoder

type Storage

type Storage interface {
	// Move moves file from src to local storage.
	Move(id, src string) (hashPath string, err error)
	// Copy copies file from src to local storage.
	Copy(id, src string) (hashPath string, err error)
	// GetFilepath returns absolute file path.
	GetFilepath(id, hashPath string) string
	// Delete removes file from local storage.
	Delete(id, hashPath string) error
	// DeleteByName removes file or empty dir. It returns (false, nil) if dir is not empty.
	DeleteByName(name string) (bool, error)
	// GetEtag returns etag of file content.
	GetEtag(id, hashPath string) (string, error)
}

Storage is used to implement file modification operations.

func NewStorage

func NewStorage(filesRoot string, etagEncoder EtagEncoder) Storage

Jump to

Keyboard shortcuts

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