Documentation
¶
Index ¶
- Constants
- type IO
- type Limit
- func (l *Limit) CanRead() bool
- func (l *Limit) CanWrite() bool
- func (l *Limit) Close() error
- func (l *Limit) MakeReadLimitError(req, n int64) error
- func (l *Limit) MakeWriteLimitError(req, n int64) error
- func (l *Limit) MaxCount() (r, w int64)
- func (l *Limit) MaxCountRead() int64
- func (l *Limit) MaxCountWrite() int64
- func (l *Limit) Read(p []byte) (n int, err error)
- func (l *Limit) ReadFrom(r io.Reader) (n int64, err error)
- func (l *Limit) RemainingCount() (r, w int64)
- func (l *Limit) RemainingCountRead() int64
- func (l *Limit) RemainingCountWrite() int64
- func (l *Limit) SetMaxCount(r, w int64)
- func (l *Limit) SetMaxCountRead(r int64)
- func (l *Limit) SetMaxCountWrite(w int64)
- func (l *Limit) Write(p []byte) (n int, err error)
- func (l *Limit) WriteTo(w io.Writer) (n int64, err error)
- type LimitError
- type Meter
- func (m *Meter) AddCount(r, w int64) (nr, nw int64)
- func (m *Meter) AddCountRead(r int64) int64
- func (m *Meter) AddCountWrite(w int64) int64
- func (m *Meter) CanRead() bool
- func (m *Meter) CanWrite() bool
- func (m *Meter) Close() error
- func (m *Meter) Count() (r, w int64)
- func (m *Meter) CountRead() int64
- func (m *Meter) CountWrite() int64
- func (m *Meter) Read(p []byte) (n int, err error)
- func (m *Meter) ReadFrom(r io.Reader) (n int64, err error)
- func (m *Meter) ResetCount()
- func (m *Meter) ResetCountRead()
- func (m *Meter) ResetCountWrite()
- func (m *Meter) SetCount(r, w int64)
- func (m *Meter) SetCountRead(r int64)
- func (m *Meter) SetCountWrite(w int64)
- func (m *Meter) Write(p []byte) (n int, err error)
- func (m *Meter) WriteTo(w io.Writer) (n int64, err error)
Constants ¶
const Unlimited = -1
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limit ¶ added in v0.2.0
type Limit struct {
*Meter
// contains filtered or unexported fields
}
Limit restricts the total bytes read and written, through the underlying io.Reader and io.Writer interfaces, by governing I/O requests forwarded to an embedded Meter.
func NewLimit ¶ added in v0.2.0
NewLimit returns a new Limit that restricts the total bytes read from r and written to w to a maximum of rMax and wMax bytes, respectively.
func NewReadLimit ¶ added in v0.2.0
NewReadLimit returns a new Limit that restricts the total bytes read from r to a maximum of rMax bytes.
func NewReadWriteLimit ¶ added in v0.2.0
func NewReadWriteLimit(rw io.ReadWriter, rMax, wMax int64) *Limit
NewReadWriteLimit returns a new Limit that restricts the total bytes read from and written to rw to a maximum of rMax and wMax bytes, respectively.
func NewWriteLimit ¶ added in v0.2.0
NewWriteLimit returns a new Limit that restricts the total bytes written to w to a maximum of wMax bytes.
func (*Limit) CanRead ¶ added in v0.2.0
CanRead returns true if the Limit is capable of reading bytes.
func (*Limit) CanWrite ¶ added in v0.2.0
CanWrite returns true if the Limit is capable of writing bytes.
func (*Limit) MakeReadLimitError ¶ added in v0.2.0
MakeReadLimitError returns a LimitError describing a short read of n bytes after attempting to read req bytes.
func (*Limit) MakeWriteLimitError ¶ added in v0.2.0
MakeWriteLimitError returns a LimitError describing a short write of n bytes after attempting to write req bytes.
func (*Limit) MaxCount ¶ added in v0.2.0
MaxCount returns the maximum bytes that may be read and written.
func (*Limit) MaxCountRead ¶ added in v0.2.0
MaxCountRead returns the maximum bytes that may be read.
func (*Limit) MaxCountWrite ¶ added in v0.2.0
MaxCountWrite returns the maximum bytes that may be written.
func (*Limit) Read ¶ added in v0.2.0
Read reads bytes from the underlying io.Reader to p and increments the total bytes read by n until the total bytes read reaches the maximum limit.
See Meter for additional details.
func (*Limit) ReadFrom ¶ added in v0.2.0
ReadFrom copies bytes from r to the underlying io.Writer and increments the total bytes written by n until the total bytes written reaches the maximum limit.
See Meter for additional details.
func (*Limit) RemainingCount ¶ added in v0.2.0
RemainingCount returns the total bytes that may be read and written before exceeding their respective limits.
func (*Limit) RemainingCountRead ¶ added in v0.2.0
RemainingCountRead returns the total bytes that may be read before exceeding the read limit.
func (*Limit) RemainingCountWrite ¶ added in v0.2.0
RemainingCountWrite returns the total bytes that may be written before exceeding the write limit.
func (*Limit) SetMaxCount ¶ added in v0.2.0
SetMaxCount restricts the total bytes read and written to a maximum of r and w bytes, respectively.
func (*Limit) SetMaxCountRead ¶ added in v0.2.0
SetMaxCountRead restricts the total bytes read to a maximum of r bytes.
func (*Limit) SetMaxCountWrite ¶ added in v0.2.0
SetMaxCountWrite restricts the total bytes written to a maximum of w bytes.
type LimitError ¶ added in v0.2.0
type LimitError struct {
// Limit is the object that imposed the I/O limit.
*Limit
// Requested is the number of bytes requested for read/write.
Requested int64
// Accepted is the number of bytes successfully read/written.
Accepted int64
// contains filtered or unexported fields
}
LimitError is returned when a short read/write occurs due to a byte limit.
func (LimitError) Error ¶ added in v0.2.0
func (e LimitError) Error() string
String returns a string representation of the LimitError.
type Meter ¶
Meter records the total bytes read and written, through the underlying io.Reader and io.Writer given at construction, using any of the following interfaces:
- io.Reader (read)
- io.ReaderFrom (write)
- io.Writer (write)
- io.WriterTo (read)
Constructors also exist for read-only, write-only, and read-write Meters. Methods without an underlying interface return io.ErrClosedPipe.
Meter also implements the io.Closer interface. Closing a Meter closes each underlying interface that implements io.Closer.
func NewMeter ¶
NewMeter returns a new Meter that counts the total bytes read from r and written to w.
func NewReadMeter ¶
NewReadMeter returns a new Meter that counts the total bytes read from r.
func NewReadWriteMeter ¶
func NewReadWriteMeter(rw io.ReadWriter) *Meter
NewReadWriteMeter returns a new Meter that counts the total bytes read from and written to rw.
func NewWriteMeter ¶
NewWriteMeter returns a new Meter that counts the total bytes written to w.
func (*Meter) AddCount ¶ added in v0.2.0
AddCount increments the total bytes read by r and written by w and returns the new byte counts.
func (*Meter) AddCountRead ¶ added in v0.2.0
AddCountRead increments the total bytes read by r and returns the new byte count.
func (*Meter) AddCountWrite ¶ added in v0.2.0
AddCountWrite increments the total bytes written by w and returns the new byte count.
func (*Meter) CanRead ¶ added in v0.2.0
CanRead returns true if the Meter is capable of reading bytes.
func (*Meter) CanWrite ¶ added in v0.2.0
CanWrite returns true if the Meter is capable of writing bytes.
func (*Meter) Close ¶
Close closes each underlying interface that implements io.Closer.
See io.Closer for details.
func (*Meter) CountWrite ¶ added in v0.2.0
CountWrite returns the total bytes written.
func (*Meter) Read ¶
Read reads bytes from the underlying io.Reader to p and increments the total bytes read by n.
See io.Reader for details.
func (*Meter) ReadFrom ¶
ReadFrom copies bytes from r to the underlying io.Writer and increments the total bytes written by n.
See io.ReaderFrom for details.
func (*Meter) ResetCount ¶ added in v0.2.0
func (m *Meter) ResetCount()
ResetCount sets the total bytes read and written to zero.
func (*Meter) ResetCountRead ¶ added in v0.2.0
func (m *Meter) ResetCountRead()
ResetCountRead sets the total bytes read to zero.
func (*Meter) ResetCountWrite ¶ added in v0.2.0
func (m *Meter) ResetCountWrite()
ResetCountWrite sets the total bytes written to zero.
func (*Meter) SetCountRead ¶ added in v0.2.0
SetCountRead sets the total bytes read to r.
func (*Meter) SetCountWrite ¶ added in v0.2.0
SetCountWrite sets the total bytes written to w.