1
0
mirror of https://github.com/rclone/rclone.git synced 2026-01-04 17:43:50 +00:00

local: define OpenWriterAt interface and test and implement it #2252

This will enable multipart downloads in future commits
This commit is contained in:
Nick Craig-Wood
2019-04-22 19:22:42 +01:00
parent 72721f4c8d
commit 7c4fe3eb75
5 changed files with 101 additions and 7 deletions

View File

@@ -427,6 +427,12 @@ type Usage struct {
Objects *int64 `json:"objects,omitempty"` // objects in the storage system
}
// WriterAtCloser wraps io.WriterAt and io.Closer
type WriterAtCloser interface {
io.WriterAt
io.Closer
}
// Features describe the optional features of the Fs
type Features struct {
// Feature flags, whether Fs
@@ -548,6 +554,13 @@ type Features struct {
// About gets quota information from the Fs
About func() (*Usage, error)
// OpenWriterAt opens with a handle for random access writes
//
// Pass in the remote desired and the size if known.
//
// It truncates any existing object
OpenWriterAt func(remote string, size int64) (WriterAtCloser, error)
}
// Disable nil's out the named feature. If it isn't found then it
@@ -640,6 +653,9 @@ func (ft *Features) Fill(f Fs) *Features {
if do, ok := f.(Abouter); ok {
ft.About = do.About
}
if do, ok := f.(OpenWriterAter); ok {
ft.OpenWriterAt = do.OpenWriterAt
}
return ft.DisableList(Config.DisableFeatures)
}
@@ -705,6 +721,9 @@ func (ft *Features) Mask(f Fs) *Features {
if mask.About == nil {
ft.About = nil
}
if mask.OpenWriterAt == nil {
ft.OpenWriterAt = nil
}
return ft.DisableList(Config.DisableFeatures)
}
@@ -904,6 +923,16 @@ type Abouter interface {
About() (*Usage, error)
}
// OpenWriterAter is an optional interface for Fs
type OpenWriterAter interface {
// OpenWriterAt opens with a handle for random access writes
//
// Pass in the remote desired and the size if known.
//
// It truncates any existing object
OpenWriterAt(remote string, size int64) (WriterAtCloser, error)
}
// ObjectsChan is a channel of Objects
type ObjectsChan chan Object