aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/disk_object.go
diff options
context:
space:
mode:
authorMiguel Molina <miguel@erizocosmi.co>2018-07-27 15:07:25 +0200
committerMiguel Molina <miguel@erizocosmi.co>2018-07-27 15:07:25 +0200
commitccd0fa0bc17f0680038529b00f5c5a44f8e77b41 (patch)
treecfdc44429694b5f727404a0e60dd75f552621524 /plumbing/format/packfile/disk_object.go
parentffdfb7dbabb78090b27ca29b762b803969c89fd7 (diff)
downloadgo-git-ccd0fa0bc17f0680038529b00f5c5a44f8e77b41.tar.gz
plumbing: packfile, lazy object reads with DiskObjects
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Diffstat (limited to 'plumbing/format/packfile/disk_object.go')
-rw-r--r--plumbing/format/packfile/disk_object.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/plumbing/format/packfile/disk_object.go b/plumbing/format/packfile/disk_object.go
new file mode 100644
index 0000000..d3e8520
--- /dev/null
+++ b/plumbing/format/packfile/disk_object.go
@@ -0,0 +1,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
+}