diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2015-10-23 16:27:08 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2015-10-23 16:28:13 +0200 |
commit | 27aa8cdd2431068606741a589383c02c149ea625 (patch) | |
tree | d423447ee374fbfa802f7ff354651fd34afe0fb2 /formats/packfile/common.go | |
parent | fa058d42fa3bc53f39108a56dad67157169b2191 (diff) | |
download | go-git-27aa8cdd2431068606741a589383c02c149ea625.tar.gz |
formats/packfile: cleanup
Diffstat (limited to 'formats/packfile/common.go')
-rw-r--r-- | formats/packfile/common.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/formats/packfile/common.go b/formats/packfile/common.go new file mode 100644 index 0000000..4a97dc7 --- /dev/null +++ b/formats/packfile/common.go @@ -0,0 +1,39 @@ +package packfile + +import ( + "fmt" + "io" +) + +type trackingReader struct { + r io.Reader + n int +} + +func (t *trackingReader) Pos() int { return t.n } + +func (t *trackingReader) Read(p []byte) (n int, err error) { + n, err = t.r.Read(p) + if err != nil { + return 0, err + } + + t.n += n + + return n, err +} + +func (t *trackingReader) ReadByte() (c byte, err error) { + var p [1]byte + n, err := t.r.Read(p[:]) + if err != nil { + return 0, err + } + + if n > 1 { + return 0, fmt.Errorf("read %d bytes, should have read just 1", n) + } + + t.n += n // n is 1 + return p[0], nil +} |