You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2013/07/08 05:59:04 UTC
git commit: [CB-3992] Allow FileWriter.write() to accept File as
argument
Updated Branches:
refs/heads/master 24462465e -> c1c1f3727
[CB-3992] Allow FileWriter.write() to accept File as argument
(Cherry-picked from cordova-js bfc74d6)
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/c1c1f372
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/c1c1f372
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/c1c1f372
Branch: refs/heads/master
Commit: c1c1f37275afaaea74b03facfcd7353c7c337a1d
Parents: 2446246
Author: Ian Clelland <ic...@chromium.org>
Authored: Sun Jul 7 23:48:30 2013 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Sun Jul 7 23:58:34 2013 -0400
----------------------------------------------------------------------
www/FileWriter.js | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c1c1f372/www/FileWriter.js
----------------------------------------------------------------------
diff --git a/www/FileWriter.js b/www/FileWriter.js
index 7994ed4..3115b51 100644
--- a/www/FileWriter.js
+++ b/www/FileWriter.js
@@ -97,27 +97,28 @@ FileWriter.prototype.abort = function() {
*/
FileWriter.prototype.write = function(data) {
- var isBinary = false;
-
- // If we don't have Blob or ArrayBuffer support, don't bother.
- if (typeof window.Blob !== 'undefined' && typeof window.ArrayBuffer !== 'undefined') {
-
- // Check to see if the incoming data is a blob
- if (data instanceof Blob) {
- var that=this;
- var fileReader = new FileReader();
- fileReader.onload = function() {
- // Call this method again, with the arraybuffer as argument
- FileWriter.prototype.write.call(that, this.result);
- };
+ var that=this;
+ var supportsBinary = (typeof window.Blob !== 'undefined' && typeof window.ArrayBuffer !== 'undefined');
+ var isBinary;
+
+ // Check to see if the incoming data is a blob
+ if (data instanceof File || (supportsBinary && data instanceof Blob)) {
+ var fileReader = new FileReader();
+ fileReader.onload = function() {
+ // Call this method again, with the arraybuffer as argument
+ FileWriter.prototype.write.call(that, this.result);
+ };
+ if (supportsBinary) {
fileReader.readAsArrayBuffer(data);
- return;
+ } else {
+ fileReader.readAsText(data);
}
-
- // Mark data type for safer transport over the binary bridge
- isBinary = (data instanceof ArrayBuffer);
+ return;
}
+ // Mark data type for safer transport over the binary bridge
+ isBinary = supportsBinary && (data instanceof ArrayBuffer);
+
// Throw an exception if we are already writing a file
if (this.readyState === FileWriter.WRITING) {
throw new FileError(FileError.INVALID_STATE_ERR);