return int(int64(len(r.s)) - r.i)
}
+// Size returns the original length of the underlying byte slice.
+// Size is the number of bytes available for reading via ReadAt.
+// The returned value is always the same and is not affected by calls
+// to any other method.
+func (r *Reader) Size() int64 { return int64(len(r.s)) }
+
func (r *Reader) Read(b []byte) (n int, err error) {
if len(b) == 0 {
return 0, nil
t.Errorf("behavior differs: with = %#v; without: %#v", with, withOut)
}
}
+
+// tests that Len is affected by reads, but Size is not.
+func TestReaderLenSize(t *testing.T) {
+ r := NewReader([]byte("abc"))
+ io.CopyN(ioutil.Discard, r, 1)
+ if r.Len() != 2 {
+ t.Errorf("Len = %d; want 2", r.Len())
+ }
+ if r.Size() != 3 {
+ t.Errorf("Size = %d; want 3", r.Size())
+ }
+}
return int(int64(len(r.s)) - r.i)
}
+// Size returns the original length of the underlying string.
+// Size is the number of bytes available for reading via ReadAt.
+// The returned value is always the same and is not affected by calls
+// to any other method.
+func (r *Reader) Size() int64 { return int64(len(r.s)) }
+
func (r *Reader) Read(b []byte) (n int, err error) {
if len(b) == 0 {
return 0, nil
"bytes"
"fmt"
"io"
+ "io/ioutil"
"os"
"strings"
"sync"
}
}
}
+
+// tests that Len is affected by reads, but Size is not.
+func TestReaderLenSize(t *testing.T) {
+ r := strings.NewReader("abc")
+ io.CopyN(ioutil.Discard, r, 1)
+ if r.Len() != 2 {
+ t.Errorf("Len = %d; want 2", r.Len())
+ }
+ if r.Size() != 3 {
+ t.Errorf("Size = %d; want 3", r.Size())
+ }
+}