From 6ac7d2caee89cdfdb4f6c273a88d1173d234c21b Mon Sep 17 00:00:00 2001 From: dchapes Date: Sat, 11 Feb 2017 14:45:20 -0500 Subject: Accept interfaces where appropriate. (#103) * Accept interfaces where appropriate. `Fpdf.RawWriteBuf` only needs an `io.Reader`, it doesn't have to be a `bytes.Buffer`. The only reason I can see not to do this is to avoid the interface "boxing" if the caller is actually using a `bytes.Buffer`; however, since eventually this gets into `binary.Read` which takes an `io.Reader` the boxing will happen anyway (and possibly repeatedly if `readByte` gets called a number of times; I didn't bother to check). * Also use interface for segmentRead * Use read-only bytes.Reader instead of bytes.Buffer where appropriate. --- font.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'font.go') diff --git a/font.go b/font.go index 35f59f1..4d151c2 100644 --- a/font.go +++ b/font.go @@ -144,22 +144,22 @@ type segmentType struct { data []byte } -func segmentRead(f *os.File) (s segmentType, err error) { - if err = binary.Read(f, binary.LittleEndian, &s.marker); err != nil { +func segmentRead(r io.Reader) (s segmentType, err error) { + if err = binary.Read(r, binary.LittleEndian, &s.marker); err != nil { return } if s.marker != 128 { err = fmt.Errorf("font file is not a valid binary Type1") return } - if err = binary.Read(f, binary.LittleEndian, &s.tp); err != nil { + if err = binary.Read(r, binary.LittleEndian, &s.tp); err != nil { return } - if err = binary.Read(f, binary.LittleEndian, &s.size); err != nil { + if err = binary.Read(r, binary.LittleEndian, &s.size); err != nil { return } s.data = make([]byte, s.size) - _, err = f.Read(s.data) + _, err = r.Read(s.data) return } -- cgit v1.2.1-24-ge1ad