From 0d999e1db6cd8736ab697de8ce848fa3a5274b9f Mon Sep 17 00:00:00 2001 From: Joshua Sjoding Date: Wed, 24 Feb 2016 22:40:30 -0800 Subject: 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 --- core/object.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'core') 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 -- cgit