Skip to content

Commit

Permalink
Merge pull request #66 from testwill/ioutil
Browse files Browse the repository at this point in the history
chore: remove refs to deprecated io/ioutil
  • Loading branch information
vbatts authored Jul 20, 2023
2 parents f966b14 + 919f9ab commit db25994
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 37 deletions.
7 changes: 3 additions & 4 deletions archive/tar/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package tar
import (
"bytes"
"io"
"io/ioutil"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -140,7 +139,7 @@ func (tr *Reader) next() (*Header, error) {
continue // This is a meta header affecting the next header
case TypeGNULongName, TypeGNULongLink:
format.mayOnlyBe(FormatGNU)
realname, err := ioutil.ReadAll(tr)
realname, err := io.ReadAll(tr)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -334,7 +333,7 @@ func mergePAX(hdr *Header, paxHdrs map[string]string) (err error) {
// parsePAX parses PAX headers.
// If an extended header (type 'x') is invalid, ErrHeader is returned
func parsePAX(r io.Reader) (map[string]string, error) {
buf, err := ioutil.ReadAll(r)
buf, err := io.ReadAll(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -916,7 +915,7 @@ func discard(tr *Reader, n int64) error {
}
}

copySkipped, err = io.CopyN(ioutil.Discard, r, n-seekSkipped)
copySkipped, err = io.CopyN(io.Discard, r, n-seekSkipped)
out:
if err == io.EOF && seekSkipped+copySkipped < n {
err = io.ErrUnexpectedEOF
Expand Down
5 changes: 2 additions & 3 deletions archive/tar/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math"
"os"
"path"
Expand Down Expand Up @@ -773,7 +772,7 @@ func TestReadTruncation(t *testing.T) {
"testdata/pax-path-hdr.tar",
"testdata/sparse-formats.tar",
} {
buf, err := ioutil.ReadFile(p)
buf, err := os.ReadFile(p)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
Expand Down Expand Up @@ -865,7 +864,7 @@ func TestReadTruncation(t *testing.T) {
}
cnt++
if s2 == "manual" {
if _, err = tr.writeTo(ioutil.Discard); err != nil {
if _, err = tr.writeTo(io.Discard); err != nil {
break
}
}
Expand Down
11 changes: 5 additions & 6 deletions archive/tar/tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math"
"os"
"path"
Expand Down Expand Up @@ -264,7 +263,7 @@ func TestFileInfoHeaderSymlink(t *testing.T) {
case "android", "nacl", "plan9", "windows":
t.Skip("symlinks not supported")
}
tmpdir, err := ioutil.TempDir("", "TestFileInfoHeaderSymlink")
tmpdir, err := os.MkdirTemp("", "TestFileInfoHeaderSymlink")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -329,7 +328,7 @@ func TestRoundTrip(t *testing.T) {
if !reflect.DeepEqual(rHdr, hdr) {
t.Errorf("Header mismatch.\n got %+v\nwant %+v", rHdr, hdr)
}
rData, err := ioutil.ReadAll(tr)
rData, err := io.ReadAll(tr)
if err != nil {
t.Fatalf("Read: %v", err)
}
Expand Down Expand Up @@ -806,9 +805,9 @@ func Benchmark(b *testing.B) {
b.Run(v.label, func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
// Writing to ioutil.Discard because we want to
// Writing to io.Discard because we want to
// test purely the writer code and not bring in disk performance into this.
tw := NewWriter(ioutil.Discard)
tw := NewWriter(io.Discard)
for _, file := range v.files {
if err := tw.WriteHeader(file.hdr); err != nil {
b.Errorf("unexpected WriteHeader error: %v", err)
Expand Down Expand Up @@ -846,7 +845,7 @@ func Benchmark(b *testing.B) {
if _, err := tr.Next(); err != nil {
b.Errorf("unexpected Next error: %v", err)
}
if _, err := io.Copy(ioutil.Discard, tr); err != nil {
if _, err := io.Copy(io.Discard, tr); err != nil {
b.Errorf("unexpected Copy error : %v", err)
}
}
Expand Down
3 changes: 1 addition & 2 deletions archive/tar/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/hex"
"errors"
"io"
"io/ioutil"
"os"
"path"
"reflect"
Expand Down Expand Up @@ -520,7 +519,7 @@ func TestWriter(t *testing.T) {
}

if v.file != "" {
want, err := ioutil.ReadFile(v.file)
want, err := os.ReadFile(v.file)
if err != nil {
t.Fatalf("ReadFile() = %v, want nil", err)
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/tar-split/checksize.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"log"
"os"

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

packFh, err := ioutil.TempFile("", "packed.")
packFh, err := os.CreateTemp("", "packed.")
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -60,7 +59,7 @@ func CommandChecksize(c *cli.Context) {
log.Fatal(err)
}
num++
if _, err := io.Copy(ioutil.Discard, tr); err != nil {
if _, err := io.Copy(io.Discard, tr); err != nil {
log.Fatal(err)
}
}
Expand All @@ -76,7 +75,7 @@ func CommandChecksize(c *cli.Context) {
}
fmt.Printf(" -- size of metadata uncompressed: %dk\n", fi.Size()/1024)

gzPackFh, err := ioutil.TempFile("", "packed.gz.")
gzPackFh, err := os.CreateTemp("", "packed.gz.")
if err != nil {
log.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/tar-split/disasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"compress/gzip"
"io"
"io/ioutil"
"os"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -51,7 +50,7 @@ func CommandDisasm(c *cli.Context) {
}
var out io.Writer
if c.Bool("no-stdout") {
out = ioutil.Discard
out = io.Discard
} else {
out = os.Stdout
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/tar-split/tar_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"io"
"io/ioutil"
"os"
"testing"

Expand All @@ -29,7 +28,7 @@ func BenchmarkUpstreamTar(b *testing.B) {
fh.Close()
b.Fatal(err)
}
_, err = io.Copy(ioutil.Discard, tr)
_, err = io.Copy(io.Discard, tr)
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -57,7 +56,7 @@ func BenchmarkOurTarNoAccounting(b *testing.B) {
fh.Close()
b.Fatal(err)
}
_, err = io.Copy(ioutil.Discard, tr)
_, err = io.Copy(io.Discard, tr)
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -86,7 +85,7 @@ func BenchmarkOurTarYesAccounting(b *testing.B) {
fh.Close()
b.Fatal(err)
}
_, err = io.Copy(ioutil.Discard, tr)
_, err = io.Copy(io.Discard, tr)
if err != nil {
b.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions concept/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"os"

Expand Down Expand Up @@ -73,7 +72,7 @@ func main() {

// it is allowable, and not uncommon that there is further padding on the
// end of an archive, apart from the expected 1024 null bytes
remainder, err := ioutil.ReadAll(fh)
remainder, err := io.ReadAll(fh)
if err != nil && err != io.EOF {
log.Fatal(err, fh.Name())
}
Expand Down
5 changes: 2 additions & 3 deletions tar/asm/assemble_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"hash/crc64"
"io"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -232,7 +231,7 @@ func BenchmarkAsm(b *testing.B) {
b.Fatal(err)
}
// read it all to the bit bucket
i1, err := io.Copy(ioutil.Discard, tarStream)
i1, err := io.Copy(io.Discard, tarStream)
if err != nil {
b.Fatal(err)
}
Expand All @@ -243,7 +242,7 @@ func BenchmarkAsm(b *testing.B) {

rc := NewOutputTarStream(fgp, sup)

i2, err := io.Copy(ioutil.Discard, rc)
i2, err := io.Copy(io.Discard, rc)
if err != nil {
b.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions tar/asm/disassemble_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"archive/tar"
"fmt"
"io"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -52,14 +51,14 @@ func TestLargeJunkPadding(t *testing.T) {
}()

// Disassemble our junk file.
nilPacker := storage.NewJSONPacker(ioutil.Discard)
nilPacker := storage.NewJSONPacker(io.Discard)
rdr, err := NewInputTarStream(pR, nilPacker, nil)
if err != nil {
t.Fatal(err)
}

// Copy the entire rdr.
_, err = io.Copy(ioutil.Discard, rdr)
_, err = io.Copy(io.Discard, rdr)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions tar/storage/getter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package storage
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"strings"
"testing"
)
Expand Down Expand Up @@ -31,7 +31,7 @@ func TestGetter(t *testing.T) {
if err != nil {
t.Error(err)
}
buf, err := ioutil.ReadAll(r)
buf, err := io.ReadAll(r)
if err != nil {
t.Error(err)
}
Expand Down
3 changes: 1 addition & 2 deletions tar/storage/packer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"compress/gzip"
"io"
"io/ioutil"
"os"
"testing"
)
Expand Down Expand Up @@ -186,7 +185,7 @@ func BenchmarkGetPut(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
func() {
fh, err := ioutil.TempFile("", "tar-split.")
fh, err := os.CreateTemp("", "tar-split.")
if err != nil {
b.Fatal(err)
}
Expand Down

0 comments on commit db25994

Please sign in to comment.