-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathLBFile.h
185 lines (168 loc) · 6.37 KB
/
LBFile.h
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
/**
* @file LBFile.h
*
* @author Stephen Hess
* @copyright (c) 2014 StrongLoop. All rights reserved.
*/
#import "LBModel.h"
/**
* A local representative of a file instance on the server.
*/
@interface LBFile : LBModel
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *localPath;
@property (nonatomic, copy) NSString *container;
/**
* Blocks of this type are executed when
* LBFile:uploadWithSuccess:failure: is successful.
*/
typedef void (^LBFileUploadSuccessBlock)(LBFile *file);
/**
* Uploads the file to the server.
*
* @param success The block to be executed when the upload is successful.
* @param failure The block to be executed when the upload fails.
*/
- (void)uploadWithSuccess:(LBFileUploadSuccessBlock)success
failure:(SLFailureBlock)failure;
/**
* Blocks of this type are executed when
* LBFile:downloadWithSuccess:failure: is successful.
*/
typedef void (^LBFileDownloadSuccessBlock)();
/**
* Downloads the file from the server.
*
* @param success The block to be executed when the download is successful.
* @param failure The block to be executed when the download fails.
*/
- (void)downloadWithSuccess:(LBFileDownloadSuccessBlock)success
failure:(SLFailureBlock)failure;
/**
* Blocks of this type are executed when
* LBFile:deleteWithSuccess:failure: is successful.
*/
typedef void (^LBFileDeleteSuccessBlock)();
/**
* Delete the file from the server.
*
* @param success The block to be executed when the deletion is successful.
* @param failure The block to be executed when the deletion fails.
*/
- (void)deleteWithSuccess:(LBFileDeleteSuccessBlock)success
failure:(SLFailureBlock)failure;
@end
/**
* A local representative of the File type on the server.
*/
@interface LBFileRepository : LBModelRepository
+ (instancetype)repository;
/**
* Creates a file with the given data
*
* @param name The file name.
* @param localPath The local path to the file, without file name.
* @param container The file's container.
*/
- (LBFile *)createFileWithName:(NSString *)name
localPath:(NSString *)localPath
container:(NSString *)container;
/**
* Blocks of this type are executed when
* LBFileRepository::getFileWithName:success:failure: is successful.
*/
typedef void (^LBFileGetSuccessBlock)(LBFile* file);
/**
* Gets the file with the given name.
*
* @param name The file name.
* @param localPath The local path to the file, without file name.
* @param container The file's container.
* @param success The block to be executed when the get is successful.
* @param failure The block to be executed when the get fails.
*/
- (void)getFileWithName:(NSString *)name
localPath:(NSString *)localPath
container:(NSString *)container
success:(LBFileGetSuccessBlock)success
failure:(SLFailureBlock)failure;
/**
* Blocks of this type are executed when
* LBFileRepository::getAllFilesWithContainer:success:failure: is successful.
*/
typedef void (^LBGetAllFilesSuccessBlock)(NSArray* files);
/**
* List all files in the specified container.
*
* @param container The target container.
* @param success The block to be executed when the get is successful.
* @param failure The block to be executed when the get fails.
*/
- (void)getAllFilesWithContainer:(NSString *)container
success:(LBGetAllFilesSuccessBlock)success
failure:(SLFailureBlock)failure;
/**
* Upload a new file from the given input stream.
*
* @param name The file name, must be unique within the container.
* @param container The file's container.
* @param inputStream The input stream from which the content of file is read.
* @param contentType The content type of the file.
* @param success The block to be executed when the get is successful.
* @param failure The block to be executed when the get fails.
*/
- (void)uploadWithName:(NSString *)name
container:(NSString *)container
inputStream:(NSInputStream *)inputStream
contentType:(NSString *)contentType
length:(NSInteger)length
success:(LBFileUploadSuccessBlock)success
failure:(SLFailureBlock)failure;
/**
* Upload a new file from the given binary data.
*
* @param name The file name, must be unique within the container.
* @param container The file's container.
* @param data The data from which the content of file is read.
* @param contentType The content type of the file.
* @param success The block to be executed when the get is successful.
* @param failure The block to be executed when the get fails.
*/
- (void)uploadWithName:(NSString *)name
container:(NSString *)container
data:(NSData *)data
contentType:(NSString *)contentType
success:(LBFileUploadSuccessBlock)success
failure:(SLFailureBlock)failure;
/**
* Download content of specified file using the specified output stream.
*
* @param name The file name.
* @param container The file's container.
* @param outputStream The output stream to which the content of file is written.
* @param success The block to be executed when the get is successful.
* @param failure The block to be executed when the get fails.
*/
- (void)downloadWithName:(NSString *)name
container:(NSString *)container
outputStream:(NSOutputStream *)outputStream
success:(LBFileDownloadSuccessBlock)success
failure:(SLFailureBlock)failure;
/**
* Blocks of this type are executed when
* LBFileRepository::downloadAsDataWithName:container:success:failure: is successful.
*/
typedef void (^LBFileDownloadAsDataSuccessBlock)(NSData *data);
/**
* Download content of specified file as a binray data.
*
* @param name The file name.
* @param container The file's container.
* @param success The block to be executed when the get is successful.
* @param failure The block to be executed when the get fails.
*/
- (void)downloadAsDataWithName:(NSString *)name
container:(NSString *)container
success:(LBFileDownloadAsDataSuccessBlock)success
failure:(SLFailureBlock)failure;
@end