image_info 1.1.2 → 1.2.0
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 +5 -5
- data/.ruby-version +1 -0
- data/.travis.yml +2 -5
- data/CHANGELOG.md +45 -14
- data/README.md +22 -1
- data/image_info.gemspec +2 -2
- data/lib/image_info/configuration.rb +2 -1
- data/lib/image_info/parser.rb +4 -4
- data/lib/image_info/processor.rb +2 -3
- data/lib/image_info/request_handler.rb +15 -3
- data/lib/image_info/version.rb +1 -1
- metadata +28 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c283f102f87200ff3e0e3fb823551aa689599576390bab279c63c305868b3ffd
|
4
|
+
data.tar.gz: 5b831b50c1977baeac9919d107d29dff41be41961a3a4ad77ecff7e7906e2b8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1c8acb5dfd7c70902bac0af3a64d9647552318fa11f47ec8004814bea68f0aa89ab66ee7876177e161cf7153bde257cae5a9f8553b9d273b4d3e34f2642c6a6
|
7
|
+
data.tar.gz: 269f7d92862fc6b53c53741a9c756ccc622c47c7b04740fb37c2472474bc8cc369dacfdf409fe644f4d57809f6e265cc639ddf67d066bc029bd34f69faabf3b0
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.6
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,25 +1,56 @@
|
|
1
|
-
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
|
9
|
+
## [1.2.0] - 2020-07-24
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Allows to set a maximum image size in bytes to fetch. The HTTP connection
|
13
|
+
will be aborted as soon as the max size is reached. Setting a value to
|
14
|
+
`zero` or a negative number will deactivate this feature. Default to `-1` not
|
15
|
+
to break retro compatibility.
|
16
|
+
|
17
|
+
### Fixed
|
18
|
+
|
19
|
+
- Partial image loading was sometime yielding empty results. Image size and
|
20
|
+
type was not set properly in this case.
|
21
|
+
- `max_concurrency` option was not properly set by default.
|
22
|
+
- Locks dependencies to their major version.
|
23
|
+
- `typhoeus` is now locked to `~> 1.0`
|
24
|
+
- `image_size` is now locked to `~> 2.0`
|
25
|
+
|
26
|
+
## [1.1.2] - 2015-08-12
|
27
|
+
### Fixed
|
2
28
|
|
3
29
|
- Fix issues with schemaless uri (ex: `//foo.com`)
|
4
30
|
|
5
|
-
|
31
|
+
## [1.1.1] - 2015-08-11
|
32
|
+
### Adds
|
6
33
|
|
7
|
-
|
34
|
+
- Adds image partial loading and abort the connection as soon as image
|
35
|
+
size and type has been found.
|
8
36
|
|
9
|
-
|
10
|
-
stream capability to fetch images and get its size and type, aborting the
|
11
|
-
request if necessary. Make sure to use typhoeus `>= 0.7.3` in order to benefit
|
12
|
-
from this update since there was an issue with previous typhoeus version when
|
13
|
-
aborting ongoing requests.
|
37
|
+
### Fixed
|
14
38
|
|
15
|
-
Fixes
|
39
|
+
- Fixes URL encoding issues.
|
16
40
|
|
17
|
-
|
41
|
+
## [1.1.0] - 2015-07-19
|
42
|
+
### Adds
|
18
43
|
|
19
|
-
|
44
|
+
- Introduces `width` and `height` method.
|
20
45
|
|
21
|
-
|
46
|
+
## [1.0.0] - 2015-07-19
|
47
|
+
### Adds
|
22
48
|
|
23
|
-
|
49
|
+
- First release 🎆
|
24
50
|
|
25
|
-
|
51
|
+
[Unreleased]: https://github.com/gottfrois/image_info/compare/v1.2.0...HEAD
|
52
|
+
[1.2.0]: https://github.com/gottfrois/image_info/compare/v1.1.2...v1.2.0
|
53
|
+
[1.1.2]: https://github.com/gottfrois/image_info/compare/v1.1.1...v1.1.2
|
54
|
+
[1.1.1]: https://github.com/gottfrois/image_info/compare/v1.1.0...v1.1.1
|
55
|
+
[1.1.0]: https://github.com/gottfrois/image_info/compare/v1.0.0...v1.1.0
|
56
|
+
[1.0.0]: https://github.com/gottfrois/image_info/releases/tag/v1.0.0
|
data/README.md
CHANGED
@@ -60,6 +60,8 @@ images.map &:type
|
|
60
60
|
|
61
61
|
## Configuration
|
62
62
|
|
63
|
+
### Concurrency
|
64
|
+
|
63
65
|
You can configure the `max_concurrency` value (20 by default) used to fetch images in parallel:
|
64
66
|
|
65
67
|
```ruby
|
@@ -74,6 +76,26 @@ or at runtime:
|
|
74
76
|
ImageInfo.from('http://foo.com/foo.png', max_concurrency: 10)
|
75
77
|
```
|
76
78
|
|
79
|
+
### Image Size Limit
|
80
|
+
|
81
|
+
You can set a `max_image_size` for which the connection will be aborted
|
82
|
+
if reached.
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
ImageInfo.configure do |config|
|
86
|
+
config.max_image_size = 5 * 1024 * 1024 # 5Mb
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
or at runtime:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
ImageInfo.from('http://foo.com/foo.png', max_image_size: -1)
|
94
|
+
```
|
95
|
+
|
96
|
+
Setting the value to zero or a negative number simply disable the limit.
|
97
|
+
By default it is set to `-1`.
|
98
|
+
|
77
99
|
## Development
|
78
100
|
|
79
101
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -88,4 +110,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/gottfr
|
|
88
110
|
## License
|
89
111
|
|
90
112
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
91
|
-
|
data/image_info.gemspec
CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency "typhoeus"
|
23
|
-
spec.add_dependency "image_size"
|
22
|
+
spec.add_dependency "typhoeus", "~> 1.0"
|
23
|
+
spec.add_dependency "image_size", "~> 2.0"
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.10"
|
26
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/image_info/parser.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'image_size'
|
2
|
+
require 'image_info/null_parser'
|
2
3
|
|
3
4
|
module ImageInfo
|
4
5
|
class Parser
|
@@ -25,13 +26,12 @@ module ImageInfo
|
|
25
26
|
def set_image_type
|
26
27
|
image.type = parser.format
|
27
28
|
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
29
|
+
|
31
30
|
def parser
|
32
31
|
@parser ||= ::ImageSize.new(data)
|
33
|
-
rescue ImageSize::FormatError
|
32
|
+
rescue ::ImageSize::FormatError, NoMethodError
|
34
33
|
@parser ||= ::ImageInfo::NullParser.new
|
35
34
|
end
|
35
|
+
|
36
36
|
end
|
37
37
|
end
|
data/lib/image_info/processor.rb
CHANGED
@@ -2,7 +2,6 @@ require 'typhoeus'
|
|
2
2
|
|
3
3
|
require 'image_info/image'
|
4
4
|
require 'image_info/parser'
|
5
|
-
require 'image_info/null_parser'
|
6
5
|
require 'image_info/request_handler'
|
7
6
|
|
8
7
|
module ImageInfo
|
@@ -10,7 +9,7 @@ module ImageInfo
|
|
10
9
|
|
11
10
|
attr_reader :images, :options
|
12
11
|
|
13
|
-
def initialize(urls, options = {})
|
12
|
+
def initialize(urls, options = { max_concurrency: ::ImageInfo.config.max_concurrency })
|
14
13
|
@images = Array(urls).map { |uri| ::ImageInfo::Image.new(uri) }.keep_if(&:valid?)
|
15
14
|
@options = options
|
16
15
|
end
|
@@ -25,7 +24,7 @@ module ImageInfo
|
|
25
24
|
private
|
26
25
|
|
27
26
|
def hydra
|
28
|
-
@hydra ||= ::Typhoeus::Hydra.new(max_concurrency: options[:max_concurrency])
|
27
|
+
@hydra ||= ::Typhoeus::Hydra.new(max_concurrency: options[:max_concurrency].to_i)
|
29
28
|
end
|
30
29
|
|
31
30
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
|
1
3
|
module ImageInfo
|
2
4
|
class RequestHandler
|
3
5
|
|
@@ -12,15 +14,25 @@ module ImageInfo
|
|
12
14
|
::Typhoeus::Request.new(image.uri.to_s, followlocation: true, accept_encoding: :gzip).tap do |request|
|
13
15
|
request.on_body do |chunk|
|
14
16
|
buffer.write(chunk)
|
15
|
-
|
17
|
+
buffer.rewind
|
18
|
+
:abort if max_image_size_reached? || found_image_info?
|
16
19
|
end
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
20
23
|
private
|
21
24
|
|
22
|
-
def found_image_info?
|
23
|
-
::ImageInfo::Parser.new(image,
|
25
|
+
def found_image_info?
|
26
|
+
::ImageInfo::Parser.new(image, buffer).call
|
27
|
+
end
|
28
|
+
|
29
|
+
def max_image_size_reached?
|
30
|
+
return false if max_image_size <= 0
|
31
|
+
buffer.size > max_image_size
|
32
|
+
end
|
33
|
+
|
34
|
+
def max_image_size
|
35
|
+
::ImageInfo.config.max_image_size
|
24
36
|
end
|
25
37
|
end
|
26
38
|
end
|
data/lib/image_info/version.rb
CHANGED
metadata
CHANGED
@@ -1,97 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image_info
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pierre-Louis Gottfrois
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: image_size
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '2.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '2.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.10'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.10'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '10.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '10.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: webmock
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
description: ImageInfo finds the size and type of a single or multiple images from
|
@@ -102,9 +102,10 @@ executables: []
|
|
102
102
|
extensions: []
|
103
103
|
extra_rdoc_files: []
|
104
104
|
files:
|
105
|
-
- .gitignore
|
106
|
-
- .rspec
|
107
|
-
- .
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".ruby-version"
|
108
|
+
- ".travis.yml"
|
108
109
|
- CHANGELOG.md
|
109
110
|
- Gemfile
|
110
111
|
- LICENSE.txt
|
@@ -126,24 +127,23 @@ homepage: https://github.com/gottfrois/image_info
|
|
126
127
|
licenses:
|
127
128
|
- MIT
|
128
129
|
metadata: {}
|
129
|
-
post_install_message:
|
130
|
+
post_install_message:
|
130
131
|
rdoc_options: []
|
131
132
|
require_paths:
|
132
133
|
- lib
|
133
134
|
required_ruby_version: !ruby/object:Gem::Requirement
|
134
135
|
requirements:
|
135
|
-
- -
|
136
|
+
- - ">="
|
136
137
|
- !ruby/object:Gem::Version
|
137
138
|
version: '0'
|
138
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
140
|
requirements:
|
140
|
-
- -
|
141
|
+
- - ">="
|
141
142
|
- !ruby/object:Gem::Version
|
142
143
|
version: '0'
|
143
144
|
requirements: []
|
144
|
-
|
145
|
-
|
146
|
-
signing_key:
|
145
|
+
rubygems_version: 3.0.8
|
146
|
+
signing_key:
|
147
147
|
specification_version: 4
|
148
148
|
summary: ImageInfo finds the size and type of a single or multiple images from the
|
149
149
|
web by fetching as little as needed.
|