Updated Branches: refs/heads/master b02ec10bc -> bfc74d647
[CB-3992] Allow FileWriter.write() to accept File as argument Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/bfc74d64 Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/bfc74d64 Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/bfc74d64 Branch: refs/heads/master Commit: bfc74d647e1e0858b7cca4c21ac73efe7ec95380 Parents: b02ec10 Author: Ian Clelland <[email protected]> Authored: Mon Jun 24 13:27:44 2013 -0400 Committer: Ian Clelland <[email protected]> Committed: Mon Jun 24 14:44:38 2013 -0400 ---------------------------------------------------------------------- lib/common/plugin/FileWriter.js | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-js/blob/bfc74d64/lib/common/plugin/FileWriter.js ---------------------------------------------------------------------- diff --git a/lib/common/plugin/FileWriter.js b/lib/common/plugin/FileWriter.js index 98ee8d6..9cd2ad6 100644 --- a/lib/common/plugin/FileWriter.js +++ b/lib/common/plugin/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);
