1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
-
-
- var utils = require('cordova/utils');
- var exec = require('cordova/exec');
- var Entry = require('./Entry');
- var FileWriter = require('./FileWriter');
- var File = require('./File');
- var FileError = require('./FileError');
-
-
- var FileEntry = function (name, fullPath, fileSystem, nativeURL) {
-
- if (fullPath && /\/$/.test(fullPath)) {
- fullPath = fullPath.substring(0, fullPath.length - 1);
- }
- if (nativeURL && /\/$/.test(nativeURL)) {
- nativeURL = nativeURL.substring(0, nativeURL.length - 1);
- }
-
- FileEntry.__super__.constructor.apply(this, [true, false, name, fullPath, fileSystem, nativeURL]);
- };
-
- utils.extend(FileEntry, Entry);
-
-
- FileEntry.prototype.createWriter = function (successCallback, errorCallback) {
- this.file(function (filePointer) {
- var writer = new FileWriter(filePointer);
-
- if (writer.localURL === null || writer.localURL === '') {
- if (errorCallback) {
- errorCallback(new FileError(FileError.INVALID_STATE_ERR));
- }
- } else {
- if (successCallback) {
- successCallback(writer);
- }
- }
- }, errorCallback);
- };
-
-
- FileEntry.prototype.file = function (successCallback, errorCallback) {
- var localURL = this.toInternalURL();
- var win = successCallback && function (f) {
- var file = new File(f.name, localURL, f.type, f.lastModifiedDate, f.size);
- successCallback(file);
- };
- var fail = errorCallback && function (code) {
- errorCallback(new FileError(code));
- };
- exec(win, fail, 'File', 'getFileMetadata', [localURL]);
- };
-
- module.exports = FileEntry;
|