Skip to content

Commit b3584d3

Browse files
committed
all: replace io/ioutil with io and os package
Signed-off-by: cui fliter <imcusg@gmail.com>
1 parent c86fa9a commit b3584d3

30 files changed

+63
-88
lines changed

acme/autocert/autocert_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"crypto/x509/pkix"
1818
"encoding/asn1"
1919
"fmt"
20-
"io/ioutil"
20+
"io"
2121
"math/big"
2222
"net/http"
2323
"net/http/httptest"
@@ -941,7 +941,7 @@ func TestEndToEndALPN(t *testing.T) {
941941
t.Fatal(err)
942942
}
943943
defer res.Body.Close()
944-
b, err := ioutil.ReadAll(res.Body)
944+
b, err := io.ReadAll(res.Body)
945945
if err != nil {
946946
t.Fatal(err)
947947
}
@@ -995,7 +995,7 @@ func TestEndToEndHTTP(t *testing.T) {
995995
t.Fatal(err)
996996
}
997997
defer res.Body.Close()
998-
b, err := ioutil.ReadAll(res.Body)
998+
b, err := io.ReadAll(res.Body)
999999
if err != nil {
10001000
t.Fatal(err)
10011001
}

acme/autocert/cache.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package autocert
77
import (
88
"context"
99
"errors"
10-
"io/ioutil"
1110
"os"
1211
"path/filepath"
1312
)
@@ -48,7 +47,7 @@ func (d DirCache) Get(ctx context.Context, name string) ([]byte, error) {
4847
done = make(chan struct{})
4948
)
5049
go func() {
51-
data, err = ioutil.ReadFile(name)
50+
data, err = os.ReadFile(name)
5251
close(done)
5352
}()
5453
select {
@@ -119,7 +118,7 @@ func (d DirCache) Delete(ctx context.Context, name string) error {
119118
// writeTempFile writes b to a temporary file, closes the file and returns its path.
120119
func (d DirCache) writeTempFile(prefix string, b []byte) (name string, reterr error) {
121120
// TempFile uses 0600 permissions
122-
f, err := ioutil.TempFile(string(d), prefix)
121+
f, err := os.CreateTemp(string(d), prefix)
123122
if err != nil {
124123
return "", err
125124
}

acme/autocert/cache_test.go

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

77
import (
88
"context"
9-
"io/ioutil"
109
"os"
1110
"path/filepath"
1211
"reflect"
@@ -17,7 +16,7 @@ import (
1716
var _ Cache = DirCache("/")
1817

1918
func TestDirCache(t *testing.T) {
20-
dir, err := ioutil.TempDir("", "autocert")
19+
dir, err := os.MkdirTemp("", "autocert")
2120
if err != nil {
2221
t.Fatal(err)
2322
}

acme/http.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"encoding/json"
1313
"errors"
1414
"fmt"
15-
"io/ioutil"
15+
"io"
1616
"math/big"
1717
"net/http"
1818
"strconv"
@@ -310,7 +310,7 @@ func isRetriable(code int) bool {
310310
func responseError(resp *http.Response) error {
311311
// don't care if ReadAll returns an error:
312312
// json.Unmarshal will fail in that case anyway
313-
b, _ := ioutil.ReadAll(resp.Body)
313+
b, _ := io.ReadAll(resp.Body)
314314
e := &wireError{Status: resp.StatusCode}
315315
if err := json.Unmarshal(b, e); err != nil {
316316
// this is not a regular error response:

acme/http_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package acme
77
import (
88
"context"
99
"fmt"
10-
"io/ioutil"
10+
"io"
1111
"net/http"
1212
"net/http/httptest"
1313
"reflect"
@@ -54,7 +54,7 @@ func TestErrorResponse(t *testing.T) {
5454
res := &http.Response{
5555
StatusCode: 400,
5656
Status: "400 Bad Request",
57-
Body: ioutil.NopCloser(strings.NewReader(s)),
57+
Body: io.NopCloser(strings.NewReader(s)),
5858
Header: http.Header{"X-Foo": {"bar"}},
5959
}
6060
err := responseError(res)

acme/rfc8555.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"errors"
1414
"fmt"
1515
"io"
16-
"io/ioutil"
1716
"net/http"
1817
"time"
1918
)
@@ -390,7 +389,7 @@ func (c *Client) fetchCertRFC(ctx context.Context, url string, bundle bool) ([][
390389
// Get all the bytes up to a sane maximum.
391390
// Account very roughly for base64 overhead.
392391
const max = maxCertChainSize + maxCertChainSize/33
393-
b, err := ioutil.ReadAll(io.LimitReader(res.Body, max+1))
392+
b, err := io.ReadAll(io.LimitReader(res.Body, max+1))
394393
if err != nil {
395394
return nil, fmt.Errorf("acme: fetch cert response stream: %v", err)
396395
}
@@ -469,7 +468,7 @@ func (c *Client) ListCertAlternates(ctx context.Context, url string) ([]string,
469468

470469
// We don't need the body but we need to discard it so we don't end up
471470
// preventing keep-alive
472-
if _, err := io.Copy(ioutil.Discard, res.Body); err != nil {
471+
if _, err := io.Copy(io.Discard, res.Body); err != nil {
473472
return nil, fmt.Errorf("acme: cert alternates response stream: %v", err)
474473
}
475474
alts := linkHeader(res.Header, "alternate")

acme/rfc8555_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"encoding/pem"
1818
"errors"
1919
"fmt"
20-
"io/ioutil"
20+
"io"
2121
"math/big"
2222
"net/http"
2323
"net/http/httptest"
@@ -148,7 +148,7 @@ func TestRFC_postKID(t *testing.T) {
148148
w.Header().Set("Location", "/account-1")
149149
w.Write([]byte(`{"status":"valid"}`))
150150
case "/post":
151-
b, _ := ioutil.ReadAll(r.Body) // check err later in decodeJWSxxx
151+
b, _ := io.ReadAll(r.Body) // check err later in decodeJWSxxx
152152
head, err := decodeJWSHead(bytes.NewReader(b))
153153
if err != nil {
154154
t.Errorf("decodeJWSHead: %v", err)
@@ -194,7 +194,7 @@ func TestRFC_postKID(t *testing.T) {
194194
t.Fatal(err)
195195
}
196196
defer res.Body.Close()
197-
b, _ := ioutil.ReadAll(res.Body) // don't care about err - just checking b
197+
b, _ := io.ReadAll(res.Body) // don't care about err - just checking b
198198
if string(b) != "pong" {
199199
t.Errorf("res.Body = %q; want pong", b)
200200
}
@@ -297,7 +297,7 @@ func TestRFC_Register(t *testing.T) {
297297
"orders": %q
298298
}`, email, s.url("/accounts/1/orders"))
299299

300-
b, _ := ioutil.ReadAll(r.Body) // check err later in decodeJWSxxx
300+
b, _ := io.ReadAll(r.Body) // check err later in decodeJWSxxx
301301
head, err := decodeJWSHead(bytes.NewReader(b))
302302
if err != nil {
303303
t.Errorf("decodeJWSHead: %v", err)
@@ -528,7 +528,7 @@ func TestRFC_UpdateReg(t *testing.T) {
528528
w.WriteHeader(http.StatusOK)
529529
w.Write([]byte(`{"status": "valid"}`))
530530

531-
b, _ := ioutil.ReadAll(r.Body) // check err later in decodeJWSxxx
531+
b, _ := io.ReadAll(r.Body) // check err later in decodeJWSxxx
532532
head, err := decodeJWSHead(bytes.NewReader(b))
533533
if err != nil {
534534
t.Errorf("decodeJWSHead: %v", err)
@@ -668,7 +668,7 @@ func TestRFC_DeactivateReg(t *testing.T) {
668668
Orders: s.url("/accounts/1/orders"),
669669
})
670670

671-
b, _ := ioutil.ReadAll(r.Body) // check err later in decodeJWSxxx
671+
b, _ := io.ReadAll(r.Body) // check err later in decodeJWSxxx
672672
head, err := decodeJWSHead(bytes.NewReader(b))
673673
if err != nil {
674674
t.Errorf("decodeJWSHead: %v", err)
@@ -700,7 +700,7 @@ func TestRFC_DeactivateReg(t *testing.T) {
700700
})
701701
}
702702
var req account
703-
b, _ := ioutil.ReadAll(r.Body) // check err later in decodeJWSxxx
703+
b, _ := io.ReadAll(r.Body) // check err later in decodeJWSxxx
704704
head, err := decodeJWSHead(bytes.NewReader(b))
705705
if err != nil {
706706
t.Errorf("decodeJWSHead: %v", err)

internal/wycheproof/wycheproof_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"encoding/hex"
1313
"encoding/json"
1414
"fmt"
15-
"io/ioutil"
1615
"log"
1716
"os"
1817
"os/exec"
@@ -62,7 +61,7 @@ func TestMain(m *testing.M) {
6261
}
6362

6463
func readTestVector(t *testing.T, f string, dest interface{}) {
65-
b, err := ioutil.ReadFile(filepath.Join(wycheproofTestVectorsDir, f))
64+
b, err := os.ReadFile(filepath.Join(wycheproofTestVectorsDir, f))
6665
if err != nil {
6766
t.Fatalf("failed to read json file: %v", err)
6867
}

openpgp/armor/armor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package armor
77
import (
88
"bytes"
99
"hash/adler32"
10-
"io/ioutil"
10+
"io"
1111
"testing"
1212
)
1313

@@ -29,7 +29,7 @@ func TestDecodeEncode(t *testing.T) {
2929
t.Errorf("result.Header: got:%#v", result.Header)
3030
}
3131

32-
contents, err := ioutil.ReadAll(result.Body)
32+
contents, err := io.ReadAll(result.Body)
3333
if err != nil {
3434
t.Error(err)
3535
}

openpgp/packet/compressed_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"bytes"
99
"encoding/hex"
1010
"io"
11-
"io/ioutil"
1211
"testing"
1312
)
1413

@@ -25,7 +24,7 @@ func TestCompressed(t *testing.T) {
2524
return
2625
}
2726

28-
contents, err := ioutil.ReadAll(c.Body)
27+
contents, err := io.ReadAll(c.Body)
2928
if err != nil && err != io.EOF {
3029
t.Error(err)
3130
return

0 commit comments

Comments
 (0)