説明なし

CDVFile.h 6.9KB

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