From: guoguangwu Date: Sun, 9 Jul 2023 05:29:02 +0000 (+0800) Subject: chore: remove refs to deprecated io/ioutil X-Git-Url: http://www.git.stargrave.org/?p=btrtrc.git;a=commitdiff_plain;h=7036f221f4abe4d979f5ac2ff0b09f045f8716bd chore: remove refs to deprecated io/ioutil --- diff --git a/bencode/both_test.go b/bencode/both_test.go index b0bb074d..fdcb90d9 100644 --- a/bencode/both_test.go +++ b/bencode/both_test.go @@ -2,7 +2,7 @@ package bencode import ( "bytes" - "io/ioutil" + "os" "testing" "github.com/stretchr/testify/assert" @@ -10,7 +10,7 @@ import ( ) func loadFile(name string, t *testing.T) []byte { - data, err := ioutil.ReadFile(name) + data, err := os.ReadFile(name) require.NoError(t, err) return data } diff --git a/cmd/torrent-pick/main.go b/cmd/torrent-pick/main.go index 8dd5a773..73a597f3 100644 --- a/cmd/torrent-pick/main.go +++ b/cmd/torrent-pick/main.go @@ -5,7 +5,6 @@ import ( "bufio" "fmt" "io" - "io/ioutil" "log" "net" "net/http" @@ -107,7 +106,7 @@ func main() { return } - tmpdir, err := ioutil.TempDir("", "torrent-pick-") + tmpdir, err := os.MkdirTemp("", "torrent-pick-") if err != nil { log.Fatal(err) } diff --git a/internal/testutil/greeting.go b/internal/testutil/greeting.go index 954ad913..6544483c 100644 --- a/internal/testutil/greeting.go +++ b/internal/testutil/greeting.go @@ -6,7 +6,6 @@ package testutil import ( - "io/ioutil" "os" "path/filepath" @@ -41,7 +40,7 @@ func GreetingMetaInfo() *metainfo.MetaInfo { // and a corresponding metainfo describing it. The temporary directory can be // cleaned away with os.RemoveAll. func GreetingTestTorrent() (tempDir string, metaInfo *metainfo.MetaInfo) { - tempDir, err := ioutil.TempDir(os.TempDir(), "") + tempDir, err := os.MkdirTemp(os.TempDir(), "") if err != nil { panic(err) } diff --git a/internal/testutil/spec.go b/internal/testutil/spec.go index 42d91ba3..63e4a74c 100644 --- a/internal/testutil/spec.go +++ b/internal/testutil/spec.go @@ -2,7 +2,6 @@ package testutil import ( "io" - "io/ioutil" "strings" "github.com/anacrolix/missinggo/expect" @@ -53,7 +52,7 @@ func (t *Torrent) Info(pieceLength int64) metainfo.Info { } } err := info.GeneratePieces(func(fi metainfo.FileInfo) (io.ReadCloser, error) { - return ioutil.NopCloser(strings.NewReader(t.GetFile(strings.Join(fi.Path, "/")).Data)), nil + return io.NopCloser(strings.NewReader(t.GetFile(strings.Join(fi.Path, "/")).Data)), nil }) expect.Nil(err) return info diff --git a/issue211_test.go b/issue211_test.go index 7794f8a5..a76be07a 100644 --- a/issue211_test.go +++ b/issue211_test.go @@ -5,7 +5,6 @@ package torrent import ( "io" - "io/ioutil" "testing" "github.com/stretchr/testify/assert" @@ -38,5 +37,5 @@ func TestDropTorrentWithMmapStorageWhileHashing(t *testing.T) { r := tt.NewReader() go tt.Drop() - io.Copy(ioutil.Discard, r) + io.Copy(io.Discard, r) } diff --git a/metainfo/metainfo_test.go b/metainfo/metainfo_test.go index d1a6c356..335631f9 100644 --- a/metainfo/metainfo_test.go +++ b/metainfo/metainfo_test.go @@ -2,7 +2,6 @@ package metainfo import ( "io" - "io/ioutil" "os" "path" "path/filepath" @@ -68,7 +67,7 @@ func TestNumPieces(t *testing.T) { PieceLength: _case.PieceLength, } err := info.GeneratePieces(func(fi FileInfo) (io.ReadCloser, error) { - return ioutil.NopCloser(missinggo.ZeroReader), nil + return io.NopCloser(missinggo.ZeroReader), nil }) assert.NoError(t, err) assert.EqualValues(t, _case.NumPieces, info.NumPieces()) diff --git a/mse/mse.go b/mse/mse.go index a5477b8f..c3a9f3d3 100644 --- a/mse/mse.go +++ b/mse/mse.go @@ -12,7 +12,6 @@ import ( "expvar" "fmt" "io" - "io/ioutil" "math" "math/big" "strconv" @@ -409,7 +408,7 @@ func (h *handshake) initerSteps() (ret io.ReadWriter, selected CryptoMethod, err if err != nil { return } - _, err = io.CopyN(ioutil.Discard, r, int64(padLen)) + _, err = io.CopyN(io.Discard, r, int64(padLen)) if err != nil { return } @@ -474,7 +473,7 @@ func (h *handshake) receiverSteps() (ret io.ReadWriter, chosen CryptoMethod, err } cryptoProvidesCount.Add(strconv.FormatUint(uint64(provides), 16), 1) chosen = h.chooseMethod(provides) - _, err = io.CopyN(ioutil.Discard, r, int64(padLen)) + _, err = io.CopyN(io.Discard, r, int64(padLen)) if err != nil { return } diff --git a/mse/mse_test.go b/mse/mse_test.go index a38e9cc1..f7f7fe7a 100644 --- a/mse/mse_test.go +++ b/mse/mse_test.go @@ -5,7 +5,6 @@ import ( "crypto/rand" "crypto/rc4" "io" - "io/ioutil" "net" "sync" "testing" @@ -131,7 +130,7 @@ func (tr *trackReader) Read(b []byte) (n int, err error) { func TestReceiveRandomData(t *testing.T) { tr := trackReader{rand.Reader, 0} - _, _, err := ReceiveHandshake(readWriter{&tr, ioutil.Discard}, nil, DefaultCryptoSelector) + _, _, err := ReceiveHandshake(readWriter{&tr, io.Discard}, nil, DefaultCryptoSelector) // No skey matches require.Error(t, err) // Establishing S, and then reading the maximum padding for giving up on diff --git a/storage/piece-resource.go b/storage/piece-resource.go index ec3848df..5327f31d 100644 --- a/storage/piece-resource.go +++ b/storage/piece-resource.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "path" "sort" "strconv" @@ -141,7 +140,7 @@ func (s piecePerResourcePiece) MarkComplete() error { if ccr, ok := s.rp.(ConsecutiveChunkReader); ok { return ccr.ReadConsecutiveChunks(s.incompleteDirPath() + "/") } - return ioutil.NopCloser(io.NewSectionReader(incompleteChunks, 0, s.mp.Length())), nil + return io.NopCloser(io.NewSectionReader(incompleteChunks, 0, s.mp.Length())), nil }() if err != nil { return fmt.Errorf("getting incomplete chunks reader: %w", err) diff --git a/test/transfer_test.go b/test/transfer_test.go index 683d589b..501872fd 100644 --- a/test/transfer_test.go +++ b/test/transfer_test.go @@ -2,7 +2,6 @@ package test import ( "io" - "io/ioutil" "os" "sync" "testing" @@ -46,7 +45,7 @@ func newFileCacheClientStorageFactory(ps fileCacheClientStorageFactoryParams) St storage.ResourcePiecesOpts{ Capacity: sharedCapacity, }), - ioutil.NopCloser(nil), + io.NopCloser(nil), } } } diff --git a/tracker/udp_test.go b/tracker/udp_test.go index cf18e0de..232aeb19 100644 --- a/tracker/udp_test.go +++ b/tracker/udp_test.go @@ -6,7 +6,7 @@ import ( "crypto/rand" "errors" "fmt" - "io/ioutil" + "io" "net" "net/url" "sync" @@ -179,7 +179,7 @@ func TestURLPathOption(t *testing.T) { r = bytes.NewReader(b[:n]) udp.Read(r, &h) udp.Read(r, &AnnounceRequest{}) - all, _ := ioutil.ReadAll(r) + all, _ := io.ReadAll(r) if string(all) != "\x02\x09/announce" { t.FailNow() }