feat: buffer fetched HTTP bodies
Alan Pearce alan@alanpearce.eu
Mon, 24 Mar 2025 18:37:49 +0100
2 files changed, 25 insertions(+), 1 deletions(-)
A internal/fetcher/buf.go
@@ -0,0 +1,24 @@+package fetcher + +import ( + "bufio" + "io" + + "gitlab.com/tozd/go/errors" +) + +type Reader struct { + closer io.ReadCloser + *bufio.Reader +} + +func NewReadCloser(body io.ReadCloser) *Reader { + return &Reader{ + closer: body, + Reader: bufio.NewReader(body), + } +} + +func (r *Reader) Close() error { + return errors.WithStack(r.closer.Close()) +}
M internal/fetcher/http.go → internal/fetcher/http.go
@@ -94,5 +94,5 @@ default: err = errors.Errorf("got response code %d, don't know what to do", res.StatusCode) } - return body, newMtime, err + return NewReadCloser(body), newMtime, err }