summaryrefslogtreecommitdiff
path: root/workhorse/internal/upload/destination/reader.go
blob: 925a9468e144a4e352969a6440a5400529b634b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package destination

import "io"

type hardLimitReader struct {
	r io.Reader
	n int64
}

func (h *hardLimitReader) Read(p []byte) (int, error) {
	nRead, err := h.r.Read(p)
	h.n -= int64(nRead)
	if h.n < 0 {
		err = ErrEntityTooLarge
	}
	return nRead, err
}