s3 0.3.6 → 0.3.7

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.
@@ -1,14 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- s3 (0.3.6)
5
- http_connection
4
+ s3 (0.3.7)
6
5
  proxies
7
6
 
8
7
  GEM
9
8
  remote: http://rubygems.org/
10
9
  specs:
11
- http_connection (1.3.1)
12
10
  mocha (0.9.8)
13
11
  rake
14
12
  proxies (0.2.1)
@@ -20,7 +18,6 @@ PLATFORMS
20
18
 
21
19
  DEPENDENCIES
22
20
  bundler (>= 1.0.0)
23
- http_connection
24
21
  mocha
25
22
  proxies
26
23
  s3!
data/lib/s3.rb CHANGED
@@ -16,6 +16,7 @@ require "s3/bucket"
16
16
  require "s3/connection"
17
17
  require "s3/exceptions"
18
18
  require "s3/object"
19
+ require "s3/request"
19
20
  require "s3/service"
20
21
  require "s3/signature"
21
22
  require "s3/version"
@@ -21,6 +21,8 @@ module S3
21
21
  # * <tt>:proxy</tt> - Hash for Net::HTTP Proxy settings
22
22
  # { :host => "proxy.mydomain.com", :port => "80, :user => "user_a", :password => "secret" }
23
23
  # * <tt>:proxy</tt> - Hash for Net::HTTP Proxy settings
24
+ # * <tt>:chunk_size</tt> - Size of a chunk when streaming
25
+ # (1048576 (1 MiB) by default)
24
26
  def initialize(options = {})
25
27
  @access_key_id = options.fetch(:access_key_id)
26
28
  @secret_access_key = options.fetch(:secret_access_key)
@@ -28,6 +30,7 @@ module S3
28
30
  @debug = options.fetch(:debug, false)
29
31
  @timeout = options.fetch(:timeout, 60)
30
32
  @proxy = options.fetch(:proxy, nil)
33
+ @chunk_size = options.fetch(:chunk_size, 1048576)
31
34
  end
32
35
 
33
36
  # Makes request with given HTTP method, sets missing parameters,
@@ -64,7 +67,7 @@ module S3
64
67
  end
65
68
 
66
69
  path = URI.escape(path)
67
- request = Net::HTTPGenericRequest.new(method.to_s.upcase, !!body, true, path)
70
+ request = Request.new(@chunk_size, method.to_s.upcase, !!body, method.to_s.upcase != "HEAD", path)
68
71
 
69
72
  headers = self.class.parse_headers(headers)
70
73
  headers.each do |key, value|
@@ -73,9 +73,7 @@ module S3
73
73
  # Download the content of the object, and caches it. Pass true
74
74
  # to clear the cache and download the object again.
75
75
  def content(reload = false)
76
- if reload or @content.nil?
77
- get_object
78
- end
76
+ get_object if reload or @content.nil?
79
77
  @content
80
78
  end
81
79
 
@@ -236,13 +234,13 @@ module S3
236
234
  end
237
235
 
238
236
  def parse_headers(response)
239
- self.etag = response["etag"]
240
- self.content_type = response["content-type"]
241
- self.content_disposition = response["content-disposition"]
242
- self.cache_control = response["cache-control"]
243
- self.content_encoding = response["content-encoding"]
244
- self.last_modified = response["last-modified"]
245
- if response["content-range"]
237
+ self.etag = response["etag"] if response.key?("etag")
238
+ self.content_type = response["content-type"] if response.key?("content-type")
239
+ self.content_disposition = response["content-disposition"] if response.key?("content-disposition")
240
+ self.cache_control = response["cache-control"] if response.key?("cache-control")
241
+ self.content_encoding = response["content-encoding"] if response.key?("content-encoding")
242
+ self.last_modified = response["last-modified"] if response.key?("last-modified")
243
+ if response.key?("content-range")
246
244
  self.size = response["content-range"].sub(/[^\/]+\//, "").to_i
247
245
  else
248
246
  self.size = response["content-length"]
@@ -0,0 +1,31 @@
1
+ module S3
2
+ # Class responsible for sending chunked requests
3
+ # properly. Net::HTTPGenericRequest has hardcoded chunk_size, so we
4
+ # inherit the class and override chunk_size.
5
+ class Request < Net::HTTPGenericRequest
6
+ def initialize(chunk_size, m, reqbody, resbody, path, initheader = nil)
7
+ @chunk_size = chunk_size
8
+ super(m, reqbody, resbody, path, initheader)
9
+ end
10
+
11
+ private
12
+
13
+ def send_request_with_body_stream(sock, ver, path, f)
14
+ unless content_length() or chunked?
15
+ raise ArgumentError, "Content-Length not given and Transfer-Encoding is not `chunked'"
16
+ end
17
+ supply_default_content_type
18
+ write_header sock, ver, path
19
+ if chunked?
20
+ while s = f.read(@chunk_size)
21
+ sock.write(sprintf("%x\r\n", s.length) << s << "\r\n")
22
+ end
23
+ sock.write "0\r\n\r\n"
24
+ else
25
+ while s = f.read(@chunk_size)
26
+ sock.write s
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module S3
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.7"
3
3
  end
data/s3.gemspec CHANGED
@@ -16,7 +16,6 @@ Gem::Specification.new do |s|
16
16
  s.rubyforge_project = "s3"
17
17
 
18
18
  s.add_dependency "proxies"
19
- s.add_dependency "http_connection"
20
19
  s.add_development_dependency "test-unit", ">= 2.0"
21
20
  s.add_development_dependency "mocha"
22
21
  s.add_development_dependency "bundler", ">= 1.0.0"
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 6
9
- version: 0.3.6
8
+ - 7
9
+ version: 0.3.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Jakub Ku\xC5\xBAma"
@@ -30,22 +30,9 @@ dependencies:
30
30
  type: :runtime
31
31
  prerelease: false
32
32
  version_requirements: *id001
33
- - !ruby/object:Gem::Dependency
34
- name: http_connection
35
- requirement: &id002 !ruby/object:Gem::Requirement
36
- none: false
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- segments:
41
- - 0
42
- version: "0"
43
- type: :runtime
44
- prerelease: false
45
- version_requirements: *id002
46
33
  - !ruby/object:Gem::Dependency
47
34
  name: test-unit
48
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ requirement: &id002 !ruby/object:Gem::Requirement
49
36
  none: false
50
37
  requirements:
51
38
  - - ">="
@@ -56,10 +43,10 @@ dependencies:
56
43
  version: "2.0"
57
44
  type: :development
58
45
  prerelease: false
59
- version_requirements: *id003
46
+ version_requirements: *id002
60
47
  - !ruby/object:Gem::Dependency
61
48
  name: mocha
62
- requirement: &id004 !ruby/object:Gem::Requirement
49
+ requirement: &id003 !ruby/object:Gem::Requirement
63
50
  none: false
64
51
  requirements:
65
52
  - - ">="
@@ -69,10 +56,10 @@ dependencies:
69
56
  version: "0"
70
57
  type: :development
71
58
  prerelease: false
72
- version_requirements: *id004
59
+ version_requirements: *id003
73
60
  - !ruby/object:Gem::Dependency
74
61
  name: bundler
75
- requirement: &id005 !ruby/object:Gem::Requirement
62
+ requirement: &id004 !ruby/object:Gem::Requirement
76
63
  none: false
77
64
  requirements:
78
65
  - - ">="
@@ -84,7 +71,7 @@ dependencies:
84
71
  version: 1.0.0
85
72
  type: :development
86
73
  prerelease: false
87
- version_requirements: *id005
74
+ version_requirements: *id004
88
75
  description: "S3 library provides access to Amazon's Simple Storage Service. It supports both: European and US buckets through REST API."
89
76
  email:
90
77
  - qoobaa@gmail.com
@@ -111,6 +98,7 @@ files:
111
98
  - lib/s3/object.rb
112
99
  - lib/s3/objects_extension.rb
113
100
  - lib/s3/parser.rb
101
+ - lib/s3/request.rb
114
102
  - lib/s3/service.rb
115
103
  - lib/s3/signature.rb
116
104
  - lib/s3/version.rb
@@ -135,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
123
  requirements:
136
124
  - - ">="
137
125
  - !ruby/object:Gem::Version
138
- hash: 4530267442220315944
126
+ hash: 3296897330677873024
139
127
  segments:
140
128
  - 0
141
129
  version: "0"