img: delete file on error
This commit is contained in:
parent
c06c7958e2
commit
8d972ff74b
1 changed files with 3 additions and 0 deletions
|
@ -37,6 +37,7 @@ func ImgToJPEG(file io.ReadSeeker, outputPath string) error {
|
|||
|
||||
if format == "jpeg" {
|
||||
if _, err = file.Seek(0, io.SeekStart); err != nil {
|
||||
os.Remove(outputPath)
|
||||
return fmt.Errorf("failed to reset file position: %w", err)
|
||||
}
|
||||
|
||||
|
@ -48,11 +49,13 @@ func ImgToJPEG(file io.ReadSeeker, outputPath string) error {
|
|||
}
|
||||
|
||||
if _, err = file.Seek(0, io.SeekStart); err != nil {
|
||||
os.Remove(outputPath)
|
||||
return fmt.Errorf("failed to reset file position: %w", err)
|
||||
}
|
||||
|
||||
img, _, err := image.Decode(file)
|
||||
if err != nil {
|
||||
os.Remove(outputPath)
|
||||
return fmt.Errorf("failed to decode image: %w", err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue