2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-15 09:44:15 +00:00
restic/backend/interface.go

79 lines
2.0 KiB
Go
Raw Normal View History

2014-09-23 20:39:12 +00:00
package backend
2016-01-23 16:08:03 +00:00
import "io"
2014-10-07 21:19:26 +00:00
2015-03-28 10:50:23 +00:00
// Type is the type of a Blob.
2014-09-23 20:39:12 +00:00
type Type string
2016-01-23 11:46:20 +00:00
// These are the different data types a backend can store.
2014-09-23 20:39:12 +00:00
const (
Data Type = "data"
2014-09-23 20:39:12 +00:00
Key = "key"
Lock = "lock"
Snapshot = "snapshot"
2015-04-26 13:48:35 +00:00
Index = "index"
Config = "config"
2014-10-04 14:49:39 +00:00
)
2016-01-23 11:46:20 +00:00
// Backend is used to store and access data.
2015-03-28 10:50:23 +00:00
type Backend interface {
2016-01-23 11:46:20 +00:00
// Location returns a string that describes the type and location of the
// repository.
2015-03-28 10:50:23 +00:00
Location() string
2014-10-07 21:19:26 +00:00
2015-03-28 10:50:23 +00:00
// Create creates a new Blob. The data is available only after Finalize()
// has been called on the returned Blob.
Create() (Blob, error)
2015-03-28 10:50:23 +00:00
// Test a boolean value whether a Blob with the name and type exists.
Test(t Type, name string) (bool, error)
2014-12-21 14:57:41 +00:00
2015-03-28 10:50:23 +00:00
// Remove removes a Blob with type t and name.
Remove(t Type, name string) error
2014-12-21 14:57:41 +00:00
2015-03-28 10:50:23 +00:00
// Close the backend
Close() error
Lister
2016-01-23 13:12:12 +00:00
// Load returns the data stored in the backend for h at the given offset
// and saves it in p. Load has the same semantics as io.ReaderAt.
Load(h Handle, p []byte, off int64) (int, error)
2016-01-23 22:27:58 +00:00
2016-01-24 00:15:35 +00:00
// Save stores the data in the backend under the given handle.
Save(h Handle, p []byte) error
2016-01-23 22:27:58 +00:00
// Stat returns information about the blob identified by h.
Stat(h Handle) (BlobInfo, error)
2014-12-21 14:57:41 +00:00
}
2016-01-23 11:46:20 +00:00
// Lister implements listing data items stored in a backend.
2015-03-28 10:50:23 +00:00
type Lister interface {
// List returns a channel that yields all names of blobs of type t in an
// arbitrary order. A goroutine is started for this. If the channel done is
// closed, sending stops.
2015-03-28 10:50:23 +00:00
List(t Type, done <-chan struct{}) <-chan string
2014-12-21 14:57:41 +00:00
}
2014-10-04 17:20:15 +00:00
2016-01-23 11:46:20 +00:00
// Deleter are backends that allow to self-delete all content stored in them.
2014-12-21 16:02:49 +00:00
type Deleter interface {
2015-03-28 10:50:23 +00:00
// Delete the complete repository.
2014-12-21 14:57:41 +00:00
Delete() error
}
2016-01-23 22:27:58 +00:00
// BlobInfo is returned by Stat() and contains information about a stored blob.
type BlobInfo struct {
Size int64
}
2016-01-23 11:46:20 +00:00
// Blob is old.
2015-03-28 10:50:23 +00:00
type Blob interface {
io.Writer
2014-12-21 14:57:41 +00:00
2015-03-28 10:50:23 +00:00
// Finalize moves the data blob to the final location for type and name.
Finalize(t Type, name string) error
2015-03-28 10:50:23 +00:00
// Size returns the number of bytes written to the backend so far.
Size() uint
2014-12-21 14:57:41 +00:00
}