Skip to content

Commit

Permalink
Replaced deprecated io/ioutil package with proper implementations of …
Browse files Browse the repository at this point in the history
…io/os packages.

As of Go v1.16, the io/ioutil package has been deprecated and replaced with io and os implementations.
https://go.dev/doc/go1.16#ioutil
  • Loading branch information
zachary-walters committed Oct 3, 2023
1 parent a6e3d81 commit e35529d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
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)
}

0 comments on commit e35529d

Please sign in to comment.