Documentation ¶
Overview ¶
Package fileutil collects some file utility functions.
Index ¶
- func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error
- func IsEOF(err error) bool
- func PunchHole(f *os.File, off, len int64) error
- func Read(r io.Reader, buf []byte) (err error)
- func TempFile(dir, prefix, suffix string) (f *os.File, err error)
- type FadviseAdvice
- type GoMFile
- type MFile
- type MFileHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fadvise ¶
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 PunchHole ¶
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 ¶
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 ¶
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.
Types ¶
type FadviseAdvice ¶
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 ¶
type GoMFile struct {
// contains filtered or unexported fields
}
GoMFile is a concurrent access safe version of MFile.
func NewGoMFile ¶
NewGoMFile return a newly created GoMFile.
func (*GoMFile) SetChanged ¶
func (m *GoMFile) SetChanged()
func (*GoMFile) SetHandler ¶
func (m *GoMFile) SetHandler(h MFileHandler)
type MFile ¶
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 ¶
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 ¶
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 ¶
func (m *MFile) SetChanged()
SetChanged forces next File() to unconditionally handle modification of the wrapped os.File.
func (*MFile) SetHandler ¶
func (m *MFile) SetHandler(h MFileHandler)
SetHandler sets a function to be invoked when modification of MFile is to be processed.
type MFileHandler ¶
MFileHandler resolves modifications of File. Possible File context is expected to be a part of the handler's closure.
Directories ¶
Path | Synopsis |
---|---|
WIP: Package falloc provides allocation/deallocation of space within a file/store (WIP, unstable API).
|
WIP: Package falloc provides allocation/deallocation of space within a file/store (WIP, unstable API). |
WIP: 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.
|
WIP: 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. |
WIP: Package storage defines and implements storage providers and store accessors.
|
WIP: Package storage defines and implements storage providers and store accessors. |