Merge pull request #233 from macdonst/is229

Issue #229: Deprecate FileMgr code in file.js
This commit is contained in:
macdonst 2011-09-13 14:00:32 -07:00
commit e9bb66622c

View File

@ -11,8 +11,6 @@ PhoneGap.addResource("file");
/**
* This class provides some useful information about a file.
* This is the fields returned when navigator.fileMgr.getFileProperties()
* is called.
* @constructor
*/
var FileProperties = function(filePath) {
@ -61,64 +59,9 @@ FileError.QUOTA_EXCEEDED_ERR = 10;
FileError.TYPE_MISMATCH_ERR = 11;
FileError.PATH_EXISTS_ERR = 12;
//-----------------------------------------------------------------------------
// File manager
//-----------------------------------------------------------------------------
/** @constructor */
var FileMgr = function() {
};
FileMgr.prototype.getFileProperties = function(filePath) {
return PhoneGap.exec(null, null, "File", "getFileProperties", [filePath]);
};
FileMgr.prototype.getFileBasePaths = function() {
};
FileMgr.prototype.testSaveLocationExists = function(successCallback, errorCallback) {
return PhoneGap.exec(successCallback, errorCallback, "File", "testSaveLocationExists", []);
};
FileMgr.prototype.testFileExists = function(fileName, successCallback, errorCallback) {
return PhoneGap.exec(successCallback, errorCallback, "File", "testFileExists", [fileName]);
};
FileMgr.prototype.testDirectoryExists = function(dirName, successCallback, errorCallback) {
return PhoneGap.exec(successCallback, errorCallback, "File", "testDirectoryExists", [dirName]);
};
FileMgr.prototype.getFreeDiskSpace = function(successCallback, errorCallback) {
return PhoneGap.exec(successCallback, errorCallback, "File", "getFreeDiskSpace", []);
};
FileMgr.prototype.write = function(fileName, data, position, successCallback, errorCallback) {
PhoneGap.exec(successCallback, errorCallback, "File", "write", [fileName, data, position]);
};
FileMgr.prototype.truncate = function(fileName, size, successCallback, errorCallback) {
PhoneGap.exec(successCallback, errorCallback, "File", "truncate", [fileName, size]);
};
FileMgr.prototype.readAsText = function(fileName, encoding, successCallback, errorCallback) {
PhoneGap.exec(successCallback, errorCallback, "File", "readAsText", [fileName, encoding]);
};
FileMgr.prototype.readAsDataURL = function(fileName, successCallback, errorCallback) {
PhoneGap.exec(successCallback, errorCallback, "File", "readAsDataURL", [fileName]);
};
PhoneGap.addConstructor(function() {
if (typeof navigator.fileMgr === "undefined") {
navigator.fileMgr = new FileMgr();
}
});
//-----------------------------------------------------------------------------
// File Reader
//-----------------------------------------------------------------------------
// TODO: All other FileMgr function operate on the SD card as root. However,
// for FileReader & FileWriter the root is not SD card. Should this be changed?
/**
* This class reads the mobile device file system.
@ -208,8 +151,7 @@ FileReader.prototype.readAsText = function(file, encoding) {
var me = this;
// Read file
navigator.fileMgr.readAsText(this.fileName, enc,
PhoneGap.exec(
// Success callback
function(r) {
var evt;
@ -235,7 +177,6 @@ FileReader.prototype.readAsText = function(file, encoding) {
me.onloadend({"type":"loadend", "target":me});
}
},
// Error callback
function(e) {
var evt;
@ -259,8 +200,7 @@ FileReader.prototype.readAsText = function(file, encoding) {
if (typeof me.onloadend === "function") {
me.onloadend({"type":"loadend", "target":me});
}
}
);
}, "File", "readAsText", [this.fileName, enc]);
};
@ -290,8 +230,7 @@ FileReader.prototype.readAsDataURL = function(file) {
var me = this;
// Read file
navigator.fileMgr.readAsDataURL(this.fileName,
PhoneGap.exec(
// Success callback
function(r) {
var evt;
@ -317,7 +256,6 @@ FileReader.prototype.readAsDataURL = function(file) {
me.onloadend({"type":"loadend", "target":me});
}
},
// Error callback
function(e) {
var evt;
@ -341,8 +279,7 @@ FileReader.prototype.readAsDataURL = function(file) {
if (typeof me.onloadend === "function") {
me.onloadend({"type":"loadend", "target":me});
}
}
);
}, "File", "readAsDataURL", [this.fileName]);
};
/**
@ -464,8 +401,7 @@ FileWriter.prototype.write = function(text) {
}
// Write file
navigator.fileMgr.write(this.fileName, text, this.position,
PhoneGap.exec(
// Success callback
function(r) {
var evt;
@ -492,7 +428,6 @@ FileWriter.prototype.write = function(text) {
me.onwriteend({"type":"writeend", "target":me});
}
},
// Error callback
function(e) {
var evt;
@ -517,9 +452,7 @@ FileWriter.prototype.write = function(text) {
if (typeof me.onwriteend === "function") {
me.onwriteend({"type":"writeend", "target":me});
}
}
);
}, "File", "write", [this.fileName, text, this.position]);
};
/**
@ -579,8 +512,7 @@ FileWriter.prototype.truncate = function(size) {
}
// Write file
navigator.fileMgr.truncate(this.fileName, size,
PhoneGap.exec(
// Success callback
function(r) {
var evt;
@ -606,7 +538,6 @@ FileWriter.prototype.truncate = function(size) {
me.onwriteend({"type":"writeend", "target":me});
}
},
// Error callback
function(e) {
var evt;
@ -630,8 +561,7 @@ FileWriter.prototype.truncate = function(size) {
if (typeof me.onwriteend === "function") {
me.onwriteend({"type":"writeend", "target":me});
}
}
);
}, "File", "truncate", [this.fileName, size]);
};
/**