StorageMetadata.swift 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // Copyright 2022 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import Foundation
  15. import FirebaseStorageInternal
  16. /**
  17. * Class which represents the metadata on an object in Firebase Storage. This metadata is
  18. * returned on successful operations, and can be used to retrieve download URLs, content types,
  19. * and a Storage reference to the object in question. Full documentation can be found at the GCS
  20. * Objects#resource docs.
  21. * @see https://cloud.google.com/storage/docs/json_api/v1/objects#resource
  22. */
  23. @objc(FIRStorageMetadata) open class StorageMetadata: NSObject {
  24. // MARK: - Public APIs
  25. /**
  26. * The name of the bucket containing this object.
  27. */
  28. @objc public let bucket: String
  29. /**
  30. * Cache-Control directive for the object data.
  31. */
  32. @objc public var cacheControl: String? {
  33. get {
  34. return impl.cacheControl
  35. }
  36. set(newValue) {
  37. impl.cacheControl = newValue
  38. }
  39. }
  40. /**
  41. * Content-Disposition of the object data.
  42. */
  43. @objc public var contentDisposition: String? {
  44. get {
  45. return impl.contentDisposition
  46. }
  47. set(newValue) {
  48. impl.contentDisposition = newValue
  49. }
  50. }
  51. /**
  52. * Content-Encoding of the object data.
  53. */
  54. @objc public var contentEncoding: String? {
  55. get {
  56. return impl.contentEncoding
  57. }
  58. set(newValue) {
  59. impl.contentEncoding = newValue
  60. }
  61. }
  62. /**
  63. * Content-Language of the object data.
  64. */
  65. @objc public var contentLanguage: String? {
  66. get {
  67. return impl.contentLanguage
  68. }
  69. set(newValue) {
  70. impl.contentLanguage = newValue
  71. }
  72. }
  73. /**
  74. * Content-Type of the object data.
  75. */
  76. @objc public var contentType: String? {
  77. get {
  78. return impl.contentType
  79. }
  80. set(newValue) {
  81. impl.contentType = newValue
  82. }
  83. }
  84. /**
  85. * MD5 hash of the data; encoded using base64.
  86. */
  87. @objc public let md5Hash: String?
  88. /**
  89. * The content generation of this object. Used for object versioning.
  90. */
  91. @objc public let generation: Int64
  92. /**
  93. * User-provided metadata, in key/value pairs.
  94. */
  95. @objc public var customMetadata: [String: String]? {
  96. get {
  97. return impl.customMetadata
  98. }
  99. set(newValue) {
  100. impl.customMetadata = newValue
  101. }
  102. }
  103. /**
  104. * The version of the metadata for this object at this generation. Used
  105. * for preconditions and for detecting changes in metadata. A metageneration number is only
  106. * meaningful in the context of a particular generation of a particular object.
  107. */
  108. @objc public let metageneration: Int64
  109. /**
  110. * The name of this object, in gs://bucket/path/to/object.txt, this is object.txt.
  111. */
  112. @objc public let name: String?
  113. /**
  114. * The full path of this object, in gs://bucket/path/to/object.txt, this is path/to/object.txt.
  115. */
  116. @objc public let path: String?
  117. /**
  118. * Content-Length of the data in bytes.
  119. */
  120. @objc public let size: Int64
  121. /**
  122. * The creation time of the object in RFC 3339 format.
  123. */
  124. @objc public let timeCreated: Date?
  125. /**
  126. * The modification time of the object metadata in RFC 3339 format.
  127. */
  128. @objc public let updated: Date?
  129. /**
  130. * A reference to the object in Firebase Storage.
  131. */
  132. @objc public let storageReference: StorageReference?
  133. /**
  134. * Creates a Dictionary from the contents of the metadata.
  135. * @return A Dictionary that represents the contents of the metadata.
  136. */
  137. @objc open func dictionaryRepresentation() -> [String: Any] {
  138. return impl.dictionaryRepresentation()
  139. }
  140. /**
  141. * Determines if the current metadata represents a "file".
  142. */
  143. @objc public let isFile: Bool
  144. /**
  145. * Determines if the current metadata represents a "folder".
  146. */
  147. @objc public let isFolder: Bool
  148. // MARK: - Public Initializers
  149. @objc override public convenience init() {
  150. self.init(impl: FIRIMPLStorageMetadata(dictionary: [:])!)
  151. }
  152. /**
  153. * Creates an instance of StorageMetadata from the contents of a dictionary.
  154. * @return An instance of StorageMetadata that represents the contents of a dictionary.
  155. */
  156. @objc public convenience init(dictionary: [String: Any]) {
  157. self.init(impl: FIRIMPLStorageMetadata(dictionary: dictionary)!)
  158. }
  159. // MARK: - Internal APIs
  160. internal let impl: FIRIMPLStorageMetadata
  161. internal init(impl: FIRIMPLStorageMetadata) {
  162. self.impl = impl
  163. bucket = impl.bucket
  164. md5Hash = impl.md5Hash
  165. generation = impl.generation
  166. metageneration = impl.metageneration
  167. name = impl.name
  168. path = impl.path
  169. size = impl.size
  170. timeCreated = impl.timeCreated
  171. updated = impl.updated
  172. if let ref = impl.storageReference {
  173. storageReference = StorageReference(ref)
  174. } else {
  175. storageReference = nil
  176. }
  177. isFile = impl.isFile
  178. isFolder = impl.isFolder
  179. }
  180. }