-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPFFile.h
More file actions
389 lines (285 loc) · 14.5 KB
/
PFFile.h
File metadata and controls
389 lines (285 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
//
// PFFile.h
//
// Copyright 2011-present Parse Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
#if TARGET_OS_IPHONE
#import <Parse/PFConstants.h>
#else
#import <ParseOSX/PFConstants.h>
#endif
PF_ASSUME_NONNULL_BEGIN
@class BFTask;
/*!
`PFFile` representes a file of binary data stored on the Parse servers.
This can be a image, video, or anything else that an application needs to reference in a non-relational way.
*/
@interface PFFile : NSObject
///--------------------------------------
/// @name Creating a PFFile
///--------------------------------------
/*!
@abstract Creates a file with given data. A name will be assigned to it by the server.
@param data The contents of the new `PFFile`.
@returns A new `PFFile`.
*/
+ (instancetype)fileWithData:(NSData *)data;
/*!
@abstract Creates a file with given data and name.
@param name The name of the new PFFile. The file name must begin with and
alphanumeric character, and consist of alphanumeric characters, periods,
spaces, underscores, or dashes.
@param data The contents of the new `PFFile`.
@returns A new `PFFile` object.
*/
+ (instancetype)fileWithName:(PF_NULLABLE NSString *)name data:(NSData *)data;
/*!
@abstract Creates a file with the contents of another file.
@warning This method raises an exception if the file at path is not accessible
or if there is not enough disk space left.
@param name The name of the new `PFFile`. The file name must begin with and alphanumeric character,
and consist of alphanumeric characters, periods, spaces, underscores, or dashes.
@param path The path to the file that will be uploaded to Parse.
@returns A new `PFFile` instance.
*/
+ (instancetype)fileWithName:(PF_NULLABLE NSString *)name contentsAtPath:(NSString *)path;
/*!
@abstract Creates a file with the contents of another file.
@param name The name of the new `PFFile`. The file name must begin with and alphanumeric character,
and consist of alphanumeric characters, periods, spaces, underscores, or dashes.
@param path The path to the file that will be uploaded to Parse.
@param error On input, a pointer to an error object.
If an error occurs, this pointer is set to an actual error object containing the error information.
You may specify `nil` for this parameter if you do not want the error information.
@returns A new `PFFile` instance or `nil` if the error occured.
*/
+ (instancetype)fileWithName:(PF_NULLABLE NSString *)name contentsAtPath:(NSString *)path error:(NSError **)error;
/*!
@abstract Creates a file with given data, name and content type.
@warning This method raises an exception if the data supplied is not accessible or could not be saved.
@param name The name of the new `PFFile`. The file name must begin with and alphanumeric character,
and consist of alphanumeric characters, periods, spaces, underscores, or dashes.
@param data The contents of the new `PFFile`.
@param contentType Represents MIME type of the data.
@returns A new `PFFile` instance.
*/
+ (instancetype)fileWithName:(PF_NULLABLE NSString *)name
data:(NSData *)data
contentType:(PF_NULLABLE NSString *)contentType;
/*!
@abstract Creates a file with given data, name and content type.
@param name The name of the new `PFFile`. The file name must begin with and alphanumeric character,
and consist of alphanumeric characters, periods, spaces, underscores, or dashes.
@param data The contents of the new `PFFile`.
@param contentType Represents MIME type of the data.
@param error On input, a pointer to an error object.
If an error occurs, this pointer is set to an actual error object containing the error information.
You may specify `nil` for this parameter if you do not want the error information.
@returns A new `PFFile` instance or `nil` if the error occured.
*/
+ (instancetype)fileWithName:(PF_NULLABLE NSString *)name
data:(NSData *)data
contentType:(PF_NULLABLE NSString *)contentType
error:(NSError **)error;
/*!
@abstract Creates a file with given data and content type.
@param data The contents of the new `PFFile`.
@param contentType Represents MIME type of the data.
@returns A new `PFFile` object.
*/
+ (instancetype)fileWithData:(NSData *)data contentType:(PF_NULLABLE NSString *)contentType;
/*!
@abstract The name of the file.
@discussion Before the file is saved, this is the filename given by
the user. After the file is saved, that name gets prefixed with a unique
identifier.
*/
@property (nonatomic, copy, readonly) NSString *name;
/*!
@abstract The url of the file.
*/
@property (PF_NULLABLE_PROPERTY nonatomic, copy, readonly) NSString *url;
///--------------------------------------
/// @name Storing Data with Parse
///--------------------------------------
/*!
@abstract Whether the file has been uploaded for the first time.
*/
@property (nonatomic, assign, readonly) BOOL isDirty;
/*!
@abstract Saves the file *synchronously*.
@returns Returns whether the save succeeded.
*/
- (BOOL)save;
/*!
@abstract Saves the file *synchronously* and sets an error if it occurs.
@param error Pointer to an `NSError` that will be set if necessary.
@returns Returns whether the save succeeded.
*/
- (BOOL)save:(NSError **)error;
/*!
@abstract Saves the file *asynchronously*.
@returns The task, that encapsulates the work being done.
*/
- (BFTask *)saveInBackground;
/*!
@abstract Saves the file *asynchronously*
@param progressBlock The block should have the following argument signature: `^(int percentDone)`
@returns The task, that encapsulates the work being done.
*/
- (BFTask *)saveInBackgroundWithProgressBlock:(PF_NULLABLE PFProgressBlock)progressBlock;
/*!
@abstract Saves the file *asynchronously* and executes the given block.
@param block The block should have the following argument signature: `^(BOOL succeeded, NSError *error)`.
*/
- (void)saveInBackgroundWithBlock:(PF_NULLABLE PFBooleanResultBlock)block;
/*!
@abstract Saves the file *asynchronously* and executes the given block.
@discussion This method will execute the progressBlock periodically with the percent progress.
`progressBlock` will get called with `100` before `resultBlock` is called.
@param block The block should have the following argument signature: `^(BOOL succeeded, NSError *error)`
@param progressBlock The block should have the following argument signature: `^(int percentDone)`
*/
- (void)saveInBackgroundWithBlock:(PF_NULLABLE PFBooleanResultBlock)block
progressBlock:(PF_NULLABLE PFProgressBlock)progressBlock;
/*
@abstract Saves the file *asynchronously* and calls the given callback.
@param target The object to call selector on.
@param selector The selector to call.
It should have the following signature: `(void)callbackWithResult:(NSNumber *)result error:(NSError *)error`.
`error` will be `nil` on success and set if there was an error.
`[result boolValue]` will tell you whether the call succeeded or not.
*/
- (void)saveInBackgroundWithTarget:(PF_NULLABLE_S id)target selector:(PF_NULLABLE_S SEL)selector;
///--------------------------------------
/// @name Getting Data from Parse
///--------------------------------------
/*!
@abstract Whether the data is available in memory or needs to be downloaded.
*/
@property (assign, readonly) BOOL isDataAvailable;
/*!
@abstract *Synchronously* gets the data from cache if available or fetches its contents from the network.
@returns The `NSData` object containing file data. Returns `nil` if there was an error in fetching.
*/
- (PF_NULLABLE NSData *)getData;
/*!
@abstract This method is like <getData> but avoids ever holding the entire `PFFile` contents in memory at once.
@discussion This can help applications with many large files avoid memory warnings.
@returns A stream containing the data. Returns `nil` if there was an error in fetching.
*/
- (PF_NULLABLE NSInputStream *)getDataStream;
/*!
@abstract *Synchronously* gets the data from cache if available or fetches its contents from the network.
Sets an error if it occurs.
@param error Pointer to an `NSError` that will be set if necessary.
@returns The `NSData` object containing file data. Returns `nil` if there was an error in fetching.
*/
- (PF_NULLABLE NSData *)getData:(NSError **)error;
/*!
@abstract This method is like <getData> but avoids ever holding the entire `PFFile` contents in memory at once.
@param error Pointer to an `NSError` that will be set if necessary.
@returns A stream containing the data. Returns nil if there was an error in
fetching.
*/
- (PF_NULLABLE NSInputStream *)getDataStream:(NSError **)error;
/*!
@abstract This method is like <getData> but it fetches asynchronously to avoid blocking the current thread.
@see getData
@returns The task, that encapsulates the work being done.
*/
- (BFTask *)getDataInBackground;
/*!
@abstract This method is like <getData> but it fetches asynchronously to avoid blocking the current thread.
@discussion This can help applications with many large files avoid memory warnings.
@see getData
@param progressBlock The block should have the following argument signature: ^(int percentDone)
@returns The task, that encapsulates the work being done.
*/
- (BFTask *)getDataInBackgroundWithProgressBlock:(PF_NULLABLE PFProgressBlock)progressBlock;
/*!
@abstract This method is like <getDataInBackground> but avoids
ever holding the entire `PFFile` contents in memory at once.
@discussion This can help applications with many large files avoid memory warnings.
@returns The task, that encapsulates the work being done.
*/
- (BFTask *)getDataStreamInBackground;
/*!
@abstract This method is like <getDataStreamInBackground>, but yields a live-updating stream.
@discussion Instead of <getDataStream>, which yields a stream that can be read from only after the request has
completed, this method gives you a stream directly written to by the HTTP session. As this stream is not pre-buffered,
it is strongly advised to use the `NSStreamDelegate` methods, in combination with a run loop, to consume the data in
the stream, to do proper async file downloading.
@note You MUST open this stream before reading from it.
@note Do NOT call <waitUntilFinished> on this task from the main thread. It may result in a deadlock.
@returns A task that produces a *live* stream that is being written to with the data from the server.
*/
- (BFTask *)getDataDownloadStreamInBackground;
/*!
@abstract This method is like <getDataInBackground> but avoids
ever holding the entire `PFFile` contents in memory at once.
@discussion This can help applications with many large files avoid memory warnings.
@param progressBlock The block should have the following argument signature: ^(int percentDone)
@returns The task, that encapsulates the work being done.
*/
- (BFTask *)getDataStreamInBackgroundWithProgressBlock:(PF_NULLABLE PFProgressBlock)progressBlock;
/*!
@abstract This method is like <getDataStreamInBackgroundWithProgrssBlock>, but yields a live-updating stream.
@discussion Instead of <getDataStream>, which yields a stream that can be read from only after the request has
completed, this method gives you a stream directly written to by the HTTP session. As this stream is not pre-buffered,
it is strongly advised to use the `NSStreamDelegate` methods, in combination with a run loop, to consume the data in
the stream, to do proper async file downloading.
@note You MUST open this stream before reading from it.
@note Do NOT call <waitUntilFinished> on this task from the main thread. It may result in a deadlock.
@param progressBlock The block should have the following argument signature: `^(int percentDone)`
@returns A task that produces a *live* stream that is being written to with the data from the server.
*/
- (BFTask *)getDataDownloadStreamInBackgroundWithProgressBlock:(PF_NULLABLE PFProgressBlock)progressBlock;
/*!
@abstract *Asynchronously* gets the data from cache if available or fetches its contents from the network.
@param block The block should have the following argument signature: `^(NSData *result, NSError *error)`
*/
- (void)getDataInBackgroundWithBlock:(PF_NULLABLE PFDataResultBlock)block;
/*!
@abstract This method is like <getDataInBackgroundWithBlock:> but avoids
ever holding the entire `PFFile` contents in memory at once.
@discussion This can help applications with many large files avoid memory warnings.
@param block The block should have the following argument signature: `(NSInputStream *result, NSError *error)`
*/
- (void)getDataStreamInBackgroundWithBlock:(PF_NULLABLE PFDataStreamResultBlock)block;
/*!
@abstract *Asynchronously* gets the data from cache if available or fetches its contents from the network.
@discussion This method will execute the progressBlock periodically with the percent progress.
`progressBlock` will get called with `100` before `resultBlock` is called.
@param resultBlock The block should have the following argument signature: ^(NSData *result, NSError *error)
@param progressBlock The block should have the following argument signature: ^(int percentDone)
*/
- (void)getDataInBackgroundWithBlock:(PF_NULLABLE PFDataResultBlock)resultBlock
progressBlock:(PF_NULLABLE PFProgressBlock)progressBlock;
/*!
@abstract This method is like <getDataInBackgroundWithBlock:progressBlock:> but avoids
ever holding the entire `PFFile` contents in memory at once.
@discussion This can help applications with many large files avoid memory warnings.
@param resultBlock The block should have the following argument signature: `^(NSInputStream *result, NSError *error)`.
@param progressBlock The block should have the following argument signature: `^(int percentDone)`.
*/
- (void)getDataStreamInBackgroundWithBlock:(PF_NULLABLE PFDataStreamResultBlock)resultBlock
progressBlock:(PF_NULLABLE PFProgressBlock)progressBlock;
/*
@abstract *Asynchronously* gets the data from cache if available or fetches its contents from the network.
@param target The object to call selector on.
@param selector The selector to call.
It should have the following signature: `(void)callbackWithResult:(NSData *)result error:(NSError *)error`.
`error` will be `nil` on success and set if there was an error.
*/
- (void)getDataInBackgroundWithTarget:(PF_NULLABLE_S id)target selector:(PF_NULLABLE_S SEL)selector;
///--------------------------------------
/// @name Interrupting a Transfer
///--------------------------------------
/*!
@abstract Cancels the current request (upload or download of file).
*/
- (void)cancel;
@end
PF_ASSUME_NONNULL_END