Skip to content

Commit 83e452b

Browse files
committed
Remove uses of deprecated io/ioutil library
1 parent c233c42 commit 83e452b

File tree

8 files changed

+20
-27
lines changed

8 files changed

+20
-27
lines changed

chunk.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package gofakes3
33
import (
44
"fmt"
55
"io"
6-
"io/ioutil"
76
)
87

98
type chunkedReader struct {
@@ -42,7 +41,7 @@ func (r *chunkedReader) Read(p []byte) (n int, err error) {
4241
r.notFirstChunk = true
4342
} else {
4443
// skip last chunk's b"\r\n"
45-
_, err = io.CopyN(ioutil.Discard, r.inner, 2)
44+
_, err = io.CopyN(io.Discard, r.inner, 2)
4645
if err != nil {
4746
return n, err
4847
}
@@ -54,7 +53,7 @@ func (r *chunkedReader) Read(p []byte) (n int, err error) {
5453
return n, err
5554
}
5655
r.chunkRemain = chunkSize
57-
_, err = io.CopyN(ioutil.Discard, r.inner, 16+64+2) // "chunk-signature=" + sizeOfHash + "\r\n"
56+
_, err = io.CopyN(io.Discard, r.inner, 16+64+2) // "chunk-signature=" + sizeOfHash + "\r\n"
5857
if err != nil {
5958
return n, err
6059
}

chunk_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package gofakes3
33
import (
44
"errors"
55
"io"
6-
"io/ioutil"
76
"strings"
87
"testing"
98

@@ -30,7 +29,7 @@ func TestChunkedUploadSuccess(t *testing.T) {
3029

3130
inner := strings.NewReader(payload)
3231
chunkedReader := newChunkedReader(inner)
33-
buf, err := ioutil.ReadAll(chunkedReader)
32+
buf, err := io.ReadAll(chunkedReader)
3433
assert.Equal(t, nil, err)
3534
assert.Equal(t, string(buf), strings.Repeat("a", 65536+1024))
3635
}
@@ -43,23 +42,23 @@ func (errReader) Read(p []byte) (n int, err error) {
4342

4443
func TestChunkedUploadFail(t *testing.T) {
4544
chunkedReader := newChunkedReader(errReader{})
46-
buf, err := ioutil.ReadAll(chunkedReader)
45+
buf, err := io.ReadAll(chunkedReader)
4746
assert.Equal(t, errors.New("err"), err)
4847
assert.Equal(t, "", string(buf))
4948

5049
chunkedReader = newChunkedReader(io.MultiReader(
5150
strings.NewReader("10000;chunk-signature=ad80c730a21e5b8d04586a2213dd63b9a0e99e0e2307b0ade35a65485a288648\r\n"),
5251
errReader{},
5352
))
54-
buf, err = ioutil.ReadAll(chunkedReader)
53+
buf, err = io.ReadAll(chunkedReader)
5554
assert.Equal(t, errors.New("err"), err)
5655
assert.Equal(t, "", string(buf))
5756

5857
chunkedReader = newChunkedReader(io.MultiReader(
5958
strings.NewReader("incorrect_data"),
6059
errReader{},
6160
))
62-
buf, err = ioutil.ReadAll(chunkedReader)
61+
buf, err = io.ReadAll(chunkedReader)
6362
assert.Equal(t, errors.New("expected integer"), err)
6463
assert.Equal(t, "", string(buf))
6564

@@ -69,7 +68,7 @@ func TestChunkedUploadFail(t *testing.T) {
6968
strings.NewReader(payload),
7069
errReader{},
7170
))
72-
buf, err = ioutil.ReadAll(chunkedReader)
71+
buf, err = io.ReadAll(chunkedReader)
7372
assert.Equal(t, errors.New("err"), err)
7473
assert.Equal(t, strings.Repeat("a", 200), string(buf))
7574

gofakes3.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"encoding/hex"
77
"fmt"
88
"io"
9-
"io/ioutil"
109
"math"
1110
"net/http"
1211
"net/textproto"
@@ -1121,7 +1120,7 @@ func (g *GoFakeS3) xmlEncoder(w http.ResponseWriter) *xml.Encoder {
11211120
}
11221121

11231122
func (g *GoFakeS3) xmlDecodeBody(rdr io.ReadCloser, into interface{}) (err error) {
1124-
body, err := ioutil.ReadAll(rdr)
1123+
body, err := io.ReadAll(rdr)
11251124
defer CheckClose(rdr, &err)
11261125
if err != nil {
11271126
return err

gofakes3_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"context"
77
"fmt"
88
"io"
9-
"io/ioutil"
109
"mime/multipart"
1110
"net/http"
1211
"net/http/httputil"
@@ -402,7 +401,7 @@ func TestCopyObject(t *testing.T) {
402401
t.Error(err)
403402
}
404403
}()
405-
data, err := ioutil.ReadAll(obj.Contents)
404+
data, err := io.ReadAll(obj.Contents)
406405
ts.OK(err)
407406

408407
if string(data) != "content" {
@@ -449,7 +448,7 @@ func TestCopyObjectWithSpecialChars(t *testing.T) {
449448
if err != nil {
450449
t.Fatalf("object not found with key %v", srcKey)
451450
}
452-
objContent, err := ioutil.ReadAll(obj.Body)
451+
objContent, err := io.ReadAll(obj.Body)
453452
ts.OK(err)
454453
if !bytes.Equal([]byte(content), objContent) {
455454
ts.Fatalf("object contents are different %v!=%v", content, objContent)
@@ -617,7 +616,7 @@ func TestGetObjectRange(t *testing.T) {
617616
}
618617
}()
619618

620-
out, err := ioutil.ReadAll(obj.Body)
619+
out, err := io.ReadAll(obj.Body)
621620
ts.OK(err)
622621
if !bytes.Equal(expected, out) {
623622
ts.Fatal("range failed", hdr, err)
@@ -943,7 +942,7 @@ func TestObjectVersions(t *testing.T) {
943942
ts.Error(err)
944943
}
945944
}()
946-
bts, err := ioutil.ReadAll(out.Body)
945+
bts, err := io.ReadAll(out.Body)
947946
ts.OK(err)
948947
if !bytes.Equal(bts, contents) {
949948
ts.Fatal("body mismatch. found:", string(bts), "expected:", string(contents))

init_internal_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package gofakes3
44
// tests that use struct internals, etc go in this package.
55

66
import (
7-
"io/ioutil"
7+
"io"
88
"log"
99
"testing"
1010
)
@@ -32,5 +32,5 @@ func (t TT) OKAll(vs ...interface{}) {
3232
func init() {
3333
// Tests that may cause log output that merits inspection belong in
3434
// gofakes3_test.
35-
log.SetOutput(ioutil.Discard)
35+
log.SetOutput(io.Discard)
3636
}

init_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"flag"
1616
"fmt"
1717
"io"
18-
"io/ioutil"
1918
"log"
2019
"net"
2120
"net/http"
@@ -75,7 +74,7 @@ func runTestMain(m *testing.M) (err error) {
7574
var logOutput *os.File
7675

7776
if logFile == "" {
78-
logOutput, err = ioutil.TempFile("", "gofakes3-*.log")
77+
logOutput, err = os.CreateTemp("", "gofakes3-*.log")
7978
} else {
8079
logOutput, err = os.Create(logFile)
8180
}
@@ -267,7 +266,7 @@ func (ts *testServer) backendGetString(bucket, key string, rnge *gofakes3.Object
267266
ts.Error(err)
268267
}
269268
}()
270-
data, err := ioutil.ReadAll(obj.Contents)
269+
data, err := io.ReadAll(obj.Contents)
271270
ts.OK(err)
272271

273272
return string(data)
@@ -818,7 +817,7 @@ func readBody(tt gofakes3.TT, body interface{}) []byte {
818817
case []byte:
819818
return body
820819
case io.Reader:
821-
out, err := ioutil.ReadAll(body)
820+
out, err := io.ReadAll(body)
822821
tt.OK(err)
823822
return out
824823
default:

internal/s3assumer/s300001_get_version_after_versioning_suspended.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"time"
98

109
"github.com/aws/aws-sdk-go-v2/aws"
@@ -82,7 +81,7 @@ func (t *S300001GetVersionAfterVersioningSuspended) Run(ctx *Context) error {
8281
err = closeErr
8382
}
8483
}()
85-
return ioutil.ReadAll(rdr)
84+
return io.ReadAll(rdr)
8685
}
8786

8887
for ver, body := range versions {

util.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package gofakes3
22

33
import (
44
"io"
5-
"io/ioutil"
65
"strconv"
76
)
87

@@ -27,7 +26,7 @@ func parseClampedInt(in string, defaultValue, min, max int64) (int64, error) {
2726
return v, nil
2827
}
2928

30-
// ReadAll is a fakeS3-centric replacement for ioutil.ReadAll(), for use when
29+
// ReadAll is a fakeS3-centric replacement for io.ReadAll(), for use when
3130
// the size of the result is known ahead of time. It is considerably faster to
3231
// preallocate the entire slice than to allow growslice to be triggered
3332
// repeatedly, especially with larger buffers.
@@ -48,7 +47,7 @@ func ReadAll(r io.Reader, size int64) (b []byte, err error) {
4847
return nil, ErrIncompleteBody
4948
}
5049

51-
if extra, err := ioutil.ReadAll(r); err != nil {
50+
if extra, err := io.ReadAll(r); err != nil {
5251
return nil, err
5352
} else if len(extra) > 0 {
5453
return nil, ErrIncompleteBody

0 commit comments

Comments
 (0)