示例#1
0
文件: pack.go 项目: jbrukh/ggit
//parse the pack's meta data and close it
func (p *packIdxParser) ParsePack() *Pack {
	//parse the index and construct the pack
	idx := p.parseIdx()
	objects := make([]*PackedObject, idx.count)
	pack := &Pack{
		PackVersion,
		objects,
		idx,
		p.name,
		p.packOpener,
		nil,
	}
	//verify the pack file
	if err := pack.open(); err != nil {
		util.PanicErrf("Could not open pack file %s: %s", pack.name, err)
	}
	dataParser := util.NewDataParser(bufio.NewReader(pack.file))
	dataParser.ConsumeString(PackSignature)
	dataParser.ConsumeBytes([]byte{0, 0, 0, PackVersion})
	count := dataParser.ParseIntBigEndian(4)
	if count != idx.count {
		util.PanicErrf("Pack file count doesn't match idx file count for pack-%s!", p.name) //todo: don't panic.
	}
	pack.close()
	return pack
}
示例#2
0
文件: pack.go 项目: jbrukh/ggit
func newPackedObjectParser(data []byte, oid *objects.ObjectId) (p *packedObjectParser, e error) {
	compressedReader := bytes.NewReader(data)
	var zr io.ReadCloser
	if zr, e = zlib.NewReader(compressedReader); e == nil {
		defer zr.Close()
		exploder := util.NewDataParser(bufio.NewReader(zr))
		exploded := exploder.Bytes()
		explodedReader := bufio.NewReader(bytes.NewReader(exploded))
		op := NewObjectParser(explodedReader, oid)
		pop := packedObjectParser{
			op,
			exploded,
		}
		p = &pop
	}
	return
}