如何使用Go解压缩git pack文件?

I'm trying to unpack a git pack file using pure go. The only lib I could find is github.com/jbrukh/ggit/api -> parse but I have a hard me to figure out how it is supposed to work. Basically all I need is to provide the body of the pack file and get back the git objects (which I assume are compressed using zlib). I've tried several approaches including forking and trying to use the private functions but with no success(i.e it panics).

package main

import(

    log "github.com/golang/glog"
    "io/ioutil"
    "bytes"
    "bufio"
    "flag"
    "os"
    "github.com/jbrukh/ggit/api/parse"
)

func main(){
    flag.Parse()
    defer log.Flush()
    packPath := "/Users/user/go/src/gopath/test_pack_no_header"
    b, err := ioutil.ReadFile(packPath)
    if err !=nil{
        panic(err)
    }
    sha := "9eabf5b536662000f79978c4d1b6e4eff5c8d785"

    reader := bufio.NewReader(bytes.NewBuffer(b))
    openner := func()(*os.File, error){
        return os.Open(packPath)
    }
    po  := parse.NewPackIdxParser(reader, openner,  sha)
    if err !=nil{
        log.Error(err)
        return
    }
    pack := po.ParsePack()  
    log.Error("oo is %s", pack)

}

Panic:

go run main.go -logtostderr
panic: expected string: �tOc

goroutine 1 [running]:
github.com/jbrukh/ggit/util.PanicErrf(0x1d4b30, 0x13, 0xc8200537d8, 0x1, 0x1)
    /Users/user/go/src/github.com/jbrukh/ggit/util/data_parser.go:72 +0x63
github.com/jbrukh/ggit/util.(*DataParser).ConsumeString(0xc820086380, 0x1b3910, 0x4)
    /Users/user/go/src/github.com/jbrukh/ggit/util/data_parser.go:226 +0x1a5
github.com/jbrukh/ggit/api/parse.(*packIdxParser).parseIdx(0xc820053ed0, 0xc820053ba0)
    /Users/user/go/src/github.com/jbrukh/ggit/api/parse/pack.go:320 +0x66
github.com/jbrukh/ggit/api/parse.(*packIdxParser).ParsePack(0xc820053ed0, 0xc820086380)
    /Users/user/go/src/github.com/jbrukh/ggit/api/parse/pack.go:400 +0x4e
main.main()
    /Users/user/go/src/gopath/tools/main.go:33 +0x450
exit status 2
exit status 1
2016-02-12 16:28:16.322504062 +0200 EET

Note: I need to unpack only a pack file and as in the attempted example above I don't have the idx file.

For what it's worth I ended-up with a brute-force approach. Not a robust solution but it works for what I need (decode a pack file of a known object type).

package main

import(
    "compress/zlib"
    log "github.com/golang/glog"
    "io/ioutil"
    "bytes"
    "flag"
    "io"
)

func main(){
    flag.Parse()
    defer log.Flush()
    packPath := "/Users/usr/test_pack_no_header"
    b, err := ioutil.ReadFile(packPath)
    if err !=nil{
        panic(err)
    }
    buf := bytes.NewBuffer(b)

    i := 0
    for {
        decoded, err := readObjectRaw(bytes.NewBuffer(buf.Bytes()))
        if err ==nil{
            log.Errorf("i %v, decoded is %s", i, decoded)
            //return
        }
        if _, err = buf.ReadByte(); err ==  io.EOF{
            log.Errorf("EOF")
            return
        }
        i++
    }

}


func readObjectRaw(reader io.Reader)([]byte, error){
    r, err := zlib.NewReader(reader)
    if err !=nil{
        //log.Error(err)
        return nil, err
    }
    defer r.Close()
    def := bytes.NewBuffer(nil)
    _, err = io.Copy(def, r)
    if err !=nil{
        //log.Errorf("%v bytes copied, err %v", i, err)
        return nil, err
    }
    return def.Bytes(), nil
}