Skip to content
This repository was archived by the owner on Oct 5, 2023. It is now read-only.

Commit 026ba73

Browse files
committed
stop using the deprecated io/ioutil package
1 parent 6bc0edd commit 026ba73

File tree

8 files changed

+15
-21
lines changed

8 files changed

+15
-21
lines changed

api.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package httpapi
33
import (
44
"errors"
55
"fmt"
6-
"io/ioutil"
76
"net/http"
87
"os"
98
"path/filepath"
@@ -74,7 +73,7 @@ func ApiAddr(ipfspath string) (ma.Multiaddr, error) {
7473

7574
apiFile := filepath.Join(baseDir, DefaultApiFile)
7675

77-
api, err := ioutil.ReadFile(apiFile)
76+
api, err := os.ReadFile(apiFile)
7877
if err != nil {
7978
return nil, err
8079
}

api_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package httpapi
22

33
import (
44
"context"
5-
"io/ioutil"
65
"net/http"
76
"net/http/httptest"
87
"os"
@@ -92,7 +91,7 @@ func (np *NodeProvider) MakeAPISwarm(ctx context.Context, fullIdentity bool, n i
9291

9392
func (NodeProvider) makeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]iface.CoreAPI, error) {
9493

95-
dir, err := ioutil.TempDir("", "httpapi-tb-")
94+
dir, err := os.MkdirTemp("", "httpapi-tb-")
9695
if err != nil {
9796
return nil, err
9897
}

apifile.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8-
"io/ioutil"
98

109
"github.com/ipfs/go-cid"
1110
files "github.com/ipfs/go-ipfs-files"
@@ -113,7 +112,7 @@ func (f *apiFile) Seek(offset int64, whence int) (int64, error) {
113112
}
114113

115114
if f.at < offset && offset-f.at < forwardSeekLimit { //forward skip
116-
r, err := io.CopyN(ioutil.Discard, f.r.Output, offset-f.at)
115+
r, err := io.CopyN(io.Discard, f.r.Output, offset-f.at)
117116

118117
f.at += r
119118
return f.at, err

dag.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88

99
blocks "github.com/ipfs/go-block-format"
1010
"github.com/ipfs/go-cid"
@@ -24,7 +24,7 @@ func (api *HttpDagServ) Get(ctx context.Context, c cid.Cid) (format.Node, error)
2424
return nil, err
2525
}
2626

27-
data, err := ioutil.ReadAll(r)
27+
data, err := io.ReadAll(r)
2828
if err != nil {
2929
return nil, err
3030
}

name.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
"fmt"
77
"io"
88

9-
"github.com/ipfs/interface-go-ipfs-core"
9+
iface "github.com/ipfs/interface-go-ipfs-core"
1010
caopts "github.com/ipfs/interface-go-ipfs-core/options"
11-
"github.com/ipfs/interface-go-ipfs-core/options/namesys"
11+
nsopts "github.com/ipfs/interface-go-ipfs-core/options/namesys"
1212
"github.com/ipfs/interface-go-ipfs-core/path"
1313
)
1414

object.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ import (
55
"context"
66
"fmt"
77
"io"
8-
"io/ioutil"
98

109
"github.com/ipfs/go-cid"
1110
ipld "github.com/ipfs/go-ipld-format"
1211
"github.com/ipfs/go-merkledag"
1312
ft "github.com/ipfs/go-unixfs"
14-
"github.com/ipfs/interface-go-ipfs-core"
13+
iface "github.com/ipfs/interface-go-ipfs-core"
1514
caopts "github.com/ipfs/interface-go-ipfs-core/options"
1615
"github.com/ipfs/interface-go-ipfs-core/path"
1716
)
@@ -71,7 +70,7 @@ func (api *ObjectAPI) Get(ctx context.Context, p path.Path) (ipld.Node, error) {
7170
if err != nil {
7271
return nil, err
7372
}
74-
b, err := ioutil.ReadAll(r)
73+
b, err := io.ReadAll(r)
7574
if err != nil {
7675
return nil, err
7776
}

requestbuilder.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import (
55
"context"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"strconv"
109
"strings"
1110

12-
"github.com/ipfs/go-ipfs-files"
11+
files "github.com/ipfs/go-ipfs-files"
1312
)
1413

1514
type RequestBuilder interface {
@@ -59,7 +58,7 @@ func (r *requestBuilder) Body(body io.Reader) RequestBuilder {
5958

6059
// FileBody sets the request body to the given reader wrapped into multipartreader.
6160
func (r *requestBuilder) FileBody(body io.Reader) RequestBuilder {
62-
pr, _ := files.NewReaderPathFile("/dev/stdin", ioutil.NopCloser(body), nil)
61+
pr, _ := files.NewReaderPathFile("/dev/stdin", io.NopCloser(body), nil)
6362
d := files.NewMapDirectory(map[string]files.Node{"": pr})
6463
r.body = files.NewMultiFileReader(d, false)
6564

response.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"errors"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"mime"
109
"net/http"
1110
"net/url"
@@ -45,7 +44,7 @@ func (r *Response) Close() error {
4544
if r.Output != nil {
4645

4746
// drain output (response body)
48-
_, err1 := io.Copy(ioutil.Discard, r.Output)
47+
_, err1 := io.Copy(io.Discard, r.Output)
4948
err2 := r.Output.Close()
5049
if err1 != nil {
5150
return err1
@@ -117,7 +116,7 @@ func (r *Request) Send(c *http.Client) (*Response, error) {
117116
case resp.StatusCode == http.StatusNotFound:
118117
e.Message = "command not found"
119118
case contentType == "text/plain":
120-
out, err := ioutil.ReadAll(resp.Body)
119+
out, err := io.ReadAll(resp.Body)
121120
if err != nil {
122121
fmt.Fprintf(os.Stderr, "ipfs-shell: warning! response (%d) read error: %s\n", resp.StatusCode, err)
123122
}
@@ -140,7 +139,7 @@ func (r *Request) Send(c *http.Client) (*Response, error) {
140139
// This is a server-side bug (probably).
141140
e.Code = cmds.ErrImplementation
142141
fmt.Fprintf(os.Stderr, "ipfs-shell: warning! unhandled response (%d) encoding: %s", resp.StatusCode, contentType)
143-
out, err := ioutil.ReadAll(resp.Body)
142+
out, err := io.ReadAll(resp.Body)
144143
if err != nil {
145144
fmt.Fprintf(os.Stderr, "ipfs-shell: response (%d) read error: %s\n", resp.StatusCode, err)
146145
}
@@ -150,7 +149,7 @@ func (r *Request) Send(c *http.Client) (*Response, error) {
150149
nresp.Output = nil
151150

152151
// drain body and close
153-
_, _ = io.Copy(ioutil.Discard, resp.Body)
152+
_, _ = io.Copy(io.Discard, resp.Body)
154153
_ = resp.Body.Close()
155154
}
156155

0 commit comments

Comments
 (0)