|
| 1 | +/** |
| 2 | + * Copyright (c) 2015-present, Parse, LLC. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. An additional grant |
| 7 | + * of patent rights can be found in the PATENTS file in the same directory. |
| 8 | + */ |
| 9 | + |
| 10 | +#import <Parse/PFConstants.h> |
| 11 | +#import <Parse/PFFile.h> |
| 12 | + |
| 13 | +NS_ASSUME_NONNULL_BEGIN |
| 14 | + |
| 15 | +/** |
| 16 | + This category lists all methods of `PFFile` class that are synchronous, but have asynchronous counterpart, |
| 17 | + Calling one of these synchronous methods could potentially block the current thread for a large amount of time, |
| 18 | + since it might be fetching from network or saving/loading data from disk. |
| 19 | + */ |
| 20 | +@interface PFFile (Synchronous) |
| 21 | + |
| 22 | +///-------------------------------------- |
| 23 | +/// @name Storing Data with Parse |
| 24 | +///-------------------------------------- |
| 25 | + |
| 26 | +/** |
| 27 | + Saves the file *synchronously*. |
| 28 | +
|
| 29 | + @return Returns whether the save succeeded. |
| 30 | + */ |
| 31 | +- (BOOL)save PF_SWIFT_UNAVAILABLE; |
| 32 | + |
| 33 | +/** |
| 34 | + Saves the file *synchronously* and sets an error if it occurs. |
| 35 | +
|
| 36 | + @param error Pointer to an `NSError` that will be set if necessary. |
| 37 | +
|
| 38 | + @return Returns whether the save succeeded. |
| 39 | + */ |
| 40 | +- (BOOL)save:(NSError **)error; |
| 41 | + |
| 42 | +///-------------------------------------- |
| 43 | +/// @name Getting Data from Parse |
| 44 | +///-------------------------------------- |
| 45 | + |
| 46 | +/** |
| 47 | + Whether the data is available in memory or needs to be downloaded. |
| 48 | + */ |
| 49 | +@property (nonatomic, assign, readonly, getter=isDataAvailable) BOOL dataAvailable; |
| 50 | + |
| 51 | +/** |
| 52 | + *Synchronously* gets the data from cache if available or fetches its contents from the network. |
| 53 | +
|
| 54 | + @return The `NSData` object containing file data. Returns `nil` if there was an error in fetching. |
| 55 | + */ |
| 56 | +- (nullable NSData *)getData PF_SWIFT_UNAVAILABLE; |
| 57 | + |
| 58 | +/** |
| 59 | + *Synchronously* gets the data from cache if available or fetches its contents from the network. |
| 60 | + Sets an error if it occurs. |
| 61 | +
|
| 62 | + @param error Pointer to an `NSError` that will be set if necessary. |
| 63 | +
|
| 64 | + @return The `NSData` object containing file data. Returns `nil` if there was an error in fetching. |
| 65 | + */ |
| 66 | +- (nullable NSData *)getData:(NSError **)error; |
| 67 | + |
| 68 | +/** |
| 69 | + This method is like `-getData` but avoids ever holding the entire `PFFile` contents in memory at once. |
| 70 | +
|
| 71 | + This can help applications with many large files avoid memory warnings. |
| 72 | +
|
| 73 | + @return A stream containing the data. Returns `nil` if there was an error in fetching. |
| 74 | + */ |
| 75 | +- (nullable NSInputStream *)getDataStream PF_SWIFT_UNAVAILABLE; |
| 76 | + |
| 77 | +/** |
| 78 | + This method is like `-getData` but avoids ever holding the entire `PFFile` contents in memory at once. |
| 79 | +
|
| 80 | + @param error Pointer to an `NSError` that will be set if necessary. |
| 81 | +
|
| 82 | + @return A stream containing the data. Returns nil if there was an error in |
| 83 | + fetching. |
| 84 | + */ |
| 85 | +- (nullable NSInputStream *)getDataStream:(NSError **)error; |
| 86 | + |
| 87 | +@end |
| 88 | + |
| 89 | +NS_ASSUME_NONNULL_END |
0 commit comments