prawnpdf/prawn — pull request #587 by fidothe (2013-11-24 12:30:04+00:00)
Title: Refactor so images via Pathname are read in binmode

* Separate out image IO opening and verification logic
* test that embedded images parse correctly (this was the problem that
was being masked before)
* Add simple matcher to tidy up checking XObject parseability
* fixes #570:
* don't rely on binmode being defined on IO-like objects (re: #585)

Pathname instances respond to #read but not #binmode, and the old code
was assuming that anything which responded to #read was an IO, with the
result that Pathname instances were beign treated as IO's and getting
read called on them, bypassing File.binread (things responding
to #binmode have that called so with a real IO it would have #read
called after it had been put into binmode...

The fix is simple enough: treat everything that responds to `rewind` as
an IO (IO's and Files), and anything else treat as a path, and open it
'rb'.

The call to `#binmode` is guarded because of #585, and the chances of other
IO-alikes not implementing binmode either.