Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7EA81109A3 for ; Mon, 8 Jul 2013 03:59:10 +0000 (UTC) Received: (qmail 95050 invoked by uid 500); 8 Jul 2013 03:59:10 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 94987 invoked by uid 500); 8 Jul 2013 03:59:06 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 94980 invoked by uid 99); 8 Jul 2013 03:59:05 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Jul 2013 03:59:05 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id DD7AF88528A; Mon, 8 Jul 2013 03:59:04 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ian@apache.org To: commits@cordova.apache.org Message-Id: <1d70eee95d194d51a70ee0d306c474aa@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: [CB-3992] Allow FileWriter.write() to accept File as argument Date: Mon, 8 Jul 2013 03:59:04 +0000 (UTC) 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 Authored: Sun Jul 7 23:48:30 2013 -0400 Committer: Ian Clelland 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);