package fileutil

import "k8s.io/kubernetes/Godeps/_workspace/src/github.com/cznic/fileutil"

Package fileutil collects some file utility functions.

Index

Functions

func Read

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

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.

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

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

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

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

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

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

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

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.

Source Files

fileutil.go test_deps.go

Directories

PathSynopsis
Godeps/_workspace/src/github.com/cznic/fileutil/fallocWIP: Package falloc provides allocation/deallocation of space within a file/store (WIP, unstable API).
Godeps/_workspace/src/github.com/cznic/fileutil/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.
Godeps/_workspace/src/github.com/cznic/fileutil/storageWIP: Package storage defines and implements storage providers and store accessors.
Version
v0.16.2
Published
May 4, 2015
Platform
js/wasm
Imports
8 packages
Last checked
3 minutes ago

Tools for package owners.