From ab59d53e2cae52b9c61a954f10509a4fe301513c Mon Sep 17 00:00:00 2001 From: trojvn Date: Tue, 10 Mar 2026 04:15:29 +0300 Subject: [PATCH] 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. --- main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 51aeb9a..27940ad 100644 --- a/main.go +++ b/main.go @@ -89,8 +89,12 @@ func main() { if err != nil { return } - defer file.Close() - io.Copy(hctx.BodyWriter(), file) + defer func() { + file.Close() + os.Remove(outputPath) + fmt.Println("File removed after download") + }() + _, _ = io.Copy(hctx.BodyWriter(), file) } return output, nil })