pdfcpu / pdfcpu

A PDF processor written in Go.

Home Page:http://pdfcpu.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Avoid unnecessary copying with filters.

fancycode opened this issue · comments

The filters usually return a *bytes.Buffer, so copying it into a temporary bytes.Buffer to get the underlying []byte can be avoided.

Example:

var buf bytes.Buffer
if _, err := io.Copy(&buf, c); err != nil {
return err
}
sd.Content = buf.Bytes()

Same applies for the filters itself which can be chained and in such casees also don't need to copy from the passed io.Reader if it is actually a *bytes.Buffer.