Documentation ¶
Overview ¶
Package bytesp is a plus to the standard "bytes" package.
Index ¶
- Variables
- type Slice
- func (s Slice) Close() error
- func (s *Slice) Read(p []byte) (n int, err error)
- func (s *Slice) ReadByte() (c byte, err error)
- func (s *Slice) ReadFrom(r io.Reader) (n int64, err error)
- func (s *Slice) ReadRune() (r rune, size int, err error)
- func (s *Slice) Reset()
- func (s *Slice) Skip(n int64) (int64, error)
- func (s *Slice) Write(p []byte) (n int, err error)
- func (s *Slice) WriteByte(c byte) error
- func (s *Slice) WriteItoa(i int64, base int) (size int, err error)
- func (s *Slice) WriteRune(r rune) (size int, err error)
- func (s *Slice) WriteString(str string) (size int, err error)
- func (s Slice) WriteTo(w io.Writer) (n int64, err error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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 (*Slice) Read ¶
Read implements the io.Reader interface. After some bytes are read, the slice shrinks.
func (*Slice) Write ¶
Write implements the io.Writer interface. Bytes are appended to the tail of the slice.
func (*Slice) WriteRune ¶
WriteRune writes a single Unicode code point, returning the number of bytes written and any error.
func (*Slice) WriteString ¶
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.