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 +1 -1
- data/changelog.md +8 -0
- data/filey-diff.gemspec +1 -1
- data/lib/filey-diff/data-sources/aws_sdk_s3.rb +23 -2
- data/spec/comparison_spec.rb +0 -1
- data/spec/data_sources_spec.rb +38 -0
- data/spec/spec_helper.rb +7 -2
- metadata +2 -2
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
gemspec
|
data/changelog.md
CHANGED
data/filey-diff.gemspec
CHANGED
@@ -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
|
-
|
23
|
-
|
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
|
data/spec/comparison_spec.rb
CHANGED
data/spec/data_sources_spec.rb
CHANGED
@@ -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
|
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-
|
12
|
+
date: 2013-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|