image_size 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44be96b790fd826a8e6471928ce381cda6a0269bb9a24d7111142b54ff1556bb
4
- data.tar.gz: 494d270c18e0e9583ce226e53a478bf5829ce3823cc212c392dc933445962a89
3
+ metadata.gz: 9caeef6f83a5e285b9925268a389b46b2d15b6def554e0480c3b4105868022e8
4
+ data.tar.gz: b1933e6c5d7fdc6686d8fe15082a64d39b76433aa659fc203c6d09c0ed937b86
5
5
  SHA512:
6
- metadata.gz: e33c991f5c78de857a38591d62b6b71f9c95693b0222bdfa7141b94a0359cf76f3e94e3cdf1c424e2935a8f1f397072473c00ac53d0656aeece5ff5e077466dc
7
- data.tar.gz: aec5519f54c0dafcc0ae424703567276161ca1c5f53306134c3c3995642a67533d7196b1671e1c74158ffed604a90d2ef61f3e7f5d175246b935954b697afe5d
6
+ metadata.gz: be6a77d33b518ca07842b3b1d4bc8793949b0fb09ede5bc46c6753f7bd51255ee078f34714c851010b0b43df9ce32e2d52a236f990155ad5dd056fd5cc297214
7
+ data.tar.gz: d63e52caaa020d1b26e573a06d74b309f154542a82f7539fcb5c44d8ea7df7d44b5fbb54e51b502fe05e8e42e4191c8b0e8281f3d169a01717355016fa1fd9e5
data/CHANGELOG.markdown CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## unreleased
4
4
 
5
+ ## v3.0.1 (2021-10-21)
6
+
7
+ * Fix reading file chunks starting after EOF and reading chunks non-consecutively [toy/image_optim_rails#12](https://github.com/toy/image_optim_rails/issues/12) [@toy](https://github.com/toy)
8
+
5
9
  ## v3.0.0 (2021-10-17)
6
10
 
7
11
  * Read only required chunks of data for files and seekable IOs [@toy](https://github.com/toy)
data/image_size.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'image_size'
5
- s.version = '3.0.0'
5
+ s.version = '3.0.1'
6
6
  s.summary = %q{Measure image size using pure Ruby}
7
7
  s.description = %q{Measure following file dimensions: apng, bmp, cur, gif, ico, j2c, jp2, jpeg, jpx, mng, pam, pbm, pcx, pgm, png, ppm, psd, svg, swf, tiff, webp, xbm, xpm}
8
8
  s.homepage = "https://github.com/toy/#{s.name}"
@@ -18,7 +18,8 @@ class ImageSize
18
18
  unless @chunks.key?(i)
19
19
  @io.seek((chunk_size * i) - @pos, IO::SEEK_CUR)
20
20
  data = @io.read(chunk_size)
21
- @pos += data.length
21
+ @pos = chunk_size * i
22
+ @pos += data.length if data
22
23
  @chunks[i] = data
23
24
  end
24
25
 
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec'
4
+
5
+ require 'image_size/seekable_io_reader'
6
+
7
+ describe ImageSize::SeekableIOReader do
8
+ context :[] do
9
+ def ios
10
+ @ios ||= []
11
+ end
12
+
13
+ def io
14
+ File.open('GPL', 'rb').tap do |io|
15
+ ios << io
16
+ end
17
+ end
18
+
19
+ after do
20
+ ios.pop.close until ios.empty?
21
+ end
22
+
23
+ def new_reader
24
+ ImageSize::SeekableIOReader.new(io)
25
+ end
26
+
27
+ let(:content){ io.read }
28
+
29
+ it 'reads as expected when pieces are read consecutively' do
30
+ reader = new_reader
31
+ 0.step(content.length + 4096, 100) do |offset|
32
+ expect(reader[offset, 100]).to eq(content[offset, 100])
33
+ end
34
+ end
35
+
36
+ it 'reads as expected when pieces are read backwards' do
37
+ reader = new_reader
38
+ (content.length + 4096).step(0, -100) do |offset|
39
+ expect(reader[offset, 100]).to eq(content[offset, 100])
40
+ end
41
+ end
42
+
43
+ it 'reads as expected when pieces are read in random order' do
44
+ 100.times do
45
+ reader = new_reader
46
+ 0.step(content.length + 4096, 100).to_a.shuffle.each do |offset|
47
+ expect(reader[offset, 100]).to eq(content[offset, 100])
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -19,7 +19,7 @@ describe ImageSize do
19
19
  :DocumentRoot => '.',
20
20
  })
21
21
  @server_thread = Thread.new{ @server.start }
22
- @server_base_url = URI("http://localhost:#{@server.config[:Port]}/")
22
+ @server_base_url = URI("http://127.0.0.1:#{@server.config[:Port]}/")
23
23
  end
24
24
 
25
25
  after :all do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_size
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keisuke Minami
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-10-17 00:00:00.000000000 Z
12
+ date: 2021-10-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -78,6 +78,7 @@ files:
78
78
  - lib/image_size/string_reader.rb
79
79
  - lib/image_size/uri_reader.rb
80
80
  - spec/image_size/chunky_reader_spec.rb
81
+ - spec/image_size/seekable_io_reader_spec.rb
81
82
  - spec/image_size_spec.rb
82
83
  - spec/images/.gitattributes
83
84
  - spec/images/bmp/v2.42x50.bmp
@@ -123,7 +124,7 @@ licenses:
123
124
  metadata:
124
125
  bug_tracker_uri: https://github.com/toy/image_size/issues
125
126
  changelog_uri: https://github.com/toy/image_size/blob/master/CHANGELOG.markdown
126
- documentation_uri: https://www.rubydoc.info/gems/image_size/3.0.0
127
+ documentation_uri: https://www.rubydoc.info/gems/image_size/3.0.1
127
128
  source_code_uri: https://github.com/toy/image_size
128
129
  post_install_message:
129
130
  rdoc_options: []
@@ -146,6 +147,7 @@ specification_version: 4
146
147
  summary: Measure image size using pure Ruby
147
148
  test_files:
148
149
  - spec/image_size/chunky_reader_spec.rb
150
+ - spec/image_size/seekable_io_reader_spec.rb
149
151
  - spec/image_size_spec.rb
150
152
  - spec/images/.gitattributes
151
153
  - spec/images/bmp/v2.42x50.bmp