Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage async await #8289

Merged
merged 18 commits into from
Jul 23, 2021
Next Next commit
Storage async await WIP
  • Loading branch information
paulb777 committed Jul 23, 2021
commit 11d52f705199a8122a91ca9feb82c0bf9d08e92c
10 changes: 10 additions & 0 deletions FirebaseStorage/Sources/FIRStorageReference.m
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ - (FIRStorageUploadTask *)putData:(NSData *)uploadData
return [self putData:uploadData metadata:metadata completion:nil];
}

- (void)__putData:(NSData *)uploadData
paulb777 marked this conversation as resolved.
Show resolved Hide resolved
metadata:(nullable FIRStorageMetadata *)metadata
completion:(nullable FIRStorageVoidMetadataError)completion {
[self putData:uploadData metadata:metadata completion:completion];
}

- (FIRStorageUploadTask *)putData:(NSData *)uploadData
metadata:(nullable FIRStorageMetadata *)metadata
completion:(nullable FIRStorageVoidMetadataError)completion {
Expand Down Expand Up @@ -315,6 +321,10 @@ - (FIRStorageDownloadTask *)dataWithMaxSize:(int64_t)size
return task;
}

- (void)__dataWithMaxSize:(int64_t)size completion:(FIRStorageVoidDataError)completion {
[self dataWithMaxSize:size completion:completion];
}

- (FIRStorageDownloadTask *)writeToFile:(NSURL *)fileURL {
return [self writeToFile:fileURL completion:nil];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,17 @@ NS_SWIFT_NAME(putData(_:metadata:));
* or an error on failure.
* @return An instance of FIRStorageUploadTask, which can be used to monitor or manage the upload.
*/
// clang-format off
- (FIRStorageUploadTask *)putData:(NSData *)uploadData
metadata:(nullable FIRStorageMetadata *)metadata
completion:(nullable void (^)(FIRStorageMetadata *_Nullable metadata,
NSError *_Nullable error))completion
NS_SWIFT_NAME(putData(_:metadata:completion:));
// clang-format on

- (void)__putData:(NSData *)uploadData
metadata:(nullable FIRStorageMetadata *)metadata
completion:(nullable void (^)(FIRStorageMetadata *_Nullable metadata,
NSError *_Nullable error))completion
NS_SWIFT_NAME(__putDataGlue(_:metadata:completion:));
/**
* Asynchronously uploads a file to the currently specified FIRStorageReference,
* without additional metadata.
Expand Down Expand Up @@ -184,12 +187,15 @@ NS_SWIFT_NAME(putData(_:metadata:));
* or an error on failure.
* @return An FIRStorageDownloadTask that can be used to monitor or manage the download.
*/
// clang-format off

- (FIRStorageDownloadTask *)dataWithMaxSize:(int64_t)size
completion:(void (^)(NSData *_Nullable data,
NSError *_Nullable error))completion
NS_SWIFT_NAME(getData(maxSize:completion:));
// clang-format on
NS_SWIFT_NAME(getData(maxSize:completion:));

- (void)__dataWithMaxSize:(int64_t)size
completion:(void (^)(NSData *_Nullable data, NSError *_Nullable error))completion
NS_SWIFT_NAME(data(maxSize:completion:));

/**
* Asynchronously retrieves a long lived download URL with a revokable token.
Expand Down
26 changes: 26 additions & 0 deletions FirebaseStorageSwift/Sources/AsyncAwait.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import FirebaseStorage

public extension StorageReference {

@discardableResult
func putDataAwait(_ uploadData: Data,
metadata: StorageMetadata? = nil) async throws -> StorageMetadata {
// TODO: Add a parameter to capture StorageUploadTask and to enable Progress tracking.
// -> StorageUploadTask {
return try await __putDataGlue(uploadData, metadata: metadata)
}
}