format_parser 2.3.0 → 2.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/README.md +13 -6
- data/format_parser.gemspec +1 -0
- data/lib/format_parser/version.rb +1 -1
- data/lib/io_utils.rb +18 -33
- data/lib/parsers/cr3_parser/decoder.rb +2 -2
- data/lib/parsers/cr3_parser.rb +13 -11
- data/lib/parsers/heif_parser.rb +46 -46
- data/lib/parsers/iso_base_media_file_format/box.rb +80 -0
- data/lib/parsers/iso_base_media_file_format/decoder.rb +348 -377
- data/lib/parsers/iso_base_media_file_format/utils.rb +89 -0
- data/lib/parsers/mov_parser/decoder.rb +53 -0
- data/lib/parsers/mov_parser.rb +48 -0
- data/lib/parsers/mp4_parser.rb +80 -0
- data/lib/parsers/pdf_parser.rb +5 -2
- data/lib/parsers/webp_parser.rb +2 -2
- data/spec/format_parser_spec.rb +1 -1
- data/spec/parsers/cr3_parser_spec.rb +3 -3
- data/spec/parsers/iso_base_media_file_format/box_spec.rb +399 -0
- data/spec/parsers/iso_base_media_file_format/decoder_spec.rb +117 -151
- data/spec/parsers/iso_base_media_file_format/utils_spec.rb +632 -0
- data/spec/parsers/mov_parser_spec.rb +139 -0
- data/spec/parsers/mp4_parser_spec.rb +188 -0
- data/spec/parsers/pdf_parser_spec.rb +37 -23
- metadata +25 -5
- data/lib/parsers/moov_parser/decoder.rb +0 -353
- data/lib/parsers/moov_parser.rb +0 -165
- data/spec/parsers/moov_parser_spec.rb +0 -144
@@ -0,0 +1,399 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FormatParser::ISOBaseMediaFileFormat::Box do
|
4
|
+
describe '.new' do
|
5
|
+
context 'when no fields/children' do
|
6
|
+
subject { described_class.new('foo', 0, 0) }
|
7
|
+
|
8
|
+
it 'sets them as empty hash/array' do
|
9
|
+
expect(subject.fields).to eq({})
|
10
|
+
expect(subject.children).to eq([])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when fields/children' do
|
15
|
+
let(:fields) { { foo: 1, bar: 'bar' } }
|
16
|
+
let(:children) { [described_class.new('bar', 0, 0)] }
|
17
|
+
|
18
|
+
subject { described_class.new('foo', 0, 0, fields, children) }
|
19
|
+
|
20
|
+
it 'sets them correctly' do
|
21
|
+
expect(subject.fields).to eq(fields)
|
22
|
+
expect(subject.children).to eq(children)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#all_children' do
|
28
|
+
context 'when no types given' do
|
29
|
+
subject do
|
30
|
+
described_class.new('root', 0, 0, nil, [
|
31
|
+
described_class.new('foo', 0, 0),
|
32
|
+
described_class.new('bar', 0, 0)
|
33
|
+
])
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns empty array' do
|
37
|
+
expect(subject.all_children).to eq([])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when no children' do
|
42
|
+
subject { described_class.new('root', 0, 0) }
|
43
|
+
|
44
|
+
it 'returns empty array' do
|
45
|
+
expect(subject.all_children('foo')).to eq([])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when no children of given type(s)' do
|
50
|
+
subject do
|
51
|
+
described_class.new('root', 0, 0, nil, [
|
52
|
+
described_class.new('foo', 0, 0),
|
53
|
+
described_class.new('bar', 0, 0, nil, [
|
54
|
+
described_class.new('baz', 0, 0)
|
55
|
+
])
|
56
|
+
])
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'returns empty array' do
|
60
|
+
expect(subject.all_children('baz')).to eq([])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when multiple children of given type(s)' do
|
65
|
+
let(:child_1) { described_class.new('foo', 0, 0) }
|
66
|
+
let(:child_2) do
|
67
|
+
described_class.new('foo', 0, 0, nil, [
|
68
|
+
described_class.new('qux', 0, 0)
|
69
|
+
])
|
70
|
+
end
|
71
|
+
let(:child_3) { described_class.new('bar', 0, 0) }
|
72
|
+
|
73
|
+
subject do
|
74
|
+
described_class.new('root', 0, 0, nil, [
|
75
|
+
child_1,
|
76
|
+
child_2,
|
77
|
+
child_3,
|
78
|
+
described_class.new('baz', 0, 0)
|
79
|
+
])
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'returns all matching direct children' do
|
83
|
+
expect(subject.all_children('foo', 'bar', 'qux')).to match_array([child_1, child_2, child_3])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#child?' do
|
89
|
+
context 'when no children' do
|
90
|
+
subject { described_class.new('root', 0, 0) }
|
91
|
+
|
92
|
+
it 'returns false' do
|
93
|
+
expect(subject.child?('foo')).to eq(false)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when no children of given type' do
|
98
|
+
subject do
|
99
|
+
described_class.new('root', 0, 0, nil, [
|
100
|
+
described_class.new('foo', 0, 0),
|
101
|
+
described_class.new('bar', 0, 0, nil, [
|
102
|
+
described_class.new('baz', 0, 0)
|
103
|
+
])
|
104
|
+
])
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'returns false' do
|
108
|
+
expect(subject.child?('baz')).to eq(false)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'when child of given type' do
|
113
|
+
subject do
|
114
|
+
described_class.new('root', 0, 0, nil, [
|
115
|
+
described_class.new('foo', 0, 0),
|
116
|
+
described_class.new('bar', 0, 0),
|
117
|
+
])
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'returns true' do
|
121
|
+
expect(subject.child?('foo')).to eq(true)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe '#first_child' do
|
127
|
+
context 'when no types given' do
|
128
|
+
subject do
|
129
|
+
described_class.new('root', 0, 0, nil, [
|
130
|
+
described_class.new('foo', 0, 0),
|
131
|
+
described_class.new('bar', 0, 0)
|
132
|
+
])
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'returns nil' do
|
136
|
+
expect(subject.first_child).to eq(nil)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'when no children' do
|
141
|
+
subject { described_class.new('root', 0, 0) }
|
142
|
+
|
143
|
+
it 'returns nil' do
|
144
|
+
expect(subject.first_child('foo')).to eq(nil)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'when no children of given type(s)' do
|
149
|
+
subject do
|
150
|
+
described_class.new('root', 0, 0, nil, [
|
151
|
+
described_class.new('foo', 0, 0),
|
152
|
+
described_class.new('bar', 0, 0, nil, [
|
153
|
+
described_class.new('baz', 0, 0)
|
154
|
+
])
|
155
|
+
])
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'returns nil' do
|
159
|
+
expect(subject.first_child('baz')).to eq(nil)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'when multiple children of given type(s)' do
|
164
|
+
let(:child) { described_class.new('bar', 0, 0) }
|
165
|
+
|
166
|
+
subject do
|
167
|
+
described_class.new('root', 0, 0, nil, [
|
168
|
+
described_class.new('foo', 0, 0, nil, [
|
169
|
+
described_class.new('qux', 0, 0)
|
170
|
+
]),
|
171
|
+
child,
|
172
|
+
described_class.new('bar', 0, 0),
|
173
|
+
described_class.new('baz', 0, 0)
|
174
|
+
])
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'returns first matching direct child' do
|
178
|
+
expect(subject.first_child('qux', 'baz', 'bar')).to eq(child)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe '#all_descendents' do
|
184
|
+
context 'when no types given' do
|
185
|
+
subject do
|
186
|
+
described_class.new('root', 0, 0, nil, [
|
187
|
+
described_class.new('foo', 0, 0),
|
188
|
+
described_class.new('bar', 0, 0)
|
189
|
+
])
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'returns empty array' do
|
193
|
+
expect(subject.all_descendents).to eq([])
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context 'when no children' do
|
198
|
+
subject { described_class.new('root', 0, 0) }
|
199
|
+
|
200
|
+
it 'returns empty array' do
|
201
|
+
expect(subject.all_descendents('root', 'foo')).to eq([])
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context 'when no descendents of given type(s)' do
|
206
|
+
subject do
|
207
|
+
described_class.new('root', 0, 0, nil, [
|
208
|
+
described_class.new('foo', 0, 0),
|
209
|
+
described_class.new('bar', 0, 0, nil, [
|
210
|
+
described_class.new('baz', 0, 0)
|
211
|
+
])
|
212
|
+
])
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'returns empty array' do
|
216
|
+
expect(subject.all_descendents('root', 'qux')).to eq([])
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
context 'when multiple descendents of given type(s)' do
|
221
|
+
let(:descendent_1) { described_class.new('bar', 0, 0) }
|
222
|
+
let(:descendent_2) { described_class.new('baz', 10, 10, nil, [descendent_3]) }
|
223
|
+
let(:descendent_3) { described_class.new('bar', 20, 20) }
|
224
|
+
|
225
|
+
subject do
|
226
|
+
described_class.new('root', 0, 0, nil, [
|
227
|
+
described_class.new('foo', 0, 0, nil, [
|
228
|
+
descendent_1
|
229
|
+
]),
|
230
|
+
descendent_2,
|
231
|
+
described_class.new('qux', 40, 40)
|
232
|
+
])
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'returns all matching descendents' do
|
236
|
+
expect(subject.all_descendents('bar', 'baz')).to match_array([descendent_1, descendent_2, descendent_3])
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
describe '#all_descendents_by_path' do
|
242
|
+
context 'when no children' do
|
243
|
+
subject { described_class.new('root', 0, 0) }
|
244
|
+
|
245
|
+
it 'returns empty array' do
|
246
|
+
expect(subject.all_descendents_by_path(['foo'])).to eq([])
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
context 'when no path' do
|
251
|
+
subject do
|
252
|
+
described_class.new('root', 0, 0, nil, [
|
253
|
+
described_class.new('foo', 0, 0, nil, [
|
254
|
+
described_class.new('bar', 0, 0)
|
255
|
+
])
|
256
|
+
])
|
257
|
+
end
|
258
|
+
|
259
|
+
it 'returns empty array' do
|
260
|
+
expect(subject.all_descendents_by_path([])).to eq([])
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
context 'when no descendents at given path' do
|
265
|
+
subject do
|
266
|
+
described_class.new('root', 0, 0, nil, [
|
267
|
+
described_class.new('foo', 0, 0, nil, [
|
268
|
+
described_class.new('bar', 0, 0)
|
269
|
+
])
|
270
|
+
])
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'returns empty array' do
|
274
|
+
expect(subject.all_descendents_by_path(%w[foo baz])).to eq([])
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
context 'when multiple descendents at given path' do
|
279
|
+
let(:descendent_1) { described_class.new('bar', 0, 0) }
|
280
|
+
let(:descendent_2) { described_class.new('bar', 0, 0) }
|
281
|
+
|
282
|
+
subject do
|
283
|
+
described_class.new('root', 0, 0, nil, [
|
284
|
+
described_class.new('foo', 0, 0, nil, [
|
285
|
+
descendent_1,
|
286
|
+
described_class.new('baz', 0, 0, nil, [
|
287
|
+
described_class.new('bar', 0, 0)
|
288
|
+
]),
|
289
|
+
descendent_2,
|
290
|
+
])
|
291
|
+
])
|
292
|
+
end
|
293
|
+
|
294
|
+
it 'returns all matching descendents' do
|
295
|
+
expect(subject.all_descendents_by_path(%w[foo bar])).to match_array([descendent_1, descendent_2])
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
describe '#first_descendent' do
|
301
|
+
context 'when no children' do
|
302
|
+
subject { described_class.new('root', 0, 0) }
|
303
|
+
|
304
|
+
it 'returns nil' do
|
305
|
+
expect(subject.first_descendent('root', 'foo')).to eq(nil)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
context 'when no descendents of given type(s)' do
|
310
|
+
subject do
|
311
|
+
described_class.new('root', 0, 0, nil, [
|
312
|
+
described_class.new('foo', 0, 0),
|
313
|
+
described_class.new('bar', 0, 0, nil, [
|
314
|
+
described_class.new('baz', 0, 0)
|
315
|
+
])
|
316
|
+
])
|
317
|
+
end
|
318
|
+
|
319
|
+
it 'returns nil' do
|
320
|
+
expect(subject.first_descendent('root', 'qux')).to eq(nil)
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
context 'when multiple descendents of given type(s)' do
|
325
|
+
let(:descendent) { described_class.new('bar', 0, 0) }
|
326
|
+
|
327
|
+
subject do
|
328
|
+
described_class.new('root', 0, 0, nil, [
|
329
|
+
described_class.new('foo', 0, 0, nil, [
|
330
|
+
descendent
|
331
|
+
]),
|
332
|
+
described_class.new('bar', 0, 0),
|
333
|
+
])
|
334
|
+
end
|
335
|
+
|
336
|
+
it 'returns first matching descendent' do
|
337
|
+
expect(subject.first_descendent('bar')).to be(descendent)
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
describe '#first_descendent_by_path' do
|
343
|
+
context 'when no children' do
|
344
|
+
subject { described_class.new('root', 0, 0) }
|
345
|
+
|
346
|
+
it 'returns nil' do
|
347
|
+
expect(subject.first_descendent_by_path(['foo'])).to eq(nil)
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
context 'when no path' do
|
352
|
+
subject do
|
353
|
+
described_class.new('root', 0, 0, nil, [
|
354
|
+
described_class.new('foo', 0, 0, nil, [
|
355
|
+
described_class.new('bar', 0, 0)
|
356
|
+
])
|
357
|
+
])
|
358
|
+
end
|
359
|
+
|
360
|
+
it 'returns nil' do
|
361
|
+
expect(subject.first_descendent_by_path([])).to eq(nil)
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
context 'when no descendents at given path' do
|
366
|
+
subject do
|
367
|
+
described_class.new('root', 0, 0, nil, [
|
368
|
+
described_class.new('foo', 0, 0, nil, [
|
369
|
+
described_class.new('bar', 0, 0)
|
370
|
+
])
|
371
|
+
])
|
372
|
+
end
|
373
|
+
|
374
|
+
it 'returns nil' do
|
375
|
+
expect(subject.first_descendent_by_path(%w[foo baz])).to eq(nil)
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
context 'when multiple descendents at given path' do
|
380
|
+
let(:descendent) { described_class.new('bar', 0, 0) }
|
381
|
+
|
382
|
+
subject do
|
383
|
+
described_class.new('root', 0, 0, nil, [
|
384
|
+
described_class.new('foo', 0, 0, nil, [
|
385
|
+
described_class.new('baz', 0, 0, nil, [
|
386
|
+
described_class.new('bar', 0, 0)
|
387
|
+
]),
|
388
|
+
descendent,
|
389
|
+
described_class.new('bar', 0, 0),
|
390
|
+
])
|
391
|
+
])
|
392
|
+
end
|
393
|
+
|
394
|
+
it 'returns first matching descendent' do
|
395
|
+
expect(subject.first_descendent_by_path(%w[foo bar])).to eq(descendent)
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
399
|
+
end
|