file

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

Handler is a wrapper around afero.Afero, providing a simple interface for reading and writing files.

func New

func New(filename string, fs afero.Fs) *Handler

New returns a new FileWriter for the given filename.

Returns nil if filename is empty.

func (*Handler) Name

func (f *Handler) Name() string

Name returns the filename.

func (*Handler) Read

func (f *Handler) Read() ([]byte, error)

Read reads the file and returns its contents.

func (*Handler) Write

func (f *Handler) Write(data []byte, opt ...Option) error

Write writes the given data to the file.

type Option added in v1.4.0

type Option uint

Option are extra options for the file writer.

const (
	// OptNone is the default option.
	OptNone Option = 1 << iota
	// OptOverwrite overwrites the file if it already exist.
	OptOverwrite
	// OptMkdirAll creates the parent directory if it does not exist.
	OptMkdirAll
)

Jump to

Keyboard shortcuts

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