diff --git a/bmp/writer_test.go b/bmp/writer_test.go index 8b573a87..7eb86c10 100644 --- a/bmp/writer_test.go +++ b/bmp/writer_test.go @@ -9,7 +9,7 @@ import ( "fmt" "image" "image/draw" - "io/ioutil" + "io" "os" "testing" "time" @@ -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) } } diff --git a/ccitt/gen.go b/ccitt/gen.go index bf8aa7fe..c6542c71 100644 --- a/ccitt/gen.go +++ b/ccitt/gen.go @@ -12,7 +12,6 @@ import ( "flag" "fmt" "go/format" - "io/ioutil" "log" "os" ) @@ -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") diff --git a/ccitt/reader_test.go b/ccitt/reader_test.go index 8de1c3d4..2ed8c37b 100644 --- a/ccitt/reader_test.go +++ b/ccitt/reader_test.go @@ -10,7 +10,6 @@ import ( "image" "image/png" "io" - "io/ioutil" "math/rand" "os" "path/filepath" @@ -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) } @@ -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) } diff --git a/colornames/gen.go b/colornames/gen.go index f0c2ea0d..1aa7e5f2 100644 --- a/colornames/gen.go +++ b/colornames/gen.go @@ -15,9 +15,9 @@ import ( "go/format" "image/color" "io" - "io/ioutil" "log" "net/http" + "os" "regexp" "sort" "strconv" @@ -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) } } diff --git a/draw/gen.go b/draw/gen.go index 33678ad7..2f18b0e5 100644 --- a/draw/gen.go +++ b/draw/gen.go @@ -12,7 +12,6 @@ import ( "flag" "fmt" "go/format" - "io/ioutil" "log" "os" "strings" @@ -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) } } diff --git a/example/font/main.go b/example/font/main.go index aee01a43..109d1bab 100644 --- a/example/font/main.go +++ b/example/font/main.go @@ -18,7 +18,6 @@ import ( "image/color" "image/draw" "image/png" - "io/ioutil" "log" "os" "path/filepath" @@ -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) } diff --git a/font/basicfont/gen.go b/font/basicfont/gen.go index fa25e60b..f576eec7 100644 --- a/font/basicfont/gen.go +++ b/font/basicfont/gen.go @@ -14,8 +14,8 @@ import ( "go/format" "image" "image/draw" - "io/ioutil" "log" + "os" "path" "path/filepath" @@ -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 { @@ -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) } } diff --git a/font/gofont/gen.go b/font/gofont/gen.go index bb867a4e..aa1edb18 100644 --- a/font/gofont/gen.go +++ b/font/gofont/gen.go @@ -21,7 +21,6 @@ import ( "bytes" "fmt" "go/format" - "io/ioutil" "log" "os" "path/filepath" @@ -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) } @@ -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) } } diff --git a/font/plan9font/example_test.go b/font/plan9font/example_test.go index c3e8f891..3d1c0727 100644 --- a/font/plan9font/example_test.go +++ b/font/plan9font/example_test.go @@ -7,7 +7,6 @@ package plan9font_test import ( "image" "image/draw" - "io/ioutil" "log" "os" "path" @@ -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 { diff --git a/font/plan9font/plan9font.go b/font/plan9font/plan9font.go index 27390599..f0d95e6f 100644 --- a/font/plan9font/plan9font.go +++ b/font/plan9font/plan9font.go @@ -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) { diff --git a/font/plan9font/plan9font_test.go b/font/plan9font/plan9font_test.go index 573f63b9..3d592796 100644 --- a/font/plan9font/plan9font_test.go +++ b/font/plan9font/plan9font_test.go @@ -6,7 +6,7 @@ package plan9font import ( "image" - "io/ioutil" + "os" "path" "path/filepath" "testing" @@ -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 { @@ -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) } diff --git a/font/sfnt/gen.go b/font/sfnt/gen.go index 1708ce9b..ecac1734 100644 --- a/font/sfnt/gen.go +++ b/font/sfnt/gen.go @@ -11,7 +11,6 @@ import ( "bytes" "fmt" "go/format" - "io/ioutil" "log" ) @@ -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) } } diff --git a/font/sfnt/kern_test.go b/font/sfnt/kern_test.go index 163dac70..eb65eb1e 100644 --- a/font/sfnt/kern_test.go +++ b/font/sfnt/kern_test.go @@ -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" @@ -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) } diff --git a/font/sfnt/proprietary_test.go b/font/sfnt/proprietary_test.go index 15dde75d..1e95e8c3 100644 --- a/font/sfnt/proprietary_test.go +++ b/font/sfnt/proprietary_test.go @@ -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" @@ -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) } diff --git a/font/sfnt/sfnt.go b/font/sfnt/sfnt.go index d693886d..26e7e862 100644 --- a/font/sfnt/sfnt.go +++ b/font/sfnt/sfnt.go @@ -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. diff --git a/font/sfnt/sfnt_test.go b/font/sfnt/sfnt_test.go index 53cc125f..c1689d69 100644 --- a/font/sfnt/sfnt_test.go +++ b/font/sfnt/sfnt_test.go @@ -8,7 +8,7 @@ import ( "bytes" "fmt" "image" - "io/ioutil" + "os" "path/filepath" "testing" @@ -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) } @@ -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) } @@ -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) } @@ -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) } @@ -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) } diff --git a/riff/example_test.go b/riff/example_test.go index 93c72b09..94eb39f5 100644 --- a/riff/example_test.go +++ b/riff/example_test.go @@ -7,7 +7,6 @@ package riff_test import ( "fmt" "io" - "io/ioutil" "log" "strings" @@ -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 } diff --git a/riff/riff.go b/riff/riff.go index 38dc0e56..2af43e57 100644 --- a/riff/riff.go +++ b/riff/riff.go @@ -16,7 +16,6 @@ package riff // import "golang.org/x/image/riff" import ( "errors" "io" - "io/ioutil" "math" ) @@ -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 } diff --git a/tiff/reader.go b/tiff/reader.go index de73f4b9..621412a8 100644 --- a/tiff/reader.go +++ b/tiff/reader.go @@ -14,7 +14,6 @@ import ( "image" "image/color" "io" - "io/ioutil" "math" "golang.org/x/image/ccitt" @@ -663,15 +662,15 @@ func Decode(r io.Reader) (img image.Image, err error) { inv := d.firstVal(tPhotometricInterpretation) == pWhiteIsZero order := ccittFillOrder(d.firstVal(tFillOrder)) r := ccitt.NewReader(io.NewSectionReader(d.r, offset, n), order, ccitt.Group3, blkW, blkH, &ccitt.Options{Invert: inv, Align: false}) - d.buf, err = ioutil.ReadAll(r) + d.buf, err = io.ReadAll(r) case cG4: inv := d.firstVal(tPhotometricInterpretation) == pWhiteIsZero order := ccittFillOrder(d.firstVal(tFillOrder)) r := ccitt.NewReader(io.NewSectionReader(d.r, offset, n), order, ccitt.Group4, blkW, blkH, &ccitt.Options{Invert: inv, Align: false}) - d.buf, err = ioutil.ReadAll(r) + d.buf, err = io.ReadAll(r) case cLZW: r := lzw.NewReader(io.NewSectionReader(d.r, offset, n), lzw.MSB, 8) - d.buf, err = ioutil.ReadAll(r) + d.buf, err = io.ReadAll(r) r.Close() case cDeflate, cDeflateOld: var r io.ReadCloser @@ -679,7 +678,7 @@ func Decode(r io.Reader) (img image.Image, err error) { if err != nil { return nil, err } - d.buf, err = ioutil.ReadAll(r) + d.buf, err = io.ReadAll(r) r.Close() case cPackBits: d.buf, err = unpackBits(io.NewSectionReader(d.r, offset, n)) diff --git a/tiff/reader_test.go b/tiff/reader_test.go index f91fd94f..3eac0ffc 100644 --- a/tiff/reader_test.go +++ b/tiff/reader_test.go @@ -11,7 +11,6 @@ import ( "errors" "image" "io" - "io/ioutil" "os" "strings" "testing" @@ -81,7 +80,7 @@ func TestUnpackBits(t *testing.T) { } func TestShortBlockData(t *testing.T) { - b, err := ioutil.ReadFile("../testdata/bw-uncompressed.tiff") + b, err := os.ReadFile("../testdata/bw-uncompressed.tiff") if err != nil { t.Fatal(err) } @@ -107,7 +106,7 @@ func TestShortBlockData(t *testing.T) { } func TestDecodeInvalidDataType(t *testing.T) { - b, err := ioutil.ReadFile("../testdata/bw-uncompressed.tiff") + b, err := os.ReadFile("../testdata/bw-uncompressed.tiff") if err != nil { t.Fatal(err) } @@ -232,7 +231,7 @@ func TestDecodeCCITT(t *testing.T) { // TestDecodeTagOrder tests that a malformed image with unsorted IFD entries is // correctly rejected. func TestDecodeTagOrder(t *testing.T) { - data, err := ioutil.ReadFile("../testdata/video-001.tiff") + data, err := os.ReadFile("../testdata/video-001.tiff") if err != nil { t.Fatal(err) } @@ -296,7 +295,7 @@ func replace(src []byte, find, repl string) ([]byte, error) { // cause a crash. // Issue 10711. func TestZeroBitsPerSample(t *testing.T) { - b0, err := ioutil.ReadFile(testdataDir + "bw-deflate.tiff") + b0, err := os.ReadFile(testdataDir + "bw-deflate.tiff") if err != nil { t.Fatal(err) } @@ -324,7 +323,7 @@ func TestZeroBitsPerSample(t *testing.T) { // the data available. // Issue 10712 func TestTileTooBig(t *testing.T) { - b0, err := ioutil.ReadFile(testdataDir + "video-001-tile-64x64.tiff") + b0, err := os.ReadFile(testdataDir + "video-001-tile-64x64.tiff") if err != nil { t.Fatal(err) } @@ -415,7 +414,7 @@ func TestLargeIFDEntry(t *testing.T) { func benchmarkDecode(b *testing.B, filename string) { b.Helper() b.StopTimer() - contents, err := ioutil.ReadFile(testdataDir + filename) + contents, err := os.ReadFile(testdataDir + filename) if err != nil { b.Fatal(err) } diff --git a/tiff/writer_test.go b/tiff/writer_test.go index 8f009e93..c8792c0a 100644 --- a/tiff/writer_test.go +++ b/tiff/writer_test.go @@ -7,7 +7,7 @@ package tiff import ( "bytes" "image" - "io/ioutil" + "io" "os" "testing" ) @@ -94,7 +94,7 @@ func benchmarkEncode(b *testing.B, name string, pixelSize int) { b.SetBytes(int64(s.X * s.Y * pixelSize)) b.ResetTimer() for i := 0; i < b.N; i++ { - Encode(ioutil.Discard, img, nil) + Encode(io.Discard, img, nil) } } diff --git a/vector/gen.go b/vector/gen.go index 010608af..f072f06a 100644 --- a/vector/gen.go +++ b/vector/gen.go @@ -9,8 +9,8 @@ package main import ( "bytes" - "io/ioutil" "log" + "os" "strings" "text/template" ) @@ -27,7 +27,7 @@ const ( ) func main() { - tmpl, err := ioutil.ReadFile("gen_acc_amd64.s.tmpl") + tmpl, err := os.ReadFile("gen_acc_amd64.s.tmpl") if err != nil { log.Fatalf("ReadFile: %v", err) } @@ -64,7 +64,7 @@ func main() { } } - if err := ioutil.WriteFile("acc_amd64.s", out.Bytes(), 0666); err != nil { + if err := os.WriteFile("acc_amd64.s", out.Bytes(), 0666); err != nil { log.Fatalf("WriteFile: %v", err) } } diff --git a/webp/decode_test.go b/webp/decode_test.go index ad65b108..d0c2b5a0 100644 --- a/webp/decode_test.go +++ b/webp/decode_test.go @@ -9,7 +9,6 @@ import ( "fmt" "image" "image/png" - "io/ioutil" "os" "strings" "testing" @@ -272,7 +271,7 @@ func TestDecodePartitionTooLarge(t *testing.T) { } func benchmarkDecode(b *testing.B, filename string) { - data, err := ioutil.ReadFile("../testdata/blue-purple-pink-large." + filename + ".webp") + data, err := os.ReadFile("../testdata/blue-purple-pink-large." + filename + ".webp") if err != nil { b.Fatal(err) }