Compare commits

..

12 Commits

Author SHA1 Message Date
Ibby
ceb4217415 chore(): update changelog 2016-10-11 21:03:52 -04:00
Ibby
798625698d 2.2.2 2016-10-11 21:03:23 -04:00
Ibby
5cfb3b033b refractor(): remove unused import 2016-10-11 21:02:53 -04:00
Ibrahim Hadeed
95d666c348 Merge pull request #682 from driftyco/fix/file
fix(file): fix writeFile method
2016-10-11 18:01:55 -07:00
Ibby
276d61bf3a fix(file): read methods can accept Blobs too 2016-10-11 20:48:53 -04:00
Ibby
397a209ad2 docs(file): improve docs 2016-10-11 20:46:05 -04:00
Ibby
d2f42ef33a fix(file): getFreeDiskSpace now works 2016-10-11 20:44:27 -04:00
Ibby
fe46907aaa docs(file): document getFreeDiskspace 2016-10-11 20:39:26 -04:00
Ibby
5c92455ee9 feat(file): getFile and getDirectory are now public
closes #657
2016-10-11 20:30:14 -04:00
Ibby
542ff4cf95 feat(file): resolveLocalFilesystemUrl and resolveDirectoryUrl are now public methods
closes #657
2016-10-11 20:16:39 -04:00
Ibby
5710eb78a8 fix(file): last parameter for writeFile now only accepts options 2016-10-11 20:13:21 -04:00
Ibby
842a80d493 fix(file): fix writeFile method
addresses #464 #552 #666
2016-10-11 20:10:47 -04:00
3 changed files with 85 additions and 49 deletions

View File

@@ -1,3 +1,19 @@
<a name="2.2.2"></a>
## [2.2.2](https://github.com/driftyco/ionic-native/compare/v2.2.1...v2.2.2) (2016-10-12)
### Bug Fixes
* **file:** getFreeDiskSpace now works ([d2f42ef](https://github.com/driftyco/ionic-native/commit/d2f42ef))
* **file:** read methods can accept Blobs too ([276d61b](https://github.com/driftyco/ionic-native/commit/276d61b))
### Features
* **file:** getFile and getDirectory are now public ([5c92455](https://github.com/driftyco/ionic-native/commit/5c92455)), closes [#657](https://github.com/driftyco/ionic-native/issues/657)
<a name="2.2.1"></a>
## [2.2.1](https://github.com/driftyco/ionic-native/compare/v2.2.0...v2.2.1) (2016-10-12)
@@ -5,11 +21,18 @@
### Bug Fixes
* **diagnostic:** misspelled getContactsAuthorizationStatus method ([#678](https://github.com/driftyco/ionic-native/issues/678)) ([bff4862](https://github.com/driftyco/ionic-native/commit/bff4862))
* **file:** fix writeFile method ([842a80d](https://github.com/driftyco/ionic-native/commit/842a80d))
* **file:** last parameter for writeFile now only accepts options ([5710eb7](https://github.com/driftyco/ionic-native/commit/5710eb7))
* **http:** export via window.IonicNative ([#675](https://github.com/driftyco/ionic-native/issues/675)) ([cf7abe1](https://github.com/driftyco/ionic-native/commit/cf7abe1))
* **location-accuracy:** accuracy param is number ([c2d4f1c](https://github.com/driftyco/ionic-native/commit/c2d4f1c)), closes [#676](https://github.com/driftyco/ionic-native/issues/676)
* **themeablebrowser:** add missed options ([#680](https://github.com/driftyco/ionic-native/issues/680)) ([e28e5b0](https://github.com/driftyco/ionic-native/commit/e28e5b0))
### Features
* **file:** resolveLocalFilesystemUrl and resolveDirectoryUrl are now public methods ([542ff4c](https://github.com/driftyco/ionic-native/commit/542ff4c)), closes [#657](https://github.com/driftyco/ionic-native/issues/657)
<a name="2.2.0"></a>
# [2.2.0](https://github.com/driftyco/ionic-native/compare/v2.1.9...v2.2.0) (2016-10-11)

View File

@@ -1,6 +1,6 @@
{
"name": "ionic-native",
"version": "2.2.1",
"version": "2.2.2",
"description": "Native plugin wrappers for Cordova and Ionic with TypeScript, ES6+, Promise and Observable support",
"main": "dist/es5/index.js",
"module": "dist/esm/index.js",

View File

@@ -1,4 +1,4 @@
import { Plugin, Cordova } from './plugin';
import {Plugin, pluginWarn} from './plugin';
declare var window: any;
declare var cordova: any;
@@ -301,10 +301,10 @@ export interface FileReader {
onabort: (evt: ProgressEvent) => void;
abort(): void;
readAsText(fe: File, encoding?: string): void;
readAsDataURL(fe: File): void;
readAsBinaryString(fe: File): void;
readAsArrayBuffer(fe: File): void;
readAsText(fe: File | Blob, encoding?: string): void;
readAsDataURL(fe: File | Blob): void;
readAsBinaryString(fe: File | Blob): void;
readAsArrayBuffer(fe: File | Blob): void;
}
declare var FileReader: {
@@ -337,6 +337,12 @@ declare var FileError: {
PATH_EXISTS_ERR: number;
};
let pluginMeta = {
plugin: 'cordova-plugin-file',
pluginRef: 'cordova.file',
repo: 'https://github.com/apache/cordova-plugin-file'
};
/**
* @name File
* @description
@@ -358,11 +364,7 @@ declare var FileError: {
* Although most of the plugin code was written when an earlier spec was current: http://www.w3.org/TR/2011/WD-file-system-api-20110419/
* It also implements the FileWriter spec : http://dev.w3.org/2009/dap/file-system/file-writer.html
*/
@Plugin({
plugin: 'cordova-plugin-file',
pluginRef: 'cordova.file',
repo: 'https://github.com/apache/cordova-plugin-file'
})
@Plugin(pluginMeta)
export class File {
static cordovaFileError: {} = {
1: 'NOT_FOUND_ERR',
@@ -381,9 +383,19 @@ export class File {
14: 'DIR_READ_ERR',
};
@Cordova()
/**
* Get free disk space
* @returns {Promise<number>} Returns a promise that resolves with the remaining free disk space
*/
static getFreeDiskSpace(): Promise<number> {
return;
return new Promise<any>((resolve, reject) => {
if (!cordova || !cordova.exec) {
pluginWarn(pluginMeta);
reject({ error: 'plugin_not_installed' });
} else {
cordova.exec(resolve, reject, 'File', 'getFreeDiskSpace', []);
}
});
}
/**
@@ -393,7 +405,6 @@ export class File {
* @param {string} dir Name of directory to check
* @return {Promise<boolean|FileError>} Returns a Promise that resolves to true if the directory exists or rejects with an error.
*/
static checkDir(path: string, dir: string): Promise<boolean|FileError> {
if ((/^\//.test(dir))) {
let err = new FileError(5);
@@ -418,7 +429,6 @@ export class File {
* @param {boolean} replace If true, replaces file with same name. If false returns error
* @return {Promise<DirectoryEntry|FileError>} Returns a Promise that resolves with a DirectoryEntry or rejects with an error.
*/
static createDir(path: string, dirName: string, replace: boolean): Promise<DirectoryEntry|FileError> {
if ((/^\//.test(dirName))) {
let err = new FileError(5);
@@ -447,7 +457,6 @@ export class File {
* @param {string} dirName The directory name
* @return {Promise<RemoveResult|FileError>} Returns a Promise that resolves to a RemoveResult or rejects with an error.
*/
static removeDir(path: string, dirName: string): Promise<RemoveResult|FileError> {
if ((/^\//.test(dirName))) {
let err = new FileError(5);
@@ -473,7 +482,6 @@ export class File {
* @param {string} newDirName The destination directory name
* @return {Promise<DirectoryEntry|Entry|FileError>} Returns a Promise that resolves to the new DirectoryEntry object or rejects with an error.
*/
static moveDir(path: string, dirName: string, newPath: string, newDirName: string): Promise<DirectoryEntry|Entry|FileError> {
newDirName = newDirName || dirName;
@@ -530,7 +538,6 @@ export class File {
* @param {string} dirName Name of directory
* @return {Promise<Entry[]>} Returns a Promise that resolves to an array of Entry objects or rejects with an error.
*/
static listDir(path: string, dirName: string): Promise<Entry[]> {
if ((/^\//.test(dirName))) {
let err = new FileError(5);
@@ -555,7 +562,6 @@ export class File {
* @param {string} dirName Name of directory
* @return {Promise<RemoveResult>} Returns a Promise that resolves with a RemoveResult or rejects with an error.
*/
static removeRecursively(path: string, dirName: string): Promise<RemoveResult> {
if ((/^\//.test(dirName))) {
let err = new FileError(5);
@@ -579,7 +585,6 @@ export class File {
* @param {string} file Name of file to check
* @return {Promise<boolean|FileError>} Returns a Promise that resolves with a boolean or rejects with an error.
*/
static checkFile(path: string, file: string): Promise<boolean|FileError> {
if ((/^\//.test(file))) {
let err = new FileError(5);
@@ -637,7 +642,6 @@ export class File {
* @param {string} fileName Name of file to remove
* @return {Promise<RemoveResult|FileError>} Returns a Promise that resolves to a RemoveResult or rejects with an error.
*/
static removeFile(path: string, fileName: string): Promise<RemoveResult|FileError> {
if ((/^\//.test(fileName))) {
let err = new FileError(5);
@@ -659,38 +663,37 @@ export class File {
* @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
* @param {string} fileName path relative to base path
* @param {string | Blob} text content or blob to write
* @param {boolean | WriteOptions} replaceOrOptions replace file if set to true. See WriteOptions for more information.
* @param {WriteOptions} options replace file if set to true. See WriteOptions for more information.
* @returns {Promise<void>} Returns a Promise that resolves or rejects with an error.
*/
static writeFile(path: string, fileName: string,
text: string | Blob, replaceOrOptions: boolean | WriteOptions): Promise<void> {
text: string | Blob, options: WriteOptions): Promise<void> {
if ((/^\//.test(fileName))) {
let err = new FileError(5);
err.message = 'file-name cannot start with \/';
return Promise.reject(err);
}
let opts: WriteOptions = {};
if (replaceOrOptions) {
if (typeof(replaceOrOptions) === 'boolean') {
opts.replace = <boolean>replaceOrOptions;
}
}
let getFileOpts: Flags = {
create: true,
exclusive: options.replace
};
return File.resolveDirectoryUrl(path)
.then((fse) => {
return File.getFile(fse, fileName, opts);
return File.getFile(fse, fileName, getFileOpts);
})
.then((fe) => {
return File.createWriter(fe);
})
.then((writer) => {
if (opts.append) {
if (options.append) {
writer.seek(writer.length);
}
if (opts.hasOwnProperty('truncate')) {
writer.truncate(opts.truncate);
if (options.truncate) {
writer.truncate(options.truncate);
}
return File.write(writer, text);
@@ -959,12 +962,14 @@ export class File {
}
/**
* @private
* Resolves a local file system URL
* @param fileUrl {string} file system url
* @returns {Promise<Entry>}
*/
private static resolveLocalFilesystemUrl(furl: string): Promise<Entry> {
static resolveLocalFilesystemUrl(fileUrl: string): Promise<Entry> {
return new Promise<Entry>((resolve, reject) => {
try {
window.resolveLocalFileSystemURL(furl, (entry) => {
window.resolveLocalFileSystemURL(fileUrl, (entry) => {
resolve(entry);
}, (err) => {
File.fillErrorMessage(err);
@@ -978,10 +983,12 @@ export class File {
}
/**
* @private
* Resolves a local directory url
* @param directoryUrl {string} directory system url
* @returns {Promise<DirectoryEntry>}
*/
private static resolveDirectoryUrl(durl: string): Promise<DirectoryEntry> {
return File.resolveLocalFilesystemUrl(durl)
static resolveDirectoryUrl(directoryUrl: string): Promise<DirectoryEntry> {
return File.resolveLocalFilesystemUrl(directoryUrl)
.then((de) => {
if (de.isDirectory) {
return <DirectoryEntry>de;
@@ -994,12 +1001,16 @@ export class File {
}
/**
* @private
* Get a directory
* @param directoryEntry {DirectoryEntry} Directory entry, obtained by resolveDirectoryUrl method
* @param directoryName {string} Directory name
* @param flags {Flags} Options
* @returns {Promise<DirectoryEntry>}
*/
private static getDirectory(fse: DirectoryEntry, dn: string, flags: Flags): Promise<DirectoryEntry> {
static getDirectory(directoryEntry: DirectoryEntry, directoryName: string, flags: Flags): Promise<DirectoryEntry> {
return new Promise<DirectoryEntry>((resolve, reject) => {
try {
fse.getDirectory(dn, flags, (de) => {
directoryEntry.getDirectory(directoryName, flags, (de) => {
resolve(de);
}, (err) => {
File.fillErrorMessage(err);
@@ -1013,14 +1024,16 @@ export class File {
}
/**
* @private
* Get a file
* @param directoryEntry {DirectoryEntry} Directory entry, obtained by resolveDirectoryUrl method
* @param fileName {string} File name
* @param flags {Flags} Options
* @returns {Promise<FileEntry>}
*/
private static getFile(fse: DirectoryEntry, fn: string, flags: Flags): Promise<FileEntry> {
static getFile(directoryEntry: DirectoryEntry, fileName: string, flags: Flags): Promise<FileEntry> {
return new Promise<FileEntry>((resolve, reject) => {
try {
fse.getFile(fn, flags, (fe) => {
resolve(fe);
}, (err) => {
directoryEntry.getFile(fileName, flags, resolve, (err) => {
File.fillErrorMessage(err);
reject(err);
});
@@ -1123,12 +1136,12 @@ export class File {
return this.writeFileInChunks(writer, gu);
}
return new Promise<void>((resolve, reject) => {
return new Promise<any>((resolve, reject) => {
writer.onwriteend = (evt) => {
if (writer.error) {
reject(writer.error);
} else {
resolve();
resolve(evt);
}
};
writer.write(gu);