iox

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: BSD-3-Clause Imports: 5 Imported by: 1

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

Jump to

Keyboard shortcuts

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