1package restic
2
3import (
4	"context"
5
6	"github.com/restic/restic/internal/crypto"
7)
8
9// Repository stores data in a backend. It provides high-level functions and
10// transparently encrypts/decrypts data.
11type Repository interface {
12
13	// Backend returns the backend used by the repository
14	Backend() Backend
15
16	Key() *crypto.Key
17
18	SetIndex(MasterIndex) error
19
20	Index() MasterIndex
21	SaveFullIndex(context.Context) error
22	SaveIndex(context.Context) error
23	LoadIndex(context.Context) error
24
25	Config() Config
26
27	LookupBlobSize(ID, BlobType) (uint, bool)
28
29	// List calls the function fn for each file of type t in the repository.
30	// When an error is returned by fn, processing stops and List() returns the
31	// error.
32	//
33	// The function fn is called in the same Goroutine List() was called from.
34	List(ctx context.Context, t FileType, fn func(ID, int64) error) error
35
36	// ListPack returns the list of blobs saved in the pack id and the length of
37	// the the pack header.
38	ListPack(context.Context, ID, int64) ([]Blob, uint32, error)
39
40	Flush(context.Context) error
41
42	SaveUnpacked(context.Context, FileType, []byte) (ID, error)
43	SaveJSONUnpacked(context.Context, FileType, interface{}) (ID, error)
44
45	LoadJSONUnpacked(ctx context.Context, t FileType, id ID, dest interface{}) error
46	// LoadAndDecrypt loads and decrypts the file with the given type and ID,
47	// using the supplied buffer (which must be empty). If the buffer is nil, a
48	// new buffer will be allocated and returned.
49	LoadAndDecrypt(ctx context.Context, buf []byte, t FileType, id ID) (data []byte, err error)
50
51	LoadBlob(context.Context, BlobType, ID, []byte) ([]byte, error)
52	SaveBlob(context.Context, BlobType, []byte, ID, bool) (ID, bool, error)
53
54	LoadTree(context.Context, ID) (*Tree, error)
55	SaveTree(context.Context, *Tree) (ID, error)
56}
57
58// Lister allows listing files in a backend.
59type Lister interface {
60	List(context.Context, FileType, func(FileInfo) error) error
61}
62
63// MasterIndex keeps track of the blobs are stored within files.
64type MasterIndex interface {
65	Has(BlobHandle) bool
66	Lookup(BlobHandle) []PackedBlob
67	Count(BlobType) uint
68	PackSize(ctx context.Context, onlyHdr bool) map[ID]int64
69
70	// Each returns a channel that yields all blobs known to the index. When
71	// the context is cancelled, the background goroutine terminates. This
72	// blocks any modification of the index.
73	Each(ctx context.Context) <-chan PackedBlob
74}
75