Documentation ¶
Index ¶
- func CountLines(file string) (int, error)
- func DupReadCloser(reader io.ReadCloser) (io.ReadCloser, io.ReadCloser)
- func LimitDupReadCloser(reader io.ReadCloser, n int64) (io.ReadCloser, io.ReadCloser)
- func LimitTeeReader(r io.Reader, w io.Writer, n int64) io.Reader
- func NopCloser(w io.Writer) io.WriteCloser
- func ReadBytes(reader io.Reader, buf []byte) error
- func ReadText(filename string) (string, error)
- func ReadTextLines(filename string, opts ...TextReadOption) ([]string, error)
- func RedirectInOut() (restore func(), err error)
- type BufferPool
- type TextLineScanner
- type TextReadOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CountLines ¶
CountLines returns the number of lines in file.
func DupReadCloser ¶
func DupReadCloser(reader io.ReadCloser) (io.ReadCloser, io.ReadCloser)
DupReadCloser returns two io.ReadCloser that read from the first will be written to the second. The first returned reader needs to be read first, because the content read from it will be written to the underlying buffer of the second reader.
func LimitDupReadCloser ¶
func LimitDupReadCloser(reader io.ReadCloser, n int64) (io.ReadCloser, io.ReadCloser)
LimitDupReadCloser returns two io.ReadCloser that read from the first will be written to the second. But the second io.ReadCloser is limited to up to n bytes. The first returned reader needs to be read first, because the content read from it will be written to the underlying buffer of the second reader.
func LimitTeeReader ¶
LimitTeeReader returns a Reader that writes up to n bytes to w what it reads from r. First n bytes reads from r performed through it are matched with corresponding writes to w. There is no internal buffering - the write must complete before the first n bytes read completes. Any error encountered while writing is reported as a read error.
func NopCloser ¶
func NopCloser(w io.Writer) io.WriteCloser
NopCloser returns an io.WriteCloser that does nothing on calling Close.
func ReadTextLines ¶
func ReadTextLines(filename string, opts ...TextReadOption) ([]string, error)
ReadTextLines reads the text lines from given file.
func RedirectInOut ¶
func RedirectInOut() (restore func(), err error)
RedirectInOut redirects stdin to r, stdout to w, and callers need to call restore afterwards.
Types ¶
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
A BufferPool is a pool to buffer bytes.Buffer objects.
func NewBufferPool ¶
func NewBufferPool(capability int) *BufferPool
NewBufferPool returns a BufferPool.
func (*BufferPool) Get ¶
func (bp *BufferPool) Get() *bytes.Buffer
Get returns a bytes.Buffer object from bp.
type TextLineScanner ¶
type TextLineScanner struct {
// contains filtered or unexported fields
}
A TextLineScanner is a scanner that can scan lines from given reader.
func NewTextLineScanner ¶
func NewTextLineScanner(reader io.Reader) *TextLineScanner
NewTextLineScanner returns a TextLineScanner with given reader.
func (*TextLineScanner) Line ¶
func (scanner *TextLineScanner) Line() (string, error)
Line returns the next available line.
func (*TextLineScanner) Scan ¶
func (scanner *TextLineScanner) Scan() bool
Scan checks if scanner has more lines to read.
type TextReadOption ¶
type TextReadOption func(*textReadOptions)
TextReadOption defines the method to customize the text reading functions.
func KeepSpace ¶
func KeepSpace() TextReadOption
KeepSpace customizes the reading functions to keep leading and tailing spaces.
func OmitWithPrefix ¶
func OmitWithPrefix(prefix string) TextReadOption
OmitWithPrefix customizes the reading functions to ignore the lines with given leading prefix.
func WithoutBlank ¶
func WithoutBlank() TextReadOption
WithoutBlank customizes the reading functions to ignore blank lines.