azure-storage-file 1.0.0 → 2.0.3

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.
@@ -1,228 +1,228 @@
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/common/service/serialization"
27
-
28
- module Azure::Storage
29
- module File
30
- module Serialization
31
- include Azure::Storage::Common::Service::Serialization
32
-
33
- def self.share_enumeration_results_from_xml(xml)
34
- xml = slopify(xml)
35
- expect_node("EnumerationResults", xml)
36
-
37
- results = enumeration_results_from_xml(xml, Azure::Storage::Common::Service::EnumerationResults.new)
38
-
39
- return results unless (xml > "Shares").any? && ((xml > "Shares") > "Share").any?
40
-
41
- if xml.Shares.Share.count == 0
42
- results.push(share_from_xml(xml.Shares.Share))
43
- else
44
- xml.Shares.Share.each { |share_node|
45
- results.push(share_from_xml(share_node))
46
- }
47
- end
48
-
49
- results
50
- end
51
-
52
- def self.share_from_xml(xml)
53
- xml = slopify(xml)
54
- expect_node("Share", xml)
55
-
56
- Share::Share.new do |share|
57
- share.name = xml.Name.text if (xml > "Name").any?
58
- share.properties = share_properties_from_xml(xml.Properties) if (xml > "Properties").any?
59
- share.metadata = metadata_from_xml(xml.Metadata) if (xml > "Metadata").any?
60
- end
61
- end
62
-
63
- def self.share_properties_from_xml(xml)
64
- xml = slopify(xml)
65
- expect_node("Properties", xml)
66
-
67
- props = {}
68
- props[:last_modified] = (xml > "Last-Modified").text if (xml > "Last-Modified").any?
69
- props[:etag] = xml.ETag.text if (xml > "ETag").any?
70
- props[:quota] = xml.Quota.text if (xml > "Quota").any?
71
- props
72
- end
73
-
74
- def self.share_from_headers(headers)
75
- Share::Share.new do |share|
76
- share.properties = share_properties_from_headers(headers)
77
- share.quota = quota_from_headers(headers)
78
- share.metadata = metadata_from_headers(headers)
79
- end
80
- end
81
-
82
- def self.share_properties_from_headers(headers)
83
- props = {}
84
- props[:last_modified] = headers["Last-Modified"]
85
- props[:etag] = headers["ETag"]
86
- props
87
- end
88
-
89
- def self.quota_from_headers(headers)
90
- headers["x-ms-share-quota"] ? headers["x-ms-share-quota"].to_i : nil
91
- end
92
-
93
- def self.share_stats_from_xml(xml)
94
- xml = slopify(xml)
95
- expect_node("ShareStats", xml)
96
- xml.ShareUsage.text.to_i
97
- end
98
-
99
- def self.directories_and_files_enumeration_results_from_xml(xml)
100
- xml = slopify(xml)
101
- expect_node("EnumerationResults", xml)
102
-
103
- results = enumeration_results_from_xml(xml, Azure::Storage::Common::Service::EnumerationResults.new)
104
-
105
- return results unless (xml > "Entries").any?
106
-
107
- if ((xml > "Entries") > "File").any?
108
- if xml.Entries.File.count == 0
109
- results.push(file_from_xml(xml.Entries.File))
110
- else
111
- xml.Entries.File.each { |file_node|
112
- results.push(file_from_xml(file_node))
113
- }
114
- end
115
- end
116
-
117
- if ((xml > "Entries") > "Directory").any?
118
- if xml.Entries.Directory.count == 0
119
- results.push(directory_from_xml(xml.Entries.Directory))
120
- else
121
- xml.Entries.Directory.each { |directory_node|
122
- results.push(directory_from_xml(directory_node))
123
- }
124
- end
125
- end
126
-
127
- results
128
- end
129
-
130
- def self.file_from_xml(xml)
131
- xml = slopify(xml)
132
- expect_node("File", xml)
133
-
134
- File.new do |file|
135
- file.name = xml.Name.text if (xml > "Name").any?
136
- file.properties = file_properties_from_xml(xml.Properties) if (xml > "Properties").any?
137
- end
138
- end
139
-
140
- def self.file_properties_from_xml(xml)
141
- xml = slopify(xml)
142
- expect_node("Properties", xml)
143
-
144
- props = {}
145
- props[:content_length] = (xml > "Content-Length").text.to_i if (xml > "Content-Length").any?
146
- props
147
- end
148
-
149
- def self.directory_from_xml(xml)
150
- xml = slopify(xml)
151
- expect_node("Directory", xml)
152
-
153
- Directory::Directory.new do |directory|
154
- directory.name = xml.Name.text if (xml > "Name").any?
155
- end
156
- end
157
-
158
- def self.directory_from_headers(headers)
159
- Directory::Directory.new do |directory|
160
- directory.properties = directory_properties_from_headers(headers)
161
- directory.metadata = metadata_from_headers(headers)
162
- end
163
- end
164
-
165
- def self.directory_properties_from_headers(headers)
166
- props = {}
167
- props[:last_modified] = headers["Last-Modified"]
168
- props[:etag] = headers["ETag"]
169
- props
170
- end
171
-
172
- def self.file_from_headers(headers)
173
- File.new do |file|
174
- file.properties = file_properties_from_headers(headers)
175
- file.metadata = metadata_from_headers(headers)
176
- end
177
- end
178
-
179
- def self.file_properties_from_headers(headers)
180
- props = {}
181
-
182
- props[:last_modified] = headers["Last-Modified"]
183
- props[:etag] = headers["ETag"]
184
- props[:type] = headers["x-ms-type"]
185
-
186
- props[:content_length] = headers["Content-Length"].to_i unless headers["Content-Length"].nil?
187
- props[:content_length] = headers["x-ms-content-length"].to_i unless headers["x-ms-content-length"].nil?
188
-
189
- props[:content_type] = headers["Content-Type"]
190
- props[:content_encoding] = headers["Content-Encoding"]
191
- props[:content_language] = headers["Content-Language"]
192
- props[:content_disposition] = headers["Content-Disposition"]
193
- props[:content_md5] = headers["x-ms-content-md5"] || headers["Content-MD5"]
194
- props[:range_md5] = headers["Content-MD5"] if headers["x-ms-content-md5"] && headers["Content-MD5"]
195
- props[:cache_control] = headers["Cache-Control"]
196
-
197
- props[:copy_id] = headers["x-ms-copy-id"]
198
- props[:copy_status] = headers["x-ms-copy-status"]
199
- props[:copy_source] = headers["x-ms-copy-source"]
200
- props[:copy_progress] = headers["x-ms-copy-progress"]
201
- props[:copy_completion_time] = headers["x-ms-copy-completion-time"]
202
- props[:copy_status_description] = headers["x-ms-copy-status-description"]
203
-
204
- props[:accept_ranges] = headers["Accept-Ranges"].to_i if headers["Accept-Ranges"]
205
-
206
- props
207
- end
208
-
209
- def self.range_list_from_xml(xml)
210
- xml = slopify(xml)
211
- expect_node("Ranges", xml)
212
-
213
- range_list = []
214
- return range_list unless (xml > "Range").any?
215
-
216
- if xml.Range.count == 0
217
- range_list.push [xml.Range.Start.text.to_i, xml.Range.End.text.to_i]
218
- else
219
- xml.Range.each { |range|
220
- range_list.push [range.Start.text.to_i, range.End.text.to_i]
221
- }
222
- end
223
-
224
- range_list
225
- end
226
- end
227
- end
228
- 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
+ require "azure/storage/common/service/serialization"
27
+
28
+ module Azure::Storage
29
+ module File
30
+ module Serialization
31
+ include Azure::Storage::Common::Service::Serialization
32
+
33
+ def self.share_enumeration_results_from_xml(xml)
34
+ xml = slopify(xml)
35
+ expect_node("EnumerationResults", xml)
36
+
37
+ results = enumeration_results_from_xml(xml, Azure::Storage::Common::Service::EnumerationResults.new)
38
+
39
+ return results unless (xml > "Shares").any? && ((xml > "Shares") > "Share").any?
40
+
41
+ if xml.Shares.Share.count == 0
42
+ results.push(share_from_xml(xml.Shares.Share))
43
+ else
44
+ xml.Shares.Share.each { |share_node|
45
+ results.push(share_from_xml(share_node))
46
+ }
47
+ end
48
+
49
+ results
50
+ end
51
+
52
+ def self.share_from_xml(xml)
53
+ xml = slopify(xml)
54
+ expect_node("Share", xml)
55
+
56
+ Share::Share.new do |share|
57
+ share.name = xml.Name.text if (xml > "Name").any?
58
+ share.properties = share_properties_from_xml(xml.Properties) if (xml > "Properties").any?
59
+ share.metadata = metadata_from_xml(xml.Metadata) if (xml > "Metadata").any?
60
+ end
61
+ end
62
+
63
+ def self.share_properties_from_xml(xml)
64
+ xml = slopify(xml)
65
+ expect_node("Properties", xml)
66
+
67
+ props = {}
68
+ props[:last_modified] = (xml > "Last-Modified").text if (xml > "Last-Modified").any?
69
+ props[:etag] = xml.ETag.text if (xml > "ETag").any?
70
+ props[:quota] = xml.Quota.text if (xml > "Quota").any?
71
+ props
72
+ end
73
+
74
+ def self.share_from_headers(headers)
75
+ Share::Share.new do |share|
76
+ share.properties = share_properties_from_headers(headers)
77
+ share.quota = quota_from_headers(headers)
78
+ share.metadata = metadata_from_headers(headers)
79
+ end
80
+ end
81
+
82
+ def self.share_properties_from_headers(headers)
83
+ props = {}
84
+ props[:last_modified] = headers["Last-Modified"]
85
+ props[:etag] = headers["ETag"]
86
+ props
87
+ end
88
+
89
+ def self.quota_from_headers(headers)
90
+ headers["x-ms-share-quota"] ? headers["x-ms-share-quota"].to_i : nil
91
+ end
92
+
93
+ def self.share_stats_from_xml(xml)
94
+ xml = slopify(xml)
95
+ expect_node("ShareStats", xml)
96
+ xml.ShareUsage.text.to_i
97
+ end
98
+
99
+ def self.directories_and_files_enumeration_results_from_xml(xml)
100
+ xml = slopify(xml)
101
+ expect_node("EnumerationResults", xml)
102
+
103
+ results = enumeration_results_from_xml(xml, Azure::Storage::Common::Service::EnumerationResults.new)
104
+
105
+ return results unless (xml > "Entries").any?
106
+
107
+ if ((xml > "Entries") > "File").any?
108
+ if xml.Entries.File.count == 0
109
+ results.push(file_from_xml(xml.Entries.File))
110
+ else
111
+ xml.Entries.File.each { |file_node|
112
+ results.push(file_from_xml(file_node))
113
+ }
114
+ end
115
+ end
116
+
117
+ if ((xml > "Entries") > "Directory").any?
118
+ if xml.Entries.Directory.count == 0
119
+ results.push(directory_from_xml(xml.Entries.Directory))
120
+ else
121
+ xml.Entries.Directory.each { |directory_node|
122
+ results.push(directory_from_xml(directory_node))
123
+ }
124
+ end
125
+ end
126
+
127
+ results
128
+ end
129
+
130
+ def self.file_from_xml(xml)
131
+ xml = slopify(xml)
132
+ expect_node("File", xml)
133
+
134
+ File.new do |file|
135
+ file.name = xml.Name.text if (xml > "Name").any?
136
+ file.properties = file_properties_from_xml(xml.Properties) if (xml > "Properties").any?
137
+ end
138
+ end
139
+
140
+ def self.file_properties_from_xml(xml)
141
+ xml = slopify(xml)
142
+ expect_node("Properties", xml)
143
+
144
+ props = {}
145
+ props[:content_length] = (xml > "Content-Length").text.to_i if (xml > "Content-Length").any?
146
+ props
147
+ end
148
+
149
+ def self.directory_from_xml(xml)
150
+ xml = slopify(xml)
151
+ expect_node("Directory", xml)
152
+
153
+ Directory::Directory.new do |directory|
154
+ directory.name = xml.Name.text if (xml > "Name").any?
155
+ end
156
+ end
157
+
158
+ def self.directory_from_headers(headers)
159
+ Directory::Directory.new do |directory|
160
+ directory.properties = directory_properties_from_headers(headers)
161
+ directory.metadata = metadata_from_headers(headers)
162
+ end
163
+ end
164
+
165
+ def self.directory_properties_from_headers(headers)
166
+ props = {}
167
+ props[:last_modified] = headers["Last-Modified"]
168
+ props[:etag] = headers["ETag"]
169
+ props
170
+ end
171
+
172
+ def self.file_from_headers(headers)
173
+ File.new do |file|
174
+ file.properties = file_properties_from_headers(headers)
175
+ file.metadata = metadata_from_headers(headers)
176
+ end
177
+ end
178
+
179
+ def self.file_properties_from_headers(headers)
180
+ props = {}
181
+
182
+ props[:last_modified] = headers["Last-Modified"]
183
+ props[:etag] = headers["ETag"]
184
+ props[:type] = headers["x-ms-type"]
185
+
186
+ props[:content_length] = headers["Content-Length"].to_i unless headers["Content-Length"].nil?
187
+ props[:content_length] = headers["x-ms-content-length"].to_i unless headers["x-ms-content-length"].nil?
188
+
189
+ props[:content_type] = headers["Content-Type"]
190
+ props[:content_encoding] = headers["Content-Encoding"]
191
+ props[:content_language] = headers["Content-Language"]
192
+ props[:content_disposition] = headers["Content-Disposition"]
193
+ props[:content_md5] = headers["x-ms-content-md5"] || headers["Content-MD5"]
194
+ props[:range_md5] = headers["Content-MD5"] if headers["x-ms-content-md5"] && headers["Content-MD5"]
195
+ props[:cache_control] = headers["Cache-Control"]
196
+
197
+ props[:copy_id] = headers["x-ms-copy-id"]
198
+ props[:copy_status] = headers["x-ms-copy-status"]
199
+ props[:copy_source] = headers["x-ms-copy-source"]
200
+ props[:copy_progress] = headers["x-ms-copy-progress"]
201
+ props[:copy_completion_time] = headers["x-ms-copy-completion-time"]
202
+ props[:copy_status_description] = headers["x-ms-copy-status-description"]
203
+
204
+ props[:accept_ranges] = headers["Accept-Ranges"].to_i if headers["Accept-Ranges"]
205
+
206
+ props
207
+ end
208
+
209
+ def self.range_list_from_xml(xml)
210
+ xml = slopify(xml)
211
+ expect_node("Ranges", xml)
212
+
213
+ range_list = []
214
+ return range_list unless (xml > "Range").any?
215
+
216
+ if xml.Range.count == 0
217
+ range_list.push [xml.Range.Start.text.to_i, xml.Range.End.text.to_i]
218
+ else
219
+ xml.Range.each { |range|
220
+ range_list.push [range.Start.text.to_i, range.End.text.to_i]
221
+ }
222
+ end
223
+
224
+ range_list
225
+ end
226
+ end
227
+ end
228
+ end