Skip to content

Commit

Permalink
all: replace use of io/ioutil
Browse files Browse the repository at this point in the history
Removes an import from the generated files.

Fixes #48.
  • Loading branch information
kevinburke committed Sep 7, 2022
1 parent adf7cd2 commit 4a992e3
Show file tree
Hide file tree
Showing 15 changed files with 366 additions and 510 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ race-test: lint go-race-test
$(GOPATH)/bin/go-bindata:
go install -v ./...

testdata/assets/bindata.go:
go-bindata -o testdata/assets/bindata.go -pkg assets ./testdata/benchmark

$(BENCHSTAT):
go get golang.org/x/perf/cmd/benchstat

Expand Down
5 changes: 2 additions & 3 deletions benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package bindata_test

import (
"go/format"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -27,7 +26,7 @@ func BenchmarkBindata(b *testing.B) {
b.Fatal(err)
}
b.SetBytes(size)
outDir, err := ioutil.TempDir("", "bench_bindata")
outDir, err := os.MkdirTemp("", "bench_bindata")
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -59,7 +58,7 @@ var formatSink []byte
func BenchmarkFormatSource(b *testing.B) {
// https://github.com/golang/go/issues/26528
// unformatted.out is any large go-bindata source file.
data, err := ioutil.ReadFile("testdata/unformatted.out")
data, err := os.ReadFile("testdata/unformatted.out")
if os.IsNotExist(err) {
b.Skip("source file does not exist")
return
Expand Down
3 changes: 1 addition & 2 deletions debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ func writeDebugHeader(w io.Writer) error {
_, err := fmt.Fprintf(w, `import (
"crypto/sha256"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
// bindataRead reads the given file from disk. It returns an error on failure.
func bindataRead(path, name string) ([]byte, error) {
buf, err := ioutil.ReadFile(path)
buf, err := os.ReadFile(path)
if err != nil {
err = fmt.Errorf("Error reading asset %%s at %%s: %`+wrappedError+`", name, path, err)
}
Expand Down
7 changes: 1 addition & 6 deletions release.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"crypto/sha256"
"fmt"
"io"
"io/ioutil"
"os"
"unicode"
"unicode/utf8"
Expand Down Expand Up @@ -148,7 +147,6 @@ func header_compressed_nomemcopy(w io.Writer) error {
"crypto/sha256"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -187,7 +185,6 @@ func header_compressed_memcopy(w io.Writer) error {
"crypto/sha256"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -222,7 +219,6 @@ func header_uncompressed_nomemcopy(w io.Writer) error {
_, err := fmt.Fprintf(w, `import (
"crypto/sha256"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -250,7 +246,6 @@ func header_uncompressed_memcopy(w io.Writer) error {
_, err := fmt.Fprintf(w, `import (
"crypto/sha256"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -400,7 +395,7 @@ func uncompressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error {
return err
}

b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package bindata
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
)
Expand All @@ -30,7 +30,7 @@ func TestSanitize(t *testing.T) {

func TestEncode(t *testing.T) {
t.Skip("used to test unicode ranges")
data, err := ioutil.ReadFile("testdata/fa.js")
data, err := os.ReadFile("testdata/fa.js")
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func RestoreAsset(dir, name string) error {
if err != nil {
return err
}
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
err = os.WriteFile(_filePath(dir, name), data, info.Mode())
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions safefile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ package bindata
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"
)

func ensureFileContains(name, data string) error {
b, err := ioutil.ReadFile(name)
b, err := os.ReadFile(name)
if err != nil {
return err
}
Expand Down Expand Up @@ -141,7 +140,7 @@ func TestOverwriting(t *testing.T) {
defer os.Remove(name)

olddata := "This is old data"
err := ioutil.WriteFile(name, []byte(olddata), 0600)
err := os.WriteFile(name, []byte(olddata), 0600)
if err != nil {
t.Fatal(err)
}
Expand Down
568 changes: 347 additions & 221 deletions testdata/assets/bindata.go

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions testdata/out/compress-memcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions testdata/out/compress-nomemcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions testdata/out/debug.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4a992e3

Please sign in to comment.