Documentation
¶
Overview ¶
package reader provides Reader. It implements the io.Reader, io.ReaderAt, io.WriterTo, io.Seeker, io.ByteScanner, and io.RuneScanner interfaces by reading from a byte slice or a string.
Index ¶
- type Reader
- func (r *Reader[S]) Len() int
- func (r *Reader[S]) Read(p []byte) (n int, err error)
- func (r *Reader[S]) ReadAt(p []byte, off int64) (n int, err error)
- func (r *Reader[S]) ReadByte() (byte, error)
- func (r *Reader[S]) ReadRune() (ch rune, size int, err error)
- func (r *Reader[S]) Reset(s S)
- func (r *Reader[S]) Seek(offset int64, whence int) (int64, error)
- func (r *Reader[S]) Size() int64
- func (r *Reader[S]) UnreadByte() error
- func (r *Reader[S]) UnreadRune() error
- func (r *Reader[S]) WriteTo(w io.Writer) (n int64, err error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Reader ¶
A Reader implements the io.Reader, io.ReaderAt, io.WriterTo, io.Seeker, io.ByteScanner, and io.RuneScanner interfaces by reading from a byte slice or a string. A Reader is read-only and supports seeking. The zero value for Reader operates like a Reader of an empty slice or an empty string.
func (*Reader[S]) Len ¶
Len returns the number of bytes of the unread portion of the slice or string.
Example ¶
package main
import (
"fmt"
"github.com/weiwenchen2022/reader"
)
func main() {
fmt.Println(reader.New([]byte("Hi!")).Len(), reader.New("Hi!").Len())
fmt.Println(reader.New([]byte("こんにちは!")).Len(), reader.New("こんにちは!").Len())
}
Output: 3 3 16 16
func (*Reader[S]) Reset ¶
func (r *Reader[S]) Reset(s S)
Reset resets the Reader to be reading from s.
func (*Reader[S]) Size ¶
Size returns the original length of the underlying byte slice or string. Size is the number of bytes available for reading via ReadAt. The returned value is always the same and is not affected by any method calls except Reset.
func (*Reader[S]) UnreadByte ¶
UnreadByte complements ReadByte in implementing the io.ByteScanner interface.
func (*Reader[S]) UnreadRune ¶
UnreadRune complements ReadRune in implementing the io.RuneScanner interface.