bytes

package
v0.0.0-...-84d6781 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const NewlineLen int = 1

Variables

View Source
var Newline []byte
View Source
var SD bytesT

SD is the namespace for SD-like functions.

Functions

func Encode

func Encode(data *[]byte, chars []rune) error

Encode appends the UTF-8 encoding of a slice of runes to the provided byte slice.

Parameters:

  • data: A pointer to a byte slice where the encoded UTF-8 bytes will be appended.
  • chars: A slice of runes to encode.

Returns:

  • error: An error if the provided data parameter is nil.

func IndicesOf

func IndicesOf(slice []byte, sep []byte) []int

IndicesOf returns a slice of indices that specify where the separator occurs in the data.

Parameters:

  • slice: The data.
  • sep: The separator.

Returns:

  • []int: The indices. Nil if no separator is found.

Types

type MultiWriter

type MultiWriter struct {
	// contains filtered or unexported fields
}

MultiWriter is a writer that writes multiple data to the underlying io.Writer. Useful for writing many bytes at once.

func New

func New(w io.Writer) (*MultiWriter, error)

New creates a new MultiWriter for the given io.Writer.

Parameters:

  • w: The underlying io.Writer.

Returns:

  • *MultiWriter: The new MultiWriter.
  • error: An error if w is nil.

func (*MultiWriter) Print

func (w *MultiWriter) Print(args ...any) error

Print writes the given arguments to the underlying io.Writer.

Parameters:

  • args: The arguments to write.

Returns:

  • error: An error if writing failed.

Errors:

  • io.ErrShortWrite: If the data is not fully written.
  • any other error returned by the underlying io.Writer.

func (*MultiWriter) Printf

func (w *MultiWriter) Printf(format string, args ...any) error

Printf formats the given arguments according to the given format string and writes the result to the underlying io.Writer.

Parameters:

  • format: The format string.
  • args: The arguments to format.

Returns:

  • error: An error if writing failed.

Errors:

  • io.ErrShortWrite: If the data is not fully written.
  • any other error returned by the underlying io.Writer.

func (*MultiWriter) Println

func (w *MultiWriter) Println(args ...any) error

Println writes the given arguments to the underlying io.Writer, followed by a newline.

Parameters:

  • args: The arguments to write.

Returns:

  • error: An error if writing failed.

Errors:

  • io.ErrShortWrite: If the data is not fully written.
  • any other error returned by the underlying io.Writer.

func (*MultiWriter) Write

func (mw *MultiWriter) Write(data []byte) (int, error)

Write implements io.Writer.

func (*MultiWriter) WriteBytes

func (w *MultiWriter) WriteBytes(data []byte) error

WriteBytes writes the data to the underlying io.Writer. This does the same thing as Write, but does not return the number of bytes written.

Parameters:

  • data: The data to write.

Returns:

  • error: An error if writing failed.

Errors:

  • io.ErrShortWrite: If the data is not fully written.
  • any other error returned by the underlying io.Writer.

func (*MultiWriter) WriteMany

func (w *MultiWriter) WriteMany(datas ...[]byte) error

WriteMany writes many data to the underlying io.Writer. This is a convenience function that acts like WriteBytes for many data in a more efficient way.

Parameters:

  • datas: The datas to write.

Returns:

  • error: An error if writing failed.

Errors:

  • io.ErrShortWrite: If the data is not fully written.
  • any other error returned by the underlying io.Writer.

func (*MultiWriter) WriteNewline

func (w *MultiWriter) WriteNewline() error

WriteNewline writes a newline character to the underlying io.Writer.

Returns:

  • error: An error if writing failed.

Errors:

  • io.ErrShortWrite: If the data is not fully written.
  • any other error returned by the underlying io.Writer.

func (*MultiWriter) WriteString

func (w *MultiWriter) WriteString(str string) error

WriteString writes the given string to the underlying io.Writer.

Parameters:

  • str: The string to write.

Returns:

  • error: An error if writing failed.

Errors:

  • io.ErrShortWrite: If the data is not fully written.
  • any other error returned by the underlying io.Writer.

func (MultiWriter) Written

func (w MultiWriter) Written() int

Written returns the total number of bytes written.

Returns:

  • int: The total number of bytes written.

Jump to

Keyboard shortcuts

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