fix(file): readAsText() and adds readAsDataURL() in File plugin (#346)

* Updates docs for CameraPreview, Base64ToGallery and Developer.MD

-DEVELOPER.md: Corrects 'npm run tslint' instruction to 'npm run lint'
-CameraPreview: Fixes syntax error in hide
-Base64ToGallery: Adds desc of options obj props

* Fixes resolveLocalFileSystemURL bug in File.readAsText() and adds File.readAsDataUrl()

- File.readAsText(): window.resolveLocalFileSystemURL() was incorrectly implemented

* Updates callback arg in File.checkFile()

Callback arg of window.resolveLocalFileSystemURL was fileSystem, but it actually returns fileEntry

* Corrects repo link and comments out setFlashMode()

- Repo prop and link in desc were not pointing to the same gh repo as the plugin
- setFlashMode() is not currently available in the repo that gets pulled by the corodova plugin
This commit is contained in:
Alex Muramoto 2016-07-22 11:08:11 -07:00 committed by Ibrahim Hadeed
parent b95191af06
commit 77d31cdf42
2 changed files with 60 additions and 22 deletions

View File

@ -33,13 +33,13 @@ export interface CameraPreviewSize {
* @description
* Showing camera preview in HTML
*
* Requires {@link module:driftyco/ionic-native} and the Cordova plugin: `cordova-plugin-camera-preview`. For more info, please see the [Cordova Camera Preview Plugin Docs](https://github.com/westonganger/cordova-plugin-camera-preview).
* Requires {@link module:driftyco/ionic-native} and the Cordova plugin: `cordova-plugin-camera-preview`. For more info, please see the [Cordova Camera Preview Plugin Docs](https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview).
*
*/
@Plugin({
plugin: 'cordova-plugin-camera-preview',
pluginRef: 'cordova.plugins.camerapreview',
repo: 'https://github.com/westonganger/cordova-plugin-camera-preview',
repo: 'https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview',
platforms: ['Android', 'iOS']
})
export class CameraPreview {
@ -104,10 +104,10 @@ export class CameraPreview {
/**
* Set the default mode for the Flash.
*/
@Cordova({
sync: true
})
static setFlashMode(mode: number): void { };
// @Cordova({
// sync: true
// })
// static setFlashMode(mode: number): void { };
/**
* Set camera color effect.

View File

@ -363,9 +363,9 @@ export class File {
try {
var directory = path + file;
window.resolveLocalFileSystemURL(directory, function (fileSystem) {
if (fileSystem.isFile === true) {
resolveFn(fileSystem);
window.resolveLocalFileSystemURL(directory, function (fileEntry) {
if (fileEntry.isFile === true) {
resolveFn(fileEntry);
} else {
rejectFn({code: 13, message: 'input is not a file'});
}
@ -474,21 +474,17 @@ export class File {
/**
* Read a file as string.
*
* @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
* @param {string} fileName Name of file to move
* @param {string} uri Base FileSystem. Please refer to the iOS and Android filesystems above
* @return Returns a Promise that resolves or rejects with an error.
*/
static readAsText(path: string, fileName: string): Promise<any> {
static readAsText(file_uri: string): Promise<any> {
let resolveFn, rejectFn;
let promise = new Promise((resolve, reject) => {resolveFn = resolve; rejectFn = reject; });
if ((/^\//.test(fileName))) {
rejectFn('file-name cannot start with \/');
}
try {
window.resolveLocalFileSystemURL(path, function (fileSystem) {
fileSystem.getFile(fileName, {create: false}, function (fileEntry) {
window.resolveLocalFileSystemURL(file_uri, function (fileEntry) {
fileEntry.file(function (file) {
var reader = new FileReader();
@ -503,10 +499,52 @@ export class File {
};
reader.readAsText(file);
}, function (error) {
error.message = File.cordovaFileError[error.code];
rejectFn(error);
});
}, function (err) {
err.message = File.cordovaFileError[err.code];
rejectFn(err);
});
}, function (er) {
er.message = File.cordovaFileError[er.code];
rejectFn(er);
});
} catch (e) {
e.message = File.cordovaFileError[e.code];
rejectFn(e);
}
return promise;
}
/**
* Read a file as string.
*
* @param {string} uri Base FileSystem. Please refer to the iOS and Android filesystems above
* @return Returns a Promise that resolves or rejects with an error.
*/
static readAsDataURL(file_uri: string): Promise<any> {
let resolveFn, rejectFn;
let promise = new Promise((resolve, reject) => {resolveFn = resolve; rejectFn = reject; });
try {
window.resolveLocalFileSystemURL(file_uri, function (fileEntry) {
fileEntry.file(function (file) {
var reader = new FileReader();
reader.onloadend = function(e) {
if (this.result !== undefined && this.result !== null) {
resolveFn(this.result);
} else if (this.error !== undefined && this.error !== null) {
rejectFn(this.error);
} else {
rejectFn({code: null, message: 'READER_ONLOADEND_ERR'});
}
};
reader.readAsDataURL(file);
}, function (err) {
err.message = File.cordovaFileError[err.code];
rejectFn(err);