diff --git a/lib/fastimage.rb b/lib/fastimage.rb index 69c30dd..1096dfa 100644 --- a/lib/fastimage.rb +++ b/lib/fastimage.rb @@ -200,8 +200,6 @@ 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, @@ -220,6 +218,9 @@ class FastImage end end + ensure + uri.rewind if uri.respond_to?(:rewind) + end private diff --git a/test/test.rb b/test/test.rb index 7769a80..7538194 100644 --- a/test/test.rb +++ b/test/test.rb @@ -292,6 +292,18 @@ class FastImageTest < Test::Unit::TestCase end end + def test_should_rewind_ios + string = File.read(File.join(FixturePath, "test.bmp")) + stringio = StringIO.new(string) + FastImage.type(stringio) + assert_equal 0, stringio.pos + + string = File.read(File.join(FixturePath, "test.xml")) + stringio = StringIO.new(string) + FastImage.type(stringio) + assert_equal 0, stringio.pos + end + def test_gzipped_file url = "http://example.nowhere/#{GzipTestImg}" assert_equal([970, 450], FastImage.size(url))