iox

package
v0.5.49 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: BSD-3-Clause Imports: 5 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

iox

Package iox provides boilerplate wrapper functions for the Go standard io functions to Read, Open, Write, and Save, with implementations for commonly used encoding formats.

The top-level iox functions define standard Encoder and Decoder interfaces, and functions to return these.

The specific encoder format implementations provide these EncoderFunc and DecoderFunc args.

Buffered io is used, and errors are returned.

Documentation

Overview

Package iox provides boilerplate wrapper functions for the Go standard io functions to Read, Open, Write, and Save, with implementations for commonly used encoding formats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(v any, filename string, f DecoderFunc) error

Open reads the given object from the given filename using the given DecoderFunc

func OpenFS

func OpenFS(v any, fsys fs.FS, filename string, f DecoderFunc) error

OpenFS reads the given object from the given filename using the given DecoderFunc, using the given fs.FS filesystem (e.g., for embed files)

func OpenFiles

func OpenFiles(v any, filenames []string, f DecoderFunc) error

OpenFiles reads the given object from the given filenames using the given DecoderFunc

func OpenFilesFS

func OpenFilesFS(v any, fsys fs.FS, filenames []string, f DecoderFunc) error

OpenFilesFS reads the given object from the given filenames using the given DecoderFunc, using the given fs.FS filesystem (e.g., for embed files)

func Read

func Read(v any, reader io.Reader, f DecoderFunc) error

Read reads the given object from the given reader, using the given DecoderFunc

func ReadBytes

func ReadBytes(v any, data []byte, f DecoderFunc) error

ReadBytes reads the given object from the given bytes, using the given DecoderFunc

func Save

func Save(v any, filename string, f EncoderFunc) error

Save writes the given object to the given filename using the given EncoderFunc

func Write

func Write(v any, writer io.Writer, f EncoderFunc) error

Write writes the given object using the given EncoderFunc

func WriteBytes

func WriteBytes(v any, f EncoderFunc) ([]byte, error)

WriteBytes writes the given object, returning bytes of the encoding, using the given EncoderFunc

Types

type Decoder

type Decoder interface {
	// Decode decodes from io.Reader specified at creation
	Decode(v any) error
}

Decoder is an interface for standard decoder types

type DecoderFunc

type DecoderFunc func(r io.Reader) Decoder

DecoderFunc is a function that creates a new Decoder for given reader

func NewDecoderFunc

func NewDecoderFunc[T Decoder](f func(r io.Reader) T) DecoderFunc

NewDecoderFunc returns a DecoderFunc for a specific Decoder type

type Encoder

type Encoder interface {
	// Encode encodes to io.Writer specified at creation
	Encode(v any) error
}

Encoder is an interface for standard encoder types

type EncoderFunc

type EncoderFunc func(w io.Writer) Encoder

EncoderFunc is a function that creates a new Encoder for given writer

func NewEncoderFunc

func NewEncoderFunc[T Encoder](f func(w io.Writer) T) EncoderFunc

NewEncoderFunc returns a EncoderFunc for a specific Encoder type

Directories

Path Synopsis
Package gzipx provides a convenience wrapper for gzip encoding for reader and writer.
Package gzipx provides a convenience wrapper for gzip encoding for reader and writer.
Package imagex provides utilities for images: opening, saving, and encoding them in the standard formats, wrapping them for the web, and asserting them in tests.
Package imagex provides utilities for images: opening, saving, and encoding them in the standard formats, wrapping them for the web, and asserting them in tests.
Package jsonx provides functions for opening, reading, saving, and writing values in JSON.
Package jsonx provides functions for opening, reading, saving, and writing values in JSON.
Package tomlx provides functions for reading and writing TOML.
Package tomlx provides functions for reading and writing TOML.
Package xmlx provides functions for opening, reading, saving, and writing values in XML.
Package xmlx provides functions for opening, reading, saving, and writing values in XML.
Package yamlx provides functions for opening, reading, saving, and writing values in YAML.
Package yamlx provides functions for opening, reading, saving, and writing values in YAML.

Jump to

Keyboard shortcuts

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