exbytes

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2025 License: MPL-2.0 Imports: 3 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrWriterBufferFull = errors.New("exbytes.Writer: buffer full")

Functions

This section is empty.

Types

type Writer

type Writer []byte

Writer is a simple byte writer that does not allow extending the buffer.

Writes always go after the current len() and will fail if the slice capacity is too low.

The correct way to use this is to create a slice with sufficient capacity and zero length:

x := make([]byte, 0, 11)
w := (*Writer)(&x)
w.Write([]byte("hello"))
w.WriteByte(' ')
w.WriteString("world")
fmt.Println(string(x)) // "hello world"
Example
package main

import (
	"fmt"

	"go.mau.fi/util/exbytes"
)

func main() {
	x := make([]byte, 0, 11)
	w := (*exbytes.Writer)(&x)
	w.Write([]byte("hello"))
	w.WriteByte(' ')
	w.WriteString("world")
	fmt.Println(string(x))
}
Output:

hello world

func (*Writer) String

func (w *Writer) String() string

func (*Writer) Write

func (w *Writer) Write(b []byte) (n int, err error)

func (*Writer) WriteByte

func (w *Writer) WriteByte(r byte) error

func (*Writer) WriteString

func (w *Writer) WriteString(s string) (n int, err error)

Jump to

Keyboard shortcuts

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