Skip to content

Commit db25994

Browse files
authored
Merge pull request #66 from testwill/ioutil
chore: remove refs to deprecated io/ioutil
2 parents f966b14 + 919f9ab commit db25994

File tree

12 files changed

+26
-37
lines changed

12 files changed

+26
-37
lines changed

archive/tar/reader.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package tar
77
import (
88
"bytes"
99
"io"
10-
"io/ioutil"
1110
"strconv"
1211
"strings"
1312
"time"
@@ -140,7 +139,7 @@ func (tr *Reader) next() (*Header, error) {
140139
continue // This is a meta header affecting the next header
141140
case TypeGNULongName, TypeGNULongLink:
142141
format.mayOnlyBe(FormatGNU)
143-
realname, err := ioutil.ReadAll(tr)
142+
realname, err := io.ReadAll(tr)
144143
if err != nil {
145144
return nil, err
146145
}
@@ -334,7 +333,7 @@ func mergePAX(hdr *Header, paxHdrs map[string]string) (err error) {
334333
// parsePAX parses PAX headers.
335334
// If an extended header (type 'x') is invalid, ErrHeader is returned
336335
func parsePAX(r io.Reader) (map[string]string, error) {
337-
buf, err := ioutil.ReadAll(r)
336+
buf, err := io.ReadAll(r)
338337
if err != nil {
339338
return nil, err
340339
}
@@ -916,7 +915,7 @@ func discard(tr *Reader, n int64) error {
916915
}
917916
}
918917

919-
copySkipped, err = io.CopyN(ioutil.Discard, r, n-seekSkipped)
918+
copySkipped, err = io.CopyN(io.Discard, r, n-seekSkipped)
920919
out:
921920
if err == io.EOF && seekSkipped+copySkipped < n {
922921
err = io.ErrUnexpectedEOF

archive/tar/reader_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"errors"
1111
"fmt"
1212
"io"
13-
"io/ioutil"
1413
"math"
1514
"os"
1615
"path"
@@ -773,7 +772,7 @@ func TestReadTruncation(t *testing.T) {
773772
"testdata/pax-path-hdr.tar",
774773
"testdata/sparse-formats.tar",
775774
} {
776-
buf, err := ioutil.ReadFile(p)
775+
buf, err := os.ReadFile(p)
777776
if err != nil {
778777
t.Fatalf("unexpected error: %v", err)
779778
}
@@ -865,7 +864,7 @@ func TestReadTruncation(t *testing.T) {
865864
}
866865
cnt++
867866
if s2 == "manual" {
868-
if _, err = tr.writeTo(ioutil.Discard); err != nil {
867+
if _, err = tr.writeTo(io.Discard); err != nil {
869868
break
870869
}
871870
}

archive/tar/tar_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"errors"
1010
"fmt"
1111
"io"
12-
"io/ioutil"
1312
"math"
1413
"os"
1514
"path"
@@ -264,7 +263,7 @@ func TestFileInfoHeaderSymlink(t *testing.T) {
264263
case "android", "nacl", "plan9", "windows":
265264
t.Skip("symlinks not supported")
266265
}
267-
tmpdir, err := ioutil.TempDir("", "TestFileInfoHeaderSymlink")
266+
tmpdir, err := os.MkdirTemp("", "TestFileInfoHeaderSymlink")
268267
if err != nil {
269268
t.Fatal(err)
270269
}
@@ -329,7 +328,7 @@ func TestRoundTrip(t *testing.T) {
329328
if !reflect.DeepEqual(rHdr, hdr) {
330329
t.Errorf("Header mismatch.\n got %+v\nwant %+v", rHdr, hdr)
331330
}
332-
rData, err := ioutil.ReadAll(tr)
331+
rData, err := io.ReadAll(tr)
333332
if err != nil {
334333
t.Fatalf("Read: %v", err)
335334
}
@@ -806,9 +805,9 @@ func Benchmark(b *testing.B) {
806805
b.Run(v.label, func(b *testing.B) {
807806
b.ReportAllocs()
808807
for i := 0; i < b.N; i++ {
809-
// Writing to ioutil.Discard because we want to
808+
// Writing to io.Discard because we want to
810809
// test purely the writer code and not bring in disk performance into this.
811-
tw := NewWriter(ioutil.Discard)
810+
tw := NewWriter(io.Discard)
812811
for _, file := range v.files {
813812
if err := tw.WriteHeader(file.hdr); err != nil {
814813
b.Errorf("unexpected WriteHeader error: %v", err)
@@ -846,7 +845,7 @@ func Benchmark(b *testing.B) {
846845
if _, err := tr.Next(); err != nil {
847846
b.Errorf("unexpected Next error: %v", err)
848847
}
849-
if _, err := io.Copy(ioutil.Discard, tr); err != nil {
848+
if _, err := io.Copy(io.Discard, tr); err != nil {
850849
b.Errorf("unexpected Copy error : %v", err)
851850
}
852851
}

archive/tar/writer_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"encoding/hex"
1010
"errors"
1111
"io"
12-
"io/ioutil"
1312
"os"
1413
"path"
1514
"reflect"
@@ -520,7 +519,7 @@ func TestWriter(t *testing.T) {
520519
}
521520

522521
if v.file != "" {
523-
want, err := ioutil.ReadFile(v.file)
522+
want, err := os.ReadFile(v.file)
524523
if err != nil {
525524
t.Fatalf("ReadFile() = %v, want nil", err)
526525
}

cmd/tar-split/checksize.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"compress/gzip"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"log"
109
"os"
1110

@@ -31,7 +30,7 @@ func CommandChecksize(c *cli.Context) {
3130
}
3231
fmt.Printf("inspecting %q (size %dk)\n", fh.Name(), fi.Size()/1024)
3332

34-
packFh, err := ioutil.TempFile("", "packed.")
33+
packFh, err := os.CreateTemp("", "packed.")
3534
if err != nil {
3635
log.Fatal(err)
3736
}
@@ -60,7 +59,7 @@ func CommandChecksize(c *cli.Context) {
6059
log.Fatal(err)
6160
}
6261
num++
63-
if _, err := io.Copy(ioutil.Discard, tr); err != nil {
62+
if _, err := io.Copy(io.Discard, tr); err != nil {
6463
log.Fatal(err)
6564
}
6665
}
@@ -76,7 +75,7 @@ func CommandChecksize(c *cli.Context) {
7675
}
7776
fmt.Printf(" -- size of metadata uncompressed: %dk\n", fi.Size()/1024)
7877

79-
gzPackFh, err := ioutil.TempFile("", "packed.gz.")
78+
gzPackFh, err := os.CreateTemp("", "packed.gz.")
8079
if err != nil {
8180
log.Fatal(err)
8281
}

cmd/tar-split/disasm.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"compress/gzip"
55
"io"
6-
"io/ioutil"
76
"os"
87

98
"github.com/sirupsen/logrus"
@@ -51,7 +50,7 @@ func CommandDisasm(c *cli.Context) {
5150
}
5251
var out io.Writer
5352
if c.Bool("no-stdout") {
54-
out = ioutil.Discard
53+
out = io.Discard
5554
} else {
5655
out = os.Stdout
5756
}

cmd/tar-split/tar_benchmark_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"io"
5-
"io/ioutil"
65
"os"
76
"testing"
87

@@ -29,7 +28,7 @@ func BenchmarkUpstreamTar(b *testing.B) {
2928
fh.Close()
3029
b.Fatal(err)
3130
}
32-
_, err = io.Copy(ioutil.Discard, tr)
31+
_, err = io.Copy(io.Discard, tr)
3332
if err != nil {
3433
b.Fatal(err)
3534
}
@@ -57,7 +56,7 @@ func BenchmarkOurTarNoAccounting(b *testing.B) {
5756
fh.Close()
5857
b.Fatal(err)
5958
}
60-
_, err = io.Copy(ioutil.Discard, tr)
59+
_, err = io.Copy(io.Discard, tr)
6160
if err != nil {
6261
b.Fatal(err)
6362
}
@@ -86,7 +85,7 @@ func BenchmarkOurTarYesAccounting(b *testing.B) {
8685
fh.Close()
8786
b.Fatal(err)
8887
}
89-
_, err = io.Copy(ioutil.Discard, tr)
88+
_, err = io.Copy(io.Discard, tr)
9089
if err != nil {
9190
b.Fatal(err)
9291
}

concept/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"flag"
88
"fmt"
99
"io"
10-
"io/ioutil"
1110
"log"
1211
"os"
1312

@@ -73,7 +72,7 @@ func main() {
7372

7473
// it is allowable, and not uncommon that there is further padding on the
7574
// end of an archive, apart from the expected 1024 null bytes
76-
remainder, err := ioutil.ReadAll(fh)
75+
remainder, err := io.ReadAll(fh)
7776
if err != nil && err != io.EOF {
7877
log.Fatal(err, fh.Name())
7978
}

tar/asm/assemble_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
"hash/crc64"
99
"io"
10-
"io/ioutil"
1110
"os"
1211
"testing"
1312

@@ -232,7 +231,7 @@ func BenchmarkAsm(b *testing.B) {
232231
b.Fatal(err)
233232
}
234233
// read it all to the bit bucket
235-
i1, err := io.Copy(ioutil.Discard, tarStream)
234+
i1, err := io.Copy(io.Discard, tarStream)
236235
if err != nil {
237236
b.Fatal(err)
238237
}
@@ -243,7 +242,7 @@ func BenchmarkAsm(b *testing.B) {
243242

244243
rc := NewOutputTarStream(fgp, sup)
245244

246-
i2, err := io.Copy(ioutil.Discard, rc)
245+
i2, err := io.Copy(io.Discard, rc)
247246
if err != nil {
248247
b.Fatal(err)
249248
}

tar/asm/disassemble_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"archive/tar"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"os"
98
"testing"
109

@@ -52,14 +51,14 @@ func TestLargeJunkPadding(t *testing.T) {
5251
}()
5352

5453
// Disassemble our junk file.
55-
nilPacker := storage.NewJSONPacker(ioutil.Discard)
54+
nilPacker := storage.NewJSONPacker(io.Discard)
5655
rdr, err := NewInputTarStream(pR, nilPacker, nil)
5756
if err != nil {
5857
t.Fatal(err)
5958
}
6059

6160
// Copy the entire rdr.
62-
_, err = io.Copy(ioutil.Discard, rdr)
61+
_, err = io.Copy(io.Discard, rdr)
6362
if err != nil {
6463
t.Fatal(err)
6564
}

0 commit comments

Comments
 (0)