mirror of
https://github.com/sdsykes/fastimage.git
synced 2025-12-30 00:05:02 -05:00
Always rewind the given IO
When an error occured when extracting dimensions, rewinding would be skipped and the code would jump straight to "rescue" statements. We want that the IO is always rewinded, even in case of errors. Note that this doesn't affect the return value of the method, because the return value of a method-level "ensure" is always ignored by Ruby.
This commit is contained in:
parent
9c7ada1a41
commit
04d1030756
@ -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
|
||||
|
||||
12
test/test.rb
12
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))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user