File: chain_base.go

package info (click to toggle)
golang-github-git-lfs-gitobj 2.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 432 kB
  • sloc: makefile: 2; sh: 1
file content (49 lines) | stat: -rw-r--r-- 1,115 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package pack

import (
	"compress/zlib"
	"io"
)

// ChainBase represents the "base" component of a delta-base chain.
type ChainBase struct {
	// offset returns the offset into the given io.ReaderAt where the read
	// will begin.
	offset int64
	// size is the total uncompressed size of the data in the base chain.
	size int64
	// typ is the type of data that this *ChainBase encodes.
	typ PackedObjectType

	// r is the io.ReaderAt yielding a stream of zlib-compressed data.
	r io.ReaderAt
}

// Unpack inflates and returns the uncompressed data encoded in the base
// element.
//
// If there was any error in reading the compressed data (invalid headers,
// etc.), it will be returned immediately.
func (b *ChainBase) Unpack() ([]byte, error) {
	zr, err := zlib.NewReader(&OffsetReaderAt{
		r: b.r,
		o: b.offset,
	})

	if err != nil {
		return nil, err
	}

	defer zr.Close()

	buf := make([]byte, b.size)
	if _, err := io.ReadFull(zr, buf); err != nil {
		return nil, err
	}
	return buf, nil
}

// ChainBase returns the type of the object it encodes.
func (b *ChainBase) Type() PackedObjectType {
	return b.typ
}