1
0
Fork 1
mirror of https://github.com/vbatts/tar-split.git synced 2024-11-23 08:35:41 +00:00

chore: remove refs to deprecated io/ioutil

Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
This commit is contained in:
guoguangwu 2023-07-20 18:25:32 +08:00
parent f966b14096
commit 919f9abf38
12 changed files with 26 additions and 37 deletions

View file

@ -7,7 +7,6 @@ package tar
import (
"bytes"
"io"
"io/ioutil"
"strconv"
"strings"
"time"
@ -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
}
@ -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
}
@ -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

View file

@ -10,7 +10,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math"
"os"
"path"
@ -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)
}
@ -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
}
}

View file

@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math"
"os"
"path"
@ -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)
}
@ -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)
}
@ -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)
@ -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)
}
}

View file

@ -9,7 +9,6 @@ import (
"encoding/hex"
"errors"
"io"
"io/ioutil"
"os"
"path"
"reflect"
@ -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)
}

View file

@ -5,7 +5,6 @@ import (
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"log"
"os"
@ -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)
}
@ -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)
}
}
@ -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)
}

View file

@ -3,7 +3,6 @@ package main
import (
"compress/gzip"
"io"
"io/ioutil"
"os"
"github.com/sirupsen/logrus"
@ -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
}

View file

@ -2,7 +2,6 @@ package main
import (
"io"
"io/ioutil"
"os"
"testing"
@ -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)
}
@ -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)
}
@ -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)
}

View file

@ -7,7 +7,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"os"
@ -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())
}

View file

@ -7,7 +7,6 @@ import (
"fmt"
"hash/crc64"
"io"
"io/ioutil"
"os"
"testing"
@ -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)
}
@ -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)
}

View file

@ -4,7 +4,6 @@ import (
"archive/tar"
"fmt"
"io"
"io/ioutil"
"os"
"testing"
@ -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)
}

View file

@ -3,7 +3,7 @@ package storage
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"strings"
"testing"
)
@ -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)
}

View file

@ -4,7 +4,6 @@ import (
"bytes"
"compress/gzip"
"io"
"io/ioutil"
"os"
"testing"
)
@ -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)
}