files

package
v0.0.0-...-f1d979d Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2018 License: GPL-3.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotDirectory returned by NextFile() when it's called not for directory
	ErrNotDirectory = errors.New("couldn't call NextFile(), this isn't a directory")
	// ErrNotReader returned when Read() or Close() called on a directory
	ErrNotReader = errors.New("this file is a directory, can't use Reader functions")
)

Functions

This section is empty.

Types

type File

type File interface {
	// Files implement ReadCloser, but can only be read from or closed if
	// they are not directories
	io.ReadCloser

	// FileName returns a filename associated with this file
	FileName() string

	// FullPath returns the full path used when adding with this file
	FullPath() string

	// IsDirectory returns true if the File is a directory (and therefore
	// supports calling `NextFile`) and false if the File is a normal file
	// (and therefor supports calling `Read` and `Close`)
	IsDirectory() bool

	// NextFile returns the next child file available (if the File is a
	// directory). It will return (nil, io.EOF) if no more files are
	// available. If the file is a regular file (not a directory), NextFile
	// will return a non-nil error.
	NextFile() (File, error)
}

File is an interface that provides functionality for handling files/directories as values that can be supplied to commands. For directories, child files are accessed serially by calling `NextFile()`.

func NewFileFromPart

func NewFileFromPart(part *multipart.Part) (File, error)

NewFileFromPart transforms part of multipart to File

func NewLinkFile

func NewLinkFile(name, path, target string, stat os.FileInfo) File

NewLinkFile returns an instance of Symlink

type FileInfo

type FileInfo interface {
	AbsPath() string
	Stat() os.FileInfo
}

FileInfo provides os.FileInfo and absolute path of file

type MultiFileReader

type MultiFileReader struct {
	io.Reader
	// contains filtered or unexported fields
}

MultiFileReader reads from a `commands.File` (which can be a directory of files or a regular file) as HTTP multipart encoded data.

func NewMultiFileReader

func NewMultiFileReader(file File, form bool) *MultiFileReader

NewMultiFileReader constructs a MultiFileReader. `file` can be any `commands.File`. If `form` is set to true, the multipart data will have a Content-Type of 'multipart/form-data', if `form` is false, the Content-Type will be 'multipart/mixed'.

func (*MultiFileReader) Boundary

func (mfr *MultiFileReader) Boundary() string

Boundary returns the boundary string to be used to separate files in the multipart data

func (*MultiFileReader) Read

func (mfr *MultiFileReader) Read(buf []byte) (written int, err error)

type MultipartFile

type MultipartFile struct {
	File

	Part      *multipart.Part
	Reader    *multipart.Reader
	Mediatype string
}

MultipartFile implements File, and is created from a `multipart.Part`. It can be either a directory or file (checked by calling `IsDirectory()`).

func (*MultipartFile) Close

func (f *MultipartFile) Close() error

Close implements io.Closer

func (*MultipartFile) FileName

func (f *MultipartFile) FileName() string

FileName returns a filename associated with this file

func (*MultipartFile) FullPath

func (f *MultipartFile) FullPath() string

FullPath returns the full path used when adding with this file

func (*MultipartFile) IsDirectory

func (f *MultipartFile) IsDirectory() bool

IsDirectory returns true if the File is a directory (and therefore supports calling `NextFile`) and false if the File is a normal file (and therefor supports calling `Read` and `Close`)

func (*MultipartFile) NextFile

func (f *MultipartFile) NextFile() (File, error)

NextFile returns the next child file available (if the File is a directory). It will return (nil, io.EOF) if no more files are available. If the file is a regular file (not a directory), NextFile will return a non-nil error.

func (*MultipartFile) Read

func (f *MultipartFile) Read(p []byte) (int, error)

type PeekFile

type PeekFile interface {
	SizeFile

	Peek(n int) File
	Length() int
}

PeekFile returns file length and provides Peek method

type ReaderFile

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

ReaderFile is a implementation of File created from an `io.Reader`. ReaderFiles are never directories, and can be read from and closed.

func NewReaderFile

func NewReaderFile(filename, path string, reader io.ReadCloser, stat os.FileInfo) *ReaderFile

NewReaderFile creates new instance of ReaderFile

func NewReaderPathFile

func NewReaderPathFile(filename, path string, reader io.ReadCloser, stat os.FileInfo) (*ReaderFile, error)

NewReaderPathFile retrieves an absolute representation of path and creates new instance of ReaderFile

func (*ReaderFile) AbsPath

func (f *ReaderFile) AbsPath() string

AbsPath implements FileInfo

func (*ReaderFile) Close

func (f *ReaderFile) Close() error

Close implements io.Closer

func (*ReaderFile) FileName

func (f *ReaderFile) FileName() string

FileName returns a filename associated with this file

func (*ReaderFile) FullPath

func (f *ReaderFile) FullPath() string

FullPath returns the full path used when adding with this file

func (*ReaderFile) IsDirectory

func (f *ReaderFile) IsDirectory() bool

IsDirectory returns true if the File is a directory (and therefore supports calling `NextFile`) and false if the File is a normal file (and therefor supports calling `Read` and `Close`)

func (*ReaderFile) NextFile

func (f *ReaderFile) NextFile() (File, error)

NextFile returns the next child file available (if the File is a directory). It will return (nil, io.EOF) if no more files are available. If the file is a regular file (not a directory), NextFile will return a non-nil error.

func (*ReaderFile) Read

func (f *ReaderFile) Read(p []byte) (int, error)

Read implements io.Reader

func (*ReaderFile) Size

func (f *ReaderFile) Size() (int64, error)

Size implements SizeFile

func (*ReaderFile) Stat

func (f *ReaderFile) Stat() os.FileInfo

Stat implements FileInfo

type SizeFile

type SizeFile interface {
	File

	Size() (int64, error)
}

SizeFile is a file that has size

type SliceFile

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

SliceFile implements File, and provides simple directory handling. It contains children files, and is created from a `[]File`. SliceFiles are always directories, and can't be read from or closed.

func NewSliceFile

func NewSliceFile(filename, path string, files []File) *SliceFile

NewSliceFile returns an instance of SliceFile

func (*SliceFile) Close

func (f *SliceFile) Close() error

Close implements io.Closer

func (*SliceFile) FileName

func (f *SliceFile) FileName() string

FileName returns a filename associated with this file

func (*SliceFile) FullPath

func (f *SliceFile) FullPath() string

FullPath returns the full path used when adding with this file

func (*SliceFile) IsDirectory

func (f *SliceFile) IsDirectory() bool

IsDirectory returns true if the File is a directory (and therefore supports calling `NextFile`) and false if the File is a normal file (and therefor supports calling `Read` and `Close`)

func (*SliceFile) Length

func (f *SliceFile) Length() int

Length implements PeekFile

func (*SliceFile) NextFile

func (f *SliceFile) NextFile() (File, error)

NextFile returns the next child file available (if the File is a directory). It will return (nil, io.EOF) if no more files are available. If the file is a regular file (not a directory), NextFile will return a non-nil error.

func (*SliceFile) Peek

func (f *SliceFile) Peek(n int) File

Peek implements PeekFile

func (*SliceFile) Read

func (f *SliceFile) Read(p []byte) (int, error)

func (*SliceFile) Size

func (f *SliceFile) Size() (int64, error)

Size implements PeekFile

type StatFile

type StatFile interface {
	File

	Stat() os.FileInfo
}

StatFile provides os.FileInfo for file

type Symlink struct {
	Target string
	// contains filtered or unexported fields
}

Symlink represents symbolic link

func (*Symlink) Close

func (lf *Symlink) Close() error

Close implements io.Closer

func (*Symlink) FileName

func (lf *Symlink) FileName() string

FileName returns a filename associated with this file

func (*Symlink) FullPath

func (lf *Symlink) FullPath() string

FullPath returns the full path used when adding with this file

func (*Symlink) IsDirectory

func (lf *Symlink) IsDirectory() bool

IsDirectory returns true if the File is a directory (and therefore supports calling `NextFile`) and false if the File is a normal file (and therefor supports calling `Read` and `Close`)

func (*Symlink) NextFile

func (lf *Symlink) NextFile() (File, error)

NextFile returns the next child file available (if the File is a directory). It will return (nil, io.EOF) if no more files are available. If the file is a regular file (not a directory), NextFile will return a non-nil error.

func (*Symlink) Read

func (lf *Symlink) Read(b []byte) (int, error)

Read implements io.Reader

Jump to

Keyboard shortcuts

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