module SrcsetImages::DimensionsPatch

Public Instance Methods

peek() click to toggle source

from github.com/planio-gmbh/html2odt/commit/36335201cb5440a5ba3ca05f9eb6d8ac556a98ca Default implemenation of IO#peek from GEM_PATH/dimensions-1.3.0/lib/dimensions/io.rb:

def peek
  unless no_peeking?
    read(pos + 1024) while @reader.width.nil? && pos < 6144
    rewind
  end
end

It had two problems:

a) if the file is shorter than 6144 bytes, it would keep reading infinitely b) if the width can only be detected after the 6144 limit, it would not work

as expected

Now we keep reading the file, until we can determine a width or until there's nothing left to read.

# File lib/middleman-srcset_images/dimensions_patch.rb, line 24
def peek
  return if no_peeking?

  while read(pos + 1024) && @reader.width.nil?
  end

  rewind
end