iox

package
v0.0.0-...-115e584 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountLines

func CountLines(file string) (int, error)

CountLines returns the number of lines in file.

func DupReadCloser

func DupReadCloser(reader io.ReadCloser) (io.ReadCloser, io.ReadCloser)

DupReadCloser 返回两个io.ReadCloser 需要先读取第一个io.ReadCloser的内容,因为只有读过的内容才会被写入到第二个io.ReadCloser中

func NopCloser

func NopCloser(w io.Writer) io.WriteCloser

NopCloser returns a io.WriteCloser that does nothing on calling Close.

func ReadBytes

func ReadBytes(reader io.Reader, buf []byte) error

ReadBytes 读取reader的前len(buf)字节的内容到buf中

func ReadText

func ReadText(filename string) (string, error)

ReadText 读取文件filename的内容,并去除两边的空白字符

func ReadTextLines

func ReadTextLines(filename string, opts ...TextReadOption) ([]string, error)

ReadTextLines 从指定filename中读取文本行

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.

func (*BufferPool) Put

func (bp *BufferPool) Put(buf *bytes.Buffer)

Put returns buf into 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 用于自定义textReadOptions对象

func KeepSpace

func KeepSpace() TextReadOption

KeepSpace 保留文本两边的空格

func OmitWithPrefix

func OmitWithPrefix(prefix string) TextReadOption

OmitWithPrefix 让ReadTextLines函数在收集文本行的时候忽略含有prefix前缀的文本行

func WithoutBlank

func WithoutBlank() TextReadOption

WithoutBlank 让ReadTextLines函数在收集文本行的时候忽略空白行

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL