azure-storage-blob 1.1.0 → 2.0.0

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
- SHA1:
3
- metadata.gz: 3e3941be4da83f43257cf6fbac2a635079749dcf
4
- data.tar.gz: 638399581dd8f938067caa056be80c9d23e81a58
2
+ SHA256:
3
+ metadata.gz: 17ffe6e32cdb3b54c9af1f1d42cfca19c907279cb143b28e4c0348ea4d7a55b3
4
+ data.tar.gz: 7334b27de90a31bb7dd80d1ac8be7896c7df98f6138523d55943df9bf8b7cdb6
5
5
  SHA512:
6
- metadata.gz: 6556378bcdf790fab6a944bd8c5fbf530e23b61f86ec41f8652b0f53a219ebfb4b5a97399035fdcebccbc00ad22f59b56346628a28cc3a5355d82b1fc18aa3ae
7
- data.tar.gz: 33a830df775c9b64403e8e06f63f4d331bd14cbfefddb6e320c76efa0b2a3f4b9eb45f10d2886d088aca5898b065d38d25a2ac62fe97c8e12c8bff8d26b73d61
6
+ metadata.gz: 9b493606e1d9a99ed179257aab510a8ae64f77feb44a95c3d4c821c8f1f881b51351141a29f5bc147f1e042104d0d2b34d2aa699041b68526477b0f9c0dde886
7
+ data.tar.gz: 4ab005444bb1c6e2e5923731b97eb20ad8f98b72066bbd70248e9649b16277a3a7728379e8b2ccfc58f258e27ce401c6c8366ba333c21e3d44defe2edaeab637
@@ -1,26 +1,26 @@
1
- # frozen_string_literal: true
2
-
3
- #-------------------------------------------------------------------------
4
- # # Copyright (c) Microsoft and contributors. All rights reserved.
5
- #
6
- # The MIT License(MIT)
7
-
8
- # Permission is hereby granted, free of charge, to any person obtaining a copy
9
- # of this software and associated documentation files(the "Software"), to deal
10
- # in the Software without restriction, including without limitation the rights
11
- # to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12
- # copies of the Software, and to permit persons to whom the Software is
13
- # furnished to do so, subject to the following conditions :
14
-
15
- # The above copyright notice and this permission notice shall be included in
16
- # all copies or substantial portions of the Software.
17
-
18
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
- # THE SOFTWARE.
25
- #--------------------------------------------------------------------------
26
- require "azure/storage/blob/autoload"
1
+ # frozen_string_literal: true
2
+
3
+ #-------------------------------------------------------------------------
4
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
5
+ #
6
+ # The MIT License(MIT)
7
+
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files(the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions :
14
+
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+ #--------------------------------------------------------------------------
26
+ require "azure/storage/blob/autoload"
@@ -1,244 +1,244 @@
1
- # frozen_string_literal: true
2
-
3
- #-------------------------------------------------------------------------
4
- # # Copyright (c) Microsoft and contributors. All rights reserved.
5
- #
6
- # The MIT License(MIT)
7
-
8
- # Permission is hereby granted, free of charge, to any person obtaining a copy
9
- # of this software and associated documentation files(the "Software"), to deal
10
- # in the Software without restriction, including without limitation the rights
11
- # to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12
- # copies of the Software, and to permit persons to whom the Software is
13
- # furnished to do so, subject to the following conditions :
14
-
15
- # The above copyright notice and this permission notice shall be included in
16
- # all copies or substantial portions of the Software.
17
-
18
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
- # THE SOFTWARE.
25
- #--------------------------------------------------------------------------
26
-
27
- module Azure::Storage
28
- module Blob
29
- # Public: Creates a new append blob. Note that calling create_append_blob to create an append
30
- # blob only initializes the blob. To add content to an append blob, call append_blob_blocks method.
31
- #
32
- # ==== Attributes
33
- #
34
- # * +container+ - String. The container name.
35
- # * +blob+ - String. The blob name.
36
- # * +options+ - Hash. Optional parameters.
37
- #
38
- # ==== Options
39
- #
40
- # Accepted key/value pairs in options parameter are:
41
- # * +:content_type+ - String. Content type for the blob. Will be saved with blob.
42
- # * +:content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
43
- # * +:content_language+ - String. Content language for the blob. Will be saved with blob.
44
- # * +:content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
45
- # * +:cache_control+ - String. Cache control for the blob. Will be saved with blob.
46
- # * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
47
- # and also can be used to attach additional metadata
48
- # * +:metadata+ - Hash. Custom metadata values to store with the blob.
49
- # * +:timeout+ - Integer. A timeout in seconds.
50
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
51
- # in the analytics logs when storage analytics logging is enabled.
52
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
53
- # only if the blob has been modified since the specified date/time. If the blob has not been modified,
54
- # the Blob service returns status code 412 (Precondition Failed).
55
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
56
- # only if the blob has not been modified since the specified date/time. If the blob has been modified,
57
- # the Blob service returns status code 412 (Precondition Failed).
58
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
59
- # only if the blob's ETag value matches the value specified. If the values do not match,
60
- # the Blob service returns status code 412 (Precondition Failed).
61
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
62
- # only if the blob's ETag value does not match the value specified. If the values are identical,
63
- # the Blob service returns status code 412 (Precondition Failed).
64
- # * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active lease,
65
- # specify the valid lease ID for this header.
66
- #
67
- # See http://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
68
- #
69
- # Returns a Blob
70
- def create_append_blob(container, blob, options = {})
71
- query = {}
72
- StorageService.with_query query, "timeout", options[:timeout] if options[:timeout]
73
-
74
- uri = blob_uri(container, blob, query)
75
-
76
- headers = {}
77
-
78
- # set x-ms-blob-type to AppendBlob
79
- StorageService.with_header headers, "x-ms-blob-type", "AppendBlob"
80
-
81
- # ensure content-length is 0
82
- StorageService.with_header headers, "Content-Length", 0
83
-
84
- # set the rest of the optional headers
85
- StorageService.with_header headers, "x-ms-blob-content-type", options[:content_type]
86
- StorageService.with_header headers, "x-ms-blob-content-encoding", options[:content_encoding]
87
- StorageService.with_header headers, "x-ms-blob-content-language", options[:content_language]
88
- StorageService.with_header headers, "x-ms-blob-content-md5", options[:content_md5]
89
- StorageService.with_header headers, "x-ms-blob-cache-control", options[:cache_control]
90
- StorageService.with_header headers, "x-ms-blob-content-disposition", options[:content_disposition]
91
-
92
- StorageService.add_metadata_to_headers options[:metadata], headers
93
- add_blob_conditional_headers options, headers
94
- headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
95
- headers["x-ms-blob-content-type"] = Default::CONTENT_TYPE_VALUE unless headers["x-ms-blob-content-type"]
96
-
97
- # call PutBlob with empty body
98
- response = call(:put, uri, nil, headers, options)
99
-
100
- result = Serialization.blob_from_headers(response.headers)
101
- result.name = blob
102
- result.metadata = options[:metadata] if options[:metadata]
103
-
104
- result
105
- end
106
-
107
- # Public: Commits a new block of data to the end of an existing append blob.
108
- # This operation is permitted only on blobs created with the create_append_blob API.
109
- #
110
- # ==== Attributes
111
- #
112
- # * +container+ - String. The container name.
113
- # * +blob+ - String. The blob name.
114
- # * +content+ - IO or String. The content of the blob.
115
- # * +options+ - Hash. Optional parameters.
116
- #
117
- # ==== Options
118
- #
119
- # Accepted key/value pairs in options parameter are:
120
- # * +:content_md5+ - String. Content MD5 for the request contents.
121
- # * +:max_size+ - Integer. The max length in bytes permitted for the append blob
122
- # * +:append_position+ - Integer. A number indicating the byte offset to compare. It will succeed only if the append position is equal to this number
123
- # * +:timeout+ - Integer. A timeout in seconds.
124
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
125
- # in the analytics logs when storage analytics logging is enabled.
126
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to append a block only if
127
- # the blob has been modified since the specified date/time. If the blob has not been modified,
128
- # the Blob service returns status code 412 (Precondition Failed).
129
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to append a block only if
130
- # the blob has not been modified since the specified date/time. If the blob has been modified,
131
- # the Blob service returns status code 412 (Precondition Failed).
132
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to append a block only if
133
- # the blob's ETag value matches the value specified. If the values do not match,
134
- # the Blob service returns status code 412 (Precondition Failed).
135
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to append a block only if
136
- # the blob's ETag value does not match the value specified. If the values are identical,
137
- # the Blob service returns status code 412 (Precondition Failed).
138
- # * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an
139
- # active lease, specify the valid lease ID for this header.
140
- #
141
- # See http://msdn.microsoft.com/en-us/library/azure/mt427365.aspx
142
- #
143
- # Returns a Blob
144
- def append_blob_block(container, blob, content, options = {})
145
- query = { "comp" => "appendblock" }
146
- StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
147
-
148
- uri = blob_uri(container, blob, query)
149
-
150
- headers = {}
151
- StorageService.with_header headers, "Content-MD5", options[:content_md5]
152
- StorageService.with_header headers, "x-ms-lease-id", options[:lease_id]
153
- StorageService.with_header headers, "x-ms-blob-condition-maxsize", options[:max_size]
154
- StorageService.with_header headers, "x-ms-blob-condition-appendpos", options[:append_position]
155
-
156
- add_blob_conditional_headers options, headers
157
- headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
158
-
159
- response = call(:put, uri, content, headers, options)
160
- result = Serialization.blob_from_headers(response.headers)
161
- result.name = blob
162
-
163
- result
164
- end
165
-
166
- # Public: Creates a new append blob with given content
167
- #
168
- # ==== Attributes
169
- #
170
- # * +container+ - String. The container name.
171
- # * +blob+ - String. The blob name.
172
- # * +content+ - IO or String. Content to write.
173
- # * +options+ - Hash. Optional parameters.
174
- #
175
- # ==== Options
176
- #
177
- # Accepted key/value pairs in options parameter are:
178
- # * +:content_type+ - String. Content type for the blob. Will be saved with blob.
179
- # * +:content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
180
- # * +:content_language+ - String. Content language for the blob. Will be saved with blob.
181
- # * +:content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
182
- # * +:cache_control+ - String. Cache control for the blob. Will be saved with blob.
183
- # * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
184
- # and also can be used to attach additional metadata
185
- # * +:max_size+ - Integer. The max length in bytes permitted for the append blob.
186
- # * +:metadata+ - Hash. Custom metadata values to store with the blob.
187
- # * +:timeout+ - Integer. A timeout in seconds.
188
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
189
- # in the analytics logs when storage analytics logging is enabled.
190
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
191
- # only if the blob has been modified since the specified date/time. If the blob has not been modified,
192
- # the Blob service returns status code 412 (Precondition Failed).
193
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
194
- # only if the blob has not been modified since the specified date/time. If the blob has been modified,
195
- # the Blob service returns status code 412 (Precondition Failed).
196
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
197
- # only if the blob's ETag value matches the value specified. If the values do not match,
198
- # the Blob service returns status code 412 (Precondition Failed).
199
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
200
- # only if the blob's ETag value does not match the value specified. If the values are identical,
201
- # the Blob service returns status code 412 (Precondition Failed).
202
- # * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active lease,
203
- # specify the valid lease ID for this header.
204
- #
205
- # See http://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
206
- #
207
- # Returns a Blob
208
- def create_append_blob_from_content(container, blob, content, options = {})
209
- # Fail fast if content has larger size than max_size
210
- max_size = options.delete :max_size
211
- if max_size
212
- if content.respond_to?(:size) && max_size < content.size
213
- raise Azure::Storage::Common::Core::StorageError.new("Given content has exceeded the specified maximum size for the blob.")
214
- end
215
- end
216
- options[:content_type] = get_or_apply_content_type(content, options[:content_type])
217
- create_append_blob(container, blob, options)
218
- content = StringIO.new(content) if content.is_a? String
219
- # initialize the append block options.
220
- append_block_options = {}
221
- append_block_options[:if_modified_since] = options[:if_modified_since] if options[:if_modified_since]
222
- append_block_options[:if_unmodified_since] = options[:if_unmodified_since] if options[:if_unmodified_since]
223
- append_block_options[:if_match] = options[:if_match] if options[:if_match]
224
- append_block_options[:if_none_match] = options[:if_none_match] if options[:if_none_match]
225
- append_block_options[:lease_id] = options[:lease_id] if options[:lease_id]
226
- append_block_options[:max_size] = max_size if max_size
227
- position = 0
228
- while !content.eof?
229
- payload = content.read(BlobConstants::DEFAULT_WRITE_BLOCK_SIZE_IN_BYTES)
230
- # set the append position to make sure that each append is going to the correct offset.
231
- append_block_options[:append_position] = position
232
- append_blob_block(container, blob, payload, append_block_options)
233
- # calculate the position after the append.
234
- position += payload.size
235
- end
236
-
237
- get_properties_options = {}
238
- get_properties_options[:lease_id] = options[:lease_id] if options[:lease_id]
239
-
240
- # Get the blob properties
241
- get_blob_properties(container, blob, get_properties_options)
242
- end
243
- end
244
- end
1
+ # frozen_string_literal: true
2
+
3
+ #-------------------------------------------------------------------------
4
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
5
+ #
6
+ # The MIT License(MIT)
7
+
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files(the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions :
14
+
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+ #--------------------------------------------------------------------------
26
+
27
+ module Azure::Storage
28
+ module Blob
29
+ # Public: Creates a new append blob. Note that calling create_append_blob to create an append
30
+ # blob only initializes the blob. To add content to an append blob, call append_blob_blocks method.
31
+ #
32
+ # ==== Attributes
33
+ #
34
+ # * +container+ - String. The container name.
35
+ # * +blob+ - String. The blob name.
36
+ # * +options+ - Hash. Optional parameters.
37
+ #
38
+ # ==== Options
39
+ #
40
+ # Accepted key/value pairs in options parameter are:
41
+ # * +:content_type+ - String. Content type for the blob. Will be saved with blob.
42
+ # * +:content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
43
+ # * +:content_language+ - String. Content language for the blob. Will be saved with blob.
44
+ # * +:content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
45
+ # * +:cache_control+ - String. Cache control for the blob. Will be saved with blob.
46
+ # * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
47
+ # and also can be used to attach additional metadata
48
+ # * +:metadata+ - Hash. Custom metadata values to store with the blob.
49
+ # * +:timeout+ - Integer. A timeout in seconds.
50
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
51
+ # in the analytics logs when storage analytics logging is enabled.
52
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
53
+ # only if the blob has been modified since the specified date/time. If the blob has not been modified,
54
+ # the Blob service returns status code 412 (Precondition Failed).
55
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
56
+ # only if the blob has not been modified since the specified date/time. If the blob has been modified,
57
+ # the Blob service returns status code 412 (Precondition Failed).
58
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
59
+ # only if the blob's ETag value matches the value specified. If the values do not match,
60
+ # the Blob service returns status code 412 (Precondition Failed).
61
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
62
+ # only if the blob's ETag value does not match the value specified. If the values are identical,
63
+ # the Blob service returns status code 412 (Precondition Failed).
64
+ # * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active lease,
65
+ # specify the valid lease ID for this header.
66
+ #
67
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
68
+ #
69
+ # Returns a Blob
70
+ def create_append_blob(container, blob, options = {})
71
+ query = {}
72
+ StorageService.with_query query, "timeout", options[:timeout] if options[:timeout]
73
+
74
+ uri = blob_uri(container, blob, query)
75
+
76
+ headers = {}
77
+
78
+ # set x-ms-blob-type to AppendBlob
79
+ StorageService.with_header headers, "x-ms-blob-type", "AppendBlob"
80
+
81
+ # ensure content-length is 0
82
+ StorageService.with_header headers, "Content-Length", 0
83
+
84
+ # set the rest of the optional headers
85
+ StorageService.with_header headers, "x-ms-blob-content-type", options[:content_type]
86
+ StorageService.with_header headers, "x-ms-blob-content-encoding", options[:content_encoding]
87
+ StorageService.with_header headers, "x-ms-blob-content-language", options[:content_language]
88
+ StorageService.with_header headers, "x-ms-blob-content-md5", options[:content_md5]
89
+ StorageService.with_header headers, "x-ms-blob-cache-control", options[:cache_control]
90
+ StorageService.with_header headers, "x-ms-blob-content-disposition", options[:content_disposition]
91
+
92
+ StorageService.add_metadata_to_headers options[:metadata], headers
93
+ add_blob_conditional_headers options, headers
94
+ headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
95
+ headers["x-ms-blob-content-type"] = Default::CONTENT_TYPE_VALUE unless headers["x-ms-blob-content-type"]
96
+
97
+ # call PutBlob with empty body
98
+ response = call(:put, uri, nil, headers, options)
99
+
100
+ result = Serialization.blob_from_headers(response.headers)
101
+ result.name = blob
102
+ result.metadata = options[:metadata] if options[:metadata]
103
+
104
+ result
105
+ end
106
+
107
+ # Public: Commits a new block of data to the end of an existing append blob.
108
+ # This operation is permitted only on blobs created with the create_append_blob API.
109
+ #
110
+ # ==== Attributes
111
+ #
112
+ # * +container+ - String. The container name.
113
+ # * +blob+ - String. The blob name.
114
+ # * +content+ - IO or String. The content of the blob.
115
+ # * +options+ - Hash. Optional parameters.
116
+ #
117
+ # ==== Options
118
+ #
119
+ # Accepted key/value pairs in options parameter are:
120
+ # * +:content_md5+ - String. Content MD5 for the request contents.
121
+ # * +:max_size+ - Integer. The max length in bytes permitted for the append blob
122
+ # * +:append_position+ - Integer. A number indicating the byte offset to compare. It will succeed only if the append position is equal to this number
123
+ # * +:timeout+ - Integer. A timeout in seconds.
124
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
125
+ # in the analytics logs when storage analytics logging is enabled.
126
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to append a block only if
127
+ # the blob has been modified since the specified date/time. If the blob has not been modified,
128
+ # the Blob service returns status code 412 (Precondition Failed).
129
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to append a block only if
130
+ # the blob has not been modified since the specified date/time. If the blob has been modified,
131
+ # the Blob service returns status code 412 (Precondition Failed).
132
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to append a block only if
133
+ # the blob's ETag value matches the value specified. If the values do not match,
134
+ # the Blob service returns status code 412 (Precondition Failed).
135
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to append a block only if
136
+ # the blob's ETag value does not match the value specified. If the values are identical,
137
+ # the Blob service returns status code 412 (Precondition Failed).
138
+ # * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an
139
+ # active lease, specify the valid lease ID for this header.
140
+ #
141
+ # See http://msdn.microsoft.com/en-us/library/azure/mt427365.aspx
142
+ #
143
+ # Returns a Blob
144
+ def append_blob_block(container, blob, content, options = {})
145
+ query = { "comp" => "appendblock" }
146
+ StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
147
+
148
+ uri = blob_uri(container, blob, query)
149
+
150
+ headers = {}
151
+ StorageService.with_header headers, "Content-MD5", options[:content_md5]
152
+ StorageService.with_header headers, "x-ms-lease-id", options[:lease_id]
153
+ StorageService.with_header headers, "x-ms-blob-condition-maxsize", options[:max_size]
154
+ StorageService.with_header headers, "x-ms-blob-condition-appendpos", options[:append_position]
155
+
156
+ add_blob_conditional_headers options, headers
157
+ headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
158
+
159
+ response = call(:put, uri, content, headers, options)
160
+ result = Serialization.blob_from_headers(response.headers)
161
+ result.name = blob
162
+
163
+ result
164
+ end
165
+
166
+ # Public: Creates a new append blob with given content
167
+ #
168
+ # ==== Attributes
169
+ #
170
+ # * +container+ - String. The container name.
171
+ # * +blob+ - String. The blob name.
172
+ # * +content+ - IO or String. Content to write.
173
+ # * +options+ - Hash. Optional parameters.
174
+ #
175
+ # ==== Options
176
+ #
177
+ # Accepted key/value pairs in options parameter are:
178
+ # * +:content_type+ - String. Content type for the blob. Will be saved with blob.
179
+ # * +:content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
180
+ # * +:content_language+ - String. Content language for the blob. Will be saved with blob.
181
+ # * +:content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
182
+ # * +:cache_control+ - String. Cache control for the blob. Will be saved with blob.
183
+ # * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
184
+ # and also can be used to attach additional metadata
185
+ # * +:max_size+ - Integer. The max length in bytes permitted for the append blob.
186
+ # * +:metadata+ - Hash. Custom metadata values to store with the blob.
187
+ # * +:timeout+ - Integer. A timeout in seconds.
188
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
189
+ # in the analytics logs when storage analytics logging is enabled.
190
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
191
+ # only if the blob has been modified since the specified date/time. If the blob has not been modified,
192
+ # the Blob service returns status code 412 (Precondition Failed).
193
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
194
+ # only if the blob has not been modified since the specified date/time. If the blob has been modified,
195
+ # the Blob service returns status code 412 (Precondition Failed).
196
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
197
+ # only if the blob's ETag value matches the value specified. If the values do not match,
198
+ # the Blob service returns status code 412 (Precondition Failed).
199
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
200
+ # only if the blob's ETag value does not match the value specified. If the values are identical,
201
+ # the Blob service returns status code 412 (Precondition Failed).
202
+ # * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active lease,
203
+ # specify the valid lease ID for this header.
204
+ #
205
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
206
+ #
207
+ # Returns a Blob
208
+ def create_append_blob_from_content(container, blob, content, options = {})
209
+ # Fail fast if content has larger size than max_size
210
+ max_size = options.delete :max_size
211
+ if max_size
212
+ if content.respond_to?(:size) && max_size < content.size
213
+ raise Azure::Storage::Common::Core::StorageError.new("Given content has exceeded the specified maximum size for the blob.")
214
+ end
215
+ end
216
+ options[:content_type] = get_or_apply_content_type(content, options[:content_type])
217
+ create_append_blob(container, blob, options)
218
+ content = StringIO.new(content) if content.is_a? String
219
+ # initialize the append block options.
220
+ append_block_options = {}
221
+ append_block_options[:if_modified_since] = options[:if_modified_since] if options[:if_modified_since]
222
+ append_block_options[:if_unmodified_since] = options[:if_unmodified_since] if options[:if_unmodified_since]
223
+ append_block_options[:if_match] = options[:if_match] if options[:if_match]
224
+ append_block_options[:if_none_match] = options[:if_none_match] if options[:if_none_match]
225
+ append_block_options[:lease_id] = options[:lease_id] if options[:lease_id]
226
+ append_block_options[:max_size] = max_size if max_size
227
+ position = 0
228
+ while !content.eof?
229
+ payload = content.read(BlobConstants::DEFAULT_WRITE_BLOCK_SIZE_IN_BYTES)
230
+ # set the append position to make sure that each append is going to the correct offset.
231
+ append_block_options[:append_position] = position
232
+ append_blob_block(container, blob, payload, append_block_options)
233
+ # calculate the position after the append.
234
+ position += payload.size
235
+ end
236
+
237
+ get_properties_options = {}
238
+ get_properties_options[:lease_id] = options[:lease_id] if options[:lease_id]
239
+
240
+ # Get the blob properties
241
+ get_blob_properties(container, blob, get_properties_options)
242
+ end
243
+ end
244
+ end