storj/internal/pkg/readcloser/limit.go
Kaloyan Raev f96cc9c955 HTTP Ranger (#11)
* HTTPRanger

* Migrate eestream library to use ReadCloser instead of Reader

* Use MultiReadCloser instead of MultiReader

* Adapt example cli cmds to latest serverbox changes

* Close LazyReadCloser only if only generated

* Close ReadClosers sequentially

* Close response body on unexpected status code

* Avoid double close of the pipe reader

* Better formatting for imports

* Exit instead of panicking
2018-04-17 07:39:14 -06:00

26 lines
572 B
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package readcloser
import "io"
// LimitReadCloser is a LimitReader extension that returns a ReadCloser
// that reads from r but stops with EOF after n bytes.
func LimitReadCloser(r io.ReadCloser, n int64) io.ReadCloser {
return &limitedReadCloser{io.LimitReader(r, n), r}
}
type limitedReadCloser struct {
R io.Reader
C io.Closer
}
func (l *limitedReadCloser) Read(p []byte) (n int, err error) {
return l.R.Read(p)
}
func (l *limitedReadCloser) Close() error {
return l.C.Close()
}