Module: Pdfrb::Source::HeaderReader

Defined in:
lib/pdfrb/source/header_reader.rb

Overview

Reads %PDF-x.y header (s7.5.2) and the recommended binary marker comment. Returns the detected version as a String.

Class Method Summary collapse

Class Method Details

.read(io) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pdfrb/source/header_reader.rb', line 10

def read(io)
  io.seek(0, IO::SEEK_SET)
  # Allow up to 1024 bytes of leading garbage before %PDF per
  # Acrobat tolerance.
  1024.times do
    cur = io.pos
    line = io.gets
    return nil if line.nil?

    if line.start_with?(PdfConstants::HEADER_PREFIX)
      io.seek(cur, IO::SEEK_SET)
      return parse_version(line)
    end
  end
  nil
end