filey-diff 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  gemspec
data/changelog.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ This project is [Semantically Versioned](http://semver.org).
4
+
5
+ ## 1.1.0
6
+
7
+ * Add support for gzipped S3 objects
8
+
9
+ Thanks to Alex Marchant for implementing this!
10
+
3
11
  ## 1.0.2
4
12
 
5
13
  * Remove the -number suffix from S3 ETags ([thanks
data/filey-diff.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'filey-diff'
3
- s.version = '1.0.2'
3
+ s.version = '1.1.0'
4
4
 
5
5
  s.summary = "Compare two data sources that contain file-like objects"
6
6
  s.description =
@@ -16,13 +16,34 @@ module Filey
16
16
  path = ''
17
17
  name = s3_object.key
18
18
  end
19
+
20
+ if (s3_object.head[:content_encoding] == "gzip")
21
+ last_modified, md5 =
22
+ last_modified_and_md5_from_gzipped(s3_object, path)
23
+ else
24
+ last_modified = s3_object.last_modified
25
+ md5 = s3_object.etag.gsub(/"/, '').split('-',2).first
26
+ end
27
+
19
28
  normalised_path = "./#{path}"
20
29
  Filey.new(normalised_path,
21
30
  name,
22
- s3_object.last_modified,
23
- s3_object.etag.gsub(/"/, '').split('-',2).first)
31
+ last_modified,
32
+ md5)
24
33
  }
25
34
  end
35
+
36
+ def last_modified_and_md5_from_gzipped(s3_object, path)
37
+ tempfile = Tempfile.new(File.basename(path))
38
+ tempfile.write s3_object.read
39
+ tempfile.close
40
+
41
+ gz = Zlib::GzipReader.open(tempfile.path)
42
+ last_modified = gz.mtime
43
+ md5 = Digest::MD5.hexdigest(gz.read)
44
+ gz.close
45
+ [last_modified, md5]
46
+ end
26
47
  end
27
48
  end
28
49
  end
@@ -73,5 +73,4 @@ describe Filey::Comparison do
73
73
  end
74
74
  end
75
75
  end
76
-
77
76
  end
@@ -1,4 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
+ require 'tempfile'
3
+ require 'zlib'
2
4
 
3
5
  shared_examples "a data source" do |source|
4
6
  let(:data_source) { described_class.new(source) }
@@ -57,6 +59,42 @@ describe Filey::DataSources::AwsSdkS3 do
57
59
  }
58
60
  )
59
61
  it_should_behave_like "a data source", s3_bucket
62
+
63
+ it 'provides the original md5/mtime of a gzipped file' do
64
+ original_object = objects.first
65
+ tempfile = gzip_into_tmp_file(original_object)
66
+ data_source = s3_data_source_from_file(tempfile, original_object[:path])
67
+ filey = data_source.get_fileys[0]
68
+
69
+ filey.md5.should eq(Digest::MD5.hexdigest(original_object[:content]))
70
+ # GzipWriter seems to cut off fractions of a second,
71
+ # to_i adjusts the original file to match
72
+ filey.last_modified.to_i.should eq(original_object[:mtime].to_i)
73
+ end
74
+
75
+ def s3_data_source_from_file(file, path)
76
+ file.open
77
+ data_source = Filey::DataSources::AwsSdkS3.new(S3Bucket.new([S3Object.new(
78
+ path,
79
+ file.mtime,
80
+ file.read,
81
+ { :content_encoding => 'gzip' }
82
+ )]))
83
+ end
84
+
85
+ def gzip_into_tmp_file(s3_mock_object)
86
+ tempfile = Tempfile.new("temp")
87
+
88
+ gz = Zlib::GzipWriter.open(tempfile.path, Zlib::BEST_COMPRESSION, Zlib::DEFAULT_STRATEGY)
89
+ gz.mtime = s3_mock_object[:mtime]
90
+ gz.write s3_mock_object[:content]
91
+
92
+ gz.flush
93
+ tempfile.flush
94
+
95
+ gz.close
96
+ tempfile
97
+ end
60
98
  end
61
99
 
62
100
  describe Filey::DataSources::FileSystem do
data/spec/spec_helper.rb CHANGED
@@ -4,17 +4,22 @@ require 'digest/md5'
4
4
  require File.dirname(__FILE__) + '/../lib/filey-diff'
5
5
 
6
6
  class S3Object
7
- attr_reader :key, :last_modified
7
+ attr_reader :key, :last_modified, :head
8
8
 
9
- def initialize(key, last_modified, content)
9
+ def initialize(key, last_modified, content, head = {})
10
10
  @key = key
11
11
  @last_modified = last_modified
12
12
  @content = content
13
+ @head = head
13
14
  end
14
15
 
15
16
  def etag
16
17
  Digest::MD5.hexdigest(@content)
17
18
  end
19
+
20
+ def read
21
+ @content
22
+ end
18
23
  end
19
24
 
20
25
  class S3Bucket
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filey-diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-13 00:00:00.000000000 Z
12
+ date: 2013-03-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake