github.com/fawick/restic@v0.1.1-0.20171126184616-c02923fbfc79/internal/restic/backend.go (about) 1 package restic 2 3 import ( 4 "context" 5 "io" 6 ) 7 8 // Backend is used to store and access data. 9 type Backend interface { 10 // Location returns a string that describes the type and location of the 11 // repository. 12 Location() string 13 14 // Test a boolean value whether a File with the name and type exists. 15 Test(ctx context.Context, h Handle) (bool, error) 16 17 // Remove removes a File with type t and name. 18 Remove(ctx context.Context, h Handle) error 19 20 // Close the backend 21 Close() error 22 23 // Save stores the data in the backend under the given handle. 24 Save(ctx context.Context, h Handle, rd io.Reader) error 25 26 // Load returns a reader that yields the contents of the file at h at the 27 // given offset. If length is larger than zero, only a portion of the file 28 // is returned. rd must be closed after use. If an error is returned, the 29 // ReadCloser must be nil. 30 Load(ctx context.Context, h Handle, length int, offset int64) (io.ReadCloser, error) 31 32 // Stat returns information about the File identified by h. 33 Stat(ctx context.Context, h Handle) (FileInfo, error) 34 35 // List returns a channel that yields all names of files of type t in an 36 // arbitrary order. A goroutine is started for this, which is stopped when 37 // ctx is cancelled. 38 List(ctx context.Context, t FileType) <-chan string 39 40 // IsNotExist returns true if the error was caused by a non-existing file 41 // in the backend. 42 IsNotExist(err error) bool 43 44 // Delete removes all data in the backend. 45 Delete(ctx context.Context) error 46 } 47 48 // FileInfo is returned by Stat() and contains information about a file in the 49 // backend. 50 type FileInfo struct{ Size int64 }