class PDF::Reader::XRef

def calc_junk_offset(io)


header appear somewhere within the first 1024 bytes of the file
Adobe PDF 1.4 spec (3.4.1) 12. Acrobat viewers require only that the
returns nil if no PDF data detected.
Checks up to 1024 chars into the file,

in the real world.
should always be 0, but all sort of crazy junk is prefixed to PDF files
Returns the offset of the PDF document in the +stream+. In theory this
###############################################################################
def calc_junk_offset(io)
  io.rewind
  offset = io.pos
  until (c = io.readchar) == '%' || c == 37 || offset > 1024
    offset += 1
  end
  io.rewind
  offset < 1024 ? offset : nil
rescue EOFError
  nil
end