Skip to content

Instantly share code, notes, and snippets.

@cchamplin
Created March 22, 2016 20:08
Show Gist options
  • Save cchamplin/d38dcfe0474d31b40d63 to your computer and use it in GitHub Desktop.
Save cchamplin/d38dcfe0474d31b40d63 to your computer and use it in GitHub Desktop.
ERROR: 2016/03/22 14:06:52 image_util.go:23: EOF 0
ERROR: 2016/03/22 14:06:52 image_util.go:24: File read error occurred for c:\GoWork\src\github.com\cchamplin\goimage\test\catalog\product\1\0\1000083_3.jpg - read 0 bytes
ERROR: 2016/03/22 14:06:52 image_util.go:29: File info for c:\GoWork\src\github.com\cchamplin\goimage\test\catalog\product\1\0\1000083_3.jpg: Size: 81124 Mode: -rw-rw-rw-
ERROR: 2016/03/22 14:06:52 image_util.go:33: Second read failed c:\GoWork\src\github.com\cchamplin\goimage\test\catalog\product\1\0\1000083_3.jpg: EOF
ERROR: 2016/03/22 14:06:52 image_util.go:44: Third read succeeded for c:\GoWork\src\github.com\cchamplin\goimage\test\catalog\product\1\0\1000083_3.jpg 12
f, err := os.Open(path)
defer f.Close()
if err != nil {
log.Error.Printf("Failed to open file %s", path)
return "", err
}
byteData := make([]byte, 12)
bytesRead, err := f.Read(byteData)
if err != nil {
log.Error.Printf("%v %d", err, bytesRead)
log.Error.Printf("File read error occurred for %s - read %d bytes", path, bytesRead)
fi, err := os.Stat(path)
if err != nil {
log.Error.Printf("Could not stat file %s : %v", path, err)
} else {
log.Error.Printf("File info for %s: Size: %d Mode: %v", path, fi.Size(), fi.Mode())
}
bytesRead, err = f.Read(byteData)
if err != nil {
log.Error.Printf("Second read failed %s: %v", path, err)
f.Close()
f, err = os.Open(path)
if err != nil {
log.Error.Printf("Failed to open file %s", path)
return "", err
}
bytesRead, err = f.Read(byteData)
if err != nil {
log.Error.Printf("Third read failed %s: %v", path, err)
} else {
log.Error.Printf("Third read succeeded for %s %d", path, bytesRead)
}
} else {
log.Error.Printf("Second read succeeded for %s %d", path, bytesRead)
}
return "", err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment