github.com/mckael/restic@v0.8.3/internal/restic/repository.go (about)

     1  package restic
     2  
     3  import (
     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.
    11  type Repository interface {
    12  
    13  	// Backend returns the backend used by the repository
    14  	Backend() Backend
    15  
    16  	Key() *crypto.Key
    17  
    18  	SetIndex(Index)
    19  
    20  	Index() Index
    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  	ListPack(context.Context, ID, int64) ([]Blob, int64, error)
    36  
    37  	Flush(context.Context) error
    38  
    39  	SaveUnpacked(context.Context, FileType, []byte) (ID, error)
    40  	SaveJSONUnpacked(context.Context, FileType, interface{}) (ID, error)
    41  
    42  	LoadJSONUnpacked(context.Context, FileType, ID, interface{}) error
    43  	LoadAndDecrypt(context.Context, FileType, ID) ([]byte, error)
    44  
    45  	LoadBlob(context.Context, BlobType, ID, []byte) (int, error)
    46  	SaveBlob(context.Context, BlobType, []byte, ID) (ID, error)
    47  
    48  	LoadTree(context.Context, ID) (*Tree, error)
    49  	SaveTree(context.Context, *Tree) (ID, error)
    50  }
    51  
    52  // Lister allows listing files in a backend.
    53  type Lister interface {
    54  	List(context.Context, FileType, func(FileInfo) error) error
    55  }
    56  
    57  // Index keeps track of the blobs are stored within files.
    58  type Index interface {
    59  	Has(ID, BlobType) bool
    60  	Lookup(ID, BlobType) ([]PackedBlob, bool)
    61  	Count(BlobType) uint
    62  
    63  	// Each returns a channel that yields all blobs known to the index. When
    64  	// the context is cancelled, the background goroutine terminates. This
    65  	// blocks any modification of the index.
    66  	Each(ctx context.Context) <-chan PackedBlob
    67  }