Skip to content

Commit

Permalink
all: remove refs to deprecated io/ioutil (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
testwill authored Sep 13, 2023
1 parent a3b1ff2 commit a000b5d
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 30 deletions.
3 changes: 1 addition & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -77,7 +76,7 @@ func ConvertDoc(r io.Reader) (string, map[string]string, error) {

// Save output to a file
var buf bytes.Buffer
outputFile, err := ioutil.TempFile("/tmp", "sajari-convert-")
outputFile, err := os.CreateTemp("/tmp", "sajari-convert-")
if err != nil {
// TODO: Remove this.
log.Println("TempFile Out:", err)
Expand Down
3 changes: 1 addition & 2 deletions docconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"strings"
Expand Down Expand Up @@ -98,7 +97,7 @@ func Convert(r io.Reader, mimeType string, readability bool) (*Response, error)

case "text/plain":
var b []byte
b, err = ioutil.ReadAll(r)
b, err = io.ReadAll(r)
body = string(b)
}

Expand Down
3 changes: 1 addition & 2 deletions docx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"os"
"time"
)
Expand Down Expand Up @@ -40,7 +39,7 @@ func ConvertDocx(r io.Reader) (string, map[string]string, error) {
size = si.Size()
ra = f
} else {
b, err := ioutil.ReadAll(io.LimitReader(r, maxBytes))
b, err := io.ReadAll(io.LimitReader(r, maxBytes))
if err != nil {
return "", nil, nil
}
Expand Down
4 changes: 2 additions & 2 deletions html_appengine.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//go:build appengine
// +build appengine

package docconv

import (
"io"
"io/ioutil"
"log"
)

func HTMLReadability(r io.Reader) []byte {
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
log.Printf("HTMLReadability: %v", err)
return nil
Expand Down
4 changes: 2 additions & 2 deletions html_test/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package html_test
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -39,7 +39,7 @@ This is a full sentence.
})
docconv.HTMLReadabilityOptionsValues.ReadabilityUseClasses = tt.readabilityUseClasses

data, err := ioutil.ReadFile("testdata/test.html")
data, err := os.ReadFile("testdata/test.html")
must(t, err)
got, _, err := docconv.ConvertHTML(bytes.NewReader(data), true)
must(t, err)
Expand Down
3 changes: 1 addition & 2 deletions local.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package docconv
import (
"fmt"
"io"
"io/ioutil"
"os"
)

Expand All @@ -25,7 +24,7 @@ func NewLocalFile(r io.Reader) (*LocalFile, error) {
}, nil
}

f, err := ioutil.TempFile(os.TempDir(), "docconv")
f, err := os.CreateTemp(os.TempDir(), "docconv")
if err != nil {
return nil, fmt.Errorf("error creating temporary file: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions odt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"time"
)

Expand All @@ -14,7 +13,7 @@ func ConvertODT(r io.Reader) (string, map[string]string, error) {
meta := make(map[string]string)
var textBody string

b, err := ioutil.ReadAll(io.LimitReader(r, maxBytes))
b, err := io.ReadAll(io.LimitReader(r, maxBytes))
if err != nil {
return "", nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/binary"
"fmt"
"io"
"io/ioutil"
"strings"

"google.golang.org/protobuf/proto"
Expand All @@ -21,7 +20,7 @@ func ConvertPages(r io.Reader) (string, map[string]string, error) {
meta := make(map[string]string)
var textBody string

b, err := ioutil.ReadAll(io.LimitReader(r, maxBytes))
b, err := io.ReadAll(io.LimitReader(r, maxBytes))
if err != nil {
return "", nil, fmt.Errorf("error reading data: %v", err)
}
Expand Down Expand Up @@ -57,7 +56,7 @@ func ConvertPages(r io.Reader) (string, map[string]string, error) {
// Ignore error.
// NOTE: This error was unchecked. Need to revisit this to see if it
// should be acted on.
archiveInfoData, _ := ioutil.ReadAll(io.LimitReader(bReader, archiveLength))
archiveInfoData, _ := io.ReadAll(io.LimitReader(bReader, archiveLength))

archiveInfo := &TSP.ArchiveInfo{}
err = proto.Unmarshal(archiveInfoData, archiveInfo)
Expand Down
3 changes: 1 addition & 2 deletions pdf_ocr.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package docconv
import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -39,7 +38,7 @@ func cleanupTemp(tmpDir string) {
func ConvertPDFImages(path string) (BodyResult, error) {
bodyResult := BodyResult{}

tmp, err := ioutil.TempDir(os.TempDir(), "tmp-imgs-")
tmp, err := os.MkdirTemp(os.TempDir(), "tmp-imgs-")
if err != nil {
bodyResult.err = err
return bodyResult, err
Expand Down
3 changes: 1 addition & 2 deletions pptx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"strings"
)
Expand All @@ -28,7 +27,7 @@ func ConvertPptx(r io.Reader) (string, map[string]string, error) {
size = si.Size()
ra = f
} else {
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return "", nil, nil
}
Expand Down
4 changes: 2 additions & 2 deletions rtf_test/rtf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package rtf_test

import (
"bytes"
"io/ioutil"
"os"
"strings"
"testing"

"code.sajari.com/docconv"
)

func TestConvertRTF(t *testing.T) {
data, err := ioutil.ReadFile("testdata/test.rtf")
data, err := os.ReadFile("testdata/test.rtf")
if err != nil {
t.Fatalf("got error %v, want nil", err)
}
Expand Down
9 changes: 4 additions & 5 deletions snappy/snappy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net/http"
"os"
Expand Down Expand Up @@ -119,7 +118,7 @@ func TestFramingFormat(t *testing.T) {
if _, err := NewWriter(buf).Write(src); err != nil {
t.Fatalf("Write: encoding: %v", err)
}
dst, err := ioutil.ReadAll(NewReader(buf))
dst, err := io.ReadAll(NewReader(buf))
if err != nil {
t.Fatalf("ReadAll: decoding: %v", err)
}
Expand Down Expand Up @@ -149,7 +148,7 @@ func TestReaderReset(t *testing.T) {
continue
}
r.Reset(strings.NewReader(s))
got, err := ioutil.ReadAll(r)
got, err := io.ReadAll(r)
switch s {
case encoded:
if err != nil {
Expand Down Expand Up @@ -186,7 +185,7 @@ func TestWriterReset(t *testing.T) {
failed = true
continue
}
got, err := ioutil.ReadAll(NewReader(buf))
got, err := io.ReadAll(NewReader(buf))
if err != nil {
t.Errorf("#%d: ReadAll: %v", i, err)
failed = true
Expand Down Expand Up @@ -229,7 +228,7 @@ func benchEncode(b *testing.B, src []byte) {
}

func readFile(b testing.TB, filename string) []byte {
src, err := ioutil.ReadFile(filename)
src, err := os.ReadFile(filename)
if err != nil {
b.Fatalf("failed reading %s: %s", filename, err)
}
Expand Down
3 changes: 1 addition & 2 deletions tidy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package docconv

import (
"io"
"io/ioutil"
"os"
"os/exec"
)
Expand All @@ -11,7 +10,7 @@ import (
// Errors & warnings are deliberately suppressed as underlying tools
// throw warnings very easily.
func Tidy(r io.Reader, xmlIn bool) ([]byte, error) {
f, err := ioutil.TempFile(os.TempDir(), "docconv")
f, err := os.CreateTemp(os.TempDir(), "docconv")
if err != nil {
return nil, err
}
Expand Down

0 comments on commit a000b5d

Please sign in to comment.