repos / pico

pico services mono repo
git clone https://github.com/picosh/pico.git

pico / pkg / pobj
Antonio Mika  ·  2025-03-12

reader.go

 1package pobj
 2
 3import (
 4	"errors"
 5	"io"
 6	"net/http"
 7
 8	"github.com/minio/minio-go/v7"
 9	"github.com/picosh/pico/pkg/send/utils"
10)
11
12type AllReaderAt struct {
13	Reader utils.ReadAndReaderAtCloser
14}
15
16func NewAllReaderAt(reader utils.ReadAndReaderAtCloser) *AllReaderAt {
17	return &AllReaderAt{reader}
18}
19
20func (a *AllReaderAt) ReadAt(p []byte, off int64) (n int, err error) {
21	n, err = a.Reader.ReadAt(p, off)
22
23	if errors.Is(err, io.EOF) {
24		return
25	}
26
27	resp := minio.ToErrorResponse(err)
28
29	if resp.StatusCode == http.StatusRequestedRangeNotSatisfiable {
30		err = io.EOF
31	}
32
33	return
34}
35
36func (a *AllReaderAt) Read(p []byte) (int, error) {
37	return a.Reader.Read(p)
38}
39
40func (a *AllReaderAt) Close() error {
41	return a.Reader.Close()
42}