aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/disk_object.go
blob: d3e852024396802dc391f2a5a5f7a52939dd20ca (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package packfile

import (
	"io"

	"gopkg.in/src-d/go-git.v4/plumbing"
)

// DiskObject is an object from the packfile on disk.
type DiskObject struct {
	hash     plumbing.Hash
	h        *ObjectHeader
	offset   int64
	size     int64
	typ      plumbing.ObjectType
	packfile *Packfile
}

// NewDiskObject creates a new disk object.
func NewDiskObject(
	hash plumbing.Hash,
	finalType plumbing.ObjectType,
	offset int64,
	contentSize int64,
	packfile *Packfile,
) *DiskObject {
	return &DiskObject{
		hash:     hash,
		offset:   offset,
		size:     contentSize,
		typ:      finalType,
		packfile: packfile,
	}
}

// Reader implements the plumbing.EncodedObject interface.
func (o *DiskObject) Reader() (io.ReadCloser, error) {
	return o.packfile.getObjectContent(o.offset)
}

// SetSize implements the plumbing.EncodedObject interface. This method
// is a noop.
func (o *DiskObject) SetSize(int64) {}

// SetType implements the plumbing.EncodedObject interface. This method is
// a noop.
func (o *DiskObject) SetType(plumbing.ObjectType) {}

// Hash implements the plumbing.EncodedObject interface.
func (o *DiskObject) Hash() plumbing.Hash { return o.hash }

// Size implements the plumbing.EncodedObject interface.
func (o *DiskObject) Size() int64 { return o.size }

// Type implements the plumbing.EncodedObject interface.
func (o *DiskObject) Type() plumbing.ObjectType {
	return o.typ
}

// Writer implements the plumbing.EncodedObject interface. This method always
// returns a nil writer.
func (o *DiskObject) Writer() (io.WriteCloser, error) {
	return nil, nil
}