説明なし

index.d.ts 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. // Type definitions for Apache Cordova File System plugin
  2. // Project: https://github.com/apache/cordova-plugin-file
  3. // Definitions by: Microsoft Open Technologies Inc <http://msopentech.com>
  4. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
  5. //
  6. // Copyright (c) Microsoft Open Technologies, Inc.
  7. // Licensed under the MIT license.
  8. interface Window {
  9. /**
  10. * Requests a filesystem in which to store application data.
  11. * @param type Whether the filesystem requested should be persistent, as defined above. Use one of TEMPORARY or PERSISTENT.
  12. * @param size This is an indicator of how much storage space, in bytes, the application expects to need.
  13. * @param successCallback The callback that is called when the user agent provides a filesystem.
  14. * @param errorCallback A callback that is called when errors happen, or when the request to obtain the filesystem is denied.
  15. */
  16. requestFileSystem(
  17. type: LocalFileSystem,
  18. size: number,
  19. successCallback: (fileSystem: FileSystem) => void,
  20. errorCallback?: (fileError: FileError) => void): void;
  21. /**
  22. * Look up file system Entry referred to by local URL.
  23. * @param string url URL referring to a local file or directory
  24. * @param successCallback invoked with Entry object corresponding to URL
  25. * @param errorCallback invoked if error occurs retrieving file system entry
  26. */
  27. resolveLocalFileSystemURL(url: string,
  28. successCallback: (entry: Entry) => void,
  29. errorCallback?: (error: FileError) => void): void;
  30. /**
  31. * Look up file system Entry referred to by local URI.
  32. * @param string uri URI referring to a local file or directory
  33. * @param successCallback invoked with Entry object corresponding to URI
  34. * @param errorCallback invoked if error occurs retrieving file system entry
  35. */
  36. resolveLocalFileSystemURI(uri: string,
  37. successCallback: (entry: Entry) => void,
  38. errorCallback?: (error: FileError) => void): void;
  39. TEMPORARY: number;
  40. PERSISTENT: number;
  41. }
  42. /** This interface represents a file system. */
  43. interface FileSystem {
  44. /* The name of the file system, unique across the list of exposed file systems. */
  45. name: string;
  46. /** The root directory of the file system. */
  47. root: DirectoryEntry;
  48. }
  49. /**
  50. * An abstract interface representing entries in a file system,
  51. * each of which may be a File or DirectoryEntry.
  52. */
  53. interface Entry {
  54. /** Entry is a file. */
  55. isFile: boolean;
  56. /** Entry is a directory. */
  57. isDirectory: boolean;
  58. /** The name of the entry, excluding the path leading to it. */
  59. name: string;
  60. /** The full absolute path from the root to the entry. */
  61. fullPath: string;
  62. /** The file system on which the entry resides. */
  63. filesystem: FileSystem;
  64. nativeURL: string;
  65. /**
  66. * Look up metadata about this entry.
  67. * @param successCallback A callback that is called with the time of the last modification.
  68. * @param errorCallback A callback that is called when errors happen.
  69. */
  70. getMetadata(
  71. successCallback: (metadata: Metadata) => void,
  72. errorCallback?: (error: FileError) => void): void;
  73. /**
  74. * Move an entry to a different location on the file system. It is an error to try to:
  75. * move a directory inside itself or to any child at any depth;move an entry into its parent if a name different from its current one isn't provided;
  76. * move a file to a path occupied by a directory;
  77. * move a directory to a path occupied by a file;
  78. * move any element to a path occupied by a directory which is not empty.
  79. * A move of a file on top of an existing file must attempt to delete and replace that file.
  80. * A move of a directory on top of an existing empty directory must attempt to delete and replace that directory.
  81. * @param parent The directory to which to move the entry.
  82. * @param newName The new name of the entry. Defaults to the Entry's current name if unspecified.
  83. * @param successCallback A callback that is called with the Entry for the new location.
  84. * @param errorCallback A callback that is called when errors happen.
  85. */
  86. moveTo(parent: DirectoryEntry,
  87. newName?: string,
  88. successCallback?: (entry: Entry) => void,
  89. errorCallback?: (error: FileError) => void): void;
  90. /**
  91. * Copy an entry to a different location on the file system. It is an error to try to:
  92. * copy a directory inside itself or to any child at any depth;
  93. * copy an entry into its parent if a name different from its current one isn't provided;
  94. * copy a file to a path occupied by a directory;
  95. * copy a directory to a path occupied by a file;
  96. * copy any element to a path occupied by a directory which is not empty.
  97. * A copy of a file on top of an existing file must attempt to delete and replace that file.
  98. * A copy of a directory on top of an existing empty directory must attempt to delete and replace that directory.
  99. * Directory copies are always recursive--that is, they copy all contents of the directory.
  100. * @param parent The directory to which to move the entry.
  101. * @param newName The new name of the entry. Defaults to the Entry's current name if unspecified.
  102. * @param successCallback A callback that is called with the Entry for the new object.
  103. * @param errorCallback A callback that is called when errors happen.
  104. */
  105. copyTo(parent: DirectoryEntry,
  106. newName?: string,
  107. successCallback?: (entry: Entry) => void,
  108. errorCallback?: (error: FileError) => void): void;
  109. /**
  110. * Returns a URL that can be used as the src attribute of a <video> or <audio> tag.
  111. * If that is not possible, construct a cdvfile:// URL.
  112. * @return string URL
  113. */
  114. toURL(): string;
  115. /**
  116. * Return a URL that can be passed across the bridge to identify this entry.
  117. * @return string URL that can be passed across the bridge to identify this entry
  118. */
  119. toInternalURL(): string;
  120. /**
  121. * Deletes a file or directory. It is an error to attempt to delete a directory that is not empty. It is an error to attempt to delete the root directory of a filesystem.
  122. * @param successCallback A callback that is called on success.
  123. * @param errorCallback A callback that is called when errors happen.
  124. */
  125. remove(successCallback: () => void,
  126. errorCallback?: (error: FileError) => void): void;
  127. /**
  128. * Look up the parent DirectoryEntry containing this Entry. If this Entry is the root of its filesystem, its parent is itself.
  129. * @param successCallback A callback that is called with the time of the last modification.
  130. * @param errorCallback A callback that is called when errors happen.
  131. */
  132. getParent(successCallback: (entry: Entry) => void,
  133. errorCallback?: (error: FileError) => void): void;
  134. }
  135. /** This interface supplies information about the state of a file or directory. */
  136. interface Metadata {
  137. /** This is the time at which the file or directory was last modified. */
  138. modificationTime: Date;
  139. /** The size of the file, in bytes. This must return 0 for directories. */
  140. size: number;
  141. }
  142. /** This interface represents a directory on a file system. */
  143. interface DirectoryEntry extends Entry {
  144. /**
  145. * Creates a new DirectoryReader to read Entries from this Directory.
  146. */
  147. createReader(): DirectoryReader;
  148. /**
  149. * Creates or looks up a file.
  150. * @param path Either an absolute path or a relative path from this DirectoryEntry
  151. * to the file to be looked up or created.
  152. * It is an error to attempt to create a file whose immediate parent does not yet exist.
  153. * @param options If create and exclusive are both true, and the path already exists, getFile must fail.
  154. * If create is true, the path doesn't exist, and no other error occurs, getFile must create it as a zero-length file and return a corresponding FileEntry.
  155. * If create is not true and the path doesn't exist, getFile must fail.
  156. * If create is not true and the path exists, but is a directory, getFile must fail.
  157. * Otherwise, if no other error occurs, getFile must return a FileEntry corresponding to path.
  158. * @param successCallback A callback that is called to return the File selected or created.
  159. * @param errorCallback A callback that is called when errors happen.
  160. */
  161. getFile(path: string, options?: Flags,
  162. successCallback?: (entry: FileEntry) => void,
  163. errorCallback?: (error: FileError) => void): void;
  164. /**
  165. * Creates or looks up a directory.
  166. * @param path Either an absolute path or a relative path from this DirectoryEntry
  167. * to the directory to be looked up or created.
  168. * It is an error to attempt to create a directory whose immediate parent does not yet exist.
  169. * @param options If create and exclusive are both true and the path already exists, getDirectory must fail.
  170. * If create is true, the path doesn't exist, and no other error occurs, getDirectory must create and return a corresponding DirectoryEntry.
  171. * If create is not true and the path doesn't exist, getDirectory must fail.
  172. * If create is not true and the path exists, but is a file, getDirectory must fail.
  173. * Otherwise, if no other error occurs, getDirectory must return a DirectoryEntry corresponding to path.
  174. * @param successCallback A callback that is called to return the Directory selected or created.
  175. * @param errorCallback A callback that is called when errors happen.
  176. */
  177. getDirectory(path: string, options?: Flags,
  178. successCallback?: (entry: DirectoryEntry) => void,
  179. errorCallback?: (error: FileError) => void): void;
  180. /**
  181. * Deletes a directory and all of its contents, if any. In the event of an error (e.g. trying
  182. * to delete a directory that contains a file that cannot be removed), some of the contents
  183. * of the directory may be deleted. It is an error to attempt to delete the root directory of a filesystem.
  184. * @param successCallback A callback that is called on success.
  185. * @param errorCallback A callback that is called when errors happen.
  186. */
  187. removeRecursively(successCallback: () => void,
  188. errorCallback?: (error: FileError) => void): void;
  189. }
  190. /**
  191. * This dictionary is used to supply arguments to methods
  192. * that look up or create files or directories.
  193. */
  194. interface Flags {
  195. /** Used to indicate that the user wants to create a file or directory if it was not previously there. */
  196. create?: boolean;
  197. /** By itself, exclusive must have no effect. Used with create, it must cause getFile and getDirectory to fail if the target path already exists. */
  198. exclusive?: boolean;
  199. }
  200. /**
  201. * This interface lets a user list files and directories in a directory. If there are
  202. * no additions to or deletions from a directory between the first and last call to
  203. * readEntries, and no errors occur, then:
  204. * A series of calls to readEntries must return each entry in the directory exactly once.
  205. * Once all entries have been returned, the next call to readEntries must produce an empty array.
  206. * If not all entries have been returned, the array produced by readEntries must not be empty.
  207. * The entries produced by readEntries must not include the directory itself ["."] or its parent [".."].
  208. */
  209. interface DirectoryReader {
  210. /**
  211. * Read the next block of entries from this directory.
  212. * @param successCallback Called once per successful call to readEntries to deliver the next
  213. * previously-unreported set of Entries in the associated Directory.
  214. * If all Entries have already been returned from previous invocations
  215. * of readEntries, successCallback must be called with a zero-length array as an argument.
  216. * @param errorCallback A callback indicating that there was an error reading from the Directory.
  217. */
  218. readEntries(
  219. successCallback: (entries: Entry[]) => void,
  220. errorCallback?: (error: FileError) => void): void;
  221. }
  222. /** This interface represents a file on a file system. */
  223. interface FileEntry extends Entry {
  224. /**
  225. * Creates a new FileWriter associated with the file that this FileEntry represents.
  226. * @param successCallback A callback that is called with the new FileWriter.
  227. * @param errorCallback A callback that is called when errors happen.
  228. */
  229. createWriter(successCallback: (
  230. writer: FileWriter) => void,
  231. errorCallback?: (error: FileError) => void): void;
  232. /**
  233. * Returns a File that represents the current state of the file that this FileEntry represents.
  234. * @param successCallback A callback that is called with the File.
  235. * @param errorCallback A callback that is called when errors happen.
  236. */
  237. file(successCallback: (file: File) => void,
  238. errorCallback?: (error: FileError) => void): void;
  239. }
  240. /**
  241. * This interface provides methods to monitor the asynchronous writing of blobs
  242. * to disk using progress events and event handler attributes.
  243. */
  244. interface FileSaver extends EventTarget {
  245. /** Terminate file operation */
  246. abort(): void;
  247. /**
  248. * The FileSaver object can be in one of 3 states. The readyState attribute, on getting,
  249. * must return the current state, which must be one of the following values:
  250. * INIT
  251. * WRITING
  252. * DONE
  253. */
  254. readyState: number;
  255. /** Handler for writestart events. */
  256. onwritestart: (event: ProgressEvent) => void;
  257. /** Handler for progress events. */
  258. onprogress: (event: ProgressEvent) => void;
  259. /** Handler for write events. */
  260. onwrite: (event: ProgressEvent) => void;
  261. /** Handler for abort events. */
  262. onabort: (event: ProgressEvent) => void;
  263. /** Handler for error events. */
  264. onerror: (event: ProgressEvent) => void;
  265. /** Handler for writeend events. */
  266. onwriteend: (event: ProgressEvent) => void;
  267. /** The last error that occurred on the FileSaver. */
  268. error: Error;
  269. }
  270. /**
  271. * This interface expands on the FileSaver interface to allow for multiple write
  272. * actions, rather than just saving a single Blob.
  273. */
  274. interface FileWriter extends FileSaver {
  275. /**
  276. * The byte offset at which the next write to the file will occur. This always less or equal than length.
  277. * A newly-created FileWriter will have position set to 0.
  278. */
  279. position: number;
  280. /**
  281. * The length of the file. If the user does not have read access to the file,
  282. * this will be the highest byte offset at which the user has written.
  283. */
  284. length: number;
  285. /**
  286. * Write the supplied data to the file at position.
  287. * @param {Blob|string} data The blob to write.
  288. */
  289. write(data: Blob|string): void;
  290. /**
  291. * The file position at which the next write will occur.
  292. * @param offset If nonnegative, an absolute byte offset into the file.
  293. * If negative, an offset back from the end of the file.
  294. */
  295. seek(offset: number): void;
  296. /**
  297. * Changes the length of the file to that specified. If shortening the file, data beyond the new length
  298. * will be discarded. If extending the file, the existing data will be zero-padded up to the new length.
  299. * @param size The size to which the length of the file is to be adjusted, measured in bytes.
  300. */
  301. truncate(size: number): void;
  302. }
  303. /* FileWriter states */
  304. declare var FileWriter: {
  305. INIT: number;
  306. WRITING: number;
  307. DONE: number
  308. };
  309. interface FileError {
  310. /** Error code */
  311. code: number;
  312. }
  313. declare var FileError: {
  314. new (code: number): FileError;
  315. NOT_FOUND_ERR: number;
  316. SECURITY_ERR: number;
  317. ABORT_ERR: number;
  318. NOT_READABLE_ERR: number;
  319. ENCODING_ERR: number;
  320. NO_MODIFICATION_ALLOWED_ERR: number;
  321. INVALID_STATE_ERR: number;
  322. SYNTAX_ERR: number;
  323. INVALID_MODIFICATION_ERR: number;
  324. QUOTA_EXCEEDED_ERR: number;
  325. TYPE_MISMATCH_ERR: number;
  326. PATH_EXISTS_ERR: number;
  327. };
  328. /*
  329. * Constants defined in fileSystemPaths
  330. */
  331. interface Cordova {
  332. file: {
  333. /* Read-only directory where the application is installed. */
  334. applicationDirectory: string;
  335. /* Root of app's private writable storage */
  336. applicationStorageDirectory: string;
  337. /* Where to put app-specific data files. */
  338. dataDirectory: string;
  339. /* Cached files that should survive app restarts. Apps should not rely on the OS to delete files in here. */
  340. cacheDirectory: string;
  341. /* Android: the application space on external storage. */
  342. externalApplicationStorageDirectory: string;
  343. /* Android: Where to put app-specific data files on external storage. */
  344. externalDataDirectory: string;
  345. /* Android: the application cache on external storage. */
  346. externalCacheDirectory: string;
  347. /* Android: the external storage (SD card) root. */
  348. externalRootDirectory: string;
  349. /* iOS: Temp directory that the OS can clear at will. */
  350. tempDirectory: string;
  351. /* iOS: Holds app-specific files that should be synced (e.g. to iCloud). */
  352. syncedDataDirectory: string;
  353. /* iOS: Files private to the app, but that are meaningful to other applciations (e.g. Office files) */
  354. documentsDirectory: string;
  355. /* BlackBerry10: Files globally available to all apps */
  356. sharedDirectory: string
  357. }
  358. }
  359. declare enum LocalFileSystem {
  360. PERSISTENT=1,
  361. TEMPORARY=0
  362. }