Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 77906b6

Browse files
committed
Switch of repo size
1 parent 465cba7 commit 77906b6

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

packfile/packfile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "fmt"
44

55
type Packfile struct {
66
Version uint32
7+
Size int64
78
ObjectCount int
89
Checksum []byte
910
Commits map[string]*Commit

packfile/reader.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import (
1111

1212
const MaxObjectsLimit = 1000000
1313

14+
const MaxSizeLimit = 300 * 1 << 20
15+
16+
var ErrMaxSize = fmt.Errorf("Max size exceeded for in-memory client")
17+
1418
type TrackingByteReader struct {
1519
r io.Reader
1620
n int
@@ -24,6 +28,9 @@ func (t *TrackingByteReader) Read(p []byte) (n int, err error) {
2428
return 0, err
2529
}
2630
t.n += n
31+
if t.n >= MaxSizeLimit {
32+
return n, ErrMaxSize
33+
}
2734
return n, err
2835
}
2936

@@ -103,6 +110,8 @@ func (pr *PackfileReader) Read() (*Packfile, error) {
103110
return nil, err
104111
}
105112

113+
packfile.Size = int64(pr.r.Pos())
114+
106115
return packfile, nil
107116
}
108117

0 commit comments

Comments
 (0)