aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/internal
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-09-05 19:55:01 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-09-05 19:55:01 +0200
commit19da30a8ff233285a79df9f1da8b0d88d99eb626 (patch)
treebdb2313cc29381afbad9af75bd273c5ec6d9f24b /storage/filesystem/internal
parent65427f64599e9383ab926aed75fc02f2db32022d (diff)
downloadgo-git-19da30a8ff233285a79df9f1da8b0d88d99eb626.tar.gz
core: ObjectStorage.Writer
Diffstat (limited to 'storage/filesystem/internal')
-rw-r--r--storage/filesystem/internal/index/index.go24
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
}