schema: delete the old FileReader.Skip method

Change-Id: I025bee0d2a4cc8b2cae4e825d0c3b37f14ee8b57
This commit is contained in:
Brad Fitzpatrick 2013-01-04 16:29:16 -08:00
parent 971abb5566
commit 3a8b9078ec
2 changed files with 23 additions and 30 deletions

View File

@ -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)

View File

@ -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