From 11ca295071cbe63363b3038f94adf81c2c77de93 Mon Sep 17 00:00:00 2001 From: Dmitry Borisov Date: Thu, 29 Nov 2018 09:50:13 +0300 Subject: [PATCH] Should work for readed ios --- lib/fastimage.rb | 1 + test/test.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/fastimage.rb b/lib/fastimage.rb index c00f965..975b664 100644 --- a/lib/fastimage.rb +++ b/lib/fastimage.rb @@ -332,6 +332,7 @@ class FastImage end def fetch_using_read(readable) + readable.rewind if readable.respond_to?(:rewind) # Pathnames respond to read, but always return the first # chunk of the file unlike an IO (even though the # docuementation for it refers to IO). Need to supply diff --git a/test/test.rb b/test/test.rb index 51efd28..dca9609 100644 --- a/test/test.rb +++ b/test/test.rb @@ -178,6 +178,24 @@ class FastImageTest < Test::Unit::TestCase end end + def test_should_report_type_correctly_for_ios_that_have_been_read + GoodFixtures.each do |fn, info| + File.open(File.join(FixturePath, fn), "r") do |io| + io.read + assert_equal info[0], FastImage.type(io) + end + end + end + + def test_should_report_size_correctly_for_ios_that_have_been_read + GoodFixtures.each do |fn, info| + File.open(File.join(FixturePath, fn), "r") do |io| + io.read + assert_equal info[1], FastImage.size(io) + 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|