aboutsummaryrefslogtreecommitdiffstats
path: root/core/object.go
diff options
context:
space:
mode:
authorJoshua Sjoding <joshua.sjoding@scjalliance.com>2016-02-24 22:40:30 -0800
committerJoshua Sjoding <joshua.sjoding@scjalliance.com>2016-02-25 00:38:51 -0800
commit0d999e1db6cd8736ab697de8ce848fa3a5274b9f (patch)
tree6107f49405bb605793f1bcd7ef4961ceadcb11e9 /core/object.go
parent07ca1ac7f3058ea6d3274a01973541fb84782f5e (diff)
downloadgo-git-0d999e1db6cd8736ab697de8ce848fa3a5274b9f.tar.gz
Refactor to use core.ObjectReader and core.ObjectWriter
* New function signatures provide the necessary interface to stream data from disk when using filesystem-based storage in the future * New function signatures provide proper error handling * ObjectReader and ObjectWriter interfaces added to avoid future refactoring, currently are type aliases for io.ReadCloser and io.WriteCloser respectively * Object.Reader now returns (ObjectReader, error) * Object.Writer now returns (ObjectWriter, error) * File.Contents now returns (string, error) * File.Lines now returns ([]string, error) * Blob.Reader now returns (core.ObjectReader, error) * Added internal close helper function for deferred calls to Close that need to check the return value
Diffstat (limited to 'core/object.go')
-rw-r--r--core/object.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/core/object.go b/core/object.go
index 74ea555..d56a44a 100644
--- a/core/object.go
+++ b/core/object.go
@@ -10,6 +10,21 @@ var (
ObjectNotFoundErr = errors.New("object not found")
)
+// TODO: Consider adding a Hash function to the ObjectReader and ObjectWriter
+// interfaces that returns the hash calculated for the reader or writer.
+
+// ObjectReader is a generic representation of an object reader.
+//
+// ObjectReader implements io.ReadCloser. Close should be called when finished
+// with it.
+type ObjectReader io.ReadCloser
+
+// ObjectWriter is a generic representation of an object writer.
+//
+// ObjectWriter implements io.WriterCloser. Close should be called when finished
+// with it.
+type ObjectWriter io.WriteCloser
+
// Object is a generic representation of any git object
type Object interface {
Hash() Hash
@@ -17,8 +32,8 @@ type Object interface {
SetType(ObjectType)
Size() int64
SetSize(int64)
- Reader() io.Reader
- Writer() io.Writer
+ Reader() (ObjectReader, error)
+ Writer() (ObjectWriter, error)
}
// ObjectStorage generic storage of objects