Skip to content

Instantly share code, notes, and snippets.

@Ramko9999
Last active April 25, 2021 16:58
Show Gist options
  • Select an option

  • Save Ramko9999/e5895bc4789915ff681dcff0c3818eec to your computer and use it in GitHub Desktop.

Select an option

Save Ramko9999/e5895bc4789915ff681dcff0c3818eec to your computer and use it in GitHub Desktop.
func readFileChunkWise() {
chunkSize := 10 // processing the file 10 bytes at a time
b := make([]byte, chunkSize)
file, err := os.Open("./folder/test.txt);
if err != nil {
log.Fatal(err)
}
for {
bytesRead, _ := file.Read(b);
if bytesRead == 0 { // bytesRead will be 0 at the end of the file.
break
}
// process the current bytes read
process(b, bytesRead);
}
file.Close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment