Updated Branches: refs/heads/master a8c830805 -> f008d2e9a
updatd FileWriter and plugin.xml 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/f008d2e9 Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/f008d2e9 Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/f008d2e9 Branch: refs/heads/master Commit: f008d2e9a14219ee57463ceab77569c859024a62 Parents: a8c8308 Author: Steven Gill <[email protected]> Authored: Wed Jun 19 12:42:48 2013 -0700 Committer: Steven Gill <[email protected]> Committed: Wed Jun 19 12:42:48 2013 -0700 ---------------------------------------------------------------------- plugin.xml | 2 +- www/FileWriter.js | 28 +++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/f008d2e9/plugin.xml ---------------------------------------------------------------------- diff --git a/plugin.xml b/plugin.xml index b107478..dc60a01 100644 --- a/plugin.xml +++ b/plugin.xml @@ -97,7 +97,7 @@ id="org.apache.cordova.core.FileUtils" version="0.1.0"> <source-file src="src/ios/CDVFile.m" /> <!-- ios specific file apis --> - <js-module src="www/ios/Entry.js" name="File"> + <js-module src="www/ios/Entry.js" name="Entry"> <merges target="window.Entry" /> </js-module> </platform> http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/f008d2e9/www/FileWriter.js ---------------------------------------------------------------------- diff --git a/www/FileWriter.js b/www/FileWriter.js index 10bc777..ef4ea3b 100644 --- a/www/FileWriter.js +++ b/www/FileWriter.js @@ -93,9 +93,31 @@ FileWriter.prototype.abort = function() { /** * Writes data to the file * - * @param text to be written + * @param data text or blob to be written */ -FileWriter.prototype.write = function(text) { +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); + }; + fileReader.readAsArrayBuffer(data); + return; + } + + // Mark data type for safer transport over the binary bridge + isBinary = (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); @@ -161,7 +183,7 @@ FileWriter.prototype.write = function(text) { if (typeof me.onwriteend === "function") { me.onwriteend(new ProgressEvent("writeend", {"target":me})); } - }, "File", "write", [this.fileName, text, this.position]); + }, "File", "write", [this.fileName, data, this.position, isBinary]); }; /**
