Fixed exception when getting the properties of IO objects twice (by rewinding when done)

This commit is contained in:
Sebastian Ludwig 2013-05-23 15:36:17 +02:00
parent 05a3443164
commit d3c748a74d
2 changed files with 11 additions and 0 deletions

View File

@ -173,6 +173,8 @@ class FastImage
end
end
uri.rewind if uri.respond_to?(:rewind)
raise SizeNotFound if options[:raise_on_failure] && @property == :size && !@size
rescue Timeout::Error, SocketError, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET,

View File

@ -123,6 +123,15 @@ class FastImageTest < Test::Unit::TestCase
end
end
end
def test_should_report_size_correctly_on_io_object_twice
GoodFixtures.each do |fn, info|
File.open(File.join(FixturePath, fn), "r") do |io|
assert_equal info[1], FastImage.size(io)
assert_equal info[1], FastImage.size(io)
end
end
end
def test_should_report_size_correctly_for_local_files_with_path_that_has_spaces
Dir.chdir(PathHere) do