sio

package
v0.0.0-...-1c8de56 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter(path, pattern string, filter func([]os.FileInfo, string) []os.FileInfo) ([]os.FileInfo, error)

Filter files by a name pattern.

func MatchPattern

func MatchPattern(es []os.FileInfo, pattern string) []os.FileInfo

MatchPattern matches filename to pattern

func SaveToFile

func SaveToFile(bytes []byte, dir string) error

SaveToFile saves bytes to file.

func SetLogger

func SetLogger(logger *logrus.Logger)

SetLogger sets Emul logger.

Types

type ContentType

type ContentType int

ContentType request type.

const (
	// UnknownType unarchived content
	UnknownType ContentType = iota
	// ZipType application/zip
	ZipType
	// GzipType application/x-gzip
	GzipType
	// XrarType application/x-rar-compressed
	XrarType
	// WebmType video/webm
	WebmType
	// TtcfType font/collection
	TtcfType
	// OtfType font/otf
	OtfType
	// WoffType font/woff
	WoffType
	// Woff2Type font/woff2
	Woff2Type
	// WasmType application/wasm
	WasmType
	// TtfType font/ttf
	TtfType
)

func (ContentType) String

func (s ContentType) String() string

type Filer

type Filer interface {
	CreateFile(name string) (*os.File, error)
	CloseFile(f *os.File) error
	WriteFile(f *os.File, b []byte) (n int, err error)
	ReadFile(filename string) ([]byte, error)
	ReadArchive(filename string) ([]byte, error)
	DetermineContentType(filePath string) (contentType ContentType, err error)
	BuildFilePath(dir string, filename string) (filePath string, err error)
	Mkdir(name string, perm os.FileMode) error
	CleanDir(dir string) error
	RemoveAll(path string) error
	MkdirAll(path string, perm os.FileMode) error
}

Filer sends requests to the endpoint.

func NewFiler

func NewFiler(logger slog.Logger) (filer Filer, err error)

NewFiler creates a new Filer instance.

type Sfile

type Sfile struct {
	Filer Filer
	// contains filtered or unexported fields
}

Sfile - Filer interface implementation.

func (*Sfile) BuildFilePath

func (fi *Sfile) BuildFilePath(dir string, filename string) (filePath string, err error)

BuildFilePath builds file path using directory and filename.

func (*Sfile) CleanDir

func (fi *Sfile) CleanDir(dir string) error

CleanDir removes all subdirectories and files from the directory.

func (*Sfile) CloseFile

func (fi *Sfile) CloseFile(f *os.File) error

CloseFile delegages the call to close the file.

func (*Sfile) CreateFile

func (fi *Sfile) CreateFile(name string) (*os.File, error)

CreateFile calls os.Create to create the file.

func (*Sfile) DetermineContentType

func (fi *Sfile) DetermineContentType(filePath string) (contentType ContentType, err error)

DetermineContentType determines file type.

func (*Sfile) Mkdir

func (fi *Sfile) Mkdir(name string, perm os.FileMode) error

Mkdir delegates the call to create file directory.

func (*Sfile) MkdirAll

func (fi *Sfile) MkdirAll(path string, perm os.FileMode) error

MkdirAll creates a directory named path using os.MkdirAll

func (*Sfile) ReadArchive

func (fi *Sfile) ReadArchive(filename string) ([]byte, error)

ReadArchive calls io.ReadArchive to read the file named by filename.

func (*Sfile) ReadFile

func (fi *Sfile) ReadFile(filename string) ([]byte, error)

ReadFile calls io.ReadFile to read the file named by filename.

func (*Sfile) RemoveAll

func (fi *Sfile) RemoveAll(path string) error

RemoveAll removes path and any children it contains using os.RemoveAll

func (*Sfile) WriteFile

func (fi *Sfile) WriteFile(f *os.File, buf []byte) (n int, err error)

WriteFile delegates the call to write the file.

Jump to

Keyboard shortcuts

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