github.com/stffabi/git-lfs@v2.3.5-0.20180214015214-8eeaa8d88902+incompatible/git/odb/pack/chain_base.go (about) 1 package pack 2 3 import ( 4 "compress/zlib" 5 "io" 6 ) 7 8 // ChainBase represents the "base" component of a delta-base chain. 9 type ChainBase struct { 10 // offset returns the offset into the given io.ReaderAt where the read 11 // will begin. 12 offset int64 13 // size is the total uncompressed size of the data in the base chain. 14 size int64 15 // typ is the type of data that this *ChainBase encodes. 16 typ PackedObjectType 17 18 // r is the io.ReaderAt yielding a stream of zlib-compressed data. 19 r io.ReaderAt 20 } 21 22 // Unpack inflates and returns the uncompressed data encoded in the base 23 // element. 24 // 25 // If there was any error in reading the compressed data (invalid headers, 26 // etc.), it will be returned immediately. 27 func (b *ChainBase) Unpack() ([]byte, error) { 28 zr, err := zlib.NewReader(&OffsetReaderAt{ 29 r: b.r, 30 o: b.offset, 31 }) 32 33 if err != nil { 34 return nil, err 35 } 36 37 defer zr.Close() 38 39 buf := make([]byte, b.size) 40 if _, err := io.ReadFull(zr, buf); err != nil { 41 return nil, err 42 } 43 return buf, nil 44 } 45 46 // ChainBase returns the type of the object it encodes. 47 func (b *ChainBase) Type() PackedObjectType { 48 return b.typ 49 }