aboutsummaryrefslogtreecommitdiffstats
path: root/formats/packfile/reader.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-02-25 10:18:48 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-02-25 10:18:48 +0100
commit5bc563727ffa798caee3b007c366eb66c3d69caa (patch)
tree6107f49405bb605793f1bcd7ef4961ceadcb11e9 /formats/packfile/reader.go
parent07ca1ac7f3058ea6d3274a01973541fb84782f5e (diff)
parent0d999e1db6cd8736ab697de8ce848fa3a5274b9f (diff)
downloadgo-git-5bc563727ffa798caee3b007c366eb66c3d69caa.tar.gz
Merge pull request #34 from scjalliance/object-reader-writer
Refactor to use core.ObjectReader and core.ObjectWriter
Diffstat (limited to 'formats/packfile/reader.go')
-rw-r--r--formats/packfile/reader.go64
1 files changed, 54 insertions, 10 deletions
diff --git a/formats/packfile/reader.go b/formats/packfile/reader.go
index 6f30f8a..e14b84e 100644
--- a/formats/packfile/reader.go
+++ b/formats/packfile/reader.go
@@ -187,7 +187,7 @@ func (r *Reader) newObject() (core.Object, error) {
return raw, err
}
-func (r *Reader) readREFDelta(raw core.Object) error {
+func (r *Reader) readREFDelta(raw core.Object) (err error) {
var ref core.Hash
if _, err := io.ReadFull(r.r, ref[:]); err != nil {
return err
@@ -206,7 +206,17 @@ func (r *Reader) readREFDelta(raw core.Object) error {
return err
}
- d, _ := ioutil.ReadAll(referenced.Reader())
+ reader, err := referenced.Reader()
+ if err != nil {
+ return err
+ }
+ defer close(reader, &err)
+
+ d, err := ioutil.ReadAll(reader)
+ if err != nil {
+ return err
+ }
+
patched := patchDelta(d, buf.Bytes())
if patched == nil {
return PatchingErr.n("hash %q", ref)
@@ -214,12 +224,19 @@ func (r *Reader) readREFDelta(raw core.Object) error {
raw.SetType(referenced.Type())
raw.SetSize(int64(len(patched)))
- raw.Writer().Write(patched)
+
+ writer, err := raw.Writer()
+ if err != nil {
+ return err
+ }
+ defer close(writer, &err)
+
+ writer.Write(patched)
return nil
}
-func (r *Reader) readOFSDelta(raw core.Object, steps int64) error {
+func (r *Reader) readOFSDelta(raw core.Object, steps int64) (err error) {
start := r.r.position
offset, err := decodeOffset(r.r, steps)
if err != nil {
@@ -227,7 +244,7 @@ func (r *Reader) readOFSDelta(raw core.Object, steps int64) error {
}
buf := bytes.NewBuffer(nil)
- if err := r.inflate(buf); err != nil {
+ if err = r.inflate(buf); err != nil {
return err
}
@@ -236,8 +253,22 @@ func (r *Reader) readOFSDelta(raw core.Object, steps int64) error {
return PackEntryNotFoundErr.n("offset %d", start+offset)
}
- referenced, _ := r.s.Get(ref) // FIXME: Handle error returned from Get()
- d, _ := ioutil.ReadAll(referenced.Reader())
+ referenced, err := r.s.Get(ref)
+ if err != nil {
+ return err
+ }
+
+ reader, err := referenced.Reader()
+ if err != nil {
+ return err
+ }
+ defer close(reader, &err)
+
+ d, err := ioutil.ReadAll(reader)
+ if err != nil {
+ return err
+ }
+
patched := patchDelta(d, buf.Bytes())
if patched == nil {
return PatchingErr.n("hash %q", ref)
@@ -245,13 +276,26 @@ func (r *Reader) readOFSDelta(raw core.Object, steps int64) error {
raw.SetType(referenced.Type())
raw.SetSize(int64(len(patched)))
- raw.Writer().Write(patched)
+
+ writer, err := raw.Writer()
+ if err != nil {
+ return err
+ }
+ defer close(writer, &err)
+
+ writer.Write(patched)
return nil
}
-func (r *Reader) readObject(raw core.Object) error {
- return r.inflate(raw.Writer())
+func (r *Reader) readObject(raw core.Object) (err error) {
+ writer, err := raw.Writer()
+ if err != nil {
+ return err
+ }
+ defer close(writer, &err)
+
+ return r.inflate(writer)
}
func (r *Reader) inflate(w io.Writer) error {