io 包
io 包主要定义了与输入输出相关的一些接口,即对输入输出进行了规范化。
常用函数
接口分析
- 读取数据到p中,如果数据不足len(p),可以正常返回,也可以带错误返回。
type Reader interface { Read(p []byte) (n int,err error) }
- 将p中数据写入到当前数据流中,并返回写入的字节数
type Writer interface { Write(p []byte) (n int,err error) }- 关闭数据流,网络连接,数据库等
type Closer interface { Close() error }
- 定位文件中指定位置,为下一次读写做准备
type Seeker interface { Seek(offset int64,whence int) (int64,error) }
-
type ReadWriter interface {
Reader
Writer
}
-
type ReadCloser interface {
Reader
Closer
}
-
type WriteCloser interface {
Writer
Closer
}
-
type ReadWriteCloser interface {
Reader
Writer
Closer
}
-
type ReadSeeker interface {
Reader
Seeker
}
-
type WriteSeeker interface {
Writer
Seeker
}
-
type ReadWriteSeeker interface {
Reader
Writer
Seeker
}
- 将r的数据读入到当前数据流中
type ReaderFrom interface { ReadFrom(r Reader) (n int64,err error) }
- 将当前数据流写入到w中
type WriterTo interface { WriteTo(w Writer) (n int64,err error) }
-
type ReaderAt interface {
ReadAt(p []byte,off int64) (n int,err error)
}
-
type WriterAt interface {
WriteAt(p []byte,err error)
}
-
type ByteReader interface {
ReadByte() (c byte,err error)
}
-
type ByteScanner interface {
ByteReader
UnreadByte() error
}
-
type ByteWriter interface {
WriteByte(c byte) error
}
-
type RuneReader interface {
ReadRune() (r rune,size int,err error)
}
-
type RuneScanner interface {
RuneReader
UnreadRune() error
}
-
type stringWriter interface { WriteString(s string) (n int,err error) }原文链接:https://www.f2er.com/go/189495.html