StorageTaskSnapshot.swift 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. /**
  16. * `StorageTaskSnapshot` represents an immutable view of a task.
  17. * A snapshot contains a task, storage reference, metadata (if it exists),
  18. * progress, and an error (if one occurred).
  19. */
  20. @objc(FIRStorageTaskSnapshot) open class StorageTaskSnapshot: NSObject {
  21. /**
  22. * The task this snapshot represents.
  23. */
  24. @objc public let task: StorageTask
  25. /**
  26. * Metadata returned by the task, or `nil` if no metadata returned.
  27. */
  28. @objc public let metadata: StorageMetadata?
  29. /**
  30. * The `StorageReference` this task operates on.
  31. */
  32. @objc public let reference: StorageReference
  33. /**
  34. * An object which tracks the progress of an upload or download.
  35. */
  36. @objc public let progress: Progress?
  37. /**
  38. * An error raised during task execution, or `nil` if no error occurred.
  39. */
  40. @objc public let error: Error?
  41. /**
  42. * The status of the task.
  43. */
  44. @objc public let status: StorageTaskStatus
  45. // MARK: NSObject overrides
  46. @objc override public var description: String {
  47. switch status {
  48. case .resume: return "<State: Resume>"
  49. case .progress: return "<State: Progress, Progress: \(String(describing: progress))>"
  50. case .pause: return "<State: Paused>"
  51. case .success: return "<State: Success>"
  52. case .failure: return "<State: Failed, Error: \(String(describing: error))"
  53. case .unknown: return "<State: Unknown>"
  54. }
  55. }
  56. init(task: StorageTask,
  57. state: StorageTaskState,
  58. reference: StorageReference,
  59. progress: Progress,
  60. metadata: StorageMetadata? = nil,
  61. error: NSError? = nil) {
  62. self.task = task
  63. self.reference = reference
  64. self.progress = progress
  65. self.error = error
  66. self.metadata = metadata
  67. switch state {
  68. case .queueing, .running, .resuming: status = StorageTaskStatus.resume
  69. case .progress: status = StorageTaskStatus.progress
  70. case .paused, .pausing: status = StorageTaskStatus.pause
  71. case .success, .completing: status = StorageTaskStatus.success
  72. case .cancelled, .failed, .failing: status = .failure
  73. case .unknown: status = .unknown
  74. }
  75. }
  76. }