Skip to content

Commit

Permalink
FileReader, HTML5: Simulate readAsBinaryString where it doesn't exist…
Browse files Browse the repository at this point in the history
…. Address #45.
  • Loading branch information
jayarjo committed Jul 23, 2013
1 parent 54a5846 commit 6f4dd90
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/javascript/runtime/html5/file/FileReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
*/
define("moxie/runtime/html5/file/FileReader", [
"moxie/runtime/html5/Runtime",
"moxie/core/utils/Encode",
"moxie/core/utils/Basic"
], function(extensions, Basic) {
], function(extensions, Encode, Basic) {

function FileReader() {
var _fr;
var _fr, _convertToBinary = false;

Basic.extend(this, {

Expand All @@ -45,11 +46,14 @@ define("moxie/runtime/html5/file/FileReader", [

if (Basic.typeOf(_fr[op]) === 'function') {
_fr[op](blob.getSource());
} else if (op === 'readAsBinaryString') { // readAsBinaryString is depricated in general and never existed in IE10+
_convertToBinary = true;
_fr.readAsDataURL(blob.getSource());
}
},

getResult: function() {
return _fr ? _fr.result : null;
return _fr ? (_convertToBinary ? _toBinary(_fr.result) : _fr.result) : null;
},

abort: function() {
Expand All @@ -62,6 +66,10 @@ define("moxie/runtime/html5/file/FileReader", [
_fr = null;
}
});

function _toBinary(str) {
return Encode.atob(str.substring(str.indexOf('base64,') + 7));
}
}

return (extensions.FileReader = FileReader);
Expand Down

0 comments on commit 6f4dd90

Please sign in to comment.