Skip to content

Commit b5e3b3f

Browse files
committed
Remove io/ioutil usages (deprecated since Go 1.16)
1 parent 2348fd0 commit b5e3b3f

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

auxlib_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package lua
22

33
import (
4-
"io/ioutil"
54
"os"
65
"testing"
76
)
@@ -300,10 +299,10 @@ func TestOptChannel(t *testing.T) {
300299
}
301300

302301
func TestLoadFileForShebang(t *testing.T) {
303-
tmpFile, err := ioutil.TempFile("", "")
302+
tmpFile, err := os.CreateTemp("", "")
304303
errorIfNotNil(t, err)
305304

306-
err = ioutil.WriteFile(tmpFile.Name(), []byte(`#!/path/to/lua
305+
err = os.WriteFile(tmpFile.Name(), []byte(`#!/path/to/lua
307306
print("hello")
308307
`), 0644)
309308
errorIfNotNil(t, err)
@@ -321,7 +320,7 @@ print("hello")
321320
}
322321

323322
func TestLoadFileForEmptyFile(t *testing.T) {
324-
tmpFile, err := ioutil.TempFile("", "")
323+
tmpFile, err := os.CreateTemp("", "")
325324
errorIfNotNil(t, err)
326325

327326
defer func() {

iolib.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"errors"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"os"
109
"os/exec"
1110
"syscall"
@@ -373,7 +372,7 @@ func fileReadAux(L *LState, file *lFile, idx int) int {
373372
L.Push(v)
374373
case 'a':
375374
var buf []byte
376-
buf, err = ioutil.ReadAll(file.reader)
375+
buf, err = io.ReadAll(file.reader)
377376
if err == io.EOF {
378377
L.Push(emptyLString)
379378
goto normalreturn
@@ -704,7 +703,7 @@ func ioType(L *LState) int {
704703
}
705704

706705
func ioTmpFile(L *LState) int {
707-
file, err := ioutil.TempFile("", "")
706+
file, err := os.CreateTemp("", "")
708707
if err != nil {
709708
L.Push(LNil)
710709
L.Push(LString(err.Error()))

oslib.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package lua
22

33
import (
4-
"io/ioutil"
54
"os"
65
"strings"
76
"time"
@@ -223,7 +222,7 @@ func osTime(L *LState) int {
223222
}
224223

225224
func osTmpname(L *LState) int {
226-
file, err := ioutil.TempFile("", "")
225+
file, err := os.CreateTemp("", "")
227226
if err != nil {
228227
L.RaiseError("unable to generate a unique filename")
229228
}

0 commit comments

Comments
 (0)