bytesp

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2020 License: BSD-3-Clause Imports: 4 Imported by: 24

README

bytes GoSearch

Plus to the standard bytes package.

// ByteSlice is a wrapper type for []byte.
// Its pointer form, *ByteSlice, implements io.Reader, io.Writer, io.ByteReader,
// io.ByteWriter, io.Closer, io.ReaderFrom, io.WriterTo and io.RuneReader
// interfaces.
//
// Benchmark shows *ByteSlice is a better alternative for bytes.Buffer for writings and consumes less resource.
type ByteSlice []byte

(blog about ByteSlice)

LICENSE

BSD license

Documentation

Overview

Package bytesp is a plus to the standard "bytes" package.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrInvalidRune = errors.New("Slice: invalid rune")

error for a invalid rune

Functions

This section is empty.

Types

type Slice

type Slice []byte

Slice is a wrapper type for []byte. Its pointer form, *Slice, implements io.Reader, io.Writer, io.ByteReader, io.ByteWriter, io.Closer, io.ReaderFrom, io.WriterTo and io.RuneReader interfaces.

Benchmark shows *Slice is a better alternative for bytes.Buffer for writings and consumes less resource.

Example
var b Slice
b.WriteByte(65)
b.WriteString("bc")

fmt.Println(b)
fmt.Println(string(b))
Output:

[65 98 99]
Abc

func NewPSlice

func NewPSlice(bytes []byte) *Slice

NewPSlice returns a *Slice with intialized contents.

func (Slice) Close

func (s Slice) Close() error

Close implements the io.Closer interface. It does nothing.

func (*Slice) Read

func (s *Slice) Read(p []byte) (n int, err error)

Read implements the io.Reader interface. After some bytes are read, the slice shrinks.

func (*Slice) ReadByte

func (s *Slice) ReadByte() (c byte, err error)

ReadByte implements the io.ByteReader interface.

func (*Slice) ReadFrom

func (s *Slice) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom implements the io.ReaderFrom interface.

func (*Slice) ReadRune

func (s *Slice) ReadRune() (r rune, size int, err error)

ReadRune implements the io.RuneReader interface.

func (*Slice) Reset

func (s *Slice) Reset()

Reset sets the length of the slice to 0.

func (*Slice) Skip

func (s *Slice) Skip(n int64) (int64, error)

Skip skips n bytes.

func (*Slice) Write

func (s *Slice) Write(p []byte) (n int, err error)

Write implements the io.Writer interface. Bytes are appended to the tail of the slice.

func (*Slice) WriteByte

func (s *Slice) WriteByte(c byte) error

WriteByte implements the io.ByteWriter interface.

func (*Slice) WriteItoa

func (s *Slice) WriteItoa(i int64, base int) (size int, err error)

WriteItoa converts i into text of the specified base and write to s.

func (*Slice) WriteRune

func (s *Slice) WriteRune(r rune) (size int, err error)

WriteRune writes a single Unicode code point, returning the number of bytes written and any error.

func (*Slice) WriteString

func (s *Slice) WriteString(str string) (size int, err error)

WriteString appends the contents of str to the slice, growing the slice as needed. The return value n is the length of str; err is always nil.

func (Slice) WriteTo

func (s Slice) 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