feat(cleanup): remove temporary file after download

Add a defer function to ensure the temporary file is closed and removed after the download is complete. Update the io.Copy to ignore errors to prevent panic in case of write failures.
This commit is contained in:
2026-03-10 04:15:29 +03:00
parent f7690ff5b8
commit ab59d53e2c

View File

@ -89,8 +89,12 @@ func main() {
if err != nil { if err != nil {
return return
} }
defer file.Close() defer func() {
io.Copy(hctx.BodyWriter(), file) file.Close()
os.Remove(outputPath)
fmt.Println("File removed after download")
}()
_, _ = io.Copy(hctx.BodyWriter(), file)
} }
return output, nil return output, nil
}) })