From 13ee6b696511ec85551ec4e43f8660417d6326fc Mon Sep 17 00:00:00 2001 From: Arpad Ryszka Date: Thu, 19 Mar 2026 15:05:29 +0100 Subject: [PATCH] rename Free() to Abort() --- lib.go | 12 +++++------- lib_test.go | 12 ++++++------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib.go b/lib.go index 94dfde4..0c6468a 100644 --- a/lib.go +++ b/lib.go @@ -52,8 +52,8 @@ 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, when the resources were released - // using Free(), and any of the Read operations is called again. + // experienced an error. ErrAbort is returned to the reader process, if Abort() was called and no read + // error was received before it. ErrAbort = errors.New("read aborted") ) @@ -211,11 +211,9 @@ func (r Reader) WriteTo(w io.Writer) (int64, error) { return r.reader.writeTo(w) } -// Free releases the resource held by the Reader, and puts back the underlying byte buffers into the used pool. -// -// It is used when a multi-step read operation is aborted. When a preceeding read operation resulted in an -// error, it is not necessary to call Free(). -func (r Reader) Free() { +// 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() { if r.reader == nil { return } diff --git a/lib_test.go b/lib_test.go index eb85d9e..bfd122b 100644 --- a/lib_test.go +++ b/lib_test.go @@ -151,11 +151,11 @@ func TestLib(t *testing.T) { }) }) - t.Run("free", func(t *testing.T) { + t.Run("abort", func(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.Free() + r.Abort() 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.Free() + r.Abort() 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.Free() + r.Abort() 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.Free() + r.Abort() 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.Free() + r.Abort() n, err = r.Read(b) if n != 0 || !errors.Is(err, errTest) { t.Fatal(n, err)