github.com/mckael/restic@v0.8.3/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 described by h. 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 runs fn with 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 read. 29 // 30 // The function fn may be called multiple times during the same Load invocation 31 // and therefore must be idempotent. 32 // 33 // Implementations are encouraged to use backend.DefaultLoad 34 Load(ctx context.Context, h Handle, length int, offset int64, fn func(rd io.Reader) error) error 35 36 // Stat returns information about the File identified by h. 37 Stat(ctx context.Context, h Handle) (FileInfo, error) 38 39 // List runs fn for each file in the backend which has the type t. When an 40 // error occurs (or fn returns an error), List stops and returns it. 41 // 42 // The function fn is called exactly once for each file during successful 43 // execution and at most once in case of an error. 44 // 45 // The function fn is called in the same Goroutine that List() is called 46 // from. 47 List(ctx context.Context, t FileType, fn func(FileInfo) error) error 48 49 // IsNotExist returns true if the error was caused by a non-existing file 50 // in the backend. 51 IsNotExist(err error) bool 52 53 // Delete removes all data in the backend. 54 Delete(ctx context.Context) error 55 } 56 57 // FileInfo is contains information about a file in the backend. 58 type FileInfo struct { 59 Size int64 60 Name string 61 }