file

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

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.

Documentation

Overview

Package file provides functions that combine file handling, JSON marshaling and file system abstraction.

Index

Constants

This section is empty.

Variables

View Source
var (
	// OptNone is a no-op.
	OptNone = Option{optNone}
	// OptOverwrite overwrites an existing file.
	OptOverwrite = Option{optOverwrite}
	// OptMkdirAll creates the path to the file.
	OptMkdirAll = Option{optMkdirAll}
	// OptAppend appends to the file.
	OptAppend = Option{optAppend}
)

Functions

This section is empty.

Types

type Handler

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

Handler handles file interaction.

func NewHandler

func NewHandler(fs afero.Fs) Handler

NewHandler returns a new file handler.

func (*Handler) CopyDir

func (h *Handler) CopyDir(src, dst string, opts ...Option) error

CopyDir copies the src directory recursively into dst with the given options. OptMkdirAll is always set. CopyDir does not follow symlinks.

func (*Handler) CopyFile

func (h *Handler) CopyFile(src, dst string, opts ...Option) error

CopyFile copies the file from src to dst with the given options, respecting file permissions.

func (*Handler) IsEmpty

func (h *Handler) IsEmpty(dirName string) (bool, error)

IsEmpty returns true if the given directory is empty.

func (*Handler) MkdirAll

func (h *Handler) MkdirAll(name string) error

MkdirAll creates a directory path and all parents that does not exist yet.

func (*Handler) Read

func (h *Handler) Read(name string) ([]byte, error)

Read reads the file given name and returns the bytes read.

func (*Handler) ReadJSON

func (h *Handler) ReadJSON(name string, content any) error

ReadJSON reads a JSON file from name and unmarshals it into the content interface. The interface content must be a pointer to a JSON marchalable object.

func (*Handler) ReadYAML

func (h *Handler) ReadYAML(name string, content any) error

ReadYAML reads a YAML file from name and unmarshals it into the content interface. The interface content must be a pointer to a YAML marshalable object.

func (*Handler) ReadYAMLStrict

func (h *Handler) ReadYAMLStrict(name string, content any) error

ReadYAMLStrict does the same as ReadYAML, but fails if YAML contains fields that are not specified in content.

func (*Handler) Remove

func (h *Handler) Remove(name string) error

Remove deletes the file with the given name.

func (*Handler) RemoveAll

func (h *Handler) RemoveAll(name string) error

RemoveAll deletes the file or directory with the given name.

func (*Handler) RenameFile

func (h *Handler) RenameFile(old, new string) error

RenameFile renames a file, overwriting any existing file at the destination.

func (*Handler) Stat

func (h *Handler) Stat(name string) (fs.FileInfo, error)

Stat returns a FileInfo describing the named file, or an error, if any happens.

func (*Handler) Write

func (h *Handler) Write(name string, data []byte, options ...Option) error

Write writes the data bytes into the file with the given name.

func (*Handler) WriteJSON

func (h *Handler) WriteJSON(name string, content any, options ...Option) error

WriteJSON marshals the content interface to JSON and writes it to the path with the given name.

func (*Handler) WriteYAML

func (h *Handler) WriteYAML(name string, content any, options ...Option) (err error)

WriteYAML marshals the content interface to YAML and writes it to the path with the given name.

type Option

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

Option is a bitmask of options for file operations.

Jump to

Keyboard shortcuts

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