format_parser 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'webrick'
3
+
4
+ describe 'Fetching data from HTTP remotes' do
5
+ before(:all) do
6
+ log_file ||= StringIO.new
7
+ log = WEBrick::Log.new(log_file)
8
+ options = {
9
+ :Port => 9399,
10
+ :Logger => log,
11
+ :AccessLog => [
12
+ [ log, WEBrick::AccessLog::COMMON_LOG_FORMAT ],
13
+ [ log, WEBrick::AccessLog::REFERER_LOG_FORMAT ]
14
+ ]
15
+ }
16
+ @server = WEBrick::HTTPServer.new(options)
17
+ @server.mount '/', WEBrick::HTTPServlet::FileHandler, fixtures_dir
18
+ trap("INT") { @server.stop }
19
+ @server_thread = Thread.new { @server.start }
20
+ end
21
+
22
+ it 'parses the animated PNG over HTTP' do
23
+ file_information = FormatParser.parse_http('http://localhost:9399/PNG/anim.png')
24
+ expect(file_information).not_to be_nil
25
+ expect(file_information.file_nature).to eq(:image)
26
+ end
27
+
28
+ after(:all) do
29
+ @server.stop
30
+ @server_thread.join(0.5)
31
+ end
32
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe FormatParser::RemoteIO do
4
+
5
+ it 'returns the partial content when the server supplies a 206 status' do
6
+ rio = described_class.new("https://images.invalid/img.jpg")
7
+
8
+ fake_resp = double(headers: {'Content-Range' => '10-109/2577'}, status: 206, body: 'This is the response')
9
+ expect(Faraday).to receive(:get).with("https://images.invalid/img.jpg", nil, range: "bytes=10-109").and_return(fake_resp)
10
+
11
+ rio.seek(10)
12
+ read_result = rio.read(100)
13
+ expect(read_result).to eq('This is the response')
14
+ end
15
+
16
+ it 'returns the entire content when the server supplies the Content-Range response but sends a 200 status' do
17
+ rio = described_class.new("https://images.invalid/img.jpg")
18
+
19
+ fake_resp = double(headers: {'Content-Range' => '10-109/2577'}, status: 200, body: 'This is the response')
20
+ expect(Faraday).to receive(:get).with("https://images.invalid/img.jpg", nil, range: "bytes=10-109").and_return(fake_resp)
21
+
22
+ rio.seek(10)
23
+ read_result = rio.read(100)
24
+ expect(read_result).to eq('This is the response')
25
+ end
26
+
27
+ it 'raises a specific error for all 4xx responses except 416' do
28
+ rio = described_class.new("https://images.invalid/img.jpg")
29
+
30
+ fake_resp = double(headers: {}, status: 403, body: 'Please log in')
31
+ expect(Faraday).to receive(:get).with("https://images.invalid/img.jpg", nil, range: "bytes=100-199").and_return(fake_resp)
32
+
33
+ rio.seek(100)
34
+ expect { rio.read(100) }.to raise_error(/replied with a 403 and refused/)
35
+ end
36
+
37
+ it 'returns a nil when the range cannot be satisfied and the response is 416' do
38
+ rio = described_class.new("https://images.invalid/img.jpg")
39
+
40
+ fake_resp = double(headers: {}, status: 416, body: 'You jumped off the end of the file maam')
41
+ expect(Faraday).to receive(:get).with("https://images.invalid/img.jpg", nil, range: "bytes=100-199").and_return(fake_resp)
42
+
43
+ rio.seek(100)
44
+ expect(rio.read(100)).to be_nil
45
+ end
46
+
47
+ it 'raises a specific error for all 5xx responses' do
48
+ rio = described_class.new("https://images.invalid/img.jpg")
49
+
50
+ fake_resp = double(headers: {}, status: 502, body: 'Guru meditation')
51
+ expect(Faraday).to receive(:get).with("https://images.invalid/img.jpg", nil, range: "bytes=100-199").and_return(fake_resp)
52
+
53
+ rio.seek(100)
54
+ expect { rio.read(100) }.to raise_error(/replied with a 502 and we might want to retry/)
55
+ end
56
+ end
@@ -0,0 +1,22 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter "/spec/"
4
+ end
5
+
6
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+
9
+ require 'rspec'
10
+ require 'format_parser'
11
+ require 'pry'
12
+
13
+ module SpecHelpers
14
+ def fixtures_dir
15
+ __dir__ + '/fixtures/'
16
+ end
17
+ end
18
+
19
+ RSpec.configure do |c|
20
+ c.include SpecHelpers
21
+ c.extend SpecHelpers # makes fixtures_dir available for example groups too
22
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: format_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Noah Berman
8
+ - Julik Tarkhanov
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2018-01-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: exifr
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: faraday
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '0.13'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '0.13'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '12'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '12'
70
+ - !ruby/object:Gem::Dependency
71
+ name: simplecov
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '0.15'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '0.15'
84
+ - !ruby/object:Gem::Dependency
85
+ name: pry
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '0.11'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '0.11'
98
+ - !ruby/object:Gem::Dependency
99
+ name: yard
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '0.9'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '0.9'
112
+ description: |-
113
+ A Ruby library for prying open files you can convert to a previewable format, such as video, image and audio files. It includes
114
+ a number of parser modules that try to recover metadata useful for post-processing and layout while reading the absolute
115
+ minimum amount of data possible.
116
+ email:
117
+ - noah@noahberman.org
118
+ - me@julik.nl
119
+ executables: []
120
+ extensions: []
121
+ extra_rdoc_files: []
122
+ files:
123
+ - ".gitignore"
124
+ - ".rspec"
125
+ - ".travis.yml"
126
+ - CODE_OF_CONDUCT.md
127
+ - CONTRIBUTING.md
128
+ - Gemfile
129
+ - LICENSE.txt
130
+ - README.md
131
+ - Rakefile
132
+ - format_parser.gemspec
133
+ - lib/care.rb
134
+ - lib/file_information.rb
135
+ - lib/format_parser.rb
136
+ - lib/format_parser/version.rb
137
+ - lib/io_utils.rb
138
+ - lib/parsers/aiff_parser.rb
139
+ - lib/parsers/dpx_parser.rb
140
+ - lib/parsers/exif_parser.rb
141
+ - lib/parsers/gif_parser.rb
142
+ - lib/parsers/jpeg_parser.rb
143
+ - lib/parsers/png_parser.rb
144
+ - lib/parsers/psd_parser.rb
145
+ - lib/parsers/tiff_parser.rb
146
+ - lib/read_limiter.rb
147
+ - lib/remote_io.rb
148
+ - spec/aiff_parser_spec.rb
149
+ - spec/care_spec.rb
150
+ - spec/file_information_spec.rb
151
+ - spec/format_parser_spec.rb
152
+ - spec/io_utils_spec.rb
153
+ - spec/parsers/dpx_parser_spec.rb
154
+ - spec/parsers/exif_parser_spec.rb
155
+ - spec/parsers/gif_parser_spec.rb
156
+ - spec/parsers/jpeg_parser_spec.rb
157
+ - spec/parsers/png_parser_spec.rb
158
+ - spec/parsers/psd_parser_spec.rb
159
+ - spec/parsers/tiff_parser_spec.rb
160
+ - spec/read_limiter_spec.rb
161
+ - spec/remote_fetching_spec.rb
162
+ - spec/remote_io_spec.rb
163
+ - spec/spec_helper.rb
164
+ homepage: https://github.com/WeTransfer/format_parser
165
+ licenses:
166
+ - MIT
167
+ metadata:
168
+ allowed_push_host: https://rubygems.org
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.5.2
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: A library for efficient parsing of file metadata
189
+ test_files: []