reader

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2023 License: BSD-3-Clause Imports: 3 Imported by: 0

README

reader

package reader provides Reader that is similar to bytes.Reader and strings.Reader.

Install

go get github.com/weiwenchen2022/reader

Reference

GoDoc http://godoc.org/github.com/weiwenchen2022/reader

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader[S ~[]byte | ~string] struct {
	// contains filtered or unexported fields
}

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 New

func New[S ~[]byte | ~string](s S) *Reader[S]

New returns a new Reader reading from s.

func (*Reader[S]) Len

func (r *Reader[S]) Len() int

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]) Read

func (r *Reader[S]) Read(p []byte) (n int, err error)

Read implements the io.Reader interface.

func (*Reader[S]) ReadAt

func (r *Reader[S]) ReadAt(p []byte, off int64) (n int, err error)

ReadAt implements the io.ReaderAt interface.

func (*Reader[S]) ReadByte

func (r *Reader[S]) ReadByte() (byte, error)

ReadByte implements the io.ByteReader interface.

func (*Reader[S]) ReadRune

func (r *Reader[S]) ReadRune() (ch rune, size int, err error)

ReadRune implements the io.RuneReader interface.

func (*Reader[S]) Reset

func (r *Reader[S]) Reset(s S)

Reset resets the Reader to be reading from s.

func (*Reader[S]) Seek

func (r *Reader[S]) Seek(offset int64, whence int) (int64, error)

Seek implements the io.Seeker interface.

func (*Reader[S]) Size

func (r *Reader[S]) Size() int64

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

func (r *Reader[S]) UnreadByte() error

UnreadByte complements ReadByte in implementing the io.ByteScanner interface.

func (*Reader[S]) UnreadRune

func (r *Reader[S]) UnreadRune() error

UnreadRune complements ReadRune in implementing the io.RuneScanner interface.

func (*Reader[S]) WriteTo

func (r *Reader[S]) WriteTo(w io.Writer) (n int64, err error)

WriteTo implements the io.WriterTo interface.

Jump to

Keyboard shortcuts

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