s3 0.3.13 → 0.3.14
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/s3/connection.rb +0 -1
- data/lib/s3/object.rb +14 -4
- data/lib/s3/version.rb +1 -1
- data/test/object_test.rb +16 -0
- data/test/test_helper.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 738f6e2f37dce25baa6d1248a067ffe24a662013
|
4
|
+
data.tar.gz: d365944c476e8d06ac8adeddc07062f930a04399
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e321145e101f53bcaa5b015b18b00a52c62314846975d1c58ab80c55509914de5daee41e67982c4b4562e347bb2c04bb6cc298e7858a21f3a71a380a63f47c57
|
7
|
+
data.tar.gz: 3a6431995f5c25882de1efa5a7811c336a8061634555c9f6f3f06a349035206ef38a6554c106a51bda62d92c83a462fc2508c93a530bbcf12bda4f8ce5a305bd
|
data/Gemfile.lock
CHANGED
data/lib/s3/connection.rb
CHANGED
@@ -20,7 +20,6 @@ module S3
|
|
20
20
|
# (60 by default)
|
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
|
-
# * <tt>:proxy</tt> - Hash for Net::HTTP Proxy settings
|
24
23
|
# * <tt>:chunk_size</tt> - Size of a chunk when streaming
|
25
24
|
# (1048576 (1 MiB) by default)
|
26
25
|
def initialize(options = {})
|
data/lib/s3/object.rb
CHANGED
@@ -89,6 +89,12 @@ module S3
|
|
89
89
|
@content
|
90
90
|
end
|
91
91
|
|
92
|
+
# Streams the content of the object without caching it, providing
|
93
|
+
# successive chunks to the block
|
94
|
+
def stream(options = {}, &block)
|
95
|
+
get_object(options, &block)
|
96
|
+
end
|
97
|
+
|
92
98
|
# Saves the object, returns true if successfull.
|
93
99
|
def save
|
94
100
|
put_object
|
@@ -180,9 +186,9 @@ module S3
|
|
180
186
|
object
|
181
187
|
end
|
182
188
|
|
183
|
-
def get_object(options = {})
|
189
|
+
def get_object(options = {}, &block)
|
184
190
|
response = object_request(:get, options)
|
185
|
-
parse_headers(response)
|
191
|
+
parse_headers(response, &block)
|
186
192
|
end
|
187
193
|
|
188
194
|
def object_headers(options = {})
|
@@ -245,7 +251,7 @@ module S3
|
|
245
251
|
headers
|
246
252
|
end
|
247
253
|
|
248
|
-
def parse_headers(response)
|
254
|
+
def parse_headers(response, &block)
|
249
255
|
@metadata = response.to_hash.select { |k, v| k.to_s.start_with?("x-amz-meta") }
|
250
256
|
self.etag = response["etag"] if response.key?("etag")
|
251
257
|
self.content_type = response["content-type"] if response.key?("content-type")
|
@@ -257,7 +263,11 @@ module S3
|
|
257
263
|
self.size = response["content-range"].sub(/[^\/]+\//, "").to_i
|
258
264
|
else
|
259
265
|
self.size = response["content-length"]
|
260
|
-
|
266
|
+
if block.nil?
|
267
|
+
self.content = response.body
|
268
|
+
else
|
269
|
+
response.read_body(nil, &block)
|
270
|
+
end
|
261
271
|
end
|
262
272
|
end
|
263
273
|
end
|
data/lib/s3/version.rb
CHANGED
data/test/object_test.rb
CHANGED
@@ -15,6 +15,7 @@ class ObjectTest < Test::Unit::TestCase
|
|
15
15
|
@object_mac.content = "test2"
|
16
16
|
|
17
17
|
@response_binary = Net::HTTPOK.new("1.1", "200", "OK")
|
18
|
+
@response_binary.stubs(:read_body).multiple_yields(*%w{t e s t})
|
18
19
|
@response_binary.stubs(:body).returns("test".respond_to?(:force_encoding) ? "test".force_encoding(Encoding::BINARY) : "test")
|
19
20
|
@response_binary["etag"] = ""
|
20
21
|
@response_binary["content-type"] = "image/png"
|
@@ -133,6 +134,21 @@ class ObjectTest < Test::Unit::TestCase
|
|
133
134
|
assert @object_lena.content(true)
|
134
135
|
end
|
135
136
|
|
137
|
+
test "streaming" do
|
138
|
+
@object_lena.expects(:object_request).with(:get, {}).returns(@response_binary)
|
139
|
+
|
140
|
+
expected = /test/n
|
141
|
+
io = StringIO.new
|
142
|
+
@object_lena.stream do |chunk|
|
143
|
+
io.write(chunk)
|
144
|
+
end
|
145
|
+
io.seek(0)
|
146
|
+
actual = io.read
|
147
|
+
assert_match expected, actual
|
148
|
+
assert_equal "image/png", @object_lena.content_type
|
149
|
+
assert_equal @object.instance_variable_defined?(:@content), false
|
150
|
+
end
|
151
|
+
|
136
152
|
test "retrieve" do
|
137
153
|
@object_lena.expects(:object_request).with(:head, {}).returns(@response_binary)
|
138
154
|
assert @object_lena.retrieve
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kuba Kuźma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: proxies
|