diff --git a/pkg/schema/fileread_test.go b/pkg/schema/fileread_test.go index c5ce2d8b7..4ddddd526 100644 --- a/pkg/schema/fileread_test.go +++ b/pkg/schema/fileread_test.go @@ -22,6 +22,7 @@ import ( "io/ioutil" "log" "math/rand" + "os" "testing" "camlistore.org/pkg/test" @@ -125,6 +126,26 @@ var readTests = []readTest{ "AAAAaaaaa" + "Bbbbbb" + "Cc" + "aaaaa"}, } +func skipBytes(fr *FileReader, skipBytes uint64) uint64 { + oldOff, err := fr.Seek(0, os.SEEK_CUR) + if err != nil { + panic("Failed to seek") + } + remain := fr.size - oldOff + if int64(skipBytes) > remain { + skipBytes = uint64(remain) + } + newOff, err := fr.Seek(int64(skipBytes), os.SEEK_CUR) + if err != nil { + panic("Failed to seek") + } + skipped := newOff - oldOff + if skipped < 0 { + panic("") + } + return uint64(skipped) +} + func TestReader(t *testing.T) { for idx, rt := range readTests { ss := new(Superset) @@ -136,7 +157,7 @@ func TestReader(t *testing.T) { t.Errorf("read error on test %d: %v", idx, err) continue } - fr.Skip(rt.skip) + skipBytes(fr, rt.skip) all, err := ioutil.ReadAll(fr) if err != nil { t.Errorf("read error on test %d: %v", idx, err) @@ -183,7 +204,7 @@ func TestReaderSeekStress(t *testing.T) { t.Fatal(err) } - fr.Skip(uint64(off)) + skipBytes(fr, uint64(off)) got, err := ioutil.ReadAll(fr) if err != nil { t.Fatal(err) diff --git a/pkg/schema/filereader.go b/pkg/schema/filereader.go index 93bdf2270..2d06a06e6 100644 --- a/pkg/schema/filereader.go +++ b/pkg/schema/filereader.go @@ -99,34 +99,6 @@ func (fr *FileReader) Close() error { return nil } -// Skip skips past skipBytes of the file. -// It is equivalent to but more efficient than: -// -// io.CopyN(ioutil.Discard, fr, skipBytes) -// -// It returns the number of bytes skipped. -// -// TODO(bradfitz): delete this. Legacy interface; callers should just Seek now. -func (fr *FileReader) Skip(skipBytes uint64) uint64 { - oldOff, err := fr.Seek(0, os.SEEK_CUR) - if err != nil { - panic("Failed to seek") - } - remain := fr.size - oldOff - if int64(skipBytes) > remain { - skipBytes = uint64(remain) - } - newOff, err := fr.Seek(int64(skipBytes), os.SEEK_CUR) - if err != nil { - panic("Failed to seek") - } - skipped := newOff - oldOff - if skipped < 0 { - panic("") - } - return uint64(skipped) -} - var _ interface { io.ReaderAt io.Reader