summaryrefslogtreecommitdiff
path: root/fpdf.go
diff options
context:
space:
mode:
authordchapes <dchapes@users.noreply.github.com>2017-02-11 14:45:20 -0500
committerKurt Jung <kurt.w.jung@gmail.com>2017-02-11 14:45:20 -0500
commit6ac7d2caee89cdfdb4f6c273a88d1173d234c21b (patch)
tree755bc42811eaa0654b1550a09975013c106c0ea5 /fpdf.go
parent328db88096525175c22c4337b54cc9d809332c4a (diff)
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.
Diffstat (limited to 'fpdf.go')
-rw-r--r--fpdf.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/fpdf.go b/fpdf.go
index 6ca64c6..8ab2339 100644
--- a/fpdf.go
+++ b/fpdf.go
@@ -2897,16 +2897,16 @@ func (f *Fpdf) parsepng(r io.Reader, readdpi bool) (info *ImageInfoType) {
return f.parsepngstream(buf, readdpi)
}
-func (f *Fpdf) readBeInt32(buf *bytes.Buffer) (val int32) {
- err := binary.Read(buf, binary.BigEndian, &val)
+func (f *Fpdf) readBeInt32(r io.Reader) (val int32) {
+ err := binary.Read(r, binary.BigEndian, &val)
if err != nil {
f.err = err
}
return
}
-func (f *Fpdf) readByte(buf *bytes.Buffer) (val byte) {
- err := binary.Read(buf, binary.BigEndian, &val)
+func (f *Fpdf) readByte(r io.Reader) (val byte) {
+ err := binary.Read(r, binary.BigEndian, &val)
if err != nil {
f.err = err
}
@@ -2968,12 +2968,12 @@ func (f *Fpdf) out(s string) {
}
// Add a buffered line to the document
-func (f *Fpdf) outbuf(b *bytes.Buffer) {
+func (f *Fpdf) outbuf(r io.Reader) {
if f.state == 2 {
- f.pages[f.page].ReadFrom(b)
+ f.pages[f.page].ReadFrom(r)
f.pages[f.page].WriteString("\n")
} else {
- f.buffer.ReadFrom(b)
+ f.buffer.ReadFrom(r)
f.buffer.WriteString("\n")
}
}
@@ -2990,8 +2990,8 @@ func (f *Fpdf) RawWriteStr(str string) {
// generation buffer. This is a low-level function that is not required for
// normal PDF construction. An understanding of the PDF specification is needed
// to use this method correctly.
-func (f *Fpdf) RawWriteBuf(buf *bytes.Buffer) {
- f.outbuf(buf)
+func (f *Fpdf) RawWriteBuf(r io.Reader) {
+ f.outbuf(r)
}
// Add a formatted line to the document