Skip to content

Commit

Permalink
clean io/util
Browse files Browse the repository at this point in the history
  • Loading branch information
oneplus1000 committed Aug 27, 2023
1 parent d6ac6c0 commit be1a680
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 33 deletions.
4 changes: 2 additions & 2 deletions embedfont_obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gopdf
import (
"fmt"
"io"
"io/ioutil"
"os"
)

// EmbedFontObj is an embedded font object.
Expand All @@ -23,7 +23,7 @@ func (e *EmbedFontObj) protection() *PDFProtection {
}

func (e *EmbedFontObj) write(w io.Writer, objID int) error {
b, err := ioutil.ReadFile(e.zfontpath)
b, err := os.ReadFile(e.zfontpath)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions examples/mask-image/example.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -34,7 +33,7 @@ func main() {
}

//image bytes
b, err := ioutil.ReadFile(resourcesPath + "/gopher01.jpg")
b, err := os.ReadFile(resourcesPath + "/gopher01.jpg")
if err != nil {
log.Panic(err.Error())
}
Expand Down
9 changes: 4 additions & 5 deletions fontmaker/core/fontmaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"compress/zlib"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -65,7 +64,7 @@ func (f *FontMaker) MakeFont(fontpath string, mappath string, encode string, out
var buff bytes.Buffer
gzipwriter := zlib.NewWriter(&buff)

fontbytes, err := ioutil.ReadFile(fontpath)
fontbytes, err := os.ReadFile(fontpath)
if err != nil {
return err
}
Expand All @@ -75,7 +74,7 @@ func (f *FontMaker) MakeFont(fontpath string, mappath string, encode string, out
return err
}
gzipwriter.Close()
err = ioutil.WriteFile(outfolderpath+"/"+gzfilename, buff.Bytes(), 0644)
err = os.WriteFile(outfolderpath+"/"+gzfilename, buff.Bytes(), 0644)
if err != nil {
return err
}
Expand Down Expand Up @@ -202,7 +201,7 @@ func (f *FontMaker) MakeDefinitionFile(gofontname string, mappath string, export
str += "\treturn me.family\n"
str += "}\n"

err = ioutil.WriteFile(exportfile, []byte(str), 0666)
err = os.WriteFile(exportfile, []byte(str), 0666)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -375,7 +374,7 @@ func (f *FontMaker) GetInfoFromTrueType(fontpath string, fontmaps []FontMap) (Tt

info := NewTtfInfo()

fileContent, err := ioutil.ReadFile(fontpath)
fileContent, err := os.ReadFile(fontpath)
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions fontmaker/core/ttfparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/binary"
"errors"
"io"
"io/ioutil"
"os"
"regexp"
"strconv"
Expand Down Expand Up @@ -204,7 +203,7 @@ func (t *TTFParser) SetUseKerning(use bool) {

// Parse parse
func (t *TTFParser) Parse(filepath string) error {
data, err := ioutil.ReadFile(filepath)
data, err := os.ReadFile(filepath)
if err != nil {
return err
}
Expand All @@ -213,7 +212,7 @@ func (t *TTFParser) Parse(filepath string) error {

// ParseByReader parse by io.reader
func (t *TTFParser) ParseByReader(rd io.Reader) error {
fontData, err := ioutil.ReadAll(rd)
fontData, err := io.ReadAll(rd)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions gopdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"image"
"image/png"
"io"
"io/ioutil"
"log"
"math"
"os"
Expand Down Expand Up @@ -949,7 +948,7 @@ func (gp *GoPdf) SetCharSpacing(charSpacing float64) error {

// WritePdf : write pdf file
func (gp *GoPdf) WritePdf(pdfPath string) error {
return ioutil.WriteFile(pdfPath, gp.GetBytesPdf(), 0644)
return os.WriteFile(pdfPath, gp.GetBytesPdf(), 0644)
}

// WriteTo implements the io.WriterTo interface and can
Expand Down Expand Up @@ -1600,7 +1599,7 @@ func (gp *GoPdf) AddTTFFontWithOption(family string, ttfpath string, option TtfO
if _, err := os.Stat(ttfpath); os.IsNotExist(err) {
return err
}
data, err := ioutil.ReadFile(ttfpath)
data, err := os.ReadFile(ttfpath)
if err != nil {
return err
}
Expand Down
18 changes: 9 additions & 9 deletions gopdf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gopdf
import (
"bytes"
"errors"
"io/ioutil"
"io"
"log"
"os"
"testing"
Expand Down Expand Up @@ -32,7 +32,7 @@ func BenchmarkPdfWithImageHolder(b *testing.B) {
return
}

bytesOfImg, err := ioutil.ReadFile("./test/res/chilli.jpg")
bytesOfImg, err := os.ReadFile("./test/res/chilli.jpg")
if err != nil {
b.Error(err)
return
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestPdfWithImageHolder(t *testing.T) {
pdf := setupDefaultA4PDF(t)
pdf.AddPage()

bytesOfImg, err := ioutil.ReadFile("./test/res/PNG_transparency_demonstration_1.png")
bytesOfImg, err := os.ReadFile("./test/res/PNG_transparency_demonstration_1.png")
if err != nil {
t.Error(err)
return
Expand Down Expand Up @@ -101,7 +101,7 @@ func TestRetrievingNumberOfPdfPage(t *testing.T) {
}
pdf.AddPage()

bytesOfImg, err := ioutil.ReadFile("./test/res/gopher01.jpg")
bytesOfImg, err := os.ReadFile("./test/res/gopher01.jpg")
if err != nil {
t.Error(err)
return
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestImageCrop(t *testing.T) {

pdf.AddPage()

bytesOfImg, err := ioutil.ReadFile("./test/res/gopher01.jpg")
bytesOfImg, err := os.ReadFile("./test/res/gopher01.jpg")
if err != nil {
t.Error(err)
return
Expand Down Expand Up @@ -210,7 +210,7 @@ func BenchmarkAddTTFFontByReader(b *testing.B) {
}
defer ttf.Close()

fontData, err := ioutil.ReadAll(ttf)
fontData, err := io.ReadAll(ttf)
if err != nil {
b.Error(err)
return
Expand Down Expand Up @@ -253,7 +253,7 @@ func BenchmarkAddTTFFontData(b *testing.B) {
}
defer ttf.Close()

fontData, err := ioutil.ReadAll(ttf)
fontData, err := io.ReadAll(ttf)
if err != nil {
b.Error(err)
return
Expand All @@ -276,7 +276,7 @@ func TestReuseFontData(t *testing.T) {
}
defer ttf.Close()

fontData, err := ioutil.ReadAll(ttf)
fontData, err := io.ReadAll(ttf)
if err != nil {
t.Error(err)
return
Expand Down Expand Up @@ -543,7 +543,7 @@ func TestClearValue(t *testing.T) {
return
}

bytesOfImg, err := ioutil.ReadFile("./test/res/PNG_transparency_demonstration_1.png")
bytesOfImg, err := os.ReadFile("./test/res/PNG_transparency_demonstration_1.png")
if err != nil {
t.Error(err)
return
Expand Down
6 changes: 3 additions & 3 deletions image_holder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"crypto/md5"
"fmt"
"io"
"io/ioutil"
"os"
)

// ImageHolder hold image data
Expand Down Expand Up @@ -50,7 +50,7 @@ func newImageBuff(b []byte) (*imageBuff, error) {
func newImageBuffByPath(path string) (*imageBuff, error) {
var i imageBuff
i.id = path
b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
if err != nil {
return nil, err
}
Expand All @@ -60,7 +60,7 @@ func newImageBuffByPath(path string) (*imageBuff, error) {

func newImageBuffByReader(r io.Reader) (*imageBuff, error) {

b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions image_obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"bytes"
"fmt"
"image"

// Packages image/jpeg and image/png are not used explicitly in the code below,
// but are imported for their initialization side-effect, which allows
// image.Decode to understand JPEG formatted images.
_ "image/jpeg"
_ "image/png"
"io"
"io/ioutil"
"log"
"os"
)
Expand Down Expand Up @@ -135,7 +135,7 @@ func (i *ImageObj) SetImagePath(path string) error {
// SetImage set image
func (i *ImageObj) SetImage(r io.Reader) error {

data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions image_obj_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"image"
"image/color"
"io"
"io/ioutil"
"os"
"strings"
)

Expand Down Expand Up @@ -125,7 +125,7 @@ func haveSMask(imginfo imgInfo) bool {
}

func parseImgByPath(path string) (imgInfo, error) {
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return imgInfo{}, err
}
Expand All @@ -149,7 +149,7 @@ func parseImg(raw *bytes.Reader) (imgInfo, error) {
return info, err
}
raw.Seek(0, 0)
info.data, err = ioutil.ReadAll(raw)
info.data, err = io.ReadAll(raw)
if err != nil {
return info, err
}
Expand Down Expand Up @@ -380,7 +380,7 @@ func parsePng(f *bytes.Reader, info *imgInfo, imgConfig image.Config) error {
return err
}
defer zipReader.Close()
afterZipData, err := ioutil.ReadAll(zipReader)
afterZipData, err := io.ReadAll(zipReader)
if err != nil {
return err
}
Expand Down

0 comments on commit be1a680

Please sign in to comment.