mirror of
https://github.com/benbjohnson/litestream.git
synced 2026-01-25 05:06:30 +00:00
Some checks failed
Commit / Lint (push) Has been cancelled
Commit / Build Windows (push) Has been cancelled
Commit / Build & Unit Test (push) Has been cancelled
Commit / Run S3 Mock Tests (push) Has been cancelled
Commit / Run NATS Integration Tests (push) Has been cancelled
Commit / Run S3 Integration Tests (push) Has been cancelled
Commit / Run GCP Integration Tests (push) Has been cancelled
Commit / Run Azure Blob Store Integration Tests (push) Has been cancelled
Commit / Run SFTP Integration Tests (push) Has been cancelled
30 lines
558 B
Go
30 lines
558 B
Go
package internal
|
|
|
|
import "io"
|
|
|
|
// Copied from the io package to implement io.Closer.
|
|
func LimitReadCloser(r io.ReadCloser, n int64) io.ReadCloser {
|
|
return &LimitedReadCloser{r, n}
|
|
}
|
|
|
|
type LimitedReadCloser struct {
|
|
R io.ReadCloser // underlying reader
|
|
N int64 // max bytes remaining
|
|
}
|
|
|
|
func (l *LimitedReadCloser) Close() error {
|
|
return l.R.Close()
|
|
}
|
|
|
|
func (l *LimitedReadCloser) Read(p []byte) (n int, err error) {
|
|
if l.N <= 0 {
|
|
return 0, io.EOF
|
|
}
|
|
if int64(len(p)) > l.N {
|
|
p = p[0:l.N]
|
|
}
|
|
n, err = l.R.Read(p)
|
|
l.N -= int64(n)
|
|
return
|
|
}
|