Documentation
¶
Overview ¶
Package fileutil implements some basic functions for file operations
Index ¶
- func ChunkRead(f *os.File, offset int64, size int, bufPool *sync.Pool) []string
- func ClearFile(path string) error
- func CopyFile(srcFilePath string, dstFilePath string) error
- func CreateDir(absPath string) error
- func CreateFile(path string) bool
- func CurrentPath() string
- func FileMode(path string) (fs.FileMode, error)
- func FileSize(path string) (int64, error)
- func IsDir(path string) bool
- func IsExist(path string) bool
- func IsLink(path string) bool
- func IsZipFile(filepath string) bool
- func ListFileNames(path string) ([]string, error)
- func MTime(filepath string) (int64, error)
- func MiMeType(file interface{}) string
- func ParallelChunkRead(filePath string, linesCh chan<- []string, ChunkSizeMB, MaxGoroutine int)
- func ReadCsvFile(filepath string, delimiter ...rune) ([][]string, error)
- func ReadFile(path string) (reader io.ReadCloser, closeFn func(), err error)
- func ReadFileByLine(path string) ([]string, error)
- func ReadFileToString(path string) (string, error)
- func RemoveFile(path string) error
- func Sha(filepath string, shaType ...int) (string, error)
- func UnZip(zipFile string, destPath string) error
- func WriteBytesToFile(filepath string, content []byte) error
- func WriteCsvFile(filepath string, records [][]string, append bool, delimiter ...rune) error
- func WriteMapsToCsv(filepath string, records []map[string]interface{}, appendToExistingFile bool, ...) error
- func WriteStringToFile(filepath string, content string, append bool) error
- func Zip(path string, destPath string) error
- func ZipAppendEntry(fpath string, destPath string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateDir ¶ added in v1.3.0
CreateDir create directory in absolute path. param `absPath` like /a/, /a/b/
func CurrentPath ¶ added in v1.3.8
func CurrentPath() string
CurrentPath return current absolute path.
func ListFileNames ¶
ListFileNames return all file names in the path
func MiMeType ¶ added in v1.1.8
func MiMeType(file interface{}) string
MiMeType return file mime type param `file` should be string(file path) or *os.File
func ParallelChunkRead ¶ added in v1.4.3
并行读取文件并将每个块的行发送到指定通道 filePath 文件路径 ChunkSizeMB 分块的大小(单位MB,设置为0时使用默认100MB),设置过大反而不利,视情调整 MaxGoroutine 并发读取分块的数量,设置为0时使用CPU核心数 linesCh用于接收返回结果的通道。
func ReadCsvFile ¶ added in v1.3.8
ReadCsvFile read file content into slice.
func ReadFile ¶ added in v1.4.2
func ReadFile(path string) (reader io.ReadCloser, closeFn func(), err error)
ReadFile get file reader by a url or a local file.
func ReadFileByLine ¶ added in v1.0.6
ReadFileByLine read file line by line
func ReadFileToString ¶ added in v1.0.6
ReadFileToString return string of file content
func WriteBytesToFile ¶ added in v1.3.9
WriteBytesToFile write bytes to target file.
func WriteCsvFile ¶ added in v1.4.0
WriteCsvFile write content to target csv file.
func WriteMapsToCsv ¶ added in v1.4.3
func WriteMapsToCsv(filepath string, records []map[string]interface{}, appendToExistingFile bool, delimiter rune, headers ...[]string) error
WriteMapsToCsv write slice of map to csv file. Play: https://go.dev/play/p/umAIomZFV1c filepath: Path to the CSV file. records: Slice of maps to be written. the value of map should be basic type. the maps will be sorted by key in alphabeta order, then be written into csv file. appendToExistingFile: If true, data will be appended to the file if it exists. delimiter: Delimiter to use in the CSV file. headers: order of the csv column headers, needs to be consistent with the key of the map.
func WriteStringToFile ¶ added in v1.3.9
WriteStringToFile write string to target file.
func ZipAppendEntry ¶ added in v1.4.0
ZipAppendEntry append a single file or directory by fpath to an existing zip file. Play: https://go.dev/play/p/cxvaT8TRNQp
Types ¶
This section is empty.