From f98f90a9a3e58f1d10d7b4d6286122205be334fa Mon Sep 17 00:00:00 2001 From: Ibby Hadeed Date: Sat, 13 May 2017 22:44:10 -0400 Subject: [PATCH] fix(file): various fixes (#1553) * save schanges * save changes * save changes * save changes --- package.json | 1 + src/@ionic-native/plugins/file/index.ts | 644 +++++++++++++++--------- 2 files changed, 415 insertions(+), 230 deletions(-) diff --git a/package.json b/package.json index ca53196ca6..93f9ff006b 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "@angular/compiler": "4.1.2", "@angular/compiler-cli": "4.1.2", "@angular/core": "4.1.2", + "@types/cordova": "0.0.34", "canonical-path": "0.0.2", "child-process-promise": "2.2.0", "conventional-changelog-cli": "1.2.0", diff --git a/src/@ionic-native/plugins/file/index.ts b/src/@ionic-native/plugins/file/index.ts index 5d763a1d14..c0b5d8ba0d 100644 --- a/src/@ionic-native/plugins/file/index.ts +++ b/src/@ionic-native/plugins/file/index.ts @@ -1,295 +1,505 @@ import { Injectable } from '@angular/core'; import { CordovaProperty, Plugin, CordovaCheck, IonicNativePlugin } from '@ionic-native/core'; -declare var window: any; -declare var cordova: any; +export interface IFile extends Blob { + lastModified: number; + lastModifiedDate: number; + name: string; + size: number; + type: string; +} + +export interface LocalFileSystem { + + /** + * Used for storage with no guarantee of persistence. + */ + TEMPORARY: number; + + /** + * Used for storage that should not be removed by the user agent without application or user permission. + */ + PERSISTENT: number; + + /** + * Requests a filesystem in which to store application data. + * @param type Whether the filesystem requested should be persistent, as defined above. Use one of TEMPORARY or PERSISTENT. + * @param size This is an indicator of how much storage space, in bytes, the application expects to need. + * @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; + + /** + * Allows the user to look up the Entry for a file or directory referred to by a local URL. + * @param url A URL referring to a local file in a filesystem accessable via this API. + * @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; + + /** + * see requestFileSystem. + */ + webkitRequestFileSystem(type: number, size: number, successCallback: FileSystemCallback, errorCallback?: ErrorCallback): void; +} + +export interface Metadata { + /** + * This is the time at which the file or directory was last modified. + * @readonly + */ + modificationTime: Date; + + /** + * The size of the file, in bytes. This must return 0 for directories. + * @readonly + */ + size: number; +} -/** This interface represents a file system. */ +export interface Flags { + /** + * Used to indicate that the user wants to create a file or directory if it was not previously there. + */ + create?: boolean; + + /** + * By itself, exclusive must have no effect. Used with create, it must cause getFile and getDirectory to fail if the target path already exists. + */ + exclusive?: boolean; +} + +/** + * This export interface represents a file system. + */ export interface FileSystem { - /* The name of the file system, unique across the list of exposed file systems. */ + /** + * This is the name of the file system. The specifics of naming filesystems is unspecified, but a name must be unique across the list of exposed file systems. + * @readonly + */ name: string; - /** The root directory of the file system. */ + + /** + * The root directory of the file system. + * @readonly + */ root: DirectoryEntry; } -/** - * An abstract interface representing entries in a file system, - * each of which may be a File or DirectoryEntry. - */ export interface Entry { - /** Entry is a file. */ + + /** + * Entry is a file. + */ isFile: boolean; - /** Entry is a directory. */ + + /** + * Entry is a directory. + */ isDirectory: boolean; - /** The name of the entry, excluding the path leading to it. */ - name: string; - /** The full absolute path from the root to the entry. */ - fullPath: string; - /** The file system on which the entry resides. */ - filesystem: FileSystem; - nativeURL: string; + /** * Look up metadata about this entry. * @param successCallback A callback that is called with the time of the last modification. - * @param errorCallback A callback that is called when errors happen. + * @param errorCallback ErrorCallback A callback that is called when errors happen. + */ + getMetadata(successCallback: MetadataCallback, errorCallback?: ErrorCallback): void; + + /** + * The name of the entry, excluding the path leading to it. + */ + name: string; + + /** + * The full absolute path from the root to the entry. */ - getMetadata(successCallback: (metadata: Metadata) => void, - errorCallback?: (error: FileError) => void): void; + fullPath: string; + + /** + * The file system on which the entry resides. + */ + filesystem: FileSystem; + /** * Move an entry to a different location on the file system. It is an error to try to: - * 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; - * move a file to a path occupied by a directory; - * move a directory to a path occupied by a file; - * move any element to a path occupied by a directory which is not empty. + * + * + *
  • 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;
  • + *
  • move a file to a path occupied by a directory;
  • + *
  • move a directory to a path occupied by a file;
  • + *
  • move any element to a path occupied by a directory which is not empty.
  • + *