diff options
Diffstat (limited to 'storage/filesystem/internal')
-rw-r--r-- | storage/filesystem/internal/index/index.go | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/storage/filesystem/internal/index/index.go b/storage/filesystem/internal/index/index.go index 737aca6..233dcbd 100644 --- a/storage/filesystem/internal/index/index.go +++ b/storage/filesystem/internal/index/index.go @@ -35,18 +35,26 @@ func NewFromIdx(r io.Reader) (Index, error) { // NewFrompackfile returns a new index from a packfile reader. func NewFromPackfile(rs io.ReadSeeker) (Index, error) { - index := make(Index) + s := packfile.NewSeekable(rs) + return newFromPackfile(rs, s) +} - r := packfile.NewSeekable(rs) - p := packfile.NewParser(r) +func NewFromPackfileInMemory(rs io.Reader) (Index, error) { + s := packfile.NewStream(rs) + return newFromPackfile(rs, s) +} +func newFromPackfile(r io.Reader, s packfile.ReadRecaller) (Index, error) { + index := make(Index) + + p := packfile.NewParser(s) count, err := p.ReadHeader() if err != nil { return nil, err } for i := 0; i < int(count); i++ { - offset, err := r.Offset() + offset, err := s.Offset() if err != nil { return nil, err } @@ -56,17 +64,19 @@ func NewFromPackfile(rs io.ReadSeeker) (Index, error) { return nil, err } - err = r.Remember(offset, obj) + err = s.Remember(offset, obj) if err != nil { return nil, err } - err = index.Set(obj.Hash(), offset) - if err != nil { + if err = index.Set(obj.Hash(), offset); err != nil { return nil, err } } + //The trailer records 20-byte SHA-1 checksum of all of the above. + p.ReadHash() + return index, nil } |