1
0
Fork 1
mirror of https://github.com/vbatts/tar-split.git synced 2024-11-27 02:05:40 +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 ( import (
"bytes" "bytes"
"io" "io"
"io/ioutil"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -140,7 +139,7 @@ func (tr *Reader) next() (*Header, error) {
continue // This is a meta header affecting the next header continue // This is a meta header affecting the next header
case TypeGNULongName, TypeGNULongLink: case TypeGNULongName, TypeGNULongLink:
format.mayOnlyBe(FormatGNU) format.mayOnlyBe(FormatGNU)
realname, err := ioutil.ReadAll(tr) realname, err := io.ReadAll(tr)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -334,7 +333,7 @@ func mergePAX(hdr *Header, paxHdrs map[string]string) (err error) {
// parsePAX parses PAX headers. // parsePAX parses PAX headers.
// If an extended header (type 'x') is invalid, ErrHeader is returned // If an extended header (type 'x') is invalid, ErrHeader is returned
func parsePAX(r io.Reader) (map[string]string, error) { func parsePAX(r io.Reader) (map[string]string, error) {
buf, err := ioutil.ReadAll(r) buf, err := io.ReadAll(r)
if err != nil { if err != nil {
return nil, err 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: out:
if err == io.EOF && seekSkipped+copySkipped < n { if err == io.EOF && seekSkipped+copySkipped < n {
err = io.ErrUnexpectedEOF err = io.ErrUnexpectedEOF

View file

@ -10,7 +10,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math" "math"
"os" "os"
"path" "path"
@ -773,7 +772,7 @@ func TestReadTruncation(t *testing.T) {
"testdata/pax-path-hdr.tar", "testdata/pax-path-hdr.tar",
"testdata/sparse-formats.tar", "testdata/sparse-formats.tar",
} { } {
buf, err := ioutil.ReadFile(p) buf, err := os.ReadFile(p)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
@ -865,7 +864,7 @@ func TestReadTruncation(t *testing.T) {
} }
cnt++ cnt++
if s2 == "manual" { if s2 == "manual" {
if _, err = tr.writeTo(ioutil.Discard); err != nil { if _, err = tr.writeTo(io.Discard); err != nil {
break break
} }
} }

View file

@ -9,7 +9,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math" "math"
"os" "os"
"path" "path"
@ -264,7 +263,7 @@ func TestFileInfoHeaderSymlink(t *testing.T) {
case "android", "nacl", "plan9", "windows": case "android", "nacl", "plan9", "windows":
t.Skip("symlinks not supported") t.Skip("symlinks not supported")
} }
tmpdir, err := ioutil.TempDir("", "TestFileInfoHeaderSymlink") tmpdir, err := os.MkdirTemp("", "TestFileInfoHeaderSymlink")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -329,7 +328,7 @@ func TestRoundTrip(t *testing.T) {
if !reflect.DeepEqual(rHdr, hdr) { if !reflect.DeepEqual(rHdr, hdr) {
t.Errorf("Header mismatch.\n got %+v\nwant %+v", 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 { if err != nil {
t.Fatalf("Read: %v", err) t.Fatalf("Read: %v", err)
} }
@ -806,9 +805,9 @@ func Benchmark(b *testing.B) {
b.Run(v.label, func(b *testing.B) { b.Run(v.label, func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { 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. // 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 { for _, file := range v.files {
if err := tw.WriteHeader(file.hdr); err != nil { if err := tw.WriteHeader(file.hdr); err != nil {
b.Errorf("unexpected WriteHeader error: %v", err) b.Errorf("unexpected WriteHeader error: %v", err)
@ -846,7 +845,7 @@ func Benchmark(b *testing.B) {
if _, err := tr.Next(); err != nil { if _, err := tr.Next(); err != nil {
b.Errorf("unexpected Next error: %v", err) 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) b.Errorf("unexpected Copy error : %v", err)
} }
} }

View file

@ -9,7 +9,6 @@ import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"io" "io"
"io/ioutil"
"os" "os"
"path" "path"
"reflect" "reflect"
@ -520,7 +519,7 @@ func TestWriter(t *testing.T) {
} }
if v.file != "" { if v.file != "" {
want, err := ioutil.ReadFile(v.file) want, err := os.ReadFile(v.file)
if err != nil { if err != nil {
t.Fatalf("ReadFile() = %v, want nil", err) t.Fatalf("ReadFile() = %v, want nil", err)
} }

View file

@ -5,7 +5,6 @@ import (
"compress/gzip" "compress/gzip"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
"os" "os"
@ -31,7 +30,7 @@ func CommandChecksize(c *cli.Context) {
} }
fmt.Printf("inspecting %q (size %dk)\n", fh.Name(), fi.Size()/1024) 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 { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -60,7 +59,7 @@ func CommandChecksize(c *cli.Context) {
log.Fatal(err) log.Fatal(err)
} }
num++ num++
if _, err := io.Copy(ioutil.Discard, tr); err != nil { if _, err := io.Copy(io.Discard, tr); err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }
@ -76,7 +75,7 @@ func CommandChecksize(c *cli.Context) {
} }
fmt.Printf(" -- size of metadata uncompressed: %dk\n", fi.Size()/1024) 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 { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View file

@ -3,7 +3,6 @@ package main
import ( import (
"compress/gzip" "compress/gzip"
"io" "io"
"io/ioutil"
"os" "os"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -51,7 +50,7 @@ func CommandDisasm(c *cli.Context) {
} }
var out io.Writer var out io.Writer
if c.Bool("no-stdout") { if c.Bool("no-stdout") {
out = ioutil.Discard out = io.Discard
} else { } else {
out = os.Stdout out = os.Stdout
} }

View file

@ -2,7 +2,6 @@ package main
import ( import (
"io" "io"
"io/ioutil"
"os" "os"
"testing" "testing"
@ -29,7 +28,7 @@ func BenchmarkUpstreamTar(b *testing.B) {
fh.Close() fh.Close()
b.Fatal(err) b.Fatal(err)
} }
_, err = io.Copy(ioutil.Discard, tr) _, err = io.Copy(io.Discard, tr)
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }
@ -57,7 +56,7 @@ func BenchmarkOurTarNoAccounting(b *testing.B) {
fh.Close() fh.Close()
b.Fatal(err) b.Fatal(err)
} }
_, err = io.Copy(ioutil.Discard, tr) _, err = io.Copy(io.Discard, tr)
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }
@ -86,7 +85,7 @@ func BenchmarkOurTarYesAccounting(b *testing.B) {
fh.Close() fh.Close()
b.Fatal(err) b.Fatal(err)
} }
_, err = io.Copy(ioutil.Discard, tr) _, err = io.Copy(io.Discard, tr)
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }

View file

@ -7,7 +7,6 @@ import (
"flag" "flag"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
"os" "os"
@ -73,7 +72,7 @@ func main() {
// it is allowable, and not uncommon that there is further padding on the // it is allowable, and not uncommon that there is further padding on the
// end of an archive, apart from the expected 1024 null bytes // 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 { if err != nil && err != io.EOF {
log.Fatal(err, fh.Name()) log.Fatal(err, fh.Name())
} }

View file

@ -7,7 +7,6 @@ import (
"fmt" "fmt"
"hash/crc64" "hash/crc64"
"io" "io"
"io/ioutil"
"os" "os"
"testing" "testing"
@ -232,7 +231,7 @@ func BenchmarkAsm(b *testing.B) {
b.Fatal(err) b.Fatal(err)
} }
// read it all to the bit bucket // read it all to the bit bucket
i1, err := io.Copy(ioutil.Discard, tarStream) i1, err := io.Copy(io.Discard, tarStream)
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }
@ -243,7 +242,7 @@ func BenchmarkAsm(b *testing.B) {
rc := NewOutputTarStream(fgp, sup) rc := NewOutputTarStream(fgp, sup)
i2, err := io.Copy(ioutil.Discard, rc) i2, err := io.Copy(io.Discard, rc)
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }

View file

@ -4,7 +4,6 @@ import (
"archive/tar" "archive/tar"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"testing" "testing"
@ -52,14 +51,14 @@ func TestLargeJunkPadding(t *testing.T) {
}() }()
// Disassemble our junk file. // Disassemble our junk file.
nilPacker := storage.NewJSONPacker(ioutil.Discard) nilPacker := storage.NewJSONPacker(io.Discard)
rdr, err := NewInputTarStream(pR, nilPacker, nil) rdr, err := NewInputTarStream(pR, nilPacker, nil)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
// Copy the entire rdr. // Copy the entire rdr.
_, err = io.Copy(ioutil.Discard, rdr) _, err = io.Copy(io.Discard, rdr)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -3,7 +3,7 @@ package storage
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil" "io"
"strings" "strings"
"testing" "testing"
) )
@ -31,7 +31,7 @@ func TestGetter(t *testing.T) {
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
buf, err := ioutil.ReadAll(r) buf, err := io.ReadAll(r)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }

View file

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"io" "io"
"io/ioutil"
"os" "os"
"testing" "testing"
) )
@ -186,7 +185,7 @@ func BenchmarkGetPut(b *testing.B) {
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
for pb.Next() { for pb.Next() {
func() { func() {
fh, err := ioutil.TempFile("", "tar-split.") fh, err := os.CreateTemp("", "tar-split.")
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }