Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrTimeout = errors.New("Timeout")
var (
ErrTooLarge = errors.New("reader: too large only 8MB allowed as per MaxReadSize")
)
var (
// although this is more than enough for most cases
MaxReadSize, _ = units.FromHumanSize("8mb")
)
Functions ¶
func ConnReadN ¶ added in v0.0.62
ConnReadN reads at most N bytes from reader and it optimized for connection based readers like net.Conn it should not be used for file/buffer based reading, ConnReadN should be preferred instead of 'conn.Read() without loop' . It ignores EOF, UnexpectedEOF and timeout errors Note: you are responsible for adding a timeout to context Note: if the reader supports SetReadDeadline (e.g. net.Conn), a cancelled context expires its read deadline to unblock a pending read, leaving the deadline in the past; a connection whose read was cancelled should be discarded rather than reused.
func ConnReadNWithTimeout ¶ added in v0.0.62
ConnReadNWithTimeout is same as ConnReadN but it takes timeout instead of context and it returns error if read does not finish in given time
func IsAcceptedError ¶ added in v0.0.62
IsAcceptedError checks if the error is accepted error for example: connection refused, io.EOF, io.ErrUnexpectedEOF while reading from connection
Types ¶
type KeyPressReader ¶ added in v0.0.17
type KeyPressReader struct {
Timeout time.Duration
Once *sync.Once
Raw bool
BufferSize int
// contains filtered or unexported fields
}
func (KeyPressReader) Read ¶ added in v0.0.17
func (reader KeyPressReader) Read(p []byte) (n int, err error)
Read into the buffer
func (*KeyPressReader) Start ¶ added in v0.0.17
func (reader *KeyPressReader) Start() error
func (*KeyPressReader) Stop ¶ added in v0.0.17
func (reader *KeyPressReader) Stop() error
type ReusableReadCloser ¶
type ReusableReadCloser struct {
*sync.RWMutex
io.Reader
// contains filtered or unexported fields
}
ReusableReadCloser is a reusable reader with no-op close
func NewReusableReadCloser ¶
func NewReusableReadCloser(raw interface{}) (*ReusableReadCloser, error)
NewReusableReadCloser is returned for any type of input
func (ReusableReadCloser) Close ¶
func (r ReusableReadCloser) Close() error
Close is a no-op close of ReusableReadCloser
type TimeoutReader ¶
TimeoutReader is a reader wrapper that stops waiting after Timeout.
A Timeout of zero or less disables the timeout: Read calls Reader directly.
io.Reader has no way to cancel a Read that is blocked, so a timeout only stops the caller from waiting. The underlying Read keeps running on a helper goroutine until Reader returns, so a Reader that never returns leaks that goroutine. On timeout, Read returns 0 and ErrTimeout and never writes to the caller's buffer after it returns.
Bytes (and the error) that Reader delivers after a timeout are discarded, not kept for the next Read, so the data stream has a gap. A Read after a timeout starts a new Read on Reader while the abandoned one may still be pending, so Reader must tolerate overlapping Reads. Treat ErrTimeout as terminal unless the data in flight does not matter.
Every Read with a positive Timeout allocates a scratch buffer as long as the caller's, because Reader must not be handed the caller's buffer (see above).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
keypress/buffered
command
|
|
|
keypress/raw
command
|
|
|
Package rawmode reads and changes the terminal mode of a file, including switching it to raw mode.
|
Package rawmode reads and changes the terminal mode of a file, including switching it to raw mode. |