Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced deprecated io/ioutil package with proper implementations of … #785

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _examples/factba.se/factbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strconv"

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

stop := false
Expand Down
4 changes: 2 additions & 2 deletions _examples/multipart/multipart.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"time"
Expand All @@ -14,7 +14,7 @@ func generateFormData() map[string][]byte {
f, _ := os.Open("gocolly.jpg")
defer f.Close()

imgData, _ := ioutil.ReadAll(f)
imgData, _ := io.ReadAll(f)

return map[string][]byte{
"firstname": []byte("one"),
Expand Down
3 changes: 1 addition & 2 deletions http_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"encoding/gob"
"encoding/hex"
"io"
"io/ioutil"
"math/rand"
"net/http"
"os"
Expand Down Expand Up @@ -209,7 +208,7 @@ func (h *httpBackend) Do(request *http.Request, bodySize int, checkHeadersFunc c
}
defer bodyReader.(*gzip.Reader).Close()
}
body, err := ioutil.ReadAll(bodyReader)
body, err := io.ReadAll(bodyReader)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -173,7 +172,7 @@ func (r *Request) Marshal() ([]byte, error) {
var err error
var body []byte
if r.Body != nil {
body, err = ioutil.ReadAll(r.Body)
body, err = io.ReadAll(r.Body)
if err != nil {
return nil, err
}
Expand Down
7 changes: 4 additions & 3 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ package colly
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"mime"
"net/http"
"os"
"strings"

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

// Save writes response body to disk
func (r *Response) Save(fileName string) error {
return ioutil.WriteFile(fileName, r.Body, 0644)
return os.WriteFile(fileName, r.Body, 0644)
}

// FileName returns the sanitized file name parsed from "Content-Disposition"
Expand Down Expand Up @@ -111,5 +112,5 @@ func encodeBytes(b []byte, contentType string) ([]byte, error) {
if err != nil {
return nil, err
}
return ioutil.ReadAll(r)
return io.ReadAll(r)
}
Loading