file

package
v0.0.0-...-24ca9bf Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NormalMode        os.FileMode = 0644
	DirMode           os.FileMode = 0755
	MinBufferSize                 = 16
	SmallBufferSize               = 64
	Chunk                         = 512
	DefaultBufferSize             = 1024
	DefaultBufSize                = 4096
	MaxInt                        = int(^uint(0) >> 1)
	MinRead                       = bytes.MinRead
)
View Source
const (
	PathSep      = os.PathSeparator
	ListSep      = os.PathListSeparator
	NewLine      = "\n"
	Tab          = "\t"
	NL      byte = '\n'
	TAB     byte = '\t'
	NUL     byte = 0
)

Variables

View Source
var (
	Flags = cli.Flags
	Flag  = cli.Flag
	Log   = cli.Log
)
View Source
var ErrNotImplemented = errors.New("not implemented")
View Source
var (
	V = cli.Vprintln
)

Functions

func AddTrailingSep

func AddTrailingSep(s, sep string, keepNewLines bool) string

AddTrailingSep adds a trailing separator sep to each newline in s. The actual newline character can be kept or discarded based on the keepNewLines bool.

func Fields

func Fields(s string, sep string) []string

Fields returns s separated on occurrences of sep after normalizing utf8 whitespace.

func GetFileData

func GetFileData(filename string) (string, error)

GetFileData returns the contents of the file as a string. If any error is encountered, the empty string is returned with the error.

func GetWriteCloser

func GetWriteCloser(filename string) (io.WriteCloser, error)

GetWriteCloser returns an io.WriteCloser from the given filename if the file was opened successfully.

func Lines

func Lines(s string) []string

Lines returns s separated on occurrences of newline.

func NormalizeWhitespace

func NormalizeWhitespace(s string) string

NormalizeWhitespace splits s on any utf8 whitespace and returns each element as a single space separated string.

Types

type GoFile

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

used as a memfile working GoFile

func NewGoFile

func NewGoFile(filename string) (*GoFile, io.WriteCloser, error)

NewGoFile returns a file object and an io.WriteCloser from a filename.

It checks for existance of the file and creates it as necessary. The returned file object is opened for writing only, and truncates any existing file. For append mode operations, use NewGoFileAppend().

Callers should use the io.WriteCloser for standard operations. The returned file object has buffering and additional capabilities for advanced operations.

func NewGoFileAppend

func NewGoFileAppend(filename string) (*GoFile, io.WriteCloser, error)

NewGoFileAppend returns a file object and an io.WriteCloser from a filename.

It checks for existance of the file and creates it as necessary. The returned file object is opened for writing only, and is in append mode. For truncate mode operations, use NewGoFile().

Callers should use the io.WriteCloser for standard operations. The returned file object has buffering and additional capabilities for advanced operations.

func (*GoFile) Bytes

func (f *GoFile) Bytes() []byte

func (*GoFile) Closer

func (f *GoFile) Closer() io.Closer

func (*GoFile) DebugDetails

func (f *GoFile) DebugDetails() []details

DebugDetails returns a list of interesting properties that we want to track during development and testing.

func (*GoFile) Ends

func (f *GoFile) Ends(n int) string

func (*GoFile) Fields

func (f *GoFile) Fields(sep string) []string

func (*GoFile) FileInfo

func (f *GoFile) FileInfo() fs.FileInfo

func (*GoFile) Handle

func (f *GoFile) Handle() (*os.File, io.Closer, error)

func (*GoFile) Head

func (f *GoFile) Head(n int) string

func (*GoFile) HeadBytes

func (f *GoFile) HeadBytes(n int) []byte

func (*GoFile) IsDir

func (f *GoFile) IsDir() bool

func (*GoFile) IsDirty

func (f *GoFile) IsDirty() bool

func (*GoFile) Lines

func (f *GoFile) Lines() []string

func (*GoFile) LoadData

func (f *GoFile) LoadData() error

LoadData loads all data from the source file into the memfile in the *file struct.

func (*GoFile) ModTime

func (f *GoFile) ModTime() time.Time

func (*GoFile) Mode

func (f *GoFile) Mode() fs.FileMode

func (*GoFile) Name

func (f *GoFile) Name() string

func (*GoFile) PrintDebugDetails

func (f *GoFile) PrintDebugDetails(detailSet []details)

func (*GoFile) ReadAll

func (f *GoFile) ReadAll() error

func (*GoFile) Reader

func (f *GoFile) Reader() (io.ReadCloser, error)

func (*GoFile) SaveData

func (f *GoFile) SaveData() error

SaveData saves all changes in the memfile buffer to the ' source file.

func (*GoFile) Size

func (f *GoFile) Size() int64

func (*GoFile) String

func (f *GoFile) String() string

func (*GoFile) Tail

func (f *GoFile) Tail(n int) string

func (*GoFile) TailBytes

func (f *GoFile) TailBytes(n int) []byte

func (*GoFile) Writer

func (f *GoFile) Writer() io.Writer

func (f *GoFile) Reader() io.Reader { return f.f }

type GoFile2

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

type MemFile

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

type RWCPlus

type RWCPlus interface {
	io.ReadWriteCloser
	io.Seeker
	io.StringWriter
	io.ByteWriter
}

type TimeZone

type TimeZone int
const (
	EST TimeZone = -(5 + iota)
	CST
	MST
	PST
)

American Time Zones

func (TimeZone) String

func (tz TimeZone) String() string

Jump to

Keyboard shortcuts

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