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" "bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
"os" "os"
"os/exec" "os/exec"
@@ -77,7 +76,7 @@ func ConvertDoc(r io.Reader) (string, map[string]string, error) {
// Save output to a file // Save output to a file
var buf bytes.Buffer var buf bytes.Buffer
outputFile, err := ioutil.TempFile("/tmp", "sajari-convert-") outputFile, err := os.CreateTemp("/tmp", "sajari-convert-")
if err != nil { if err != nil {
// TODO: Remove this. // TODO: Remove this.
log.Println("TempFile Out:", err) log.Println("TempFile Out:", err)
+1 -2
View File
@@ -4,7 +4,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path" "path"
"strings" "strings"
@@ -98,7 +97,7 @@ func Convert(r io.Reader, mimeType string, readability bool) (*Response, error)
case "text/plain": case "text/plain":
var b []byte var b []byte
b, err = ioutil.ReadAll(r) b, err = io.ReadAll(r)
body = string(b) body = string(b)
} }
+1 -2
View File
@@ -6,7 +6,6 @@ import (
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"time" "time"
) )
@@ -40,7 +39,7 @@ func ConvertDocx(r io.Reader) (string, map[string]string, error) {
size = si.Size() size = si.Size()
ra = f ra = f
} else { } else {
b, err := ioutil.ReadAll(io.LimitReader(r, maxBytes)) b, err := io.ReadAll(io.LimitReader(r, maxBytes))
if err != nil { if err != nil {
return "", nil, nil return "", nil, nil
} }
+2 -2
View File
@@ -1,15 +1,15 @@
//go:build appengine
// +build appengine // +build appengine
package docconv package docconv
import ( import (
"io" "io"
"io/ioutil"
"log" "log"
) )
func HTMLReadability(r io.Reader) []byte { func HTMLReadability(r io.Reader) []byte {
b, err := ioutil.ReadAll(r) b, err := io.ReadAll(r)
if err != nil { if err != nil {
log.Printf("HTMLReadability: %v", err) log.Printf("HTMLReadability: %v", err)
return nil return nil
+2 -2
View File
@@ -3,7 +3,7 @@ package html_test
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil" "os"
"testing" "testing"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
@@ -39,7 +39,7 @@ This is a full sentence.
}) })
docconv.HTMLReadabilityOptionsValues.ReadabilityUseClasses = tt.readabilityUseClasses docconv.HTMLReadabilityOptionsValues.ReadabilityUseClasses = tt.readabilityUseClasses
data, err := ioutil.ReadFile("testdata/test.html") data, err := os.ReadFile("testdata/test.html")
must(t, err) must(t, err)
got, _, err := docconv.ConvertHTML(bytes.NewReader(data), true) got, _, err := docconv.ConvertHTML(bytes.NewReader(data), true)
must(t, err) must(t, err)
+1 -2
View File
@@ -3,7 +3,6 @@ package docconv
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
) )
@@ -25,7 +24,7 @@ func NewLocalFile(r io.Reader) (*LocalFile, error) {
}, nil }, nil
} }
f, err := ioutil.TempFile(os.TempDir(), "docconv") f, err := os.CreateTemp(os.TempDir(), "docconv")
if err != nil { if err != nil {
return nil, fmt.Errorf("error creating temporary file: %v", err) return nil, fmt.Errorf("error creating temporary file: %v", err)
} }
+1 -2
View File
@@ -5,7 +5,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"time" "time"
) )
@@ -14,7 +13,7 @@ func ConvertODT(r io.Reader) (string, map[string]string, error) {
meta := make(map[string]string) meta := make(map[string]string)
var textBody string var textBody string
b, err := ioutil.ReadAll(io.LimitReader(r, maxBytes)) b, err := io.ReadAll(io.LimitReader(r, maxBytes))
if err != nil { if err != nil {
return "", nil, err return "", nil, err
} }
+2 -3
View File
@@ -7,7 +7,6 @@ import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"strings" "strings"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
@@ -21,7 +20,7 @@ func ConvertPages(r io.Reader) (string, map[string]string, error) {
meta := make(map[string]string) meta := make(map[string]string)
var textBody string var textBody string
b, err := ioutil.ReadAll(io.LimitReader(r, maxBytes)) b, err := io.ReadAll(io.LimitReader(r, maxBytes))
if err != nil { if err != nil {
return "", nil, fmt.Errorf("error reading data: %v", err) 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. // Ignore error.
// NOTE: This error was unchecked. Need to revisit this to see if it // NOTE: This error was unchecked. Need to revisit this to see if it
// should be acted on. // should be acted on.
archiveInfoData, _ := ioutil.ReadAll(io.LimitReader(bReader, archiveLength)) archiveInfoData, _ := io.ReadAll(io.LimitReader(bReader, archiveLength))
archiveInfo := &TSP.ArchiveInfo{} archiveInfo := &TSP.ArchiveInfo{}
err = proto.Unmarshal(archiveInfoData, archiveInfo) err = proto.Unmarshal(archiveInfoData, archiveInfo)
+1 -2
View File
@@ -6,7 +6,6 @@ package docconv
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
"os" "os"
"os/exec" "os/exec"
@@ -39,7 +38,7 @@ func cleanupTemp(tmpDir string) {
func ConvertPDFImages(path string) (BodyResult, error) { func ConvertPDFImages(path string) (BodyResult, error) {
bodyResult := BodyResult{} bodyResult := BodyResult{}
tmp, err := ioutil.TempDir(os.TempDir(), "tmp-imgs-") tmp, err := os.MkdirTemp(os.TempDir(), "tmp-imgs-")
if err != nil { if err != nil {
bodyResult.err = err bodyResult.err = err
return bodyResult, err return bodyResult, err
+1 -2
View File
@@ -5,7 +5,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"strings" "strings"
) )
@@ -28,7 +27,7 @@ func ConvertPptx(r io.Reader) (string, map[string]string, error) {
size = si.Size() size = si.Size()
ra = f ra = f
} else { } else {
b, err := ioutil.ReadAll(r) b, err := io.ReadAll(r)
if err != nil { if err != nil {
return "", nil, nil return "", nil, nil
} }
+2 -2
View File
@@ -2,7 +2,7 @@ package rtf_test
import ( import (
"bytes" "bytes"
"io/ioutil" "os"
"strings" "strings"
"testing" "testing"
@@ -10,7 +10,7 @@ import (
) )
func TestConvertRTF(t *testing.T) { func TestConvertRTF(t *testing.T) {
data, err := ioutil.ReadFile("testdata/test.rtf") data, err := os.ReadFile("testdata/test.rtf")
if err != nil { if err != nil {
t.Fatalf("got error %v, want nil", err) t.Fatalf("got error %v, want nil", err)
} }
+4 -5
View File
@@ -9,7 +9,6 @@ import (
"flag" "flag"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"net/http" "net/http"
"os" "os"
@@ -119,7 +118,7 @@ func TestFramingFormat(t *testing.T) {
if _, err := NewWriter(buf).Write(src); err != nil { if _, err := NewWriter(buf).Write(src); err != nil {
t.Fatalf("Write: encoding: %v", err) t.Fatalf("Write: encoding: %v", err)
} }
dst, err := ioutil.ReadAll(NewReader(buf)) dst, err := io.ReadAll(NewReader(buf))
if err != nil { if err != nil {
t.Fatalf("ReadAll: decoding: %v", err) t.Fatalf("ReadAll: decoding: %v", err)
} }
@@ -149,7 +148,7 @@ func TestReaderReset(t *testing.T) {
continue continue
} }
r.Reset(strings.NewReader(s)) r.Reset(strings.NewReader(s))
got, err := ioutil.ReadAll(r) got, err := io.ReadAll(r)
switch s { switch s {
case encoded: case encoded:
if err != nil { if err != nil {
@@ -186,7 +185,7 @@ func TestWriterReset(t *testing.T) {
failed = true failed = true
continue continue
} }
got, err := ioutil.ReadAll(NewReader(buf)) got, err := io.ReadAll(NewReader(buf))
if err != nil { if err != nil {
t.Errorf("#%d: ReadAll: %v", i, err) t.Errorf("#%d: ReadAll: %v", i, err)
failed = true failed = true
@@ -229,7 +228,7 @@ func benchEncode(b *testing.B, src []byte) {
} }
func readFile(b testing.TB, filename string) []byte { func readFile(b testing.TB, filename string) []byte {
src, err := ioutil.ReadFile(filename) src, err := os.ReadFile(filename)
if err != nil { if err != nil {
b.Fatalf("failed reading %s: %s", filename, err) b.Fatalf("failed reading %s: %s", filename, err)
} }
+1 -2
View File
@@ -2,7 +2,6 @@ package docconv
import ( import (
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
) )
@@ -11,7 +10,7 @@ import (
// Errors & warnings are deliberately suppressed as underlying tools // Errors & warnings are deliberately suppressed as underlying tools
// throw warnings very easily. // throw warnings very easily.
func Tidy(r io.Reader, xmlIn bool) ([]byte, error) { 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 { if err != nil {
return nil, err return nil, err
} }