fileutil: Index | Files | Directories

package fileutil

import ""

Package fileutil collects some file utility functions.


Package Files

fileutil.go fileutil_linux.go test_deps.go

func Fadvise Uses

func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error

Fadvise predeclares an access pattern for file data. See also 'man 2 posix_fadvise'.

func IsEOF Uses

func IsEOF(err error) bool

IsEOF reports whether err is an EOF condition.

func PunchHole Uses

func PunchHole(f *os.File, off, len int64) error

PunchHole deallocates space inside a file in the byte range starting at offset and continuing for len bytes. No-op for kernels < 2.6.38 (or < 2.7).

func Read Uses

func Read(r io.Reader, buf []byte) (err error)

Read reads buf from r. It will either fill the full buf or fail. It wraps the functionality of an io.Reader which may return less bytes than requested, but may block if not all data are ready for the io.Reader.

func TempFile Uses

func TempFile(dir, prefix, suffix string) (f *os.File, err error)

TempFile creates a new temporary file in the directory dir with a name ending with suffix, basename starting with prefix, opens the file for reading and writing, and returns the resulting *os.File. If dir is the empty string, TempFile uses the default directory for temporary files (see os.TempDir). Multiple programs calling TempFile simultaneously will not choose the same file. The caller can use f.Name() to find the pathname of the file. It is the caller's responsibility to remove the file when no longer needed.

NOTE: This function differs from ioutil.TempFile.

type FadviseAdvice Uses

type FadviseAdvice int

FadviseAdvice is used by Fadvise.

const (
    // $ grep FADV /usr/include/bits/fcntl.h
    POSIX_FADV_NORMAL     FadviseAdvice = iota // No further special treatment.
    POSIX_FADV_RANDOM                          // Expect random page references.
    POSIX_FADV_SEQUENTIAL                      // Expect sequential page references.
    POSIX_FADV_WILLNEED                        // Will need these pages.
    POSIX_FADV_DONTNEED                        // Don't need these pages.
    POSIX_FADV_NOREUSE                         // Data will be accessed once.

FAdviseAdvice values.

type GoMFile Uses

type GoMFile struct {
    // contains filtered or unexported fields

GoMFile is a concurrent access safe version of MFile.

func NewGoMFile Uses

func NewGoMFile(fname string, flag int, perm os.FileMode, delta_ns int64) (m *GoMFile, err error)

NewGoMFile return a newly created GoMFile.

func (*GoMFile) File Uses

func (m *GoMFile) File() (file *os.File, err error)

func (*GoMFile) SetChanged Uses

func (m *GoMFile) SetChanged()

func (*GoMFile) SetHandler Uses

func (m *GoMFile) SetHandler(h MFileHandler)

type MFile Uses

type MFile struct {
    // contains filtered or unexported fields

MFile represents an os.File with a guard/handler on change/modification. Example use case is an app with a configuration file which can be modified at any time and have to be reloaded in such event prior to performing something configurable by that file. The checks are made only on access to the MFile file by File() and a time threshold/hysteresis value can be chosen on creating a new MFile.

func NewMFile Uses

func NewMFile(fname string, flag int, perm os.FileMode, delta_ns int64) (m *MFile, err error)

NewMFile returns a newly created MFile or Error if any. The fname, flag and perm parameters have the same meaning as in os.Open. For meaning of the delta_ns parameter please see the (m *MFile) File() docs.

func (*MFile) File Uses

func (m *MFile) File() (file *os.File, err error)

File returns an os.File from MFile. If time elapsed between the last invocation of this function and now is at least delta_ns ns (a parameter of NewMFile) then the file is checked for change/modification. For delta_ns == 0 the modification is checked w/o getting os.Time(). If a change is detected a handler is invoked on the MFile file. Any of these steps can produce an Error. If that happens the function returns nil, Error.

func (*MFile) SetChanged Uses

func (m *MFile) SetChanged()

SetChanged forces next File() to unconditionally handle modification of the wrapped os.File.

func (*MFile) SetHandler Uses

func (m *MFile) SetHandler(h MFileHandler)

SetHandler sets a function to be invoked when modification of MFile is to be processed.

type MFileHandler Uses

type MFileHandler func(*os.File) error

MFileHandler resolves modifications of File. Possible File context is expected to be a part of the handler's closure.


fallocWIP: Package falloc provides allocation/deallocation of space within a file/store (WIP, unstable API).
hdbWIP: Package hdb provides a "handle"/value DB like store, but actually it's closer to the model of a process's virtual memory and its alloc, free and move methods.
storageWIP: Package storage defines and implements storage providers and store accessors.

Package fileutil imports 11 packages (graph) and is imported by 10 packages. Updated 2020-01-07. Refresh now. Tools for package owners.