format_parser 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/care.rb +2 -1
- data/lib/format_parser/version.rb +1 -1
- data/lib/io_constraint.rb +1 -0
- data/lib/parsers/exif_parser.rb +8 -0
- data/spec/care_spec.rb +5 -0
- data/spec/format_parser_spec.rb +10 -0
- data/spec/remote_fetching_spec.rb +13 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70fd9b84e2b397e862c2f6554eb6f3830f77b3c8
|
4
|
+
data.tar.gz: 36c2a28a96f0bea5644f550bb616983d8320961d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2603890e62f99e5a4e63dd28f1860aeee86f1f47d0a690fa559f01a27aa106104fb71195427814ac346208435a3fd720db4458cdbd8cb9cf1291c517334ca8f
|
7
|
+
data.tar.gz: 35f16d20d4a3e015d58b82297f66f2bd3df1e2ef78a0ced278c474bcec64e8d47241fc4e99368b1fa8d203bda182e509c0c58d65037539f9e7b6d5f7b98bfe0e
|
data/lib/care.rb
CHANGED
@@ -25,6 +25,7 @@ class Care
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def read(n_bytes)
|
28
|
+
return '' if n_bytes == 0 # As hardcoded for all Ruby IO objects
|
28
29
|
read = @cache.byteslice(@io, @pos, n_bytes)
|
29
30
|
return nil unless read && !read.empty?
|
30
31
|
@pos += read.bytesize
|
@@ -62,7 +63,7 @@ class Care
|
|
62
63
|
# or fetch pages where necessary
|
63
64
|
def byteslice(io, at, n_bytes)
|
64
65
|
if n_bytes < 1
|
65
|
-
raise ArgumentError, "The number of bytes to fetch must be a positive Integer"
|
66
|
+
raise ArgumentError, "The number of bytes to fetch must be a positive Integer, but was #{n_bytes}"
|
66
67
|
end
|
67
68
|
if at < 0
|
68
69
|
raise ArgumentError, "Negative offsets are not supported (got #{at})"
|
data/lib/io_constraint.rb
CHANGED
data/lib/parsers/exif_parser.rb
CHANGED
@@ -49,6 +49,8 @@ class FormatParser::EXIFParser
|
|
49
49
|
# Without the magic bytes EXIFR throws an error
|
50
50
|
@file_io.seek(0)
|
51
51
|
raw_exif_data = EXIFR::JPEG.new(@file_io) if @filetype == :jpeg
|
52
|
+
# Return if it's a CR2, which we don't parse yet
|
53
|
+
return if cr2_check(@file_io)
|
52
54
|
raw_exif_data = EXIFR::TIFF.new(@file_io) if @filetype == :tiff
|
53
55
|
# For things that we don't yet have a parser for
|
54
56
|
# we make the raw exif result available
|
@@ -69,4 +71,10 @@ class FormatParser::EXIFParser
|
|
69
71
|
(1..ORIENTATIONS.length).include?(value)
|
70
72
|
end
|
71
73
|
|
74
|
+
def cr2_check(file_io)
|
75
|
+
@file_io.seek(8)
|
76
|
+
cr2_check_bytes = @file_io.read(2)
|
77
|
+
cr2_check_bytes == "CR" ? true : false
|
78
|
+
end
|
79
|
+
|
72
80
|
end
|
data/spec/care_spec.rb
CHANGED
@@ -55,6 +55,11 @@ describe Care do
|
|
55
55
|
describe Care::IOWrapper do
|
56
56
|
it_behaves_like 'an IO object compatible with IOConstraint'
|
57
57
|
|
58
|
+
it 'always returns an empty string for a read() of 0' do
|
59
|
+
c = described_class.new(StringIO.new)
|
60
|
+
expect(c.read(0)).to eq('')
|
61
|
+
end
|
62
|
+
|
58
63
|
it 'forwards calls to read() to the Care and adjusts internal offsets' do
|
59
64
|
fake_cache_class = Class.new do
|
60
65
|
attr_reader :recorded_calls
|
data/spec/format_parser_spec.rb
CHANGED
@@ -20,4 +20,14 @@ describe FormatParser do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
describe 'when parsing fixtures' do
|
25
|
+
Dir.glob(fixtures_dir + '/**/*.*').sort.each do |fixture_path|
|
26
|
+
it "parses #{fixture_path} without raising any errors" do
|
27
|
+
File.open(fixture_path, 'rb') do |file|
|
28
|
+
FormatParser.parse(file)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
23
33
|
end
|
@@ -55,6 +55,19 @@ describe 'Fetching data from HTTP remotes' do
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
|
+
|
59
|
+
describe 'when parsing remote fixtures' do
|
60
|
+
Dir.glob(fixtures_dir + '/**/*.*').sort.each do |fixture_path|
|
61
|
+
filename = File.basename(fixture_path)
|
62
|
+
it "parses #{filename} without raising any errors" do
|
63
|
+
remote_fixture_path = fixture_path.gsub(fixtures_dir, "http://localhost:9399")
|
64
|
+
# Some of the fixtures are in dirs with spaces
|
65
|
+
cleaned_remote_fixture_path = remote_fixture_path.gsub(" ", "%20")
|
66
|
+
FormatParser.parse_http(cleaned_remote_fixture_path)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
58
71
|
|
59
72
|
after(:all) do
|
60
73
|
@server.stop
|