Documentation ¶
Overview ¶
Package fs implements file-system related functions
Index ¶
- Variables
- func DirExists(path string) bool
- func FileExists(path string) bool
- func FlatZip(zipName string, fileNames []string) error
- func GetFilePaths(dir string, exts ...string) []string
- func IsFileExt(filename string, fileExts []string) bool
- func IsTextFile(filename string) bool
- func ReadFileChunks(filename string, chunkSize int64, reader func(chunk []byte) int64) error
- func ReadFileLines(filename string) []string
- func WalkPath(path string, opts WalkPathOptions) []string
- func WriteFileLines(filename string, lines []string) error
- type WalkPathOptions
Constants ¶
This section is empty.
Variables ¶
var ( // PL is fmt.Println() but is used only for debugging. PL = fmt.Println // VL is zr.VerboseLog() but is used only for debugging. VL = zr.VerboseLog )
var TextFileExts = []string{} // TextFileExts /* 104 elements not displayed */
TextFileExts is an array of text file extensions.
Functions ¶
func FileExists ¶
FileExists returns true if the file given by 'path' exists.
func FlatZip ¶
FlatZip compresses the files specified in 'fileNames' into the ZIP archive named 'zipName'. Does not create subfolders, hence a 'flat' archive.
func GetFilePaths ¶
GetFilePaths returns a list of file names (with full path) contained in folder 'dir' that match the given file extensions. File extensions can be specified as "*.ext", ".ext", or "ext" If you don't specify 'exts', returns all files in 'dir'
func IsFileExt ¶
IsFileExt returns true if the specified 'filename' has a file extension listed in 'fileExts'. The file extensions in the list should not include '.'. For example: []string{"go", "txt", "log"} is a valid list of file extensions, but []string{".go", "*.txt", ".log"} is not.
func IsTextFile ¶
IsTextFile returns true if the given file name represents a text file type. For example "readme.txt" returns true, while "image.png" returns false.
func ReadFileChunks ¶
ReadFileChunks reads a file in chunks and repeatedly calls the supplied 'reader' function with each read chunk. This function is useful for processing large files to avoid having to load the entire file into memory.
filename: Name of the file to read from.
chunkSize: Size of chunks to read from the file, in bytes.
reader: Function to call with each read chunk, which is passed
in the 'chunk' parameter. The function should return int64(len(chunk)) to continue reading from the next position, or 0 if further reading should stop. It also accepts a negative value to skip the reading position back.
Returns an error if the file can't be opened or a read fails.
func ReadFileLines ¶
ReadFileLines reads the specified filename and returns all the lines it contains in a string array.
func WriteFileLines ¶
WriteFileLines writes lines to filename. This function is mainly used for saving text files.
Types ¶
type WalkPathOptions ¶
type WalkPathOptions struct { FileExts []string MinSize int64 MaxSize int64 ExcludeFunc func(path string, info os.FileInfo) ProgressFunc func(scanned, listed int, size int64) WalkFunc func(path string, info os.FileInfo, err error) error } // WalkPathOptions
WalkPathOptions _ _