Skip to content

Commit

Permalink
chore: remove refs to deprecated io/ioutil
Browse files Browse the repository at this point in the history
  • Loading branch information
testwill authored and anacrolix committed Jul 9, 2023
1 parent 20f5ddb commit 7036f22
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 23 deletions.
4 changes: 2 additions & 2 deletions bencode/both_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package bencode

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

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func loadFile(name string, t *testing.T) []byte {
data, err := ioutil.ReadFile(name)
data, err := os.ReadFile(name)
require.NoError(t, err)
return data
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/torrent-pick/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bufio"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/testutil/greeting.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package testutil

import (
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/testutil/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package testutil

import (
"io"
"io/ioutil"
"strings"

"github.com/anacrolix/missinggo/expect"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions issue211_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package torrent

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

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -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)
}
3 changes: 1 addition & 2 deletions metainfo/metainfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package metainfo

import (
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -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())
Expand Down
5 changes: 2 additions & 3 deletions mse/mse.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"expvar"
"fmt"
"io"
"io/ioutil"
"math"
"math/big"
"strconv"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions mse/mse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/rand"
"crypto/rc4"
"io"
"io/ioutil"
"net"
"sync"
"testing"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions storage/piece-resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"path"
"sort"
"strconv"
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions test/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package test

import (
"io"
"io/ioutil"
"os"
"sync"
"testing"
Expand Down Expand Up @@ -46,7 +45,7 @@ func newFileCacheClientStorageFactory(ps fileCacheClientStorageFactoryParams) St
storage.ResourcePiecesOpts{
Capacity: sharedCapacity,
}),
ioutil.NopCloser(nil),
io.NopCloser(nil),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tracker/udp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"crypto/rand"
"errors"
"fmt"
"io/ioutil"
"io"
"net"
"net/url"
"sync"
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit 7036f22

Please sign in to comment.