Skip to content

Commit

Permalink
use io.ReadAll instead of ioutil.ReadAll
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Sep 21, 2023
1 parent 1103de2 commit 97036c6
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 25 deletions.
2 changes: 1 addition & 1 deletion backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ type Backend interface {
// may be nil.
//
// The size can be used if the backend needs to read the whole reader; use
// gofakes3.ReadAll() for this job rather than ioutil.ReadAll().
// gofakes3.ReadAll() for this job rather than io.ReadAll().
PutObject(bucketName, key string, meta map[string]string, input io.Reader, size int64) (PutObjectResult, error)

DeleteMulti(bucketName string, objects ...string) (MultiDeleteResult, error)
Expand Down
5 changes: 3 additions & 2 deletions backend/s3afero/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/md5"
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"os"
"reflect"
Expand Down Expand Up @@ -59,7 +60,7 @@ func TestPutGet(t *testing.T) {
t.Fatal(obj.Metadata, "!=", meta)
}

result, err := ioutil.ReadAll(obj.Contents)
result, err := io.ReadAll(obj.Contents)
defer obj.Contents.Close()
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -105,7 +106,7 @@ func TestPutGetRange(t *testing.T) {
t.Fatal(obj.Metadata, "!=", meta)
}

result, err := ioutil.ReadAll(obj.Contents)
result, err := io.ReadAll(obj.Contents)
defer obj.Contents.Close()
if err != nil {
t.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ go 1.16

require (
github.com/aws/aws-sdk-go v1.44.256
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46
github.com/shabbyrobe/gocovmerge v0.0.0-20190829150210-3e036491d500
github.com/spf13/afero v1.2.1
github.com/stretchr/testify v1.8.0
go.etcd.io/bbolt v1.3.5
golang.org/x/tools v0.8.0
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce
Expand Down
7 changes: 0 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ github.com/shabbyrobe/gocovmerge v0.0.0-20190829150210-3e036491d500/go.mod h1:+n
github.com/spf13/afero v1.2.1 h1:qgMbHoJbPbw579P+1zVY+6n4nIFuIchaIjzZ/I/Yq8M=
github.com/spf13/afero v1.2.1/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
Expand Down Expand Up @@ -75,6 +71,3 @@ gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce h1:xcEWjVhvbDy+nHP67nPDDpbYrY
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
3 changes: 1 addition & 2 deletions gofakes3.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"math"
"net/http"
"net/textproto"
Expand Down Expand Up @@ -1096,7 +1095,7 @@ func (g *GoFakeS3) xmlEncoder(w http.ResponseWriter) *xml.Encoder {
}

func (g *GoFakeS3) xmlDecodeBody(rdr io.ReadCloser, into interface{}) error {
body, err := ioutil.ReadAll(rdr)
body, err := io.ReadAll(rdr)
defer rdr.Close()
if err != nil {
return err
Expand Down
9 changes: 4 additions & 5 deletions gofakes3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/http/httputil"
Expand Down Expand Up @@ -408,7 +407,7 @@ func TestCopyObject(t *testing.T) {
ts.OK(err)

defer obj.Contents.Close()
data, err := ioutil.ReadAll(obj.Contents)
data, err := io.ReadAll(obj.Contents)
ts.OK(err)

if string(data) != "content" {
Expand Down Expand Up @@ -454,7 +453,7 @@ func TestCopyObjectWithSpecialChars(t *testing.T) {
if err != nil {
t.Fatalf("object not found with key %v", srcKey)
}
objContent, err := ioutil.ReadAll(obj.Body)
objContent, err := io.ReadAll(obj.Body)
ts.OK(err)
if !bytes.Equal([]byte(content), objContent) {
ts.Fatalf("object contents are different %v!=%v", content, objContent)
Expand Down Expand Up @@ -610,7 +609,7 @@ func TestGetObjectRange(t *testing.T) {
ts.OK(err)
defer obj.Body.Close()

out, err := ioutil.ReadAll(obj.Body)
out, err := io.ReadAll(obj.Body)
ts.OK(err)
if !bytes.Equal(expected, out) {
ts.Fatal("range failed", hdr, err)
Expand Down Expand Up @@ -919,7 +918,7 @@ func TestObjectVersions(t *testing.T) {
out, err := svc.GetObject(input)
ts.OK(err)
defer out.Body.Close()
bts, err := ioutil.ReadAll(out.Body)
bts, err := io.ReadAll(out.Body)
ts.OK(err)
if !bytes.Equal(bts, contents) {
ts.Fatal("body mismatch. found:", string(bts), "expected:", string(contents))
Expand Down
4 changes: 2 additions & 2 deletions init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (ts *testServer) backendGetString(bucket, key string, rnge *gofakes3.Object
ts.OK(err)

defer obj.Contents.Close()
data, err := ioutil.ReadAll(obj.Contents)
data, err := io.ReadAll(obj.Contents)
ts.OK(err)

return string(data)
Expand Down Expand Up @@ -782,7 +782,7 @@ func readBody(tt gofakes3.TT, body interface{}) []byte {
case []byte:
return body
case io.Reader:
out, err := ioutil.ReadAll(body)
out, err := io.ReadAll(body)
tt.OK(err)
return out
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -76,7 +75,7 @@ func (t *S300001GetVersionAfterVersioningSuspended) Run(ctx *Context) error {

readCloseBody := func(rdr io.ReadCloser) ([]byte, error) {
defer rdr.Close()
return ioutil.ReadAll(rdr)
return io.ReadAll(rdr)
}

for ver, body := range versions {
Expand Down
5 changes: 2 additions & 3 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gofakes3

import (
"io"
"io/ioutil"
"strconv"
)

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

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

if extra, err := ioutil.ReadAll(r); err != nil {
if extra, err := io.ReadAll(r); err != nil {
return nil, err
} else if len(extra) > 0 {
return nil, ErrIncompleteBody
Expand Down

0 comments on commit 97036c6

Please sign in to comment.