activestorage-backblaze 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_storage/service/backblaze_service.rb +25 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91def17491b8ea4a04f7c03cac167a712e633d7297e679ec42d0149674cdcc68
|
4
|
+
data.tar.gz: 8b31f27d7574a7e70b863d5341aabb79084a7668c8a6af4ff6eb649f42065964
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d7b8c31aa2b7da9ea211f32a65b61239b065e7984ca2f5e444049585b87cf8b3026725ba931679476c838cf79af880fcd56eba2ed2eee578be69692c04eeb68
|
7
|
+
data.tar.gz: 79dbff0c379557b22cf7f8ab76bb1140d43ce21e7348026fbe88a0dda39b455e3908e04d9744694d258312ada353fc66cc139267a0c48b96a302a6db8566f702
|
@@ -12,7 +12,7 @@ class ActiveStorage::Service::BackblazeService < ActiveStorage::Service
|
|
12
12
|
b2_key_token: @key_token,
|
13
13
|
b2_bucket_name: @bucket_name,
|
14
14
|
b2_bucket_id: @bucket_id,
|
15
|
-
logger:
|
15
|
+
logger: Rails.logger
|
16
16
|
)
|
17
17
|
end
|
18
18
|
|
@@ -26,9 +26,17 @@ class ActiveStorage::Service::BackblazeService < ActiveStorage::Service
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def download(key)
|
30
|
-
|
31
|
-
|
29
|
+
def download(key, &block)
|
30
|
+
if block_given?
|
31
|
+
instrument :streaming_download, { key: key } do
|
32
|
+
stream(key, &block)
|
33
|
+
end
|
34
|
+
else
|
35
|
+
instrument :download, { key: key } do
|
36
|
+
resp = @connection.get_object(@bucket_name, key)
|
37
|
+
io = StringIO.new(resp.body)
|
38
|
+
io
|
39
|
+
end
|
32
40
|
end
|
33
41
|
end
|
34
42
|
|
@@ -76,4 +84,17 @@ class ActiveStorage::Service::BackblazeService < ActiveStorage::Service
|
|
76
84
|
raise NotImpletementedError
|
77
85
|
end
|
78
86
|
|
87
|
+
private
|
88
|
+
def stream(key, options = {}, &block)
|
89
|
+
resp = @connection.get_object(@bucket_name, key)
|
90
|
+
io = StringIO.new(resp.body)
|
91
|
+
io.binmode
|
92
|
+
|
93
|
+
chunk_size = 5.megabytes
|
94
|
+
|
95
|
+
while chunk = io.read(chunk_size)
|
96
|
+
yield chunk
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
79
100
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activestorage-backblaze
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jey
|
@@ -33,7 +33,8 @@ files:
|
|
33
33
|
- lib/active_storage/service/backblaze_service.rb
|
34
34
|
- lib/active_storage_backblaze.rb
|
35
35
|
homepage: https://github.com/gten/activestorage-backblaze
|
36
|
-
licenses:
|
36
|
+
licenses:
|
37
|
+
- MIT
|
37
38
|
metadata:
|
38
39
|
source_code_uri: https://github.com/gten/activestorage-backblaze
|
39
40
|
post_install_message:
|