diff --git a/audio/export_test.go b/audio/export_test.go index 0453b6b1a..e55312c03 100644 --- a/audio/export_test.go +++ b/audio/export_test.go @@ -16,7 +16,6 @@ package audio import ( "io" - "io/ioutil" "sync" ) @@ -64,7 +63,7 @@ func (p *dummyPlayer) Play() { p.playing = true p.m.Unlock() go func() { - if _, err := ioutil.ReadAll(p.r); err != nil { + if _, err := io.ReadAll(p.r); err != nil { panic(err) } p.m.Lock() diff --git a/audio/internal/convert/resampling_test.go b/audio/internal/convert/resampling_test.go index a971180c3..590931a4a 100644 --- a/audio/internal/convert/resampling_test.go +++ b/audio/internal/convert/resampling_test.go @@ -16,7 +16,7 @@ package convert_test import ( "bytes" - "io/ioutil" + "io" "math" "testing" @@ -70,7 +70,7 @@ func TestResampling(t *testing.T) { for _, c := range cases { inB := newSoundBytes(c.In) outS := convert.NewResampling(bytes.NewReader(inB), int64(len(inB)), c.In, c.Out) - gotB, err := ioutil.ReadAll(outS) + gotB, err := io.ReadAll(outS) if err != nil { t.Fatal(err) } diff --git a/cmd/ebitenmobile/gobind.go b/cmd/ebitenmobile/gobind.go index ca1afede3..1149bfd9d 100644 --- a/cmd/ebitenmobile/gobind.go +++ b/cmd/ebitenmobile/gobind.go @@ -21,7 +21,6 @@ package main import ( "flag" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -82,7 +81,7 @@ func invokeOriginalGobind(lang string) (pkgName string, err error) { func run() error { writeFile := func(filename string, content string) error { - if err := ioutil.WriteFile(filepath.Join(*outdir, filename), []byte(content), 0644); err != nil { + if err := os.WriteFile(filepath.Join(*outdir, filename), []byte(content), 0644); err != nil { return err } return nil diff --git a/cmd/ebitenmobile/gomobile.go b/cmd/ebitenmobile/gomobile.go index ce4106de6..ab14c2e09 100644 --- a/cmd/ebitenmobile/gomobile.go +++ b/cmd/ebitenmobile/gomobile.go @@ -17,7 +17,6 @@ package main import ( _ "embed" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -79,7 +78,7 @@ func exe(filename string) string { } func prepareGomobileCommands() (string, error) { - tmp, err := ioutil.TempDir("", "ebitenmobile-") + tmp, err := os.MkdirTemp("", "ebitenmobile-") if err != nil { return "", err } @@ -121,7 +120,7 @@ func prepareGomobileCommands() (string, error) { if err := runGo("mod", "init", modname); err != nil { return tmp, err } - if err := ioutil.WriteFile("tools.go", []byte(fmt.Sprintf(`%s + if err := os.WriteFile("tools.go", []byte(fmt.Sprintf(`%s package %s @@ -160,7 +159,7 @@ import ( if err := os.Mkdir("src", 0755); err != nil { return tmp, err } - if err := ioutil.WriteFile(filepath.Join("src", "gobind.go"), gobind_go, 0644); err != nil { + if err := os.WriteFile(filepath.Join("src", "gobind.go"), gobind_go, 0644); err != nil { return tmp, err } diff --git a/cmd/ebitenmobile/main.go b/cmd/ebitenmobile/main.go index 2fbf25370..25b44bb56 100644 --- a/cmd/ebitenmobile/main.go +++ b/cmd/ebitenmobile/main.go @@ -23,7 +23,6 @@ package main import ( "flag" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -246,13 +245,13 @@ func doBind(args []string, flagset *flag.FlagSet, buildOS string) error { frameworkNameBase = strings.Title(frameworkNameBase) dir := filepath.Join(buildO, name, frameworkNameBase+".framework", "Versions", "A") - if err := ioutil.WriteFile(filepath.Join(dir, "Headers", prefixUpper+"EbitenViewController.h"), []byte(replacePrefixes(objcH)), 0644); err != nil { + if err := os.WriteFile(filepath.Join(dir, "Headers", prefixUpper+"EbitenViewController.h"), []byte(replacePrefixes(objcH)), 0644); err != nil { return err } // TODO: Remove 'Ebitenmobileview.objc.h' here. Now it is hard since there is a header file importing // that header file. - fs, err := ioutil.ReadDir(filepath.Join(dir, "Headers")) + fs, err := os.ReadDir(filepath.Join(dir, "Headers")) if err != nil { return err } diff --git a/ebitenutil/file_js.go b/ebitenutil/file_js.go index 3df1d3e75..9c6be7eb4 100644 --- a/ebitenutil/file_js.go +++ b/ebitenutil/file_js.go @@ -16,7 +16,7 @@ package ebitenutil import ( "bytes" - "io/ioutil" + "io" "net/http" ) @@ -40,7 +40,7 @@ func OpenFile(path string) (ReadSeekCloser, error) { if err != nil { return nil, err } - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) if err != nil { return nil, err } diff --git a/examples/audio/main.go b/examples/audio/main.go index 53d4fc193..6f62d4fa4 100644 --- a/examples/audio/main.go +++ b/examples/audio/main.go @@ -27,7 +27,6 @@ import ( "image/color" _ "image/png" "io" - "io/ioutil" "log" "time" @@ -179,7 +178,7 @@ func NewPlayer(game *Game, audioContext *audio.Context, musicType musicType) (*P log.Fatal(err) return } - b, err := ioutil.ReadAll(s) + b, err := io.ReadAll(s) if err != nil { log.Fatal(err) return diff --git a/examples/keyboard/keyboard/gen.go b/examples/keyboard/keyboard/gen.go index a4639cc2a..8678d1b5c 100644 --- a/examples/keyboard/keyboard/gen.go +++ b/examples/keyboard/keyboard/gen.go @@ -19,11 +19,9 @@ package main import ( "bytes" - "errors" "image" "image/color" "image/png" - "io/ioutil" "log" "os" "os/exec" @@ -46,13 +44,7 @@ var ( ) func init() { - f, err := os.Open(filepath.Join("..", "..", "resources", "fonts", "pressstart2p.ttf")) - if err != nil { - log.Fatal(err) - } - defer f.Close() - - b, err := ioutil.ReadAll(f) + b, err := os.ReadFile(filepath.Join("..", "..", "resources", "fonts", "pressstart2p.ttf")) if err != nil { log.Fatal(err) } diff --git a/internal/gamepad/gamepad_linux.go b/internal/gamepad/gamepad_linux.go index 3e3941dc6..dd413f49f 100644 --- a/internal/gamepad/gamepad_linux.go +++ b/internal/gamepad/gamepad_linux.go @@ -19,7 +19,7 @@ package gamepad import ( "fmt" - "io/ioutil" + "os" "path/filepath" "regexp" "runtime" @@ -77,7 +77,7 @@ func (g *nativeGamepadsImpl) init(gamepads *gamepads) error { g.watch = watch } - ents, err := ioutil.ReadDir(dirName) + ents, err := os.ReadDir(dirName) if err != nil { return fmt.Errorf("gamepad: ReadDir(%s) failed: %w", dirName, err) } diff --git a/internal/png/gen.go b/internal/png/gen.go index 5412a6753..b2502586a 100644 --- a/internal/png/gen.go +++ b/internal/png/gen.go @@ -23,7 +23,6 @@ import ( "go/format" "go/parser" "go/token" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -72,12 +71,6 @@ func run() error { } for _, f := range files { - in, err := os.Open(filepath.Join(dir, f)) - if err != nil { - return err - } - defer in.Close() - out, err := os.Create(prefix + f) if err != nil { return err @@ -86,7 +79,7 @@ func run() error { // TODO: Remove call of RegisterDecoder - data, err := ioutil.ReadAll(in) + data, err := os.ReadFile(filepath.Join(dir, f)) if err != nil { return err } diff --git a/internal/processtest/processtest_test.go b/internal/processtest/processtest_test.go index 5a459416b..66c27cf0a 100644 --- a/internal/processtest/processtest_test.go +++ b/internal/processtest/processtest_test.go @@ -19,7 +19,7 @@ package processtest_test import ( "bytes" - "io/ioutil" + "os" "os/exec" "path/filepath" "strings" @@ -28,7 +28,7 @@ import ( func TestPrograms(t *testing.T) { dir := "testdata" - ents, err := ioutil.ReadDir(dir) + ents, err := os.ReadDir(dir) if err != nil { t.Fatal(err) } diff --git a/internal/shader/shader_test.go b/internal/shader/shader_test.go index bee484c69..5360ec2fe 100644 --- a/internal/shader/shader_test.go +++ b/internal/shader/shader_test.go @@ -18,7 +18,7 @@ import ( "fmt" "go/parser" "go/token" - "io/ioutil" + "os" "path/filepath" "runtime" "strings" @@ -86,7 +86,7 @@ func TestCompile(t *testing.T) { t.Skip("file open might not be implemented in this environment") } - files, err := ioutil.ReadDir("testdata") + files, err := os.ReadDir("testdata") if err != nil { t.Fatal(err) } @@ -114,7 +114,7 @@ func TestCompile(t *testing.T) { continue } - src, err := ioutil.ReadFile(filepath.Join("testdata", n)) + src, err := os.ReadFile(filepath.Join("testdata", n)) if err != nil { t.Fatal(err) } @@ -127,7 +127,7 @@ func TestCompile(t *testing.T) { vsn := name + ".expected.vs" if _, ok := fnames[vsn]; ok { - vs, err := ioutil.ReadFile(filepath.Join("testdata", vsn)) + vs, err := os.ReadFile(filepath.Join("testdata", vsn)) if err != nil { t.Fatal(err) } @@ -136,7 +136,7 @@ func TestCompile(t *testing.T) { fsn := name + ".expected.fs" if _, ok := fnames[fsn]; ok { - fs, err := ioutil.ReadFile(filepath.Join("testdata", fsn)) + fs, err := os.ReadFile(filepath.Join("testdata", fsn)) if err != nil { t.Fatal(err) } @@ -149,7 +149,7 @@ func TestCompile(t *testing.T) { hlsln := name + ".expected.hlsl" if _, ok := fnames[hlsln]; ok { - hlsl, err := ioutil.ReadFile(filepath.Join("testdata", hlsln)) + hlsl, err := os.ReadFile(filepath.Join("testdata", hlsln)) if err != nil { t.Fatal(err) } @@ -158,7 +158,7 @@ func TestCompile(t *testing.T) { metaln := name + ".expected.metal" if _, ok := fnames[metaln]; ok { - metal, err := ioutil.ReadFile(filepath.Join("testdata", metaln)) + metal, err := os.ReadFile(filepath.Join("testdata", metaln)) if err != nil { t.Fatal(err) }