aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/memory.go1
-rw-r--r--tree.go18
2 files changed, 15 insertions, 4 deletions
diff --git a/core/memory.go b/core/memory.go
index 8826966..3d8063d 100644
--- a/core/memory.go
+++ b/core/memory.go
@@ -50,7 +50,6 @@ func (o *MemoryObject) Writer() (ObjectWriter, error) {
func (o *MemoryObject) Write(p []byte) (n int, err error) {
o.cont = append(o.cont, p...)
- o.sz = int64(len(o.cont))
return len(p), nil
}
diff --git a/tree.go b/tree.go
index 86f1aaa..3058231 100644
--- a/tree.go
+++ b/tree.go
@@ -218,18 +218,30 @@ func (t *Tree) Encode(o core.Object) error {
if err != nil {
return err
}
+
+ var size int
defer checkClose(w, &err)
for _, entry := range t.Entries {
- if _, err = fmt.Fprintf(w, "%o %s", entry.Mode, entry.Name); err != nil {
+ n, err := fmt.Fprintf(w, "%o %s", entry.Mode, entry.Name)
+ if err != nil {
return err
}
- if _, err = w.Write([]byte{0x00}); err != nil {
+
+ size += n
+ n, err = w.Write([]byte{0x00})
+ if err != nil {
return err
}
- if _, err = w.Write([]byte(entry.Hash[:])); err != nil {
+
+ size += n
+ n, err = w.Write([]byte(entry.Hash[:]))
+ if err != nil {
return err
}
+ size += n
}
+
+ o.SetSize(int64(size))
return err
}