Use os.CreateTemp() rather than ioutil.TempFile()

This commit is contained in:
Ralph Slooten 2023-10-07 22:43:58 +13:00
parent e8c7298c9c
commit ea2d490686

View File

@ -6,7 +6,6 @@ import (
"image/jpeg" "image/jpeg"
"image/png" "image/png"
"io" "io"
"io/ioutil"
"math" "math"
"os" "os"
"os/exec" "os/exec"
@ -83,7 +82,7 @@ func Goptimize(file string) {
resultW := dstBounds.Dx() resultW := dstBounds.Dx()
resultH := dstBounds.Dy() resultH := dstBounds.Dy()
tmpFile, err := ioutil.TempFile(os.TempDir(), "Goptimized-") tmpFile, err := os.CreateTemp(os.TempDir(), "Goptimized-")
if err != nil { if err != nil {
fmt.Printf("Error: cannot create temporary file: %v\n", err) fmt.Printf("Error: cannot create temporary file: %v\n", err)
@ -227,7 +226,7 @@ func Goptimize(file string) {
// and overwrite it if the output is smaller than the original // and overwrite it if the output is smaller than the original
func RunOptimizer(src string, outFileArg bool, args ...string) { func RunOptimizer(src string, outFileArg bool, args ...string) {
// create a new temp file // create a new temp file
tmpFile, err := ioutil.TempFile(os.TempDir(), "Goptimized-") tmpFile, err := os.CreateTemp(os.TempDir(), "Goptimized-")
if err != nil { if err != nil {
fmt.Printf("Cannot create temporary file: %v\n", err) fmt.Printf("Cannot create temporary file: %v\n", err)