s3io 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b2ed2b4f30861a161e94ff64ee61e23e71f3419f
4
+ data.tar.gz: 782818fa50a6db024608171736737493af18ecd2
5
+ SHA512:
6
+ metadata.gz: f83f11bca34e75b13948011bd474d909dd391837072cc8b79af2b3b81e7fa5d30cf69542d54b5dc6f37acb843b4400a3a5c919765ef7727b2b85dd8a8eba7903
7
+ data.tar.gz: 29be4366b52738672e4455eb67a79eadd5f341482e364102fbd0372878d138b5303ba651a92df790d38eefda66d5bf858a29ec0cd26888863dbb9188af2997b4
data/README.md CHANGED
@@ -8,6 +8,10 @@ Amazon's official AWS SDK provides an API for S3 that isn't compatible with Ruby
8
8
 
9
9
  Currently only reads are supported with writes support coming soon.
10
10
 
11
+ ## Warning
12
+
13
+ Reads currently don't guarantee consistency if S3 file changes while being streamed. I plan to solve this, but meanwhile please keep in mind that you may read garbage if you replace S3 file while streaming it.
14
+
11
15
  ## Installation
12
16
 
13
17
  Add this line to your application's Gemfile:
@@ -61,6 +65,7 @@ It can write:
61
65
  ## To do
62
66
 
63
67
  * Code documentation
68
+ * Fix an issue where S3 file that is updated while read streaming happens may result in garbage being read
64
69
 
65
70
  ## Contributing
66
71
 
@@ -4,6 +4,10 @@ module S3io
4
4
  open(s3object, 'r', options, &block)
5
5
  end
6
6
 
7
+ # This error indicates that the object was modified between being opened
8
+ # and being read.
9
+ class ReadModifiedError < IOError; end
10
+
7
11
  class ReadWrapper < Wrapper
8
12
 
9
13
  # Default buffer size for line parser in bytes
@@ -20,6 +24,7 @@ module S3io
20
24
  @options = {
21
25
  :line_buffer_size => (options[:line_buffer_size] || LINE_BUFFER_SIZE)
22
26
  }
27
+ @last_modified = @s3object.last_modified
23
28
  end
24
29
 
25
30
  # Reads data from S3 object.
@@ -36,6 +41,12 @@ module S3io
36
41
  upper_bound = (content_length - 1) if upper_bound >= content_length
37
42
 
38
43
  data = @s3object.read :range => @pos..upper_bound
44
+
45
+ last_modified = @s3object.last_modified
46
+ unless last_modified == @last_modified
47
+ fail ReadModifiedError, "S3 object #{@s3object.key} was updated during read, last_modified=#{last_modified.to_s} (was #{@last_modified.to_s})"
48
+ end
49
+
39
50
  @pos = upper_bound + 1
40
51
 
41
52
  return data
@@ -81,6 +92,5 @@ module S3io
81
92
  end
82
93
  alias lines each
83
94
  alias each_line each
84
-
85
95
  end
86
96
  end
data/lib/s3io/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module S3io
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -6,6 +6,7 @@ require 'stringio'
6
6
  class S3ObjectReadMock
7
7
  def initialize(body = '')
8
8
  @body = body
9
+ @last_modified = Time.now
9
10
  end
10
11
 
11
12
  def read(options = {})
@@ -18,6 +19,19 @@ class S3ObjectReadMock
18
19
  def content_length
19
20
  @body.size
20
21
  end
22
+
23
+ def last_modified
24
+ @last_modified
25
+ end
26
+
27
+ def key
28
+ 'test/file/name'
29
+ end
30
+
31
+ def change_last_modified
32
+ @last_modified = @last_modified + 1
33
+ end
34
+
21
35
  end
22
36
 
23
37
  class S3ioReadWrapperTest < Test::Unit::TestCase
@@ -47,6 +61,16 @@ class S3ioReadWrapperTest < Test::Unit::TestCase
47
61
  assert_equal(S3_TEST_DATA[100..100], wrapper.read(1))
48
62
  end
49
63
 
64
+ def test_last_modified_check
65
+ wrapper = S3io::ReadWrapper.new(@s3object)
66
+
67
+ wrapper.read(100)
68
+ @s3object.change_last_modified
69
+ assert_raise S3io::ReadModifiedError do
70
+ wrapper.read(1)
71
+ end
72
+ end
73
+
50
74
  def test_each
51
75
  wrapper = S3io::ReadWrapper.new(@s3object)
52
76
 
metadata CHANGED
@@ -1,46 +1,36 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: s3io
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 0
10
- version: 1.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Arthur Pirogovski
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2013-01-22 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2014-08-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: aws-sdk
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
32
20
  type: :runtime
33
- version_requirements: *id001
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
34
27
  description: An IO-compatible wrapper for S3
35
- email:
28
+ email:
36
29
  - arthur@flyingtealeaf.com
37
30
  executables: []
38
-
39
31
  extensions: []
40
-
41
32
  extra_rdoc_files: []
42
-
43
- files:
33
+ files:
44
34
  - .gitignore
45
35
  - .travis.yml
46
36
  - Gemfile
@@ -58,38 +48,31 @@ files:
58
48
  - test/test_s3io_write_wrapper.rb
59
49
  homepage: http://github.com/fiksu/s3io
60
50
  licenses: []
61
-
51
+ metadata: {}
62
52
  post_install_message:
63
53
  rdoc_options: []
64
-
65
- require_paths:
54
+ require_paths:
66
55
  - lib
67
- required_ruby_version: !ruby/object:Gem::Requirement
68
- none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
74
- - 0
75
- version: "0"
76
- required_rubygems_version: !ruby/object:Gem::Requirement
77
- none: false
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- hash: 3
82
- segments:
83
- - 0
84
- version: "0"
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
85
66
  requirements: []
86
-
87
67
  rubyforge_project:
88
- rubygems_version: 1.8.24
68
+ rubygems_version: 2.2.2
89
69
  signing_key:
90
- specification_version: 3
91
- summary: Amazon's official AWS SDK provides an API for S3 that isn't compatible with Ruby's standard IO class and its derivatives. This gem provides a thin wrapper around AWS SDK that makes it possible to access objects stored on S3 as if they were instances of File or StringIO classes.
92
- test_files:
70
+ specification_version: 4
71
+ summary: Amazon's official AWS SDK provides an API for S3 that isn't compatible with
72
+ Ruby's standard IO class and its derivatives. This gem provides a thin wrapper around
73
+ AWS SDK that makes it possible to access objects stored on S3 as if they were instances
74
+ of File or StringIO classes.
75
+ test_files:
93
76
  - test/s3_test_data.csv
94
77
  - test/test_s3io_read_wrapper.rb
95
78
  - test/test_s3io_write_wrapper.rb