io

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoWriter occurs when a writer is not provided.
	//
	// Format:
	// 	"no writer was provided"
	ErrNoWriter error

	// ErrShortWrite occurs when a write operation writes fewer bytes than expected.
	//
	// Format:
	// 	"short write"
	ErrShortWrite error
)

Functions

func WriteBytes

func WriteBytes(w Writer, data []byte) error

WriteBytes writes the given byte slice to the provided writer.

Parameters:

  • w: The writer to which data will be written. Must not be nil.
  • data: The bytes to write. If empty, the function returns nil.

Returns:

  • error: An error if the write operation fails.

Errors:

  • ErrNoWriter: If the writer is nil.
  • any other error: Implementation-specific error.

func WriteRune added in v0.1.8

func WriteRune(w Writer, r rune) error

WriteRune writes the given rune to the writer and returns an error if the write operation fails.

Parameters:

  • w: The writer to write the rune to. Must not be nil.
  • r: The rune to write.

Returns:

  • error: An error if the write operation fails.

Errors:

  • ErrNoWriter: If the writer is nil.
  • any other error: Implementation-specific error.

func WriteString

func WriteString(w Writer, str string) error

WriteString writes the given string to the writer and returns an error if the write operation fails.

Parameters:

  • w: The writer to write the string to. Must not be nil.
  • str: The string to write. If empty, the function returns nil.

Returns:

  • error: An error if the write operation fails.

Errors:

  • ErrNoWriter: If the writer is nil.
  • any other error: Implementation-specific error.

Types

type Writer added in v0.1.8

type Writer interface {
	// Write writes len(p) bytes from p to the underlying data stream. It returns
	// the number of bytes written from p (0 <= n <= len(p)) and any error encountered
	// that caused the write to stop early.
	//
	// Parameters:
	//   - p: The bytes to write.
	//
	// Returns:
	//   - n: The number of bytes written from p. (0 <= n <= len(p))
	//   - err: An error if the write operation fails.
	//
	// Behaviors:
	// 	- Write must return a non-nil error if it returns n < len(p).
	// 	- Write must not modify the slice data, even temporarily.
	// 	- Implementations must not retain p.
	Write(p []byte) (int, error)
}

Writer is the interface that wraps the basic Write method.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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