Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadBlockHook ¶
分块读取文件
将filePath路径对应的文件数据并将读到的每一部分传入hook函数中,当过程中如果产生错误则会返回error。
分块读取可以在读取速度和内存消耗之间有一个很好的平衡。
具体使用方法如下:
func main() { byteList := make([][]byte, 0) err := ReadBlockHook("filepath...", 1024, func(data []byte) { byteList = append(byteList, data) }) if err == nil { fileData := bytes.Join(byteList, make([]byte, 0)) } ... }
func ReadLineHook ¶
逐行读取文件
将filePath路径对应的文件数据逐行读取,并将每一行读取到的数据传入hook中,过程中如果发生错误则会返回error。
逐行读取的性能会稍慢,仅占用极少的内存空间,同时由于性能慢的原因也极其不推荐用于读取非文本类文件。
具体使用方法如下:
func main (){ err := kfile.ReadLineHook("filepath...", func(data []byte) { fmt.Println(string(data)) }) ... }
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.