azure-blob 0.5.6 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ae3b7fceea9be12467a971a8145a7ebc24e4e20c9debc0ad13ec2388fdf65b8
4
- data.tar.gz: 057cd633b835d5481e73666f2656a5e0e7bc78de5110805e647a2f95f10e0c93
3
+ metadata.gz: dd9cb1fb7e43ff7b01c0c1b751c4650be08107aaf134a6f9a5916b8671e9c067
4
+ data.tar.gz: 57b4c72aa7fd6f4f7d4e43b5b167de3ac6744d486d5e099728785fe7451b282e
5
5
  SHA512:
6
- metadata.gz: 3ace2b7d5b08599d59db6c2d0df8bc376c9c1cc1b50b8671691c04ac4f72945e10fb588f115d5d34f662db126ddb5b8ded1f7263cf3b06f3a5e9b5141d02c084
7
- data.tar.gz: 1f3407a9e1826f63f77c51acb0d1583724a4b30dd64418f53369d58cdf2c3da66bc48eba7899405e01c844823e9ab64c45ffde6fc68e73264cc107e3f764ec19
6
+ metadata.gz: 0dee84bb26174192109acfb4ac186d627c20ef54e2a3f2bb1b5ad36bcb04792c5805986ec63a805bdd4332975b3b18c45d9db75ab43f9ab3dfd42124ebdcca7b
7
+ data.tar.gz: 37080e6e53228b5bad0e70927abe736f8d769dcc90b7a93f9ac6d4480c269132f1f341fc47907a0b2e60c1741c235d57de09bf8d3b7a627ae4f9b0652c219c4e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.7] 2025-02-21
4
+
5
+ - Add `copy_blob`
6
+ - Update `compose` to use `copy_blob` if 1 source key and blob is <= 256MiB
7
+
3
8
  ## [0.5.6] 2025-01-17
4
9
 
5
10
  - Fix user delegation key not refreshing (#14)
data/Rakefile CHANGED
@@ -20,6 +20,15 @@ end
20
20
  task default: %i[test]
21
21
 
22
22
  task :test do
23
+ [
24
+ "AZURE_ACCOUNT_NAME",
25
+ "AZURE_PRIVATE_CONTAINER",
26
+ "AZURE_PUBLIC_CONTAINER",
27
+ ].each do |env|
28
+ value = ENV[env]
29
+ raise "#{env} variable need to be set if you are using the nix/devenv environment, consider running generate-env-file" if value.nil? || value.empty?
30
+ end
31
+
23
32
  Rake::Task["test_client"].execute
24
33
  Rake::Task["test_rails"].execute
25
34
  end
@@ -123,16 +123,22 @@ module ActiveStorage
123
123
  def compose(source_keys, destination_key, filename: nil, content_type: nil, disposition: nil, custom_metadata: {})
124
124
  content_disposition = content_disposition_with(type: disposition, filename: filename) if disposition && filename
125
125
 
126
- client.create_append_blob(
127
- destination_key,
128
- content_type: content_type,
129
- content_disposition: content_disposition,
130
- metadata: custom_metadata,
131
- )
132
-
133
- source_keys.each do |source_key|
134
- stream(source_key) do |chunk|
135
- client.append_blob_block(destination_key, chunk)
126
+ # use copy_blob operation if composing a new blob from a single existing blob
127
+ # and that single blob is <= 256 MiB which is the upper limit for copy_blob operation
128
+ if source_keys.length == 1 && client.get_blob_properties(source_keys[0]).size <= 256.megabytes
129
+ client.copy_blob(destination_key, source_keys[0], metadata: custom_metadata)
130
+ else
131
+ client.create_append_blob(
132
+ destination_key,
133
+ content_type: content_type,
134
+ content_disposition: content_disposition,
135
+ metadata: custom_metadata,
136
+ )
137
+
138
+ source_keys.each do |source_key|
139
+ stream(source_key) do |chunk|
140
+ client.append_blob_block(destination_key, chunk)
141
+ end
136
142
  end
137
143
  end
138
144
  end
@@ -77,6 +77,25 @@ module AzureBlob
77
77
  Http.new(uri, headers, signer:).get
78
78
  end
79
79
 
80
+ # Copy a blob
81
+ #
82
+ # Calls to {Copy Blob From URL}[https://learn.microsoft.com/en-us/rest/api/storageservices/copy-blob-from-url]
83
+ #
84
+ # Takes a key (path) and a source_key (path).
85
+ #
86
+ def copy_blob(key, source_key, options = {})
87
+ uri = generate_uri("#{container}/#{key}")
88
+
89
+ source_uri = signed_uri(source_key, permissions: "r", expiry: Time.at(Time.now.to_i + 300).utc.iso8601)
90
+
91
+ headers = {
92
+ "x-ms-copy-source": source_uri.to_s,
93
+ "x-ms-requires-sync": "true",
94
+ }
95
+
96
+ Http.new(uri, headers, signer:, **options.slice(:metadata, :tags)).put
97
+ end
98
+
80
99
  # Delete a blob
81
100
  #
82
101
  # Calls to {Delete Blob}[https://learn.microsoft.com/en-us/rest/api/storageservices/delete-blob]
@@ -202,7 +221,7 @@ module AzureBlob
202
221
  uri = generate_uri(container)
203
222
  headers = {}
204
223
  headers[:"x-ms-blob-public-access"] = "blob" if options[:public_access]
205
- headers[:"x-ms-blob-public-access"] = options[:public_access] if ["container","blob"].include?(options[:public_access])
224
+ headers[:"x-ms-blob-public-access"] = options[:public_access] if [ "container", "blob" ].include?(options[:public_access])
206
225
 
207
226
  uri.query = URI.encode_www_form(restype: "container")
208
227
  response = Http.new(uri, headers, signer:).put
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AzureBlob
4
- VERSION = "0.5.6"
4
+ VERSION = "0.5.7"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: azure-blob
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joé Dupuis