I wrote a function that converts an image to a base64 string:
func getBase64Screenshot() string {
// Image name
imageName := "Screenshots/screenshot.png"
imageFileBytes, err := ioutil.ReadFile(imageName)
handleError(err)
// Converts file to base64 string
encoded := base64.StdEncoding.EncodeToString(imageFileBytes)
return encoded
}
The above function is called in a for loop
, however after some iterations of the for loop, the program just hangs at the line imageFileBytes, err := ioutil.ReadFile(imageName)
(it doesn't throw an error, it just stops running and stalls).
I ran some experiments and found that if I used a smaller image, it would make it through ~5 iterations of the for loop
before stalling, however if I screenshot my entire screen it would only make it through the first iteration of the for loop
before stalling.
My question is this: What is causing the program to hang, and is there anything I can do to prevent it from hanging?
Thanks!