1
0

rename abort to close

This commit is contained in:
Arpad Ryszka 2026-03-21 18:19:15 +01:00
parent 13ee6b6965
commit 8dd8a636af
2 changed files with 9 additions and 9 deletions

8
lib.go
View File

@ -52,7 +52,7 @@ var (
ErrZeroAllocation = errors.New("zero allocation")
// ErrAbort is returned to the writer process in case of buffered content, when the reader
// experienced an error. ErrAbort is returned to the reader process, if Abort() was called and no read
// experienced an error. ErrAbort is returned to the reader process, if Close() was called and no read
// error was received before it.
ErrAbort = errors.New("read aborted")
)
@ -211,9 +211,9 @@ func (r Reader) WriteTo(w io.Writer) (int64, error) {
return r.reader.writeTo(w)
}
// Abort releases the resource held by the Reader, and puts back the underlying byte buffers into the used pool.
// The reader cannot be used for read operations after Abort() was called.
func (r Reader) Abort() {
// Close releases the resource held by the Reader, and puts back the underlying byte buffers into the used pool.
// The reader cannot be used for read operations after Close() was called.
func (r Reader) Close() {
if r.reader == nil {
return
}

View File

@ -155,7 +155,7 @@ func TestLib(t *testing.T) {
t.Run("from blank state", func(t *testing.T) {
p := &fakePool{allocSize: 1 << 6}
r := buffer.BufferedReader(&gen{max: 1 << 12}, buffer.Options{Pool: p})
r.Abort()
r.Close()
b := make([]byte, 1<<9)
n, err := r.Read(b)
if n != 0 || !errors.Is(err, buffer.ErrAbort) {
@ -175,7 +175,7 @@ func TestLib(t *testing.T) {
t.Fatal(len(b), ok, err, p.alloc)
}
r.Abort()
r.Close()
b = make([]byte, 1<<9)
n, err := r.Read(b)
if n != 0 || !errors.Is(err, buffer.ErrAbort) {
@ -206,7 +206,7 @@ func TestLib(t *testing.T) {
t.Fatal(n, err)
}
r.Abort()
r.Close()
b = make([]byte, 1<<9)
n, err = r.Read(b)
if n != 0 || !errors.Is(err, errTest) {
@ -247,7 +247,7 @@ func TestLib(t *testing.T) {
}
}
r.Abort()
r.Close()
n, err := r.Read(b)
if n != 0 || !errors.Is(err, buffer.ErrAbort) {
t.Fatal(n, err)
@ -292,7 +292,7 @@ func TestLib(t *testing.T) {
t.Fatal(n, err)
}
r.Abort()
r.Close()
n, err = r.Read(b)
if n != 0 || !errors.Is(err, errTest) {
t.Fatal(n, err)