mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
stop using the deprecated io/ioutil package
This commit was moved from ipfs/go-ipfs-http-client@026ba730a1
This commit is contained in:
parent
1cdb9adf89
commit
0fff1d5d8e
@ -3,7 +3,6 @@ package httpapi
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -74,7 +73,7 @@ func ApiAddr(ipfspath string) (ma.Multiaddr, error) {
|
||||
|
||||
apiFile := filepath.Join(baseDir, DefaultApiFile)
|
||||
|
||||
api, err := ioutil.ReadFile(apiFile)
|
||||
api, err := os.ReadFile(apiFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
@ -92,7 +91,7 @@ func (np *NodeProvider) MakeAPISwarm(ctx context.Context, fullIdentity bool, n i
|
||||
|
||||
func (NodeProvider) makeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]iface.CoreAPI, error) {
|
||||
|
||||
dir, err := ioutil.TempDir("", "httpapi-tb-")
|
||||
dir, err := os.MkdirTemp("", "httpapi-tb-")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
files "github.com/ipfs/go-ipfs-files"
|
||||
@ -113,7 +112,7 @@ func (f *apiFile) Seek(offset int64, whence int) (int64, error) {
|
||||
}
|
||||
|
||||
if f.at < offset && offset-f.at < forwardSeekLimit { //forward skip
|
||||
r, err := io.CopyN(ioutil.Discard, f.r.Output, offset-f.at)
|
||||
r, err := io.CopyN(io.Discard, f.r.Output, offset-f.at)
|
||||
|
||||
f.at += r
|
||||
return f.at, err
|
||||
|
||||
@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
|
||||
blocks "github.com/ipfs/go-block-format"
|
||||
"github.com/ipfs/go-cid"
|
||||
@ -24,7 +24,7 @@ func (api *HttpDagServ) Get(ctx context.Context, c cid.Cid) (format.Node, error)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadAll(r)
|
||||
data, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -6,9 +6,9 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/ipfs/interface-go-ipfs-core"
|
||||
iface "github.com/ipfs/interface-go-ipfs-core"
|
||||
caopts "github.com/ipfs/interface-go-ipfs-core/options"
|
||||
"github.com/ipfs/interface-go-ipfs-core/options/namesys"
|
||||
nsopts "github.com/ipfs/interface-go-ipfs-core/options/namesys"
|
||||
"github.com/ipfs/interface-go-ipfs-core/path"
|
||||
)
|
||||
|
||||
|
||||
@ -5,13 +5,12 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
ipld "github.com/ipfs/go-ipld-format"
|
||||
"github.com/ipfs/go-merkledag"
|
||||
ft "github.com/ipfs/go-unixfs"
|
||||
"github.com/ipfs/interface-go-ipfs-core"
|
||||
iface "github.com/ipfs/interface-go-ipfs-core"
|
||||
caopts "github.com/ipfs/interface-go-ipfs-core/options"
|
||||
"github.com/ipfs/interface-go-ipfs-core/path"
|
||||
)
|
||||
@ -71,7 +70,7 @@ func (api *ObjectAPI) Get(ctx context.Context, p path.Path) (ipld.Node, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b, err := ioutil.ReadAll(r)
|
||||
b, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -5,11 +5,10 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/ipfs/go-ipfs-files"
|
||||
files "github.com/ipfs/go-ipfs-files"
|
||||
)
|
||||
|
||||
type RequestBuilder interface {
|
||||
@ -59,7 +58,7 @@ func (r *requestBuilder) Body(body io.Reader) RequestBuilder {
|
||||
|
||||
// FileBody sets the request body to the given reader wrapped into multipartreader.
|
||||
func (r *requestBuilder) FileBody(body io.Reader) RequestBuilder {
|
||||
pr, _ := files.NewReaderPathFile("/dev/stdin", ioutil.NopCloser(body), nil)
|
||||
pr, _ := files.NewReaderPathFile("/dev/stdin", io.NopCloser(body), nil)
|
||||
d := files.NewMapDirectory(map[string]files.Node{"": pr})
|
||||
r.body = files.NewMultiFileReader(d, false)
|
||||
|
||||
|
||||
@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@ -45,7 +44,7 @@ func (r *Response) Close() error {
|
||||
if r.Output != nil {
|
||||
|
||||
// drain output (response body)
|
||||
_, err1 := io.Copy(ioutil.Discard, r.Output)
|
||||
_, err1 := io.Copy(io.Discard, r.Output)
|
||||
err2 := r.Output.Close()
|
||||
if err1 != nil {
|
||||
return err1
|
||||
@ -117,7 +116,7 @@ func (r *Request) Send(c *http.Client) (*Response, error) {
|
||||
case resp.StatusCode == http.StatusNotFound:
|
||||
e.Message = "command not found"
|
||||
case contentType == "text/plain":
|
||||
out, err := ioutil.ReadAll(resp.Body)
|
||||
out, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "ipfs-shell: warning! response (%d) read error: %s\n", resp.StatusCode, err)
|
||||
}
|
||||
@ -140,7 +139,7 @@ func (r *Request) Send(c *http.Client) (*Response, error) {
|
||||
// This is a server-side bug (probably).
|
||||
e.Code = cmds.ErrImplementation
|
||||
fmt.Fprintf(os.Stderr, "ipfs-shell: warning! unhandled response (%d) encoding: %s", resp.StatusCode, contentType)
|
||||
out, err := ioutil.ReadAll(resp.Body)
|
||||
out, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "ipfs-shell: response (%d) read error: %s\n", resp.StatusCode, err)
|
||||
}
|
||||
@ -150,7 +149,7 @@ func (r *Request) Send(c *http.Client) (*Response, error) {
|
||||
nresp.Output = nil
|
||||
|
||||
// drain body and close
|
||||
_, _ = io.Copy(ioutil.Discard, resp.Body)
|
||||
_, _ = io.Copy(io.Discard, resp.Body)
|
||||
_ = resp.Body.Close()
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user