Skip to content

Commit

Permalink
Remove usage of deprecated io/ioutil package (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Sep 21, 2023
1 parent 745481c commit 79febce
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 21 deletions.
3 changes: 1 addition & 2 deletions docs/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -51,7 +50,7 @@ func main() {
html := filepath.Join(subdir, "index.html")
if _, err := os.Stat(html); os.IsNotExist(err) {
data := strings.Replace(defaultHTML, "$PKG", pkg, -1)
if err := ioutil.WriteFile(html, []byte(data), 0666); err != nil {
if err := os.WriteFile(html, []byte(data), 0666); err != nil {
log.Fatal(err)
}
log.Printf("created %s", html)
Expand Down
4 changes: 2 additions & 2 deletions internal/chunkedfile/chunkedfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ package chunkedfile // import "go.starlark.net/internal/chunkedfile"

import (
"fmt"
"io/ioutil"
"os"
"regexp"
"runtime"
"strconv"
Expand Down Expand Up @@ -56,7 +56,7 @@ type Reporter interface {
// by a newline so that the Go source position added by (*testing.T).Errorf
// appears on a separate line so as not to confused editors.
func Read(filename string, report Reporter) (chunks []Chunk) {
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
report.Errorf("%s", err)
return
Expand Down
3 changes: 1 addition & 2 deletions lib/proto/cmd/star2proto/star2proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"strings"
Expand Down Expand Up @@ -66,7 +65,7 @@ func main() {
if *descriptors != "" {
var fdset descriptorpb.FileDescriptorSet
for i, filename := range strings.Split(*descriptors, ",") {
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
log.Fatalf("--descriptors[%d]: %s", i, err)
}
Expand Down
6 changes: 3 additions & 3 deletions starlark/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package starlark_test
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
Expand All @@ -29,7 +29,7 @@ func BenchmarkStarlark(b *testing.B) {

filename := filepath.Join(testdata, file)

src, err := ioutil.ReadFile(filename)
src, err := os.ReadFile(filename)
if err != nil {
b.Error(err)
continue
Expand Down Expand Up @@ -126,7 +126,7 @@ func BenchmarkProgram(b *testing.B) {
b.Run("read", func(b *testing.B) {
for i := 0; i < b.N; i++ {
var err error
src, err = ioutil.ReadFile(filename)
src, err = os.ReadFile(filename)
if err != nil {
b.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions starlark/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package starlark
import (
"fmt"
"io"
"io/ioutil"
"log"
"math/big"
"sort"
Expand Down Expand Up @@ -416,7 +415,7 @@ func FileProgram(f *syntax.File, isPredeclared func(string) bool) (*Program, err
// CompiledProgram produces a new program from the representation
// of a compiled program previously saved by Program.Write.
func CompiledProgram(in io.Reader) (*Program, error) {
data, err := ioutil.ReadAll(in)
data, err := io.ReadAll(in)
if err != nil {
return nil, err
}
Expand Down
4 changes: 1 addition & 3 deletions starlark/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package starlark_test
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"strings"
Expand All @@ -19,12 +18,11 @@ import (
// TestProfile is a simple integration test that the profiler
// emits minimally plausible pprof-compatible output.
func TestProfile(t *testing.T) {
prof, err := ioutil.TempFile("", "profile_test")
prof, err := os.CreateTemp(t.TempDir(), "profile_test")
if err != nil {
t.Fatal(err)
}
defer prof.Close()
defer os.Remove(prof.Name())
if err := starlark.StartProfile(prof); err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions syntax/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"bytes"
"fmt"
"go/build"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"strings"
Expand Down Expand Up @@ -472,7 +472,7 @@ var dataFile = func(pkgdir, filename string) string {
func BenchmarkParse(b *testing.B) {
filename := dataFile("syntax", "testdata/scan.star")
b.StopTimer()
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
b.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions syntax/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package syntax
import (
"fmt"
"io"
"io/ioutil"
"log"
"math/big"
"os"
Expand Down Expand Up @@ -287,7 +286,7 @@ func readSource(filename string, src interface{}) ([]byte, error) {
case []byte:
return src, nil
case io.Reader:
data, err := ioutil.ReadAll(src)
data, err := io.ReadAll(src)
if err != nil {
err = &os.PathError{Op: "read", Path: filename, Err: err}
return nil, err
Expand All @@ -296,7 +295,7 @@ func readSource(filename string, src interface{}) ([]byte, error) {
case FilePortion:
return src.Content, nil
case nil:
return ioutil.ReadFile(filename)
return os.ReadFile(filename)
default:
return nil, fmt.Errorf("invalid source: %T", src)
}
Expand Down
4 changes: 2 additions & 2 deletions syntax/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"bytes"
"fmt"
"go/build"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -292,7 +292,7 @@ var dataFile = func(pkgdir, filename string) string {
func BenchmarkScan(b *testing.B) {
filename := dataFile("syntax", "testdata/scan.star")
b.StopTimer()
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
b.Fatal(err)
}
Expand Down

0 comments on commit 79febce

Please sign in to comment.