openEventsPlatformApp/plugins/cordova-plugin-file/src/ios/CDVFile.h
plugins/cordova-plugin-file/src/ios/CDVFile.hRaw
1/*
2 Licensed to the Apache Software Foundation (ASF) under one
3 or more contributor license agreements. See the NOTICE file
4 distributed with this work for additional information
5 regarding copyright ownership. The ASF licenses this file
6 to you under the Apache License, Version 2.0 (the
7 "License"); you may not use this file except in compliance
8 with the License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing,
13 software distributed under the License is distributed on an
14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 KIND, either express or implied. See the License for the
16 specific language governing permissions and limitations
17 under the License.
18 */
19
20#import <Foundation/Foundation.h>
21#import <Cordova/CDVPlugin.h>
22
23extern NSString* const kCDVAssetsLibraryPrefix;
24extern NSString* const kCDVFilesystemURLPrefix;
25
26enum CDVFileError {
27 NO_ERROR = 0,
28 NOT_FOUND_ERR = 1,
29 SECURITY_ERR = 2,
30 ABORT_ERR = 3,
31 NOT_READABLE_ERR = 4,
32 ENCODING_ERR = 5,
33 NO_MODIFICATION_ALLOWED_ERR = 6,
34 INVALID_STATE_ERR = 7,
35 SYNTAX_ERR = 8,
36 INVALID_MODIFICATION_ERR = 9,
37 QUOTA_EXCEEDED_ERR = 10,
38 TYPE_MISMATCH_ERR = 11,
39 PATH_EXISTS_ERR = 12
40};
41typedef int CDVFileError;
42
43@interface CDVFilesystemURL : NSObject {
44 NSURL *_url;
45 NSString *_fileSystemName;
46 NSString *_fullPath;
47}
48
49- (id) initWithString:(NSString*)strURL;
50- (id) initWithURL:(NSURL*)URL;
51+ (CDVFilesystemURL *)fileSystemURLWithString:(NSString *)strURL;
52+ (CDVFilesystemURL *)fileSystemURLWithURL:(NSURL *)URL;
53
54- (NSString *)absoluteURL;
55
56@property (atomic) NSURL *url;
57@property (atomic) NSString *fileSystemName;
58@property (atomic) NSString *fullPath;
59
60@end
61
62@interface CDVFilesystemURLProtocol : NSURLProtocol
63@end
64
65@protocol CDVFileSystem
66- (CDVPluginResult *)entryForLocalURI:(CDVFilesystemURL *)url;
67- (CDVPluginResult *)getFileForURL:(CDVFilesystemURL *)baseURI requestedPath:(NSString *)requestedPath options:(NSDictionary *)options;
68- (CDVPluginResult *)getParentForURL:(CDVFilesystemURL *)localURI;
69- (CDVPluginResult *)setMetadataForURL:(CDVFilesystemURL *)localURI withObject:(NSDictionary *)options;
70- (CDVPluginResult *)removeFileAtURL:(CDVFilesystemURL *)localURI;
71- (CDVPluginResult *)recursiveRemoveFileAtURL:(CDVFilesystemURL *)localURI;
72- (CDVPluginResult *)readEntriesAtURL:(CDVFilesystemURL *)localURI;
73- (CDVPluginResult *)truncateFileAtURL:(CDVFilesystemURL *)localURI atPosition:(unsigned long long)pos;
74- (CDVPluginResult *)writeToFileAtURL:(CDVFilesystemURL *)localURL withData:(NSData*)encData append:(BOOL)shouldAppend;
75- (void)copyFileToURL:(CDVFilesystemURL *)destURL withName:(NSString *)newName fromFileSystem:(NSObject<CDVFileSystem> *)srcFs atURL:(CDVFilesystemURL *)srcURL copy:(BOOL)bCopy callback:(void (^)(CDVPluginResult *))callback;
76- (void)readFileAtURL:(CDVFilesystemURL *)localURL start:(NSInteger)start end:(NSInteger)end callback:(void (^)(NSData*, NSString* mimeType, CDVFileError))callback;
77- (void)getFileMetadataForURL:(CDVFilesystemURL *)localURL callback:(void (^)(CDVPluginResult *))callback;
78
79- (NSDictionary *)makeEntryForLocalURL:(CDVFilesystemURL *)url;
80- (NSDictionary*)makeEntryForPath:(NSString*)fullPath isDirectory:(BOOL)isDir;
81
82@property (nonatomic,strong) NSString *name;
83@property (nonatomic, copy) NSURL*(^urlTransformer)(NSURL*);
84
85@optional
86- (NSString *)filesystemPathForURL:(CDVFilesystemURL *)localURI;
87- (CDVFilesystemURL *)URLforFilesystemPath:(NSString *)path;
88
89@end
90
91@interface CDVFile : CDVPlugin {
92 NSString* rootDocsPath;
93 NSString* appDocsPath;
94 NSString* appLibraryPath;
95 NSString* appTempPath;
96
97 NSMutableArray* fileSystems_;
98 BOOL userHasAllowed;
99}
100
101- (NSNumber*)checkFreeDiskSpace:(NSString*)appPath;
102- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystemName:(NSString *)fsName isDirectory:(BOOL)isDir;
103- (NSDictionary *)makeEntryForURL:(NSURL *)URL;
104- (CDVFilesystemURL *)fileSystemURLforLocalPath:(NSString *)localPath;
105
106- (NSObject<CDVFileSystem> *)filesystemForURL:(CDVFilesystemURL *)localURL;
107
108/* Native Registration API */
109- (void)registerFilesystem:(NSObject<CDVFileSystem> *)fs;
110- (NSObject<CDVFileSystem> *)fileSystemByName:(NSString *)fsName;
111
112/* Exec API */
113- (void)requestFileSystem:(CDVInvokedUrlCommand*)command;
114- (void)resolveLocalFileSystemURI:(CDVInvokedUrlCommand*)command;
115- (void)getDirectory:(CDVInvokedUrlCommand*)command;
116- (void)getFile:(CDVInvokedUrlCommand*)command;
117- (void)getParent:(CDVInvokedUrlCommand*)command;
118- (void)removeRecursively:(CDVInvokedUrlCommand*)command;
119- (void)remove:(CDVInvokedUrlCommand*)command;
120- (void)copyTo:(CDVInvokedUrlCommand*)command;
121- (void)moveTo:(CDVInvokedUrlCommand*)command;
122- (void)getFileMetadata:(CDVInvokedUrlCommand*)command;
123- (void)readEntries:(CDVInvokedUrlCommand*)command;
124- (void)readAsText:(CDVInvokedUrlCommand*)command;
125- (void)readAsDataURL:(CDVInvokedUrlCommand*)command;
126- (void)readAsArrayBuffer:(CDVInvokedUrlCommand*)command;
127- (void)write:(CDVInvokedUrlCommand*)command;
128- (void)testFileExists:(CDVInvokedUrlCommand*)command;
129- (void)testDirectoryExists:(CDVInvokedUrlCommand*)command;
130- (void)getFreeDiskSpace:(CDVInvokedUrlCommand*)command;
131- (void)truncate:(CDVInvokedUrlCommand*)command;
132- (void)doCopyMove:(CDVInvokedUrlCommand*)command isCopy:(BOOL)bCopy;
133
134/* Compatibilty with older File API */
135- (NSString*)getMimeTypeFromPath:(NSString*)fullPath;
136- (NSDictionary *)getDirectoryEntry:(NSString *)target isDirectory:(BOOL)bDirRequest;
137
138/* Conversion between filesystem paths and URLs */
139- (NSString *)filesystemPathForURL:(CDVFilesystemURL *)URL;
140
141/* Internal methods for testing */
142- (void)_getLocalFilesystemPath:(CDVInvokedUrlCommand*)command;
143
144@property (nonatomic, strong) NSString* rootDocsPath;
145@property (nonatomic, strong) NSString* appDocsPath;
146@property (nonatomic, strong) NSString* appLibraryPath;
147@property (nonatomic, strong) NSString* appTempPath;
148@property (nonatomic, strong) NSString* persistentPath;
149@property (nonatomic, strong) NSString* temporaryPath;
150@property (nonatomic, strong) NSMutableArray* fileSystems;
151
152@property BOOL userHasAllowed;
153
154@end
155
156#define kW3FileTemporary @"temporary"
157#define kW3FilePersistent @"persistent"