mirror of
https://github.com/restic/restic.git
synced 2026-11-19 23:01:08 +00:00
Use int64 for the length in the RewindReader
This commit is contained in:
1 parent
99f7fd74e3
commit
929afc63d5
4 files changed
+21
-21
No files matched your search
@@ -17,13 +17,13 @@ type RewindReader interface {
|
||||
|
||||
// Length returns the number of bytes that can be read from the Reader
|
||||
// after calling Rewind.
|
||||
Length() int
|
||||
Length() int64
|
||||
}
|
||||
|
||||
// ByteReader implements a RewindReader for a byte slice.
|
||||
type ByteReader struct {
|
||||
*bytes.Reader
|
||||
Len int
|
||||
Len int64
|
||||
}
|
||||
|
||||
// Rewind restarts the reader from the beginning of the data.
|
||||
@@ -34,7 +34,7 @@ func (b *ByteReader) Rewind() error {
|
||||
|
||||
// Length returns the number of bytes read from the reader after Rewind is
|
||||
// called.
|
||||
func (b *ByteReader) Length() int {
|
||||
func (b *ByteReader) Length() int64 {
|
||||
return b.Len
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ var _ RewindReader = &ByteReader{}
|
||||
func NewByteReader(buf []byte) *ByteReader {
|
||||
return &ByteReader{
|
||||
Reader: bytes.NewReader(buf),
|
||||
Len: len(buf),
|
||||
Len: int64(len(buf)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ var _ RewindReader = &FileReader{}
|
||||
// FileReader implements a RewindReader for an open file.
|
||||
type FileReader struct {
|
||||
io.ReadSeeker
|
||||
Len int
|
||||
Len int64
|
||||
}
|
||||
|
||||
// Rewind seeks to the beginning of the file.
|
||||
@@ -65,7 +65,7 @@ func (f *FileReader) Rewind() error {
|
||||
}
|
||||
|
||||
// Length returns the length of the file.
|
||||
func (f *FileReader) Length() int {
|
||||
func (f *FileReader) Length() int64 {
|
||||
return f.Len
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ func NewFileReader(f io.ReadSeeker) (*FileReader, error) {
|
||||
|
||||
fr := &FileReader{
|
||||
ReadSeeker: f,
|
||||
Len: int(pos),
|
||||
Len: pos,
|
||||
}
|
||||
|
||||
err = fr.Rewind()
|
||||
|
||||
@@ -57,15 +57,15 @@ func TestFileReader(t *testing.T) {
|
||||
}
|
||||
|
||||
func testRewindReader(t *testing.T, fn func() RewindReader, data []byte) {
|
||||
seed := time.Now().Unix()
|
||||
seed := time.Now().UnixNano()
|
||||
t.Logf("seed is %d", seed)
|
||||
rnd := rand.New(rand.NewSource(seed))
|
||||
|
||||
type ReaderTestFunc func(t testing.TB, r RewindReader, data []byte)
|
||||
var tests = []ReaderTestFunc{
|
||||
func(t testing.TB, rd RewindReader, data []byte) {
|
||||
if rd.Length() != len(data) {
|
||||
t.Fatalf("wrong length returned, want %d, got %d", len(data), rd.Length())
|
||||
if rd.Length() != int64(len(data)) {
|
||||
t.Fatalf("wrong length returned, want %d, got %d", int64(len(data)), rd.Length())
|
||||
}
|
||||
|
||||
buf := make([]byte, len(data))
|
||||
@@ -78,8 +78,8 @@ func testRewindReader(t *testing.T, fn func() RewindReader, data []byte) {
|
||||
t.Fatalf("wrong data returned")
|
||||
}
|
||||
|
||||
if rd.Length() != len(data) {
|
||||
t.Fatalf("wrong length returned, want %d, got %d", len(data), rd.Length())
|
||||
if rd.Length() != int64(len(data)) {
|
||||
t.Fatalf("wrong length returned, want %d, got %d", int64(len(data)), rd.Length())
|
||||
}
|
||||
|
||||
err = rd.Rewind()
|
||||
@@ -87,11 +87,11 @@ func testRewindReader(t *testing.T, fn func() RewindReader, data []byte) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if rd.Length() != len(data) {
|
||||
t.Fatalf("wrong length returned, want %d, got %d", len(data), rd.Length())
|
||||
if rd.Length() != int64(len(data)) {
|
||||
t.Fatalf("wrong length returned, want %d, got %d", int64(len(data)), rd.Length())
|
||||
}
|
||||
|
||||
buf2 := make([]byte, len(data))
|
||||
buf2 := make([]byte, int64(len(data)))
|
||||
_, err = io.ReadFull(rd, buf2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -101,8 +101,8 @@ func testRewindReader(t *testing.T, fn func() RewindReader, data []byte) {
|
||||
t.Fatalf("wrong data returned")
|
||||
}
|
||||
|
||||
if rd.Length() != len(data) {
|
||||
t.Fatalf("wrong length returned, want %d, got %d", len(data), rd.Length())
|
||||
if rd.Length() != int64(len(data)) {
|
||||
t.Fatalf("wrong length returned, want %d, got %d", int64(len(data)), rd.Length())
|
||||
}
|
||||
},
|
||||
func(t testing.TB, rd RewindReader, data []byte) {
|
||||
|
||||
Reference in new issue
Block a user