Skip to content

Commit 6a2de7e

Browse files
authored
Add API docs for FirebaseStorageSwift (#5241)
1 parent 90e4522 commit 6a2de7e

File tree

1 file changed

+109
-2
lines changed

1 file changed

+109
-2
lines changed

FirebaseStorageSwift/Sources/SwiftAPIExtension.swift

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@
1414

1515
import FirebaseStorage
1616

17-
/// getResultCallback generates a closure that returns a Result type from a closure that returns an
18-
/// optional type and Error.
17+
/// Generates a closure that returns a `Result` type from a closure that returns an optional type
18+
/// and `Error`.
19+
///
20+
/// - Parameters:
21+
/// - completion: A completion block returning a `Result` enum with either a generic object or
22+
/// an `Error`.
23+
/// - Returns: A closure parameterized with an optional generic and optional `Error` to match
24+
/// Objective C APIs.
1925
private func getResultCallback<T>(
2026
completion: @escaping (Result<T, Error>) -> Void
2127
) -> (_: T?, _: Error?) -> Void {
@@ -35,19 +41,56 @@ private func getResultCallback<T>(
3541
}
3642

3743
public extension StorageReference {
44+
/// Asynchronously retrieves a long lived download URL with a revokable token.
45+
/// This can be used to share the file with others, but can be revoked by a developer
46+
/// in the Firebase Console if desired.
47+
///
48+
/// - Parameters:
49+
/// - completion: A completion block returning a `Result` enum with either a URL or an `Error`.
3850
func downloadURL(completion: @escaping (Result<URL, Error>) -> Void) {
3951
downloadURL(completion: getResultCallback(completion: completion))
4052
}
4153

54+
/// Asynchronously downloads the object at the `StorageReference` to a `Data` object.
55+
/// A `Data` of the provided max size will be allocated, so ensure that the device has enough
56+
/// memory to complete. For downloading large files, writeToFile may be a better option.
57+
58+
/// - Parameters:
59+
/// - maxSize: The maximum size in bytes to download.
60+
/// - completion: A completion block returning a `Result` enum with either a `Data` object or
61+
/// an `Error`.
62+
///
63+
/// - Returns: A StorageDownloadTask that can be used to monitor or manage the download.
4264
func getData(maxSize: Int64, completion: @escaping (Result<Data, Error>) -> Void)
4365
-> StorageDownloadTask {
4466
return getData(maxSize: maxSize, completion: getResultCallback(completion: completion))
4567
}
4668

69+
/// Retrieves metadata associated with an object at the current path.
70+
///
71+
/// - Parameters:
72+
/// - completion: A completion block which returns a `Result` enum with either the
73+
/// object metadata or an `Error`.
4774
func getMetadata(completion: @escaping (Result<StorageMetadata, Error>) -> Void) {
4875
getMetadata(completion: getResultCallback(completion: completion))
4976
}
5077

78+
/// Resumes a previous `list` call, starting after a pagination token.
79+
/// Returns the next set of items (files) and prefixes (folders) under this StorageReference.
80+
///
81+
/// "/" is treated as a path delimiter. Firebase Storage does not support unsupported object
82+
/// paths that end with "/" or contain two consecutive "/"s. All invalid objects in GCS will be
83+
/// filtered.
84+
///
85+
/// Only available for projects using Firebase Rules Version 2.
86+
///
87+
/// - Parameters:
88+
/// - withMaxResults The maximum number of results to return in a single page. Must be
89+
/// greater than 0 and at most 1000.
90+
/// - pageToken A page token from a previous call to list.
91+
/// - completion A completion handler that will be invoked with the next items and
92+
/// prefixes under the current StorageReference. It returns a `Result` enum
93+
/// with either the list or an `Error`.
5194
func list(withMaxResults maxResults: Int64,
5295
pageToken: String,
5396
completion: @escaping (Result<StorageListResult, Error>) -> Void) {
@@ -56,16 +99,54 @@ public extension StorageReference {
5699
completion: getResultCallback(completion: completion))
57100
}
58101

102+
/// List up to `maxResults` items (files) and prefixes (folders) under this StorageReference.
103+
///
104+
/// "/" is treated as a path delimiter. Firebase Storage does not support unsupported object
105+
/// paths that end with "/" or contain two consecutive "/"s. All invalid objects in GCS will be
106+
/// filtered.
107+
///
108+
/// Only available for projects using Firebase Rules Version 2.
109+
///
110+
/// - Parameters:
111+
/// - withMaxResults The maximum number of results to return in a single page. Must be
112+
/// greater than 0 and at most 1000.
113+
/// - completion A completion handler that will be invoked with the next items and
114+
/// prefixes under the current `StorageReference`. It returns a `Result` enum
115+
/// with either the list or an `Error`.
59116
func list(withMaxResults maxResults: Int64,
60117
completion: @escaping (Result<StorageListResult, Error>) -> Void) {
61118
list(withMaxResults: maxResults,
62119
completion: getResultCallback(completion: completion))
63120
}
64121

122+
/// List all items (files) and prefixes (folders) under this StorageReference.
123+
///
124+
/// This is a helper method for calling list() repeatedly until there are no more results.
125+
/// Consistency of the result is not guaranteed if objects are inserted or removed while this
126+
/// operation is executing. All results are buffered in memory.
127+
///
128+
/// Only available for projects using Firebase Rules Version 2.
129+
///
130+
/// - Parameters:
131+
/// - completion A completion handler that will be invoked with all items and prefixes
132+
/// under the current StorageReference. It returns a `Result` enum with either the
133+
/// list or an `Error`.
65134
func listAll(completion: @escaping (Result<StorageListResult, Error>) -> Void) {
66135
listAll(completion: getResultCallback(completion: completion))
67136
}
68137

138+
/// Asynchronously uploads data to the currently specified `StorageReference`.
139+
/// This is not recommended for large files, and one should instead upload a file from disk.
140+
///
141+
/// - Parameters:
142+
/// - uploadData The `Data` to upload.
143+
/// - metadata `StorageMetadata` containing additional information (MIME type, etc.)
144+
/// about the object being uploaded.
145+
/// - completion A completion block that returns a `Result` enum with either the
146+
/// object metadata or an `Error`.
147+
///
148+
/// - Returns: An instance of `StorageUploadTask`, which can be used to monitor or manage
149+
/// the upload.
69150
func putData(_ uploadData: Data,
70151
metadata: StorageMetadata? = nil,
71152
completion: @escaping (Result<StorageMetadata, Error>) -> Void)
@@ -75,6 +156,17 @@ public extension StorageReference {
75156
completion: getResultCallback(completion: completion))
76157
}
77158

159+
/// Asynchronously uploads a file to the currently specified `StorageReference`.
160+
///
161+
/// - Parameters:
162+
/// - from A URL representing the system file path of the object to be uploaded.
163+
/// - metadata `StorageMetadata` containing additional information (MIME type, etc.)
164+
/// about the object being uploaded.
165+
/// - completion A completion block that returns a `Result` enum with either the
166+
/// object metadata or an `Error`.
167+
///
168+
/// - Returns: An instance of `StorageUploadTask`, which can be used to monitor or manage
169+
/// the upload.
78170
func putFile(from: URL,
79171
metadata: StorageMetadata? = nil,
80172
completion: @escaping (Result<StorageMetadata, Error>) -> Void)
@@ -84,11 +176,26 @@ public extension StorageReference {
84176
completion: getResultCallback(completion: completion))
85177
}
86178

179+
/// Updates the metadata associated with an object at the current path.
180+
///
181+
/// - Parameters:
182+
/// - metadata A `StorageMetadata` object with the metadata to update.
183+
/// - completion A completion block which returns a `Result` enum with either the
184+
/// object metadata or an `Error`.
87185
func updateMetadata(_ metadata: StorageMetadata,
88186
completion: @escaping (Result<StorageMetadata, Error>) -> Void) {
89187
return updateMetadata(metadata, completion: getResultCallback(completion: completion))
90188
}
91189

190+
/// Asynchronously downloads the object at the current path to a specified system filepath.
191+
///
192+
/// - Parameters:
193+
/// - toFile A file system URL representing the path the object should be downloaded to.
194+
/// - completion A completion block that fires when the file download completes. The
195+
/// block returns a `Result` enum with either an NSURL pointing to the file
196+
/// path of the downloaded file or an `Error`.
197+
///
198+
/// - Returns: A `StorageDownloadTask` that can be used to monitor or manage the download.
92199
func write(toFile: URL, completion: @escaping (Result<URL, Error>)
93200
-> Void) -> StorageDownloadTask {
94201
return write(toFile: toFile, completion: getResultCallback(completion: completion))

0 commit comments

Comments
 (0)