Skip to content

Commit

Permalink
all: replace io/ioutil with io and os package
Browse files Browse the repository at this point in the history
Signed-off-by: queryfast <[email protected]>
  • Loading branch information
racequite committed Sep 23, 2022
1 parent e7cb969 commit 9dbc74c
Show file tree
Hide file tree
Showing 23 changed files with 55 additions and 68 deletions.
4 changes: 2 additions & 2 deletions bmp/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"fmt"
"image"
"image/draw"
"io/ioutil"
"io"
"os"
"testing"
"time"
Expand Down Expand Up @@ -138,6 +138,6 @@ func BenchmarkEncode(b *testing.B) {
b.SetBytes(int64(s.X * s.Y * 4))
b.ResetTimer()
for i := 0; i < b.N; i++ {
Encode(ioutil.Discard, img)
Encode(io.Discard, img)
}
}
9 changes: 4 additions & 5 deletions ccitt/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"flag"
"fmt"
"go/format"
"io/ioutil"
"log"
"os"
)
Expand Down Expand Up @@ -264,15 +263,15 @@ func finish(w *bytes.Buffer, filename string) {
if err != nil {
log.Fatalf("format.Source: %v", err)
}
if err := ioutil.WriteFile(filename, out, 0660); err != nil {
log.Fatalf("ioutil.WriteFile: %v", err)
if err := os.WriteFile(filename, out, 0660); err != nil {
log.Fatalf("os.WriteFile: %v", err)
}
}

func copyPaste(w *bytes.Buffer, filename string) {
b, err := ioutil.ReadFile("gen.go")
b, err := os.ReadFile("gen.go")
if err != nil {
log.Fatalf("ioutil.ReadFile: %v", err)
log.Fatalf("os.ReadFile: %v", err)
}
begin := []byte("\n// COPY PASTE " + filename + " BEGIN\n\n")
end := []byte("\n// COPY PASTE " + filename + " END\n\n")
Expand Down
5 changes: 2 additions & 3 deletions ccitt/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"image"
"image/png"
"io"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
Expand Down Expand Up @@ -301,7 +300,7 @@ func testRead(t *testing.T, fileName string, sf SubFormat, align, invert, trunca
t.Fatalf("Open: %v", err)
}
defer f.Close()
gotBytes, err := ioutil.ReadAll(NewReader(f, MSB, sf, width, height, opts))
gotBytes, err := io.ReadAll(NewReader(f, MSB, sf, width, height, opts))
if err != nil {
t.Fatalf("ReadAll: %v", err)
}
Expand Down Expand Up @@ -382,7 +381,7 @@ func testRead(t *testing.T, fileName string, sf SubFormat, align, invert, trunca
t.Fatalf("Open: %v", err)
}
defer f.Close()
adhBytes, err := ioutil.ReadAll(NewReader(f, MSB, sf, width, AutoDetectHeight, opts))
adhBytes, err := io.ReadAll(NewReader(f, MSB, sf, width, AutoDetectHeight, opts))
if err != nil {
t.Fatalf("ReadAll: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions colornames/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"go/format"
"image/color"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"regexp"
"sort"
"strconv"
Expand Down Expand Up @@ -192,7 +192,7 @@ func main() {
log.Fatalf("Error while formatting code: %s\n", err)
}

if err := ioutil.WriteFile("table.go", fmted, 0644); err != nil {
if err := os.WriteFile("table.go", fmted, 0644); err != nil {
log.Fatalf("Error writing table.go: %s\n", err)
}
}
3 changes: 1 addition & 2 deletions draw/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"flag"
"fmt"
"go/format"
"io/ioutil"
"log"
"os"
"strings"
Expand Down Expand Up @@ -45,7 +44,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
if err := ioutil.WriteFile("impl.go", out, 0660); err != nil {
if err := os.WriteFile("impl.go", out, 0660); err != nil {
log.Fatal(err)
}
}
Expand Down
7 changes: 3 additions & 4 deletions example/font/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"image/color"
"image/draw"
"image/png"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -52,19 +51,19 @@ func main() {
}
var face font.Face
if strings.HasSuffix(*fontFlag, ".font") {
fontData, err := ioutil.ReadFile(*fontFlag)
fontData, err := os.ReadFile(*fontFlag)
if err != nil {
log.Fatal(err)
}
dir := filepath.Dir(*fontFlag)
face, err = plan9font.ParseFont(fontData, func(name string) ([]byte, error) {
return ioutil.ReadFile(filepath.Join(dir, filepath.FromSlash(name)))
return os.ReadFile(filepath.Join(dir, filepath.FromSlash(name)))
})
if err != nil {
log.Fatal(err)
}
} else {
fontData, err := ioutil.ReadFile(*fontFlag)
fontData, err := os.ReadFile(*fontFlag)
if err != nil {
log.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions font/basicfont/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"go/format"
"image"
"image/draw"
"io/ioutil"
"log"
"os"
"path"
"path/filepath"

Expand All @@ -34,7 +34,7 @@ func main() {
const width, height, ascent = 7 - 1, 13, 11

readFile := func(name string) ([]byte, error) {
return ioutil.ReadFile(filepath.FromSlash(path.Join("../testdata/fixed", name)))
return os.ReadFile(filepath.FromSlash(path.Join("../testdata/fixed", name)))
}
fontData, err := readFile("unicode.7x13.font")
if err != nil {
Expand Down Expand Up @@ -98,8 +98,8 @@ func main() {
if err != nil {
log.Fatalf("format.Source: %v", err)
}
if err := ioutil.WriteFile("data.go", fmted, 0644); err != nil {
log.Fatalf("ioutil.WriteFile: %v", err)
if err := os.WriteFile("data.go", fmted, 0644); err != nil {
log.Fatalf("os.WriteFile: %v", err)
}
}

Expand Down
5 changes: 2 additions & 3 deletions font/gofont/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"bytes"
"fmt"
"go/format"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -56,7 +55,7 @@ func do(ttfName string) {
if err := os.Mkdir(pkgName, 0777); err != nil && !os.IsExist(err) {
log.Fatal(err)
}
src, err := ioutil.ReadFile(filepath.Join("ttfs", ttfName))
src, err := os.ReadFile(filepath.Join("ttfs", ttfName))
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -87,7 +86,7 @@ func do(ttfName string) {
if err != nil {
log.Fatal(err)
}
if err := ioutil.WriteFile(filepath.Join(pkgName, "data.go"), dst, 0666); err != nil {
if err := os.WriteFile(filepath.Join(pkgName, "data.go"), dst, 0666); err != nil {
log.Fatal(err)
}
}
Expand Down
3 changes: 1 addition & 2 deletions font/plan9font/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package plan9font_test
import (
"image"
"image/draw"
"io/ioutil"
"log"
"os"
"path"
Expand All @@ -20,7 +19,7 @@ import (

func ExampleParseFont() {
readFile := func(name string) ([]byte, error) {
return ioutil.ReadFile(filepath.FromSlash(path.Join("../testdata/fixed", name)))
return os.ReadFile(filepath.FromSlash(path.Join("../testdata/fixed", name)))
}
fontData, err := readFile("unicode.7x13.font")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion font/plan9font/plan9font.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (f *face) subface(r rune) (*subface, rune) {

// ParseFont parses a Plan 9 font file. data is the contents of that font file,
// which gives relative filenames for subfont files. readFile returns the
// contents of those subfont files. It is similar to io/ioutil's ReadFile
// contents of those subfont files. It is similar to os's ReadFile
// function, except that it takes a relative filename instead of an absolute
// one.
func ParseFont(data []byte, readFile func(relFilename string) ([]byte, error)) (font.Face, error) {
Expand Down
6 changes: 3 additions & 3 deletions font/plan9font/plan9font_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package plan9font

import (
"image"
"io/ioutil"
"os"
"path"
"path/filepath"
"testing"
Expand All @@ -16,7 +16,7 @@ import (

func TestMetrics(t *testing.T) {
readFile := func(name string) ([]byte, error) {
return ioutil.ReadFile(filepath.FromSlash(path.Join("../testdata/fixed", name)))
return os.ReadFile(filepath.FromSlash(path.Join("../testdata/fixed", name)))
}
data, err := readFile("unicode.7x13.font")
if err != nil {
Expand Down Expand Up @@ -45,7 +45,7 @@ func TestMetrics(t *testing.T) {
}

func BenchmarkParseSubfont(b *testing.B) {
subfontData, err := ioutil.ReadFile(filepath.FromSlash("../testdata/fixed/7x13.0000"))
subfontData, err := os.ReadFile(filepath.FromSlash("../testdata/fixed/7x13.0000"))
if err != nil {
b.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions font/sfnt/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"bytes"
"fmt"
"go/format"
"io/ioutil"
"log"
)

Expand Down Expand Up @@ -53,8 +52,8 @@ func main() {
if err != nil {
log.Fatalf("format.Source: %v\n\n----\n%s\n----", err, dstUnformatted)
}
if err := ioutil.WriteFile("data.go", dst, 0666); err != nil {
log.Fatalf("ioutil.WriteFile: %v", err)
if err := os.WriteFile("data.go", dst, 0666); err != nil {
log.Fatalf("os.WriteFile: %v", err)
}
}

Expand Down
3 changes: 1 addition & 2 deletions font/sfnt/kern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ go test golang.org/x/image/font/sfnt -test.run=BulkKern -args -bulk -bulkFontDir

import (
"flag"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -78,7 +77,7 @@ func TestBulkKern(t *testing.T) {
func testFontKerning(fname string) func(*testing.T) {
return func(t *testing.T) {
t.Parallel()
b, err := ioutil.ReadFile(fname)
b, err := os.ReadFile(fname)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions font/sfnt/proprietary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ go test golang.org/x/image/font/sfnt -test.run=ProprietaryMicrosoft -args -propr
import (
"errors"
"flag"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -250,7 +250,7 @@ func testProprietary(t *testing.T, proprietor, filename string, minNumGlyphs, fi
default:
panic("unreachable")
}
file, err := ioutil.ReadFile(filepath.Join(dir, basename))
file, err := os.ReadFile(filepath.Join(dir, basename))
if err != nil {
t.Fatalf("%v\nPerhaps you need to set the -%sDir flag?", err, proprietor)
}
Expand Down
2 changes: 1 addition & 1 deletion font/sfnt/sfnt.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func u32(b []byte) uint32 {
// source is a source of byte data. Conceptually, it is like an io.ReaderAt,
// except that a common source of SFNT font data is in-memory instead of
// on-disk: a []byte containing the entire data, either as a global variable
// (e.g. "goregular.TTF") or the result of an ioutil.ReadFile call. In such
// (e.g. "goregular.TTF") or the result of an os.ReadFile call. In such
// cases, as an optimization, we skip the io.Reader / io.ReaderAt model of
// copying from the source to a caller-supplied buffer, and instead provide
// direct access to the underlying []byte data.
Expand Down
12 changes: 6 additions & 6 deletions font/sfnt/sfnt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"bytes"
"fmt"
"image"
"io/ioutil"
"os"
"path/filepath"
"testing"

Expand Down Expand Up @@ -233,7 +233,7 @@ func TestBounds(t *testing.T) {
}

func TestMetrics(t *testing.T) {
cmapFont, err := ioutil.ReadFile(filepath.FromSlash("../testdata/cmapTest.ttf"))
cmapFont, err := os.ReadFile(filepath.FromSlash("../testdata/cmapTest.ttf"))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -467,7 +467,7 @@ func TestGoRegularGlyphIndex(t *testing.T) {
}

func TestGlyphIndex(t *testing.T) {
data, err := ioutil.ReadFile(filepath.FromSlash("../testdata/cmapTest.ttf"))
data, err := os.ReadFile(filepath.FromSlash("../testdata/cmapTest.ttf"))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -778,7 +778,7 @@ func TestTrueTypeSegments(t *testing.T) {
}

func testSegments(t *testing.T, filename string, wants [][]Segment) {
data, err := ioutil.ReadFile(filepath.FromSlash("../testdata/" + filename))
data, err := os.ReadFile(filepath.FromSlash("../testdata/" + filename))
if err != nil {
t.Fatalf("ReadFile: %v", err)
}
Expand Down Expand Up @@ -816,7 +816,7 @@ func testSegments(t *testing.T, filename string, wants [][]Segment) {
}

func TestPPEM(t *testing.T) {
data, err := ioutil.ReadFile(filepath.FromSlash("../testdata/glyfTest.ttf"))
data, err := os.ReadFile(filepath.FromSlash("../testdata/glyfTest.ttf"))
if err != nil {
t.Fatalf("ReadFile: %v", err)
}
Expand Down Expand Up @@ -870,7 +870,7 @@ func TestPPEM(t *testing.T) {
}

func TestPostInfo(t *testing.T) {
data, err := ioutil.ReadFile(filepath.FromSlash("../testdata/glyfTest.ttf"))
data, err := os.ReadFile(filepath.FromSlash("../testdata/glyfTest.ttf"))
if err != nil {
t.Fatalf("ReadFile: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions riff/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package riff_test
import (
"fmt"
"io"
"io/ioutil"
"log"
"strings"

Expand Down Expand Up @@ -60,7 +59,7 @@ func dump(r *riff.Reader, indent string) error {
}
continue
}
b, err := ioutil.ReadAll(chunkData)
b, err := io.ReadAll(chunkData)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions riff/riff.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package riff // import "golang.org/x/image/riff"
import (
"errors"
"io"
"io/ioutil"
"math"
)

Expand Down Expand Up @@ -103,7 +102,7 @@ func (z *Reader) Next() (chunkID FourCC, chunkLen uint32, chunkData io.Reader, e
if z.chunkLen != 0 {
want := z.chunkLen
var got int64
got, z.err = io.Copy(ioutil.Discard, z.chunkReader)
got, z.err = io.Copy(io.Discard, z.chunkReader)
if z.err == nil && uint32(got) != want {
z.err = errShortChunkData
}
Expand Down
Loading

0 comments on commit 9dbc74c

Please sign in to comment.