Documentation ¶
Index ¶
- Constants
- Variables
- type Collection
- type Controller
- type ControllerError
- type DummyController
- type FileInfo
- type Fs
- type JSONError
- type Operation
- func (o *Operation) Destination() afero.Fs
- func (o *Operation) Error() OperationError
- func (o *Operation) Exit() error
- func (o *Operation) Index() int
- func (o *Operation) Pause() error
- func (o *Operation) RateLimit() float64
- func (o *Operation) Resume() error
- func (o *Operation) SetIndex(n int)
- func (o *Operation) SetLogger(l distillog.Logger)
- func (o *Operation) SetProgress(v ProgressSetter)
- func (o *Operation) SetRateLimit(val float64)
- func (o *Operation) SetSources(c Collection)
- func (o *Operation) Size() int64
- func (o *Operation) Sources() Collection
- func (o *Operation) Start() error
- func (o *Operation) Status() uint8
- type OperationError
- type OperationFile
- type OperationProgress
- type OsFileInfo
- type ProgressSetter
- type PublicOperation
- type Server
Constants ¶
const ( Default uint8 = iota Started Finished Aborted Paused )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Collection ¶
type Collection []FileInfo
func DirToCollection ¶
func DirToCollection(fs afero.Fs, base string) (Collection, error)
DirToCollection gets all files within a directory and adds them to a collection.
func FsToCollection ¶
func FsToCollection(localfs afero.Fs) (Collection, error)
FsToCollection takes in an afero file system and turns it into a collection of files. The collection is always recursive.
type Controller ¶
type Controller interface { // Error is a function that tells the client that their request // encountered an error. Error(err ControllerError) // Value is a function that tells the client that their request // was successful with an extra value. Value(val interface{}) error }
type ControllerError ¶
type DummyController ¶
type DummyController struct {
// contains filtered or unexported fields
}
func (*DummyController) Error ¶
func (d *DummyController) Error(err ControllerError)
func (*DummyController) GetError ¶
func (d *DummyController) GetError() *ControllerError
func (*DummyController) Read ¶
func (d *DummyController) Read(v interface{}) error
func (*DummyController) Value ¶
func (d *DummyController) Value(val interface{}) error
type FileInfo ¶
func (FileInfo) MarshalJSON ¶
type Operation ¶
type Operation struct {
// contains filtered or unexported fields
}
Operation is an object that contains a file transfer from multiple sources to one destination. An operation can be paused, resumed, or cancelled(Exit).
Operations typically endure errors but through Operation.Error these errors can be dynamically handled by an outsider package so that Operation is extensible via other packages.
func NewOperation ¶
func NewOperation(src Collection, dst afero.Fs) (*Operation, error)
NewOperation returns an operation object.
func (*Operation) Destination ¶
Destination returns the destination file system. Please note that destinations should not be changed, instead create a new operation.
func (*Operation) Error ¶
func (o *Operation) Error() OperationError
Error returns the error if there is any, or hangs if there isn't an error.
func (*Operation) Exit ¶
Exit exits out of the operation. Exit can happen while writing to a file, or while preparing to write to a file. If the file is being written to and Exit is called, then the file gets deleted afterwards.
Exit makes an operation obsolete.
func (*Operation) SetIndex ¶
SetIndex sets the index for the collection. Can be used to skip a file whilst it is being written to.
func (*Operation) SetProgress ¶
func (o *Operation) SetProgress(v ProgressSetter)
SetProgress sets the progress setter for the files.
func (*Operation) SetRateLimit ¶
SetRateLimit sets a rate limit for how fast can a reader be read.
func (*Operation) SetSources ¶
func (o *Operation) SetSources(c Collection)
SetSources sets the sources for the operation.
func (*Operation) Size ¶
Size returns the src size of the operation. Do note that this function is rather expensive as it contains tons of syscalls. Prefer to send a cached value and calling the function only when the sources have changed.
func (*Operation) Sources ¶
func (o *Operation) Sources() Collection
Sources returns the list of files that are to be copied ot the destination.
type OperationError ¶
OperationError is an error that can occur in the middle of an operation.
type OperationFile ¶
type OperationFile struct { Name string `json:"name"` Path string `json:"path"` Size int64 ModTime time.Time IsDir bool }
OperationFile is a marshallable object that is used to communicate with Controller.
type OperationProgress ¶
type OperationProgress struct {
// contains filtered or unexported fields
}
type OsFileInfo ¶
OsFileInfo is a wrapper around os.FileInfo that allows it to be marshalled to json.
func NewOsFileInfo ¶
func NewOsFileInfo(o os.FileInfo, path, abs string) OsFileInfo
func (OsFileInfo) Map ¶
func (o OsFileInfo) Map() map[string]interface{}
func (OsFileInfo) MarshalJSON ¶
func (o OsFileInfo) MarshalJSON() ([]byte, error)
type ProgressSetter ¶
type ProgressSetter interface { // Set is a function that provides real-time updates (writes) for clients. // Set must be safe for concurrent use. Set(index int, written int64) }
ProgressSetter is an interface that allows for progress setting for files. Whenever a file gets written to in *Operation, ProgressSetter's Set function is called.
In conjuction with index and src, ProgressSetter can provide real time progress of the file transfers.
type PublicOperation ¶
func (PublicOperation) Map ¶
func (po PublicOperation) Map() map[string]interface{}
func (PublicOperation) MarshalJSON ¶
func (po PublicOperation) MarshalJSON() ([]byte, error)