iohelpers

package
v4.0.0-pre-2 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TextMimetype      = "text/plain"
	CSVMimetype       = "text/csv"
	JSONMimetype      = "application/json"
	JSONArrayMimetype = "application/array+json"
	TOMLMimetype      = "application/toml"
	YAMLMimetype      = "application/yaml"
	EnvMimetype       = "application/x-env"
	CUEMimetype       = "application/cue"
)

Variables

This section is empty.

Functions

func LazyReadCloser

func LazyReadCloser(open func() (io.ReadCloser, error)) io.ReadCloser

LazyReadCloser provides an interface to a ReadCloser that will open on the first access. The wrapped io.ReadCloser must be provided by 'open'.

func LazyWriteCloser

func LazyWriteCloser(open func() (io.WriteCloser, error)) io.WriteCloser

LazyWriteCloser provides an interface to a WriteCloser that will open on the first access. The wrapped io.WriteCloser must be provided by 'open'.

func MimeAlias

func MimeAlias(m string) string

func NewEmptySkipper

func NewEmptySkipper(open func() (io.Writer, error)) io.WriteCloser

NewEmptySkipper creates an io.WriteCloser that will only start writing once a non-whitespace byte has been encountered. The wrapped io.WriteCloser must be provided by the `open` func.

func NormalizeFileMode

func NormalizeFileMode(mode os.FileMode) os.FileMode

NormalizeFileMode converts the given mode to a mode that will work as expected on the given OS. A no-op on non-Windows OSes, but on Windows modes work differently - only the owner read/write bits are honoured (i.e. the 0200 mask).

func SameSkipper

func SameSkipper(r io.Reader, open func() (io.WriteCloser, error)) io.WriteCloser

SameSkipper creates an io.WriteCloser that will only start writing once a difference with the current output has been encountered. The wrapped io.WriteCloser must be provided by 'open'.

func WriteFile

func WriteFile(fsys fs.FS, filename string, content []byte) error

WriteFile writes the given content to the file, truncating any existing file, and creating the directory structure leading up to it if necessary.

Types

type NopCloser

type NopCloser struct {
	io.Writer
}

NopCloser returns a WriteCloser with a no-op Close method wrapping the provided io.Writer.

func (*NopCloser) Close

func (n *NopCloser) Close() error

Close - implements io.Closer

Jump to

Keyboard shortcuts

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