Documentation
¶
Overview ¶
Package file defines functions that manipulate files, it's inspired by file helpers from Amoy.
Index ¶
- Constants
- Variables
- func AppendFileBytes(path string, data []byte) error
- func AppendFileLines(path string, lines []string) error
- func AppendFileString(path string, content string) error
- func CountFileLines(path string) (count int, err error)
- func LoadModule() (starlark.StringDict, error)
- func ReadFileBytes(path string) ([]byte, error)
- func ReadFileLines(path string) (lines []string, err error)
- func ReadFileString(path string) (string, error)
- func ReadFirstLines(path string, n int) (lines []string, err error)
- func ReadLastLines(path string, n int) (lines []string, err error)
- func TrimUTF8BOM(b []byte) []byte
- func WriteFileBytes(path string, data []byte) error
- func WriteFileLines(path string, lines []string) error
- func WriteFileString(path string, content string) error
- type LineFunc
Constants ¶
const ModuleName = "file"
ModuleName defines the expected name for this Module when used in starlark's load() function, eg: load('file', 'trim_bom')
Variables ¶
var ( // QuitRead indicates the arbitrary error means to quit from reading. QuitRead = errors.New("file: quit read by line") )
Functions ¶
func AppendFileBytes ¶
AppendFileBytes writes the given data to the end of a file.
func AppendFileLines ¶
AppendFileLines appends the given lines to the end of a text file.
func AppendFileString ¶
AppendFileString appends the given content string to the end of a file.
func CountFileLines ¶
CountFileLines counts all lines from the given file (the line ending chars are not included).
func LoadModule ¶
func LoadModule() (starlark.StringDict, error)
LoadModule loads the file module. It is concurrency-safe and idempotent.
func ReadFileBytes ¶
ReadFileBytes reads the whole named file and returns the contents. It's a sugar actually, simply calls os.ReadFile like ioutil.ReadFile does since Go 1.16.
func ReadFileLines ¶
ReadFileLines reads all lines from the given file (the line ending chars are not included).
func ReadFileString ¶
ReadFileString reads the whole named file and returns the contents as a string.
func ReadFirstLines ¶
ReadFirstLines reads the top n lines from the given file (the line ending chars are not included), or lesser lines if the given file doesn't contain enough line ending chars.
func ReadLastLines ¶
ReadLastLines reads the bottom n lines from the given file (the line ending chars are not included), or lesser lines if the given file doesn't contain enough line ending chars.
func TrimUTF8BOM ¶
TrimUTF8BOM removes the leading UTF-8 byte order mark from bytes.
func WriteFileBytes ¶
WriteFileBytes writes the given data into a file.
func WriteFileLines ¶
WriteFileLines writes the given lines as a text file.
func WriteFileString ¶
WriteFileString writes the given content string into a file.