aboutsummaryrefslogtreecommitdiffstats
path: root/formats/packfile/read_recaller.go
blob: 92ab1b2e032b2911dc4a4fc091bc170b94f975ca (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
38
39
package packfile

import "gopkg.in/src-d/go-git.v3/core"

var (
	// ErrDuplicatedObject is returned by Remember if an object appears several
	// times in a packfile.
	ErrDuplicatedObject = NewError("duplicated object")
	// ErrCannotRecall is returned by RecallByOffset or RecallByHash if the object
	// to recall cannot be returned.
	ErrCannotRecall = NewError("cannot recall object")
)

// The ReadRecaller interface has all the functions needed by a packfile
// Parser to operate. We provide two very different implementations:
// Seekable and Stream.
type ReadRecaller interface {
	// Read reads up to len(p) bytes into p.
	Read(p []byte) (int, error)
	// ReadByte is needed because of these:
	// - https://github.com/golang/go/commit/7ba54d45732219af86bde9a5b73c145db82b70c6
	// - https://groups.google.com/forum/#!topic/golang-nuts/fWTRdHpt0QI
	// - https://gowalker.org/compress/zlib#NewReader
	ReadByte() (byte, error)
	// Offset returns the number of bytes parsed so far from the
	// packfile.
	Offset() (int64, error)
	// Remember ask the ReadRecaller to remember the offset and hash for
	// an object, so you can later call RecallByOffset and RecallByHash.
	Remember(int64, core.Object) error
	// ForgetAll forgets all previously remembered objects.
	ForgetAll()
	// RecallByOffset returns the previously processed object found at a
	// given offset.
	RecallByOffset(int64) (core.Object, error)
	// RecallByHash returns the previously processed object with the
	// given hash.
	RecallByHash(core.Hash) (core.Object, error)
}