file

package
v0.0.0-...-5167e8f Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: AGPL-3.0 Imports: 13 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 DirHasReadableFiles

func DirHasReadableFiles(ctx context.Context, paths []string) bool

DirHasReadableFiles returns false when input directories don't have any file that can be open for read

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.

func Sanitize

func Sanitize(filename string) string

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)
	CopyReader(id string, src io.Reader) (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