Skip to content

Commit

Permalink
Merge pull request #316 from nobe4/fix-deprecated-ioutil
Browse files Browse the repository at this point in the history
fix(ioutil): transition deprecated methods
  • Loading branch information
tdewolff authored Oct 15, 2024
2 parents d601972 + b2044d5 commit 32ed0a3
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 19 deletions.
4 changes: 2 additions & 2 deletions canvas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ func TestCanvas(t *testing.T) {
//buf.Reset()
//pdfCompress = false
//c.WritePDF(buf)
//ioutil.WriteFile("test/canvas.pdf", buf.Bytes(), 0644)
//os.WriteFile("test/canvas.pdf", buf.Bytes(), 0644)
//s = regexp.MustCompile(`stream\nx(.|\n)+\nendstream\n`).ReplaceAllString(buf.String(), "stream\n\nendstream\n") // remove embedded font
//test.String(t, s, "%PDF-1.7\n1 0 obj\n<< /Subtype /TrueType /Filter /FlateDecode /Length 215980 >> stream\n\nendstream\nendobj\n5 0 obj\n<< /Type /Page /Contents 4 0 R /Group << /Type /Group /CS /DeviceRGB /I true /S /Transparency >> /MediaBox [0 0 60 93] /Parent 5 0 R /Resources << /Font << /F0 2 0 R >> /XObject << /Im0 3 0 R >> >> >>\nendobj\n6 0 obj\n<< /Type /Pages /Count 1 /Kids [5 0 R] >>\nendobj\n7 0 obj\n<< /Type /Catalog /Pages 6 0 R >>\nendobj\nxref\n0 8\n0000000000 65535 f\n0000000009 00000 n\n0000216083 00000 n\n0000227285 00000 n\n0000227491 00000 n\n0000227888 00000 n\n0000228104 00000 n\n0000228161 00000 n\ntrailer\n<< /Root 7 0 R /Size 7 >>\nstarxref\n228210\n%%EOF")

//buf.Reset()
//c.WriteEPS(buf)
//ioutil.WriteFile("test/canvas.eps", buf.Bytes(), 0644)
//os.WriteFile("test/canvas.eps", buf.Bytes(), 0644)
// TODO: test EPS when fully supported
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/pdftext/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/hex"
"fmt"
"io"
"io/ioutil"

"github.com/tdewolff/parse/v2/strconv"
)
Expand All @@ -31,7 +30,7 @@ type pdfReader struct {
}

func NewPDFReader(reader io.Reader, password string) (*pdfReader, error) {
data, err := ioutil.ReadAll(reader)
data, err := io.ReadAll(reader)
if err != nil {
return nil, err
} else if len(data) < 8 || !bytes.Equal(data[:7], []byte("%PDF-1.")) || data[7] < '0' || '7' < data[7] {
Expand Down
3 changes: 1 addition & 2 deletions examples/go-chart/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"io/ioutil"
"os"
"time"

Expand All @@ -15,7 +14,7 @@ import (
func main() {
xv, yv := xvalues(), yvalues()

dejavu, err := ioutil.ReadFile("../../resources/DejaVuSerif.ttf")
dejavu, err := os.ReadFile("../../resources/DejaVuSerif.ttf")
if err != nil {
panic(err)
}
Expand Down
15 changes: 8 additions & 7 deletions examples/html-canvas/files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions font.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package canvas
import (
"fmt"
"image/color"
"io/ioutil"
"log"
"math"
"os"
Expand Down Expand Up @@ -253,7 +252,7 @@ func LoadSystemFont(name string, style FontStyle) (*Font, error) {

// LoadFontFile loads a font from a file.
func LoadFontFile(filename string, style FontStyle) (*Font, error) {
b, err := ioutil.ReadFile(filename)
b, err := os.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("failed to load font file '%s': %w", filename, err)
}
Expand All @@ -262,7 +261,7 @@ func LoadFontFile(filename string, style FontStyle) (*Font, error) {

// LoadFontCollection loads a font from a collection file and uses the font at the specified index.
func LoadFontCollection(filename string, index int, style FontStyle) (*Font, error) {
b, err := ioutil.ReadFile(filename)
b, err := os.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("failed to load font file '%s': %w", filename, err)
}
Expand Down
5 changes: 2 additions & 3 deletions preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"image/color"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand All @@ -17,7 +16,7 @@ func loadFont(name string, style FontStyle) ([]byte, error) {
if !ok {
return nil, fmt.Errorf("failed to find font '%s'", name)
}
return ioutil.ReadFile(filename)
return os.ReadFile(filename)
}

// DrawPreview draws the canvas's preview to a Context.
Expand All @@ -40,7 +39,7 @@ func DrawPreview(ctx *Context) error {
if err != nil {
return err
}
lenna, err := ioutil.ReadFile(filepath.Join(root, "resources/lenna.png"))
lenna, err := os.ReadFile(filepath.Join(root, "resources/lenna.png"))
if err != nil {
return err
}
Expand Down

0 comments on commit 32ed0a3

Please sign in to comment.