all: remove refs to deprecated io/ioutil (#140)

This commit is contained in:
guangwu
2023-09-13 12:33:58 +08:00
committed by GitHub
parent a3b1ff20f3
commit a000b5d069
13 changed files with 20 additions and 30 deletions
+1 -2
View File
@@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
@@ -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)
+1 -2
View File
@@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"strings"
@@ -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)
}
+1 -2
View File
@@ -6,7 +6,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"os"
"time"
)
@@ -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
}
+2 -2
View File
@@ -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
+2 -2
View File
@@ -3,7 +3,7 @@ package html_test
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"testing"
"github.com/google/go-cmp/cmp"
@@ -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)
+1 -2
View File
@@ -3,7 +3,6 @@ package docconv
import (
"fmt"
"io"
"io/ioutil"
"os"
)
@@ -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)
}
+1 -2
View File
@@ -5,7 +5,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"time"
)
@@ -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
}
+2 -3
View File
@@ -7,7 +7,6 @@ import (
"encoding/binary"
"fmt"
"io"
"io/ioutil"
"strings"
"google.golang.org/protobuf/proto"
@@ -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)
}
@@ -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)
+1 -2
View File
@@ -6,7 +6,6 @@ package docconv
import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
@@ -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
+1 -2
View File
@@ -5,7 +5,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"strings"
)
@@ -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
}
+2 -2
View File
@@ -2,7 +2,7 @@ package rtf_test
import (
"bytes"
"io/ioutil"
"os"
"strings"
"testing"
@@ -10,7 +10,7 @@ import (
)
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)
}
+4 -5
View File
@@ -9,7 +9,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net/http"
"os"
@@ -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)
}
@@ -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 {
@@ -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
@@ -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)
}
+1 -2
View File
@@ -2,7 +2,6 @@ package docconv
import (
"io"
"io/ioutil"
"os"
"os/exec"
)
@@ -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
}