summaryrefslogtreecommitdiff
path: root/odb.go
diff options
context:
space:
mode:
Diffstat (limited to 'odb.go')
-rw-r--r--odb.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/odb.go b/odb.go
index 64c5415..fd27363 100644
--- a/odb.go
+++ b/odb.go
@@ -8,6 +8,7 @@ extern void _go_git_odb_backend_free(git_odb_backend *backend);
*/
import "C"
import (
+ "io"
"reflect"
"runtime"
"unsafe"
@@ -182,17 +183,21 @@ func (v *Odb) Hash(data []byte, otype ObjectType) (oid *Oid, err error) {
// contents of the object.
func (v *Odb) NewReadStream(id *Oid) (*OdbReadStream, error) {
stream := new(OdbReadStream)
+ var ctype C.git_otype
+ var csize C.size_t
runtime.LockOSThread()
defer runtime.UnlockOSThread()
- ret := C.git_odb_open_rstream(&stream.ptr, v.ptr, id.toC())
+ ret := C.git_odb_open_rstream(&stream.ptr, &csize, &ctype, v.ptr, id.toC())
runtime.KeepAlive(v)
runtime.KeepAlive(id)
if ret < 0 {
return nil, MakeGitError(ret)
}
+ stream.Size = uint64(csize)
+ stream.Type = ObjectType(ctype)
runtime.SetFinalizer(stream, (*OdbReadStream).Free)
return stream, nil
}
@@ -264,7 +269,9 @@ func (object *OdbObject) Data() (data []byte) {
}
type OdbReadStream struct {
- ptr *C.git_odb_stream
+ ptr *C.git_odb_stream
+ Size uint64
+ Type ObjectType
}
// Read reads from the stream
@@ -281,6 +288,9 @@ func (stream *OdbReadStream) Read(data []byte) (int, error) {
if ret < 0 {
return 0, MakeGitError(ret)
}
+ if ret == 0 {
+ return 0, io.EOF
+ }
header.Len = int(ret)