diff --git a/src/@ionic-native/plugins/file/index.ts b/src/@ionic-native/plugins/file/index.ts
index 8b4bfd9dd..5b0808950 100644
--- a/src/@ionic-native/plugins/file/index.ts
+++ b/src/@ionic-native/plugins/file/index.ts
@@ -1,5 +1,10 @@
import { Injectable } from '@angular/core';
-import { CordovaProperty, Plugin, CordovaCheck, IonicNativePlugin } from '@ionic-native/core';
+import {
+ CordovaCheck,
+ CordovaProperty,
+ IonicNativePlugin,
+ Plugin
+} from '@ionic-native/core';
export interface IFile extends Blob {
/**
@@ -36,7 +41,6 @@ export interface IFile extends Blob {
}
export interface LocalFileSystem {
-
/**
* Used for storage with no guarantee of persistence.
*/
@@ -54,7 +58,12 @@ export interface LocalFileSystem {
* @param successCallback The callback that is called when the user agent provides a filesystem.
* @param errorCallback A callback that is called when errors happen, or when the request to obtain the filesystem is denied.
*/
- requestFileSystem(type: number, size: number, successCallback: FileSystemCallback, errorCallback?: ErrorCallback): void;
+ requestFileSystem(
+ type: number,
+ size: number,
+ successCallback: FileSystemCallback,
+ errorCallback?: ErrorCallback
+ ): void;
/**
* Allows the user to look up the Entry for a file or directory referred to by a local URL.
@@ -62,12 +71,21 @@ export interface LocalFileSystem {
* @param successCallback A callback that is called to report the Entry to which the supplied URL refers.
* @param errorCallback A callback that is called when errors happen, or when the request to obtain the Entry is denied.
*/
- resolveLocalFileSystemURL(url: string, successCallback: EntryCallback, errorCallback?: ErrorCallback): void;
+ resolveLocalFileSystemURL(
+ url: string,
+ successCallback: EntryCallback,
+ errorCallback?: ErrorCallback
+ ): void;
/**
* see requestFileSystem.
*/
- webkitRequestFileSystem(type: number, size: number, successCallback: FileSystemCallback, errorCallback?: ErrorCallback): void;
+ webkitRequestFileSystem(
+ type: number,
+ size: number,
+ successCallback: FileSystemCallback,
+ errorCallback?: ErrorCallback
+ ): void;
}
export interface Metadata {
@@ -115,11 +133,9 @@ export interface FileSystem {
toJSON(): string;
encodeURIPath(path: string): string;
-
}
export interface Entry {
-
/**
* Entry is a file.
*/
@@ -135,7 +151,10 @@ export interface Entry {
* @param successCallback A callback that is called with the time of the last modification.
* @param errorCallback ErrorCallback A callback that is called when errors happen.
*/
- getMetadata(successCallback: MetadataCallback, errorCallback?: ErrorCallback): void;
+ getMetadata(
+ successCallback: MetadataCallback,
+ errorCallback?: ErrorCallback
+ ): void;
/**
* Set the metadata of the entry.
@@ -143,7 +162,11 @@ export interface Entry {
* @param errorCallback {Function} is called with a FileError
* @param metadataObject {Metadata} keys and values to set
*/
- setMetadata(successCallback: MetadataCallback, errorCallback: ErrorCallback, metadataObject: Metadata): void;
+ setMetadata(
+ successCallback: MetadataCallback,
+ errorCallback: ErrorCallback,
+ metadataObject: Metadata
+ ): void;
/**
* The name of the entry, excluding the path leading to it.
@@ -179,7 +202,12 @@ export interface Entry {
* A move of a file on top of an existing file must attempt to delete and replace that file.
* A move of a directory on top of an existing empty directory must attempt to delete and replace that directory.
*/
- moveTo(parent: DirectoryEntry, newName?: string, successCallback?: EntryCallback, errorCallback?: ErrorCallback): void;
+ moveTo(
+ parent: DirectoryEntry,
+ newName?: string,
+ successCallback?: EntryCallback,
+ errorCallback?: ErrorCallback
+ ): void;
/**
* Copy an entry to a different location on the file system. It is an error to try to:
@@ -196,7 +224,12 @@ export interface Entry {
*
* Directory copies are always recursive--that is, they copy all contents of the directory.
*/
- copyTo(parent: DirectoryEntry, newName?: string, successCallback?: EntryCallback, errorCallback?: ErrorCallback): void;
+ copyTo(
+ parent: DirectoryEntry,
+ newName?: string,
+ successCallback?: EntryCallback,
+ errorCallback?: ErrorCallback
+ ): void;
/**
* Returns a URL that can be used to identify this entry. Unlike the URN defined in [FILE-API-ED], it has no specific expiration; as it describes a location on disk, it should be valid at least as long as that location exists.
@@ -221,7 +254,10 @@ export interface Entry {
* @param successCallback A callback that is called to return the parent Entry.
* @param errorCallback A callback that is called when errors happen.
*/
- getParent(successCallback: DirectoryEntryCallback, errorCallback?: ErrorCallback): void;
+ getParent(
+ successCallback: DirectoryEntryCallback,
+ errorCallback?: ErrorCallback
+ ): void;
}
/**
@@ -247,7 +283,12 @@ export interface DirectoryEntry extends Entry {
* @param successCallback A callback that is called to return the File selected or created.
* @param errorCallback A callback that is called when errors happen.
*/
- getFile(path: string, options?: Flags, successCallback?: FileEntryCallback, errorCallback?: ErrorCallback): void;
+ getFile(
+ path: string,
+ options?: Flags,
+ successCallback?: FileEntryCallback,
+ errorCallback?: ErrorCallback
+ ): void;
/**
* Creates or looks up a directory.
@@ -264,14 +305,22 @@ export interface DirectoryEntry extends Entry {
* @param errorCallback A callback that is called when errors happen.
*
*/
- getDirectory(path: string, options?: Flags, successCallback?: DirectoryEntryCallback, errorCallback?: ErrorCallback): void;
+ getDirectory(
+ path: string,
+ options?: Flags,
+ successCallback?: DirectoryEntryCallback,
+ errorCallback?: ErrorCallback
+ ): void;
/**
* Deletes a directory and all of its contents, if any. In the event of an error [e.g. trying to delete a directory that contains a file that cannot be removed], some of the contents of the directory may be deleted. It is an error to attempt to delete the root directory of a filesystem.
* @param successCallback A callback that is called on success.
* @param errorCallback A callback that is called when errors happen.
*/
- removeRecursively(successCallback: VoidCallback, errorCallback?: ErrorCallback): void;
+ removeRecursively(
+ successCallback: VoidCallback,
+ errorCallback?: ErrorCallback
+ ): void;
}
/**
@@ -291,7 +340,10 @@ export interface DirectoryReader {
* @param successCallback Called once per successful call to readEntries to deliver the next previously-unreported set of Entries in the associated Directory. If all Entries have already been returned from previous invocations of readEntries, successCallback must be called with a zero-length array as an argument.
* @param errorCallback A callback indicating that there was an error reading from the Directory.
*/
- readEntries(successCallback: EntriesCallback, errorCallback?: ErrorCallback): void;
+ readEntries(
+ successCallback: EntriesCallback,
+ errorCallback?: ErrorCallback
+ ): void;
}
/**
@@ -303,7 +355,10 @@ export interface FileEntry extends Entry {
* @param successCallback A callback that is called with the new FileWriter.
* @param errorCallback A callback that is called when errors happen.
*/
- createWriter(successCallback: FileWriterCallback, errorCallback?: ErrorCallback): void;
+ createWriter(
+ successCallback: FileWriterCallback,
+ errorCallback?: ErrorCallback
+ ): void;
/**
* Returns a File that represents the current state of the file that this FileEntry represents.
@@ -417,7 +472,7 @@ export declare class FileSaver extends EventTarget {
*
Terminate the write algorithm being processed.
* Set the error attribute to a DOMError object of type "AbortError".
* Fire a progress event called abort
- * Fire a progress event called writeend
+ * Fire a progress event called write end
* Terminate this algorithm.
*
*/
@@ -459,7 +514,7 @@ export declare class FileSaver extends EventTarget {
error: Error;
/**
- * Handler for writestart events
+ * Handler for write start events
*/
onwritestart: (event: ProgressEvent) => void;
@@ -484,7 +539,7 @@ export declare class FileSaver extends EventTarget {
onerror: (event: ProgressEvent) => void;
/**
- * Handler for writeend events.
+ * Handler for write end events.
*/
onwriteend: (event: ProgressEvent) => void;
}
@@ -578,7 +633,6 @@ export declare class FileReader {
* @hidden
*/
[key: string]: any;
-
}
interface Window extends LocalFileSystem {}
@@ -600,7 +654,7 @@ declare const window: Window;
*
* ...
*
- * this.file.checkDir(this.file.dataDirectory, 'mydir').then(_ => console.log('Directory exists')).catch(err => console.log('Directory doesnt exist'));
+ * this.file.checkDir(this.file.dataDirectory, 'mydir').then(_ => console.log('Directory exists')).catch(err => console.log('Directory doesn't exist'));
*
* ```
*
@@ -624,79 +678,66 @@ declare const window: Window;
})
@Injectable()
export class File extends IonicNativePlugin {
+ /**
+ * Read-only directory where the application is installed.
+ */
+ @CordovaProperty applicationDirectory: string;
/**
* Read-only directory where the application is installed.
*/
- @CordovaProperty
- applicationDirectory: string;
-
- /**
- * Read-only directory where the application is installed.
- */
- @CordovaProperty
- applicationStorageDirectory: string;
+ @CordovaProperty applicationStorageDirectory: string;
/**
* Where to put app-specific data files.
*/
- @CordovaProperty
- dataDirectory: string;
+ @CordovaProperty dataDirectory: string;
/**
* Cached files that should survive app restarts.
* Apps should not rely on the OS to delete files in here.
*/
- @CordovaProperty
- cacheDirectory: string;
+ @CordovaProperty cacheDirectory: string;
/**
* Android: the application space on external storage.
*/
- @CordovaProperty
- externalApplicationStorageDirectory: string;
+ @CordovaProperty externalApplicationStorageDirectory: string;
/**
* Android: Where to put app-specific data files on external storage.
*/
- @CordovaProperty
- externalDataDirectory: string;
+ @CordovaProperty externalDataDirectory: string;
/**
* Android: the application cache on external storage.
*/
- @CordovaProperty
- externalCacheDirectory: string;
+ @CordovaProperty externalCacheDirectory: string;
/**
* Android: the external storage (SD card) root.
*/
- @CordovaProperty
- externalRootDirectory: string;
+ @CordovaProperty externalRootDirectory: string;
/**
* iOS: Temp directory that the OS can clear at will.
*/
- @CordovaProperty
- tempDirectory: string;
+ @CordovaProperty tempDirectory: string;
/**
* iOS: Holds app-specific files that should be synced (e.g. to iCloud).
*/
- @CordovaProperty
- syncedDataDirectory: string;
+ @CordovaProperty syncedDataDirectory: string;
/**
* iOS: Files private to the app, but that are meaningful to other applications (e.g. Office files)
*/
- @CordovaProperty
- documentsDirectory: string;
+ @CordovaProperty documentsDirectory: string;
/**
* BlackBerry10: Files globally available to all apps
*/
- @CordovaProperty
- sharedDirectory: string;
+ @CordovaProperty sharedDirectory: string;
cordovaFileError: any = {
1: 'NOT_FOUND_ERR',
@@ -712,7 +753,7 @@ export class File extends IonicNativePlugin {
11: 'TYPE_MISMATCH_ERR',
12: 'PATH_EXISTS_ERR',
13: 'WRONG_ENTRY_TYPE',
- 14: 'DIR_READ_ERR',
+ 14: 'DIR_READ_ERR'
};
/**
@@ -729,23 +770,22 @@ export class File extends IonicNativePlugin {
/**
* Check if a directory exists in a certain path, directory.
*
- * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
+ * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystem above
* @param {string} dir Name of directory to check
* @returns {Promise} Returns a Promise that resolves to true if the directory exists or rejects with an error.
*/
@CordovaCheck()
checkDir(path: string, dir: string): Promise {
- if ((/^\//.test(dir))) {
+ if (/^\//.test(dir)) {
let err = new FileError(5);
- err.message = 'directory cannot start with \/';
+ err.message = 'directory cannot start with /';
return Promise.reject(err);
}
- let fullpath = path + dir;
- return this.resolveDirectoryUrl(fullpath)
- .then(() => {
- return true;
- });
+ const fullPath = path + dir;
+ return this.resolveDirectoryUrl(fullPath).then(() => {
+ return true;
+ });
}
/**
@@ -753,16 +793,20 @@ export class File extends IonicNativePlugin {
* The replace boolean value determines whether to replace an existing directory with the same name.
* If an existing directory exists and the replace value is false, the promise will fail and return an error.
*
- * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
+ * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystem above
* @param {string} dirName Name of directory to create
* @param {boolean} replace If true, replaces file with same name. If false returns error
* @returns {Promise} Returns a Promise that resolves with a DirectoryEntry or rejects with an error.
*/
@CordovaCheck()
- createDir(path: string, dirName: string, replace: boolean): Promise {
- if ((/^\//.test(dirName))) {
+ createDir(
+ path: string,
+ dirName: string,
+ replace: boolean
+ ): Promise {
+ if (/^\//.test(dirName)) {
let err = new FileError(5);
- err.message = 'directory cannot start with \/';
+ err.message = 'directory cannot start with /';
return Promise.reject(err);
}
@@ -774,10 +818,9 @@ export class File extends IonicNativePlugin {
options.exclusive = true;
}
- return this.resolveDirectoryUrl(path)
- .then((fse) => {
- return this.getDirectory(fse, dirName, options);
- });
+ return this.resolveDirectoryUrl(path).then(fse => {
+ return this.getDirectory(fse, dirName, options);
+ });
}
/**
@@ -789,17 +832,17 @@ export class File extends IonicNativePlugin {
*/
@CordovaCheck()
removeDir(path: string, dirName: string): Promise {
- if ((/^\//.test(dirName))) {
+ if (/^\//.test(dirName)) {
let err = new FileError(5);
- err.message = 'directory cannot start with \/';
+ err.message = 'directory cannot start with /';
return Promise.reject(err);
}
return this.resolveDirectoryUrl(path)
- .then((fse) => {
+ .then(fse => {
return this.getDirectory(fse, dirName, { create: false });
})
- .then((de) => {
+ .then(de => {
return this.remove(de);
});
}
@@ -809,29 +852,33 @@ export class File extends IonicNativePlugin {
*
* @param {string} path The source path to the directory
* @param {string} dirName The source directory name
- * @param {string} newPath The destionation path to the directory
+ * @param {string} newPath The destination path to the directory
* @param {string} newDirName The destination directory name
* @returns {Promise} Returns a Promise that resolves to the new DirectoryEntry object or rejects with an error.
*/
@CordovaCheck()
- moveDir(path: string, dirName: string, newPath: string, newDirName: string): Promise {
+ moveDir(
+ path: string,
+ dirName: string,
+ newPath: string,
+ newDirName: string
+ ): Promise {
newDirName = newDirName || dirName;
- if ((/^\//.test(newDirName))) {
+ if (/^\//.test(newDirName)) {
let err = new FileError(5);
- err.message = 'directory cannot start with \/';
+ err.message = 'directory cannot start with /';
return Promise.reject(err);
}
return this.resolveDirectoryUrl(path)
- .then((fse) => {
+ .then(fse => {
return this.getDirectory(fse, dirName, { create: false });
})
- .then((srcde) => {
- return this.resolveDirectoryUrl(newPath)
- .then((deste) => {
- return this.move(srcde, deste, newDirName);
- });
+ .then(srcde => {
+ return this.resolveDirectoryUrl(newPath).then(destenation => {
+ return this.move(srcde, destenation, newDirName);
+ });
});
}
@@ -845,22 +892,26 @@ export class File extends IonicNativePlugin {
* @returns {Promise} Returns a Promise that resolves to the new Entry object or rejects with an error.
*/
@CordovaCheck()
- copyDir(path: string, dirName: string, newPath: string, newDirName: string): Promise {
- if ((/^\//.test(newDirName))) {
+ copyDir(
+ path: string,
+ dirName: string,
+ newPath: string,
+ newDirName: string
+ ): Promise {
+ if (/^\//.test(newDirName)) {
let err = new FileError(5);
- err.message = 'directory cannot start with \/';
+ err.message = 'directory cannot start with /';
return Promise.reject(err);
}
return this.resolveDirectoryUrl(path)
- .then((fse) => {
+ .then(fse => {
return this.getDirectory(fse, dirName, { create: false });
})
- .then((srcde) => {
- return this.resolveDirectoryUrl(newPath)
- .then((deste) => {
- return this.copy(srcde, deste, newDirName);
- });
+ .then(srcde => {
+ return this.resolveDirectoryUrl(newPath).then(deste => {
+ return this.copy(srcde, deste, newDirName);
+ });
});
}
@@ -873,17 +924,20 @@ export class File extends IonicNativePlugin {
*/
@CordovaCheck()
listDir(path: string, dirName: string): Promise {
- if ((/^\//.test(dirName))) {
+ if (/^\//.test(dirName)) {
let err = new FileError(5);
- err.message = 'directory cannot start with \/';
+ err.message = 'directory cannot start with /';
return Promise.reject(err);
}
return this.resolveDirectoryUrl(path)
- .then((fse) => {
- return this.getDirectory(fse, dirName, { create: false, exclusive: false });
+ .then(fse => {
+ return this.getDirectory(fse, dirName, {
+ create: false,
+ exclusive: false
+ });
})
- .then((de) => {
+ .then(de => {
let reader = de.createReader();
return this.readEntries(reader);
});
@@ -892,23 +946,23 @@ export class File extends IonicNativePlugin {
/**
* Removes all files and the directory from a desired location.
*
- * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
+ * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystem above
* @param {string} dirName Name of directory
* @returns {Promise} Returns a Promise that resolves with a RemoveResult or rejects with an error.
*/
@CordovaCheck()
removeRecursively(path: string, dirName: string): Promise {
- if ((/^\//.test(dirName))) {
+ if (/^\//.test(dirName)) {
let err = new FileError(5);
- err.message = 'directory cannot start with \/';
+ err.message = 'directory cannot start with /';
return Promise.reject(err);
}
return this.resolveDirectoryUrl(path)
- .then((fse) => {
+ .then(fse => {
return this.getDirectory(fse, dirName, { create: false });
})
- .then((de) => {
+ .then(de => {
return this.rimraf(de);
});
}
@@ -916,28 +970,27 @@ export class File extends IonicNativePlugin {
/**
* Check if a file exists in a certain path, directory.
*
- * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
+ * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystem above
* @param {string} file Name of file to check
* @returns {Promise} Returns a Promise that resolves with a boolean or rejects with an error.
*/
@CordovaCheck()
checkFile(path: string, file: string): Promise {
- if ((/^\//.test(file))) {
+ if (/^\//.test(file)) {
let err = new FileError(5);
- err.message = 'file cannot start with \/';
+ err.message = 'file cannot start with /';
return Promise.reject(err);
}
- return this.resolveLocalFilesystemUrl(path + file)
- .then((fse) => {
- if (fse.isFile) {
- return true;
- } else {
- let err = new FileError(13);
- err.message = 'input is not a file';
- return Promise.reject(err);
- }
- });
+ return this.resolveLocalFilesystemUrl(path + file).then(fse => {
+ if (fse.isFile) {
+ return true;
+ } else {
+ let err = new FileError(13);
+ err.message = 'input is not a file';
+ return Promise.reject(err);
+ }
+ });
}
/**
@@ -945,16 +998,20 @@ export class File extends IonicNativePlugin {
* The replace boolean value determines whether to replace an existing file with the same name.
* If an existing file exists and the replace value is false, the promise will fail and return an error.
*
- * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
+ * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystem above
* @param {string} fileName Name of file to create
* @param {boolean} replace If true, replaces file with same name. If false returns error
* @returns {Promise} Returns a Promise that resolves to a FileEntry or rejects with an error.
*/
@CordovaCheck()
- createFile(path: string, fileName: string, replace: boolean): Promise {
- if ((/^\//.test(fileName))) {
+ createFile(
+ path: string,
+ fileName: string,
+ replace: boolean
+ ): Promise {
+ if (/^\//.test(fileName)) {
let err = new FileError(5);
- err.message = 'file-name cannot start with \/';
+ err.message = 'file-name cannot start with /';
return Promise.reject(err);
}
@@ -966,50 +1023,53 @@ export class File extends IonicNativePlugin {
options.exclusive = true;
}
- return this.resolveDirectoryUrl(path)
- .then((fse) => {
- return this.getFile(fse, fileName, options);
- });
+ return this.resolveDirectoryUrl(path).then(fse => {
+ return this.getFile(fse, fileName, options);
+ });
}
/**
* Removes a file from a desired location.
*
- * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
+ * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystem above
* @param {string} fileName Name of file to remove
* @returns {Promise} Returns a Promise that resolves to a RemoveResult or rejects with an error.
*/
@CordovaCheck()
removeFile(path: string, fileName: string): Promise {
- if ((/^\//.test(fileName))) {
+ if (/^\//.test(fileName)) {
let err = new FileError(5);
- err.message = 'file-name cannot start with \/';
+ err.message = 'file-name cannot start with /';
return Promise.reject(err);
}
return this.resolveDirectoryUrl(path)
- .then((fse) => {
+ .then(fse => {
return this.getFile(fse, fileName, { create: false });
})
- .then((fe) => {
+ .then(fe => {
return this.remove(fe);
});
}
/** Write a new file to the desired location.
*
- * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
+ * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystem above
* @param {string} fileName path relative to base path
* @param {string | Blob | ArrayBuffer} text content, blob or ArrayBuffer to write
* @param {IWriteOptions} options replace file if set to true. See WriteOptions for more information.
* @returns {Promise} Returns a Promise that resolves to updated file entry or rejects with an error.
*/
@CordovaCheck()
- writeFile(path: string, fileName: string,
- text: string | Blob | ArrayBuffer, options: IWriteOptions = {}): Promise {
- if ((/^\//.test(fileName))) {
+ writeFile(
+ path: string,
+ fileName: string,
+ text: string | Blob | ArrayBuffer,
+ options: IWriteOptions = {}
+ ): Promise {
+ if (/^\//.test(fileName)) {
const err = new FileError(5);
- err.message = 'file-name cannot start with \/';
+ err.message = 'file-name cannot start with /';
return Promise.reject(err);
}
@@ -1035,9 +1095,13 @@ export class File extends IonicNativePlugin {
* @param {IWriteOptions} options replace file if set to true. See WriteOptions for more information.
* @returns {Promise} Returns a Promise that resolves to updated file entry or rejects with an error.
*/
- private writeFileEntry(fe: FileEntry, text: string | Blob | ArrayBuffer, options: IWriteOptions) {
+ private writeFileEntry(
+ fe: FileEntry,
+ text: string | Blob | ArrayBuffer,
+ options: IWriteOptions
+ ) {
return this.createWriter(fe)
- .then((writer) => {
+ .then(writer => {
if (options.append) {
writer.seek(writer.length);
}
@@ -1051,23 +1115,26 @@ export class File extends IonicNativePlugin {
.then(() => fe);
}
-
/** Write to an existing file.
*
- * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
+ * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystem above
* @param {string} fileName path relative to base path
* @param {string | Blob} text content or blob to write
* @returns {Promise} Returns a Promise that resolves or rejects with an error.
*/
@CordovaCheck()
- writeExistingFile(path: string, fileName: string, text: string | Blob): Promise {
+ writeExistingFile(
+ path: string,
+ fileName: string,
+ text: string | Blob
+ ): Promise {
return this.writeFile(path, fileName, text, { replace: true });
}
/**
* Read the contents of a file as text.
*
- * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
+ * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystem above
* @param {string} file Name of file, relative to path.
* @returns {Promise} Returns a Promise that resolves with the contents of the file as string or rejects with an error.
*/
@@ -1081,7 +1148,7 @@ export class File extends IonicNativePlugin {
* A data url is of the form:
* data: [][;base64],
- * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
+ * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystem above
* @param {string} file Name of file, relative to path.
* @returns {Promise} Returns a Promise that resolves with the contents of the file as data URL or rejects with an error.
*/
@@ -1092,7 +1159,7 @@ export class File extends IonicNativePlugin {
/**
* Read file and return data as a binary data.
- * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
+ * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystem above
* @param {string} file Name of file, relative to path.
* @returns {Promise} Returns a Promise that resolves with the contents of the file as string rejects with an error.
*/
@@ -1103,7 +1170,7 @@ export class File extends IonicNativePlugin {
/**
* Read file and return data as an ArrayBuffer.
- * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
+ * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystem above
* @param {string} file Name of file, relative to path.
* @returns {Promise} Returns a Promise that resolves with the contents of the file as ArrayBuffer or rejects with an error.
*/
@@ -1112,10 +1179,14 @@ export class File extends IonicNativePlugin {
return this.readFile(path, file, 'ArrayBuffer');
}
- private readFile(path: string, file: string, readAs: 'ArrayBuffer' | 'BinaryString' | 'DataURL' | 'Text'): Promise {
- if ((/^\//.test(file))) {
+ private readFile(
+ path: string,
+ file: string,
+ readAs: 'ArrayBuffer' | 'BinaryString' | 'DataURL' | 'Text'
+ ): Promise {
+ if (/^\//.test(file)) {
let err = new FileError(5);
- err.message = 'file-name cannot start with \/';
+ err.message = 'file-name cannot start with /';
return Promise.reject(err);
}
@@ -1128,7 +1199,7 @@ export class File extends IonicNativePlugin {
return new Promise((resolve, reject) => {
reader.onloadend = () => {
if (reader.result !== undefined || reader.result !== null) {
- resolve(reader.result);
+ resolve((reader.result));
} else if (reader.error !== undefined || reader.error !== null) {
reject(reader.error);
} else {
@@ -1136,12 +1207,14 @@ export class File extends IonicNativePlugin {
}
};
- fileEntry.file(file => {
- reader[`readAs${readAs}`].call(reader, file);
- }, error => {
- reject(error);
- });
-
+ fileEntry.file(
+ file => {
+ reader[`readAs${readAs}`].call(reader, file);
+ },
+ error => {
+ reject(error);
+ }
+ );
});
});
}
@@ -1149,62 +1222,70 @@ export class File extends IonicNativePlugin {
/**
* Move a file to a given path.
*
- * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
+ * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystem above
* @param {string} fileName Name of file to move
* @param {string} newPath Base FileSystem of new location
* @param {string} newFileName New name of file to move to (leave blank to remain the same)
* @returns {Promise} Returns a Promise that resolves to the new Entry or rejects with an error.
*/
@CordovaCheck()
- moveFile(path: string, fileName: string, newPath: string, newFileName: string): Promise {
+ moveFile(
+ path: string,
+ fileName: string,
+ newPath: string,
+ newFileName: string
+ ): Promise {
newFileName = newFileName || fileName;
- if ((/^\//.test(newFileName))) {
+ if (/^\//.test(newFileName)) {
let err = new FileError(5);
- err.message = 'file name cannot start with \/';
+ err.message = 'file name cannot start with /';
return Promise.reject(err);
}
return this.resolveDirectoryUrl(path)
- .then((fse) => {
+ .then(fse => {
return this.getFile(fse, fileName, { create: false });
})
- .then((srcfe) => {
- return this.resolveDirectoryUrl(newPath)
- .then((deste) => {
- return this.move(srcfe, deste, newFileName);
- });
+ .then(srcfe => {
+ return this.resolveDirectoryUrl(newPath).then(deste => {
+ return this.move(srcfe, deste, newFileName);
+ });
});
}
/**
* Copy a file in various methods. If file exists, will fail to copy.
*
- * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
+ * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystem above
* @param {string} fileName Name of file to copy
* @param {string} newPath Base FileSystem of new location
* @param {string} newFileName New name of file to copy to (leave blank to remain the same)
* @returns {Promise} Returns a Promise that resolves to an Entry or rejects with an error.
*/
@CordovaCheck()
- copyFile(path: string, fileName: string, newPath: string, newFileName: string): Promise {
+ copyFile(
+ path: string,
+ fileName: string,
+ newPath: string,
+ newFileName: string
+ ): Promise {
newFileName = newFileName || fileName;
- if ((/^\//.test(newFileName))) {
+ if (/^\//.test(newFileName)) {
let err = new FileError(5);
- err.message = 'file name cannot start with \/';
+ err.message = 'file name cannot start with /';
return Promise.reject(err);
}
return this.resolveDirectoryUrl(path)
- .then((fse) => {
+ .then(fse => {
return this.getFile(fse, fileName, { create: false });
})
- .then((srcfe) => {
- return this.resolveDirectoryUrl(newPath)
- .then((deste) => {
- return this.copy(srcfe, deste, newFileName);
- });
+ .then(srcfe => {
+ return this.resolveDirectoryUrl(newPath).then(deste => {
+ return this.copy(srcfe, deste, newFileName);
+ });
});
}
@@ -1214,7 +1295,7 @@ export class File extends IonicNativePlugin {
private fillErrorMessage(err: FileError): void {
try {
err.message = this.cordovaFileError[err.code];
- } catch (e) { }
+ } catch (e) {}
}
/**
@@ -1226,12 +1307,16 @@ export class File extends IonicNativePlugin {
resolveLocalFilesystemUrl(fileUrl: string): Promise {
return new Promise((resolve, reject) => {
try {
- window.resolveLocalFileSystemURL(fileUrl, (entry: Entry) => {
- resolve(entry);
- }, (err) => {
- this.fillErrorMessage(err);
- reject(err);
- });
+ window.resolveLocalFileSystemURL(
+ fileUrl,
+ (entry: Entry) => {
+ resolve(entry);
+ },
+ err => {
+ this.fillErrorMessage(err);
+ reject(err);
+ }
+ );
} catch (xc) {
this.fillErrorMessage(xc);
reject(xc);
@@ -1246,16 +1331,15 @@ export class File extends IonicNativePlugin {
*/
@CordovaCheck()
resolveDirectoryUrl(directoryUrl: string): Promise {
- return this.resolveLocalFilesystemUrl(directoryUrl)
- .then((de) => {
- if (de.isDirectory) {
- return de;
- } else {
- const err = new FileError(13);
- err.message = 'input is not a directory';
- return Promise.reject(err);
- }
- });
+ return this.resolveLocalFilesystemUrl(directoryUrl).then(de => {
+ if (de.isDirectory) {
+ return de;
+ } else {
+ const err = new FileError(13);
+ err.message = 'input is not a directory';
+ return Promise.reject(err);
+ }
+ });
}
/**
@@ -1266,15 +1350,24 @@ export class File extends IonicNativePlugin {
* @returns {Promise}
*/
@CordovaCheck()
- getDirectory(directoryEntry: DirectoryEntry, directoryName: string, flags: Flags): Promise {
+ getDirectory(
+ directoryEntry: DirectoryEntry,
+ directoryName: string,
+ flags: Flags
+ ): Promise {
return new Promise((resolve, reject) => {
try {
- directoryEntry.getDirectory(directoryName, flags, (de) => {
- resolve(de);
- }, (err) => {
- this.fillErrorMessage(err);
- reject(err);
- });
+ directoryEntry.getDirectory(
+ directoryName,
+ flags,
+ de => {
+ resolve(de);
+ },
+ err => {
+ this.fillErrorMessage(err);
+ reject(err);
+ }
+ );
} catch (xc) {
this.fillErrorMessage(xc);
reject(xc);
@@ -1290,10 +1383,14 @@ export class File extends IonicNativePlugin {
* @returns {Promise}
*/
@CordovaCheck()
- getFile(directoryEntry: DirectoryEntry, fileName: string, flags: Flags): Promise {
+ getFile(
+ directoryEntry: DirectoryEntry,
+ fileName: string,
+ flags: Flags
+ ): Promise {
return new Promise((resolve, reject) => {
try {
- directoryEntry.getFile(fileName, flags, resolve, (err) => {
+ directoryEntry.getFile(fileName, flags, resolve, err => {
this.fillErrorMessage(err);
reject(err);
});
@@ -1309,40 +1406,61 @@ export class File extends IonicNativePlugin {
*/
private remove(fe: Entry): Promise {
return new Promise((resolve, reject) => {
- fe.remove(() => {
- resolve({ success: true, fileRemoved: fe });
- }, (err) => {
- this.fillErrorMessage(err);
- reject(err);
- });
+ fe.remove(
+ () => {
+ resolve({ success: true, fileRemoved: fe });
+ },
+ err => {
+ this.fillErrorMessage(err);
+ reject(err);
+ }
+ );
});
}
/**
* @hidden
*/
- private move(srce: Entry, destdir: DirectoryEntry, newName: string): Promise {
+ private move(
+ srce: Entry,
+ destdir: DirectoryEntry,
+ newName: string
+ ): Promise {
return new Promise((resolve, reject) => {
- srce.moveTo(destdir, newName, (deste) => {
- resolve(deste);
- }, (err) => {
- this.fillErrorMessage(err);
- reject(err);
- });
+ srce.moveTo(
+ destdir,
+ newName,
+ deste => {
+ resolve(deste);
+ },
+ err => {
+ this.fillErrorMessage(err);
+ reject(err);
+ }
+ );
});
}
/**
* @hidden
*/
- private copy(srce: Entry, destdir: DirectoryEntry, newName: string): Promise {
+ private copy(
+ srce: Entry,
+ destdir: DirectoryEntry,
+ newName: string
+ ): Promise {
return new Promise((resolve, reject) => {
- srce.copyTo(destdir, newName, (deste) => {
- resolve(deste);
- }, (err) => {
- this.fillErrorMessage(err);
- reject(err);
- });
+ srce.copyTo(
+ destdir,
+ newName,
+ deste => {
+ resolve(deste);
+ },
+ err => {
+ this.fillErrorMessage(err);
+ reject(err);
+ }
+ );
});
}
@@ -1351,12 +1469,15 @@ export class File extends IonicNativePlugin {
*/
private readEntries(dr: DirectoryReader): Promise {
return new Promise((resolve, reject) => {
- dr.readEntries((entries) => {
- resolve(entries);
- }, (err) => {
- this.fillErrorMessage(err);
- reject(err);
- });
+ dr.readEntries(
+ entries => {
+ resolve(entries);
+ },
+ err => {
+ this.fillErrorMessage(err);
+ reject(err);
+ }
+ );
});
}
@@ -1365,12 +1486,15 @@ export class File extends IonicNativePlugin {
*/
private rimraf(de: DirectoryEntry): Promise {
return new Promise((resolve, reject) => {
- de.removeRecursively(() => {
- resolve({ success: true, fileRemoved: de });
- }, (err) => {
- this.fillErrorMessage(err);
- reject(err);
- });
+ de.removeRecursively(
+ () => {
+ resolve({ success: true, fileRemoved: de });
+ },
+ err => {
+ this.fillErrorMessage(err);
+ reject(err);
+ }
+ );
});
}
@@ -1379,25 +1503,31 @@ export class File extends IonicNativePlugin {
*/
private createWriter(fe: FileEntry): Promise {
return new Promise((resolve, reject) => {
- fe.createWriter((writer) => {
- resolve(writer);
- }, (err) => {
- this.fillErrorMessage(err);
- reject(err);
- });
+ fe.createWriter(
+ writer => {
+ resolve(writer);
+ },
+ err => {
+ this.fillErrorMessage(err);
+ reject(err);
+ }
+ );
});
}
/**
* @hidden
*/
- private write(writer: FileWriter, gu: string | Blob | ArrayBuffer): Promise {
+ private write(
+ writer: FileWriter,
+ gu: string | Blob | ArrayBuffer
+ ): Promise {
if (gu instanceof Blob) {
return this.writeFileInChunks(writer, gu);
}
return new Promise((resolve, reject) => {
- writer.onwriteend = (evt) => {
+ writer.onwriteend = evt => {
if (writer.error) {
reject(writer.error);
} else {