fs

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(name string) (*os.File, error)

func MarshalJSONFile

func MarshalJSONFile(v interface{}, filename string, perm os.FileMode) (err error)

MarshalJSONFile writes the JSON encoding of v to a file named by filename. The file is created atomically. If the file does not exist, Marshal creates it with permissions perm.

func Open

func Open(name string) (*os.File, error)

func OpenFile

func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)

func ReadFile

func ReadFile(name string) ([]byte, error)

func ReplaceFile

func ReplaceFile(name string, perm os.FileMode, fn func(w io.Writer) error) error

func UniqueDir

func UniqueDir(parent, name string) (dir string, err error)

UniqueDir creates a unique dir given the desired name and parent directory. For instance if the desired path is /usr/mydir but such a path already exists, the dir /usr/mydir_01 is returned (and so on). Path extensions are respected and the unique number is appended before any extensions (e.g. mydir.brim -> mydir_01.txt).

func UnmarshalJSONFile

func UnmarshalJSONFile(filename string, v interface{}) error

UnmarshalJSONFile parses JSON-encoded data from the file named by filename and stores the result in the value pointed to by v. Internally, Unmarshal uses json.Unmarshal.

Types

type Replacer

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

func NewFileReplacer

func NewFileReplacer(filename string, perm os.FileMode) (*Replacer, error)

NewFileReplacer returns a Replacer, an io.WriteCloser that can be used to atomically update the content of a file. Either Close or Abort must be called on the Replacer; Close will rename the temp file to the given filename, while Abort will leave the original file unmodified.

func (*Replacer) Abort

func (r *Replacer) Abort()

func (*Replacer) Close

func (r *Replacer) Close() error

func (*Replacer) Write

func (r *Replacer) Write(b []byte) (int, error)

Jump to

Keyboard shortcuts

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