f96cc9c955
* 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
26 lines
572 B
Go
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()
|
|
}
|