image_info 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 335b5d988c8fec52bf9d34596062dd56ff9d4db2
4
- data.tar.gz: 4547675b414cd13d918d5abe0349b3db7516f5cb
3
+ metadata.gz: 0e64be805d1d84727d771133650ff254e7b8cb66
4
+ data.tar.gz: 330145b1fb6c7fe6c5916de26dcac0a284240e31
5
5
  SHA512:
6
- metadata.gz: e8b7a26d43a838cb5291837e26a96c7c1bc7748c6ec86dd64a04ca00ee0f93c28c9856ea057b6e8c0ab5d8fd4b85da4c74d483b9d68425f4732df69b230e5f1a
7
- data.tar.gz: a4385f974bffe74fd345ca38f0dd39536dde0a21db75d5426d52ecb0040246b68d03fb4f606a54aed20615cb4d2b4ed06df8f2a59a2680a83b6898065b8b6212
6
+ metadata.gz: 4025152ff395c4a4abb50c1f8715fe80b9ac81ed0e02a8b987c010349241d9da2879927eaf29bc1b4b9efae0cceed58acab6a63754fffe4314b77687c451dc5c
7
+ data.tar.gz: 1576e24fa6630e7168be36b915e74b93575155a54a50dcc1d99cc33d7fd9cb8ef295d1e39e05e421e0da6477831e7944ff5021719b984fbd68bc4313341fdfcb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ * 1.1.1
2
+
3
+ Now only fetch partial image data to compute its size and type.
4
+
5
+ Thanks to [vdaubry](https://github.com/vdaubry) the gem now uses typhoeus
6
+ stream capability to fetch images and get its size and type, aborting the
7
+ request if necessary. Make sure to use typhoeus `v0.7.3` in order to benefit
8
+ from this update since there was an issue with previous typhoeus version when
9
+ aborting ongoing requests.
10
+
11
+ Fixes [#1](https://github.com/gottfrois/image_info/issues/1)
12
+
13
+ Also fix URL encoding issues.
14
+
1
15
  * 1.1.0
2
16
 
3
17
  - Introduces `width` and `height` method. Fixes [https://github.com/gottfrois/image_info/issues/2](https://github.com/gottfrois/image_info/issues/2)
data/README.md CHANGED
@@ -5,13 +5,14 @@
5
5
  [![Dependency Status](https://gemnasium.com/gottfrois/image_info.svg)](https://gemnasium.com/gottfrois/image_info)
6
6
  [![Gem Version](https://badge.fury.io/rb/image_info.svg)](http://badge.fury.io/rb/image_info)
7
7
 
8
- ImageInfo finds the size and type of a single or multiple images from the web by fetching as little as needed in batches.
8
+ ImageInfo finds the size and type of a single or multiple images from the web by fetching as little data as needed (partial image) in batches.
9
9
 
10
10
  ## Why
11
11
 
12
12
  In [LinkThumbnailer](https://github.com/gottfrois/link_thumbnailer) I needed to find images sizes not only for one image.
13
13
  A well known gem like FastImage was not enough so I decided to build my own.
14
- The gem use [typhoeus](https://github.com/typhoeus/typhoeus) under the hood to perform http requests in parallel.
14
+ The gem use [typhoeus](https://github.com/typhoeus/typhoeus)'s parallel requests and stream capability under the hood to
15
+ get images.
15
16
 
16
17
  ## Installation
17
18
 
@@ -7,7 +7,7 @@ module ImageInfo
7
7
  attr_accessor :width, :height, :type
8
8
 
9
9
  def initialize(uri)
10
- @uri = ::URI.parse(uri.to_s)
10
+ @uri = ::URI.parse(::URI.encode(uri.to_s))
11
11
  end
12
12
 
13
13
  def size
@@ -0,0 +1,12 @@
1
+ module ImageInfo
2
+ class NullParser
3
+ def width
4
+ end
5
+
6
+ def height
7
+ end
8
+
9
+ def format
10
+ end
11
+ end
12
+ end
@@ -3,12 +3,11 @@ require 'image_size'
3
3
  module ImageInfo
4
4
  class Parser
5
5
 
6
- attr_reader :image, :bytes, :parser
6
+ attr_reader :image, :data
7
7
 
8
8
  def initialize(image, data)
9
- @image = image
10
- @bytes = data.bytes
11
- @parser = ::ImageSize.new(data)
9
+ @image = image
10
+ @data = data
12
11
  end
13
12
 
14
13
  def call
@@ -26,6 +25,13 @@ module ImageInfo
26
25
  def set_image_type
27
26
  image.type = parser.format
28
27
  end
29
-
28
+
29
+ private
30
+
31
+ def parser
32
+ @parser ||= ::ImageSize.new(data)
33
+ rescue ImageSize::FormatError
34
+ @parser ||= ::ImageInfo::NullParser.new
35
+ end
30
36
  end
31
37
  end
@@ -2,6 +2,7 @@ require 'typhoeus'
2
2
 
3
3
  require 'image_info/image'
4
4
  require 'image_info/parser'
5
+ require 'image_info/null_parser'
5
6
  require 'image_info/request_handler'
6
7
 
7
8
  module ImageInfo
@@ -1,23 +1,26 @@
1
1
  module ImageInfo
2
2
  class RequestHandler
3
3
 
4
- attr_reader :image
4
+ attr_reader :image, :buffer
5
5
 
6
6
  def initialize(image)
7
7
  @image = image
8
+ @buffer = StringIO.new
8
9
  end
9
10
 
10
11
  def build
11
12
  ::Typhoeus::Request.new(image.uri.to_s, followlocation: true, accept_encoding: :gzip).tap do |request|
12
- request.on_complete { |response| on_complete(response) }
13
+ request.on_body do |chunk|
14
+ buffer.write(chunk)
15
+ :abort if found_image_info?(buffer)
16
+ end
13
17
  end
14
18
  end
15
19
 
16
20
  private
17
21
 
18
- def on_complete(response)
19
- ::ImageInfo::Parser.new(image, response.body).call if response.success?
22
+ def found_image_info?(chunk)
23
+ ::ImageInfo::Parser.new(image, chunk).call
20
24
  end
21
-
22
25
  end
23
26
  end
@@ -1,3 +1,3 @@
1
1
  module ImageInfo
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_info
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre-Louis Gottfrois
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-19 00:00:00.000000000 Z
11
+ date: 2015-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -117,6 +117,7 @@ files:
117
117
  - lib/image_info/configurable.rb
118
118
  - lib/image_info/configuration.rb
119
119
  - lib/image_info/image.rb
120
+ - lib/image_info/null_parser.rb
120
121
  - lib/image_info/parser.rb
121
122
  - lib/image_info/processor.rb
122
123
  - lib/image_info/request_handler.rb