Skip to content

Commit c853cea

Browse files
authored
Merge pull request #785 from zachary-walters/replace-deprecated-ioutil-module
Replaced deprecated io/ioutil package with proper implementations of …
2 parents a6e3d81 + e35529d commit c853cea

File tree

5 files changed

+10
-11
lines changed

5 files changed

+10
-11
lines changed

_examples/factba.se/factbase.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
6+
"os"
77
"strconv"
88

99
"github.com/gocolly/colly/v2"
@@ -45,7 +45,7 @@ func main() {
4545
if err != nil {
4646
return
4747
}
48-
ioutil.WriteFile(colly.SanitizeFileName(e.Request.Ctx.Get("date")+"_"+e.Request.Ctx.Get("slug"))+".json", jsonData, 0644)
48+
os.WriteFile(colly.SanitizeFileName(e.Request.Ctx.Get("date")+"_"+e.Request.Ctx.Get("slug"))+".json", jsonData, 0644)
4949
})
5050

5151
stop := false

_examples/multipart/multipart.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package main
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"io"
66
"net/http"
77
"os"
88
"time"
@@ -14,7 +14,7 @@ func generateFormData() map[string][]byte {
1414
f, _ := os.Open("gocolly.jpg")
1515
defer f.Close()
1616

17-
imgData, _ := ioutil.ReadAll(f)
17+
imgData, _ := io.ReadAll(f)
1818

1919
return map[string][]byte{
2020
"firstname": []byte("one"),

http_backend.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"encoding/gob"
2020
"encoding/hex"
2121
"io"
22-
"io/ioutil"
2322
"math/rand"
2423
"net/http"
2524
"os"
@@ -209,7 +208,7 @@ func (h *httpBackend) Do(request *http.Request, bodySize int, checkHeadersFunc c
209208
}
210209
defer bodyReader.(*gzip.Reader).Close()
211210
}
212-
body, err := ioutil.ReadAll(bodyReader)
211+
body, err := io.ReadAll(bodyReader)
213212
if err != nil {
214213
return nil, err
215214
}

request.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"bytes"
1919
"encoding/json"
2020
"io"
21-
"io/ioutil"
2221
"net/http"
2322
"net/url"
2423
"strings"
@@ -173,7 +172,7 @@ func (r *Request) Marshal() ([]byte, error) {
173172
var err error
174173
var body []byte
175174
if r.Body != nil {
176-
body, err = ioutil.ReadAll(r.Body)
175+
body, err = io.ReadAll(r.Body)
177176
if err != nil {
178177
return nil, err
179178
}

response.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ package colly
1717
import (
1818
"bytes"
1919
"fmt"
20-
"io/ioutil"
20+
"io"
2121
"mime"
2222
"net/http"
23+
"os"
2324
"strings"
2425

2526
"github.com/saintfish/chardet"
@@ -45,7 +46,7 @@ type Response struct {
4546

4647
// Save writes response body to disk
4748
func (r *Response) Save(fileName string) error {
48-
return ioutil.WriteFile(fileName, r.Body, 0644)
49+
return os.WriteFile(fileName, r.Body, 0644)
4950
}
5051

5152
// FileName returns the sanitized file name parsed from "Content-Disposition"
@@ -111,5 +112,5 @@ func encodeBytes(b []byte, contentType string) ([]byte, error) {
111112
if err != nil {
112113
return nil, err
113114
}
114-
return ioutil.ReadAll(r)
115+
return io.ReadAll(r)
115116
}

0 commit comments

Comments
 (0)