fastimage 2.3.0 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +59 -19
- data/lib/fastimage/version.rb +1 -1
- data/lib/fastimage.rb +8 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4eedb99b6314f24fb47381046bf63595b90b8eb8045a6b9b238a92acebc00ba
|
4
|
+
data.tar.gz: 10db6080223fb596a5fcfc904563a5f25b8209af1c4166260831e7aef9d7613e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eae9ad37f27b853c2927183802b015ca6a066e413a112d80bb119603944d07d9fba5aac36712bc12c12acb327e3031a6b8c6875120e6f8de501e0526d4e2be14
|
7
|
+
data.tar.gz: 2b8e2add3af30fe7e856b84e18ba6f9425fb939e5e789f1601fb360abb91ee5197b15adaa6cff79a2bdb89ea7a9d95306ebc0513c4882cd0a30b7ab3261173d2
|
data/README.md
CHANGED
@@ -96,38 +96,78 @@ http://sdsykes.github.io/fastimage/rdoc/FastImage.html
|
|
96
96
|
|
97
97
|
## Maintainer
|
98
98
|
|
99
|
-
FastImage is maintained by Stephen Sykes (
|
99
|
+
FastImage is maintained by Stephen Sykes (sdsykes). SamSaffron also helps out from time to time (thanks!).
|
100
100
|
|
101
101
|
## Benchmark
|
102
102
|
|
103
|
-
It's way faster than conventional methods
|
103
|
+
It's way faster than conventional methods for most types of file when fetching over the wire. Compared here by using OpenURI which will fetch the whole file.
|
104
104
|
|
105
105
|
```ruby
|
106
|
-
|
107
|
-
|
106
|
+
require 'benchmark'
|
107
|
+
require 'fastimage'
|
108
|
+
require 'open-uri'
|
109
|
+
|
110
|
+
uri = "http://upload.wikimedia.org/wikipedia/commons/b/b4/Mardin_1350660_1350692_33_images.jpg"
|
111
|
+
puts Benchmark.measure {URI.open(uri, 'rb') {|fh| p FastImage.size(fh)}}
|
108
112
|
[9545, 6623]
|
109
|
-
0.
|
113
|
+
0.059088 0.067694 0.126782 ( 0.808131)
|
110
114
|
|
111
|
-
|
115
|
+
puts Benchmark.measure {p FastImage.size(uri)}
|
112
116
|
[9545, 6623]
|
113
|
-
0.
|
117
|
+
0.006198 0.001563 0.007761 ( 0.162021)
|
114
118
|
```
|
115
119
|
|
116
|
-
The file is fetched in about
|
120
|
+
The file is fetched in about 0.8 seconds in this test (the number in brackets is the total time taken), but as FastImage doesn't need to fetch the whole thing, it completes in 0.16s.
|
121
|
+
|
122
|
+
You'll see similar excellent results for the other file types.
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
require 'benchmark'
|
126
|
+
require 'fastimage'
|
127
|
+
require 'open-uri'
|
128
|
+
|
129
|
+
uri = "https://upload.wikimedia.org/wikipedia/commons/a/a9/Augustine_Herrman_1670_Map_Virginia_Maryland.tiff"
|
130
|
+
puts Benchmark.measure {URI.open(uri, 'rb') {|fh| p FastImage.size(fh)}}
|
131
|
+
[12805, 10204]
|
132
|
+
1.332587 2.049915 3.382502 ( 19.925270)
|
117
133
|
|
118
|
-
|
119
|
-
|
120
|
-
|
134
|
+
puts Benchmark.measure {p FastImage.size(uri)}
|
135
|
+
[12805, 10204]
|
136
|
+
0.004593 0.000924 0.005517 ( 0.100592)
|
137
|
+
```
|
138
|
+
|
139
|
+
Some tiff files however do not have their metadata near the start of the file.
|
121
140
|
|
122
141
|
```ruby
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
[
|
130
|
-
|
142
|
+
require 'benchmark'
|
143
|
+
require 'fastimage'
|
144
|
+
require 'open-uri'
|
145
|
+
|
146
|
+
uri = "https://upload.wikimedia.org/wikipedia/commons/1/14/Center-Filled_LIMA.tif"
|
147
|
+
puts Benchmark.measure {URI.open(uri, 'rb') {|fh| p FastImage.size(fh)}}
|
148
|
+
[22841, 19404]
|
149
|
+
0.350304 0.321104 0.671408 ( 3.053605)
|
150
|
+
|
151
|
+
puts Benchmark.measure {p FastImage.size(uri)}
|
152
|
+
[22841, 19404]
|
153
|
+
0.163443 0.214301 0.377744 ( 2.880414)
|
154
|
+
```
|
155
|
+
|
156
|
+
Note that if you want a really fast result for this file type, [image_size](https://github.com/toy/image_size?tab=readme-ov-file#experimental-fetch-image-meta-from-http-server) might be useful as it has an optimisation for this (fetching only the needed data range).
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
require 'benchmark'
|
160
|
+
require 'image_size/uri'
|
161
|
+
require 'fastimage'
|
162
|
+
|
163
|
+
uri = "https://upload.wikimedia.org/wikipedia/commons/1/14/Center-Filled_LIMA.tif"
|
164
|
+
puts Benchmark.measure {p ImageSize.url(uri).size }
|
165
|
+
[22841, 19404]
|
166
|
+
0.008983 0.001311 0.010294 ( 0.128986)
|
167
|
+
|
168
|
+
puts Benchmark.measure {p FastImage.size(uri)}
|
169
|
+
[22841, 19404]
|
170
|
+
0.163443 0.214301 0.377744 ( 2.880414)
|
131
171
|
```
|
132
172
|
|
133
173
|
## Tests
|
data/lib/fastimage/version.rb
CHANGED
data/lib/fastimage.rb
CHANGED
@@ -321,6 +321,7 @@ class FastImage
|
|
321
321
|
res.read_body do |str|
|
322
322
|
Fiber.yield str
|
323
323
|
end
|
324
|
+
nil
|
324
325
|
end
|
325
326
|
|
326
327
|
case res['content-encoding']
|
@@ -335,6 +336,7 @@ class FastImage
|
|
335
336
|
while data = gzip.readline
|
336
337
|
Fiber.yield data
|
337
338
|
end
|
339
|
+
nil
|
338
340
|
end
|
339
341
|
end
|
340
342
|
|
@@ -388,12 +390,14 @@ class FastImage
|
|
388
390
|
Fiber.yield str
|
389
391
|
offset += LocalFileChunkSize
|
390
392
|
end
|
393
|
+
nil
|
391
394
|
end
|
392
395
|
else
|
393
396
|
read_fiber = Fiber.new do
|
394
397
|
while str = readable.read(LocalFileChunkSize)
|
395
398
|
Fiber.yield str
|
396
399
|
end
|
400
|
+
nil
|
397
401
|
end
|
398
402
|
end
|
399
403
|
|
@@ -471,6 +475,9 @@ class FastImage
|
|
471
475
|
include StreamUtil
|
472
476
|
attr_reader :pos
|
473
477
|
|
478
|
+
# read_fiber should return nil if it no longer has anything to return when resumed
|
479
|
+
# so the result of the whole Fiber block should be set to be nil in case yield is no
|
480
|
+
# longer called
|
474
481
|
def initialize(read_fiber)
|
475
482
|
@read_fiber = read_fiber
|
476
483
|
@pos = 0
|
@@ -484,7 +491,6 @@ class FastImage
|
|
484
491
|
unused_str = @str[@strpos..-1]
|
485
492
|
|
486
493
|
new_string = @read_fiber.resume
|
487
|
-
new_string = @read_fiber.resume if new_string.is_a? Net::ReadAdapter
|
488
494
|
raise CannotParseImage if !new_string
|
489
495
|
# we are dealing with bytes here, so force the encoding
|
490
496
|
new_string.force_encoding("ASCII-8BIT") if new_string.respond_to? :force_encoding
|
@@ -573,7 +579,7 @@ class FastImage
|
|
573
579
|
# the file, and is within the first 1000 chars.
|
574
580
|
begin
|
575
581
|
:svg if (1..100).detect {|n| @stream.peek(10 * n).include?("<svg")}
|
576
|
-
rescue FiberError
|
582
|
+
rescue FiberError, CannotParseImage
|
577
583
|
nil
|
578
584
|
end
|
579
585
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastimage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Sykes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fakeweb-fi
|
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
|
-
rubygems_version: 3.
|
101
|
+
rubygems_version: 3.4.10
|
102
102
|
signing_key:
|
103
103
|
specification_version: 4
|
104
104
|
summary: FastImage - Image info fast
|