Skip to content

Commit 003761d

Browse files
committed
Changing tests, using io.ErrShortWrite instead of io.ErrShortBuffer
1 parent 48d61e6 commit 003761d

File tree

6 files changed

+5
-24
lines changed

6 files changed

+5
-24
lines changed

buffer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type Buffer interface {
1212
Len() int64 // How much data is Buffered in bytes
1313
Cap() int64 // How much data can be Buffered at once in bytes.
1414
io.Reader // Read() will read from the top of the buffer [io.EOF if empty]
15-
io.Writer // Write() will write to the end of the buffer [io.ErrShortBuffer if not enough space]
15+
io.Writer // Write() will write to the end of the buffer [io.ErrShortWrite if not enough space]
1616
Reset() // Truncates the buffer, Len() == 0.
1717
}
1818

buffer_test.go

-18
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"io/ioutil"
99
"os"
1010
"testing"
11-
12-
"github.com/djherbis/buffer/wrapio"
1311
)
1412

1513
func BenchmarkMemory(b *testing.B) {
@@ -108,22 +106,6 @@ func TestSpill(t *testing.T) {
108106
}
109107
}
110108

111-
func TestWrap(t *testing.T) {
112-
if file, err := ioutil.TempFile("", "wrap.test"); err == nil {
113-
w := wrapio.NewWrapWriter(file, 0, 3)
114-
w.Write([]byte("abcdef"))
115-
116-
r := wrapio.NewWrapReader(file, 0, 2)
117-
data := make([]byte, 6)
118-
r.Read(data)
119-
if !bytes.Equal(data, []byte("dedede")) {
120-
t.Error("Wrapper error!")
121-
}
122-
file.Close()
123-
os.Remove(file.Name())
124-
}
125-
}
126-
127109
func TestFile(t *testing.T) {
128110
file, err := ioutil.TempFile("", "buffer")
129111
if err != nil {

limio/limit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type LimitedWriter struct {
99

1010
func (l *LimitedWriter) Write(p []byte) (n int, err error) {
1111
if l.N <= 0 {
12-
return 0, io.ErrShortBuffer
12+
return 0, io.ErrShortWrite
1313
}
1414
if int64(len(p)) > l.N {
1515
p = p[0:l.N]

mem.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ func (buf *memory) Write(p []byte) (n int, err error) {
3535
return limio.LimitWriter(buf.Buffer, Gap(buf)).Write(p)
3636
}
3737

38-
// BUG(Dustin): Should add io.ErrShortWrite
3938
func (buf *memory) WriteAt(p []byte, off int64) (n int, err error) {
4039
if off > buf.Len() {
41-
return 0, io.ErrShortBuffer
40+
return 0, io.ErrShortWrite
4241
} else if len64(p)+off <= buf.Len() {
4342
d := buf.Bytes()[off:]
4443
return copy(d, p), nil

multi.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (buf *chain) Read(p []byte) (n int, err error) {
9090
}
9191

9292
func (buf *chain) Write(p []byte) (n int, err error) {
93-
if n, err = buf.Buf.Write(p); err == io.ErrShortBuffer && buf.HasNext {
93+
if n, err = buf.Buf.Write(p); err == io.ErrShortWrite && buf.HasNext {
9494
err = nil
9595
}
9696
p = p[n:]

partition.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (buf *partition) Write(p []byte) (n int, err error) {
6868
n += m
6969
p = p[m:]
7070

71-
if er == io.ErrShortBuffer {
71+
if er == io.ErrShortWrite {
7272
er = nil
7373
} else if er != nil {
7474
return n, er

0 commit comments

Comments
 (0)