fileproc

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckIsDir

func CheckIsDir(path string) bool

CheckIsDir 检查指定路径是否是文件夹

func CheckPathExist

func CheckPathExist(path string) bool

CheckPathExist 检查指定路径是否存在

func FindLineChunks

func FindLineChunks(file *os.File, chunkSize int64) [][2]int64

FindLineChunks 查找文件按照每行划分的分块,每个分块的大小将在 chunkSize 和分割后的分块距离行首及行尾的距离中范围内

  • 使用该函数得到的分块是完整的行,不会出现行被分割的情况
  • 当过程中发生错误将会发生 panic
  • 返回值的成员是一个长度为 2 的数组,第一个元素是分块的起始位置,第二个元素是分块的结束位置

func FindLineChunksByOffset

func FindLineChunksByOffset(file *os.File, offset, chunkSize int64) [][2]int64

FindLineChunksByOffset 该函数与 FindLineChunks 类似,不同的是该函数可以指定 offset 从指定位置开始读取文件

func ReadLineWithParallel

func ReadLineWithParallel(filename string, chunkSize int64, handlerFunc func(string), start ...int64) (n int64, err error)

ReadLineWithParallel 并行的分行读取文件并行处理,处理过程中会将每一行的内容传入 handlerFunc 中进行处理

  • 由于是并行处理,所以处理过程中的顺序是不确定的。
  • 可通过 start 参数指定开始读取的位置,如果不指定则从文件开头开始读取。

func WriteToFile

func WriteToFile(filePath string, data []byte) error

WriteToFile 向特定文件写入内容,如果文件不存在则创建

Types

This section is empty.

Jump to

Keyboard shortcuts

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