storj/uplink/storage/streams/eof.go
Egon Elbre 5d0816430f
rename all the things (#2531)
* rename pkg/linksharing to linksharing
* rename pkg/httpserver to linksharing/httpserver
* rename pkg/eestream to uplink/eestream
* rename pkg/stream to uplink/stream
* rename pkg/metainfo/kvmetainfo to uplink/metainfo/kvmetainfo
* rename pkg/auth/signing to pkg/signing
* rename pkg/storage to uplink/storage
* rename pkg/accounting to satellite/accounting
* rename pkg/audit to satellite/audit
* rename pkg/certdb to satellite/certdb
* rename pkg/discovery to satellite/discovery
* rename pkg/overlay to satellite/overlay
* rename pkg/datarepair to satellite/repair
2019-07-28 08:55:36 +03:00

37 lines
687 B
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package streams
import "io"
// EOFReader holds reader and status of EOF
type EOFReader struct {
reader io.Reader
eof bool
err error
}
// NewEOFReader keeps track of the state, has the internal reader reached EOF
func NewEOFReader(r io.Reader) *EOFReader {
return &EOFReader{reader: r}
}
func (r *EOFReader) Read(p []byte) (n int, err error) {
n, err = r.reader.Read(p)
if err == io.EOF {
r.eof = true
} else if err != nil && r.err == nil {
r.err = err
}
return n, err
}
func (r *EOFReader) isEOF() bool {
return r.eof
}
func (r *EOFReader) hasError() bool {
return r.err != nil
}