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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d7c0eb8bb1cab9146cb415bf6b16357b7816fdbe32821c8fffda0281d2fbc5b
4
- data.tar.gz: 62b0ce9a3a4bb6816f9ba49b69ef6192c6c2d90043ffc5c1ae1d5aff5b18f08c
3
+ metadata.gz: 91def17491b8ea4a04f7c03cac167a712e633d7297e679ec42d0149674cdcc68
4
+ data.tar.gz: 8b31f27d7574a7e70b863d5341aabb79084a7668c8a6af4ff6eb649f42065964
5
5
  SHA512:
6
- metadata.gz: ec5fe0d075775943a5dc676fe01cbe98e56dbd4cba2deecc085309ea61aee60bca05790aacd35521cf5877d1c430f57bd5ebf32a00057c3f4f7cb55c2d80c4e1
7
- data.tar.gz: 27d5a9803fdd4d3ab3422e06613913a9c0de3983343dc0995d3c3bea78618cf721344dcee8648d60e4b5b6d04720a5dc26dc8906b8b5af9749de56142753da47
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: Logger.new(STDOUT)
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
- instrument :download, { key: key } do
31
- io = @connection.get_object(@bucket_name, key)
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.3
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: