stop using the deprecated io/ioutil package
This commit was moved from ipfs/go-ipfs-http-client@026ba730a1fe9a4a25a22449bec8d69c2262ccfc
web3-bot committed
Sep 23, 2022 at 07:43 UTC
0fff1d5d8e4cb2debaff1ee4e85b1266907101af
8 files changed
+15
-21
client/httpapi/api.go
+1
-2
@@ -3,7 +3,6 @@ package httpapi
3
import (
4
"errors"
5
"fmt"
6
- "io/ioutil"
6
"net/http"
7
"os"
8
"path/filepath"
@@ -74,7 +73,7 @@ func ApiAddr(ipfspath string) (ma.Multiaddr, error) {
73
74
apiFile := filepath.Join(baseDir, DefaultApiFile)
75
77
- api, err := ioutil.ReadFile(apiFile)
76
+ api, err := os.ReadFile(apiFile)
77
if err != nil {
78
return nil, err
79
}
client/httpapi/api_test.go
+1
-2
@@ -2,7 +2,6 @@ package httpapi
2
3
import (
4
"context"
5
- "io/ioutil"
5
"net/http"
6
"net/http/httptest"
7
"os"
@@ -92,7 +91,7 @@ func (np *NodeProvider) MakeAPISwarm(ctx context.Context, fullIdentity bool, n i
91
92
func (NodeProvider) makeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]iface.CoreAPI, error) {
93
95
- dir, err := ioutil.TempDir("", "httpapi-tb-")
94
+ dir, err := os.MkdirTemp("", "httpapi-tb-")
95
if err != nil {
96
return nil, err
97
}
client/httpapi/apifile.go
+1
-2
@@ -5,7 +5,6 @@ import (
5
"encoding/json"
6
"fmt"
7
"io"
8
- "io/ioutil"
8
9
"github.com/ipfs/go-cid"
10
files "github.com/ipfs/go-ipfs-files"
@@ -113,7 +112,7 @@ func (f *apiFile) Seek(offset int64, whence int) (int64, error) {
112
}
113
114
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)
116
117
f.at += r
118
return f.at, err
client/httpapi/dag.go
+2
-2
@@ -4,7 +4,7 @@ import (
4
"bytes"
5
"context"
6
"fmt"
7
- "io/ioutil"
7
+ "io"
8
9
blocks "github.com/ipfs/go-block-format"
10
"github.com/ipfs/go-cid"
@@ -24,7 +24,7 @@ func (api *HttpDagServ) Get(ctx context.Context, c cid.Cid) (format.Node, error)
24
return nil, err
25
}
26
27
- data, err := ioutil.ReadAll(r)
27
+ data, err := io.ReadAll(r)
28
if err != nil {
29
return nil, err
30
}
client/httpapi/name.go
+2
-2
@@ -6,9 +6,9 @@ import (
6
"fmt"
7
"io"
8
9
- "github.com/ipfs/interface-go-ipfs-core"
9
+ iface "github.com/ipfs/interface-go-ipfs-core"
10
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"
12
"github.com/ipfs/interface-go-ipfs-core/path"
13
)
14
client/httpapi/object.go
+2
-3
@@ -5,13 +5,12 @@ import (
5
"context"
6
"fmt"
7
"io"
8
- "io/ioutil"
8
9
"github.com/ipfs/go-cid"
10
ipld "github.com/ipfs/go-ipld-format"
11
"github.com/ipfs/go-merkledag"
12
ft "github.com/ipfs/go-unixfs"
14
- "github.com/ipfs/interface-go-ipfs-core"
13
+ iface "github.com/ipfs/interface-go-ipfs-core"
14
caopts "github.com/ipfs/interface-go-ipfs-core/options"
15
"github.com/ipfs/interface-go-ipfs-core/path"
16
)
@@ -71,7 +70,7 @@ func (api *ObjectAPI) Get(ctx context.Context, p path.Path) (ipld.Node, error) {
70
if err != nil {
71
return nil, err
72
}
74
- b, err := ioutil.ReadAll(r)
73
+ b, err := io.ReadAll(r)
74
if err != nil {
75
return nil, err
76
}
client/httpapi/requestbuilder.go
+2
-3
@@ -5,11 +5,10 @@ import (
5
"context"
6
"fmt"
7
"io"
8
- "io/ioutil"
8
"strconv"
9
"strings"
10
12
- "github.com/ipfs/go-ipfs-files"
11
+ files "github.com/ipfs/go-ipfs-files"
12
)
13
14
type RequestBuilder interface {
@@ -59,7 +58,7 @@ func (r *requestBuilder) Body(body io.Reader) RequestBuilder {
58
59
// FileBody sets the request body to the given reader wrapped into multipartreader.
60
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)
62
d := files.NewMapDirectory(map[string]files.Node{"": pr})
63
r.body = files.NewMultiFileReader(d, false)
64
client/httpapi/response.go
+4
-5
@@ -5,7 +5,6 @@ import (
5
"errors"
6
"fmt"
7
"io"
8
- "io/ioutil"
8
"mime"
9
"net/http"
10
"net/url"
@@ -45,7 +44,7 @@ func (r *Response) Close() error {
44
if r.Output != nil {
45
46
// drain output (response body)
48
- _, err1 := io.Copy(ioutil.Discard, r.Output)
47
+ _, err1 := io.Copy(io.Discard, r.Output)
48
err2 := r.Output.Close()
49
if err1 != nil {
50
return err1
@@ -117,7 +116,7 @@ func (r *Request) Send(c *http.Client) (*Response, error) {
116
case resp.StatusCode == http.StatusNotFound:
117
e.Message = "command not found"
118
case contentType == "text/plain":
120
- out, err := ioutil.ReadAll(resp.Body)
119
+ out, err := io.ReadAll(resp.Body)
120
if err != nil {
121
fmt.Fprintf(os.Stderr, "ipfs-shell: warning! response (%d) read error: %s\n", resp.StatusCode, err)
122
}
@@ -140,7 +139,7 @@ func (r *Request) Send(c *http.Client) (*Response, error) {
139
// This is a server-side bug (probably).
140
e.Code = cmds.ErrImplementation
141
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)
143
if err != nil {
144
fmt.Fprintf(os.Stderr, "ipfs-shell: response (%d) read error: %s\n", resp.StatusCode, err)
145
}
@@ -150,7 +149,7 @@ func (r *Request) Send(c *http.Client) (*Response, error) {
149
nresp.Output = nil
150
151
// drain body and close
153
- _, _ = io.Copy(ioutil.Discard, resp.Body)
152
+ _, _ = io.Copy(io.Discard, resp.Body)
153
_ = resp.Body.Close()
154
}
155