all: replace io/ioutil with io and os

Closes #1770
This commit is contained in:
Hajime Hoshi 2022-09-15 02:45:36 +09:00
parent d0556af8a4
commit 5404e4d68a
12 changed files with 25 additions and 45 deletions

View File

@ -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()

View File

@ -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)
}

View File

@ -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

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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
}

View File

@ -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)
}

View File

@ -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)
}