restic/backend/interface.go

67 lines
1.6 KiB
Go
Raw Normal View History

2014-09-23 22:39:12 +02:00
package backend
2015-03-28 11:50:23 +01:00
import "io"
2014-10-07 23:19:26 +02:00
2015-03-28 11:50:23 +01:00
// Type is the type of a Blob.
2014-09-23 22:39:12 +02:00
type Type string
const (
Data Type = "data"
2014-09-23 22:39:12 +02:00
Key = "key"
Lock = "lock"
Snapshot = "snapshot"
2015-04-26 15:48:35 +02:00
Index = "index"
Config = "config"
2014-10-04 16:49:39 +02:00
)
// A Backend manages data stored somewhere.
2015-03-28 11:50:23 +01:00
type Backend interface {
// Location returns a string that specifies the location of the repository,
// like a URL.
Location() string
2014-10-07 23:19:26 +02:00
2015-03-28 11:50:23 +01: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 11:50:23 +01:00
// Get returns an io.ReadCloser for the Blob with the given name of type t.
Get(t Type, name string) (io.ReadCloser, error)
// GetReader returns an io.ReadCloser for the Blob with the given name of
// type t at offset and length.
GetReader(t Type, name string, offset, length uint) (io.ReadCloser, error)
2015-03-28 11:50:23 +01:00
// Test a boolean value whether a Blob with the name and type exists.
Test(t Type, name string) (bool, error)
2014-12-21 15:57:41 +01:00
2015-03-28 11:50:23 +01:00
// Remove removes a Blob with type t and name.
Remove(t Type, name string) error
2014-12-21 15:57:41 +01:00
2015-03-28 11:50:23 +01:00
// Close the backend
Close() error
Lister
2014-12-21 15:57:41 +01:00
}
2015-03-28 11:50:23 +01:00
type Lister interface {
// List returns a channel that yields all names of blobs of type t in
// lexicographic order. A goroutine is started for this. If the channel
// done is closed, sending stops.
List(t Type, done <-chan struct{}) <-chan string
2014-12-21 15:57:41 +01:00
}
2014-10-04 19:20:15 +02:00
2014-12-21 17:02:49 +01:00
type Deleter interface {
2015-03-28 11:50:23 +01:00
// Delete the complete repository.
2014-12-21 15:57:41 +01:00
Delete() error
}
2015-03-28 11:50:23 +01:00
type Blob interface {
io.Writer
2014-12-21 15:57:41 +01:00
2015-03-28 11:50:23 +01:00
// Finalize moves the data blob to the final location for type and name.
Finalize(t Type, name string) error
2015-03-28 11:50:23 +01:00
// Size returns the number of bytes written to the backend so far.
Size() uint
2014-12-21 15:57:41 +01:00
}