aboutsummaryrefslogtreecommitdiff
path: root/objectstore/objectstore.go
blob: 053013edde6e850cb40bd5d7ec12ceb3b444c5ff (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Package objectstore provides interfaces for object storage backends.
package objectstore

import (
	"errors"
	"io"

	"codeberg.org/lindenii/furgit/objectid"
	"codeberg.org/lindenii/furgit/objecttype"
)

// ErrObjectNotFound indicates that an object does not exist in a backend.
// TODO: This might need to be an interface or otherwise be able to encapsulate multiple concrete backends'.
var ErrObjectNotFound = errors.New("objectstore: object not found")

// Store reads Git objects by object ID.
type Store interface {
	// ReadBytesFull reads a full serialized object as "type size\\x00content".
	//
	// In a valid repository, hashing this payload with the same algorithm yields
	// the requested object ID. Readers should treat this as a repository
	// invariant and should not re-verify it on every read.
	ReadBytesFull(id objectid.ObjectID) ([]byte, error)
	// ReadBytesContent reads an object's type and content bytes.
	ReadBytesContent(id objectid.ObjectID) (objecttype.Type, []byte, error)
	// ReadReaderFull reads a full serialized object stream as "type size\\x00content".
	// Caller must close the returned reader.
	ReadReaderFull(id objectid.ObjectID) (io.ReadCloser, error)
	// ReadReaderContent reads an object's type, declared content length,
	// and content stream.
	// Caller must close the returned reader.
	ReadReaderContent(id objectid.ObjectID) (objecttype.Type, int64, io.ReadCloser, error)
	// ReadHeader reads an object's type and declared content length.
	ReadHeader(id objectid.ObjectID) (objecttype.Type, int64, error)
	// Close releases resources associated with the backend.
	Close() error
}