fs

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2021 License: MIT Imports: 10 Imported by: 1

README

zr-fs - Zircon-Go Library: File System Module

Go Report Card

The main 'zr' package, contains OS-independent and general functionality, while most file system related functions are contained in this package.

Note: this package depends on github.com/balacode/zr

Documentation

Overview

Package fs implements file-system related functions

Index

Constants

This section is empty.

Variables

View Source
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
)
View Source
var TextFileExts = []string{} //                                                                TextFileExts

/* 104 elements not displayed */

TextFileExts is an array of text file extensions.

Functions

func DirExists

func DirExists(path string) bool

DirExists returns true if the directory/folder given by 'path' exists.

func FileExists

func FileExists(path string) bool

FileExists returns true if the file given by 'path' exists.

func FlatZip

func FlatZip(zipName string, fileNames []string) error

FlatZip compresses the files specified in 'fileNames' into the ZIP archive named 'zipName'. Does not create subfolders, hence a 'flat' archive.

func GetFilePaths

func GetFilePaths(dir string, exts ...string) []string

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

func IsFileExt(filename string, fileExts []string) bool

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

func IsTextFile(filename string) bool

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

func ReadFileChunks(
	filename string,
	chunkSize int64,
	reader func(chunk []byte) int64,
) error

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

func ReadFileLines(filename string) []string

ReadFileLines reads the specified filename and returns all the lines it contains in a string array.

func WalkPath

func WalkPath(path string, opts WalkPathOptions) []string

WalkPath _ _

func WriteFileLines

func WriteFileLines(filename string, lines []string) error

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 _ _

Jump to

Keyboard shortcuts

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