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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33fd6ee96653abe4059457cf1ba86113fc2c2a88
4
- data.tar.gz: 7f042ecb080e9d04a78d7d22102dc3905f40b0d3
3
+ metadata.gz: 70fd9b84e2b397e862c2f6554eb6f3830f77b3c8
4
+ data.tar.gz: 36c2a28a96f0bea5644f550bb616983d8320961d
5
5
  SHA512:
6
- metadata.gz: 9326f30de6b5344b9a17bd0832381ef5775094f1578173d5f5735b21aaff9f7358e7397ccf83b0c67ab7f4f71a7093ecf98d32007200f690026f953562211180
7
- data.tar.gz: 393643805c0a9d995a07d8f7fdbd7afae28b2d617ccd0f05d456799b547a0f76fc8e160ec8e8127f20f39cd8b45ca4cd25dd516d64c8e3852a009f4e7c4ccda6
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})"
@@ -1,3 +1,3 @@
1
1
  module FormatParser
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end
data/lib/io_constraint.rb CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  # We deliberately want to document and restrict the
2
3
  # number of methods an IO-ish object has to implement
3
4
  # to be usable with all our parsers. This subset is fairly
@@ -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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: format_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Berman