StorageTaskSnapshot.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. * `StorageTaskSnapshot` represents an immutable view of a task.
  18. * A snapshot contains a task, storage reference, metadata (if it exists),
  19. * progress, and an error (if one occurred).
  20. */
  21. @objc(FIRStorageTaskSnapshot) open class StorageTaskSnapshot: NSObject {
  22. /**
  23. * The task this snapshot represents.
  24. */
  25. @objc public let task: StorageTask
  26. /**
  27. * Metadata returned by the task, or `nil` if no metadata returned.
  28. */
  29. @objc public let metadata: StorageMetadata?
  30. /**
  31. * The `StorageReference` this task operates on.
  32. */
  33. @objc public let reference: StorageReference
  34. /**
  35. * An object which tracks the progress of an upload or download.
  36. */
  37. @objc public let progress: Progress?
  38. /**
  39. * An error raised during task execution, or `nil` if no error occurred.
  40. */
  41. @objc public let error: Error?
  42. /**
  43. * The status of the task.
  44. */
  45. @objc public let status: StorageTaskStatus
  46. // MARK: - NSObject overrides
  47. @objc override public var description: String {
  48. return saveDescription
  49. }
  50. private let saveDescription: String
  51. internal convenience init(task: StorageTask) {
  52. self.init(impl: task.impl.snapshot, task: task)
  53. }
  54. internal init(impl: FIRIMPLStorageTaskSnapshot, task: StorageTask) {
  55. self.task = task
  56. if let metadata = impl.metadata {
  57. self.metadata = StorageMetadata(impl: metadata)
  58. } else {
  59. metadata = nil
  60. }
  61. reference = StorageReference(impl.reference)
  62. progress = impl.progress
  63. error = impl.error
  64. status = StorageTaskStatus(rawValue: impl.status.rawValue)!
  65. saveDescription = impl.description
  66. }
  67. }