return output;
},
decodeString: function(data) {
- data = this.decode(data);
- var output = '';
- for (var i = 0; i < data.length; ++i) {
- output += String.fromCharCode(data[i]);
- }
- return this._utf8_decode(output);
+ return this._utf8_decode(this.decode(data));
},
decode: function(data) {
var output = [];
return utftext;
},
- _utf8_decode: function(utftext) {
+ _utf8_decode: function(utfarray) {
var str = '';
var i = 0, c = 0, c1 = 0, c2 = 0;
- while (i < utftext.length) {
+ while (i < utfarray.length) {
- c = utftext.charCodeAt(i);
+ c = utfarray[i];
if (c < 128) {
str += String.fromCharCode(c);
i++;
}
else if ((c > 191) && (c < 224)) {
- c1 = utftext.charCodeAt(i + 1);
+ c1 = utfarray[i + 1];
str += String.fromCharCode(((c & 31) << 6) | (c1 & 63));
i += 2;
}
else {
- c1 = utftext.charCodeAt(i + 1);
- c2 = utftext.charCodeAt(i + 2);
+ c1 = utfarray[i + 1];
+ c2 = utfarray[i + 2];
str += String.fromCharCode(((c & 15) << 12) | ((c1 & 63) << 6) | (c2 & 63));
i += 3;
}
var data = {
location: commonFS_.toRealPath(this.fullPath),
offset: 0,
- length: 1024,
+ length: 65536,
encoding: args.encoding
};
function readFile() {
- var result, encoded, str = '';
+ var result, encoded, buffers = [];
do {
result = native_.callSync('File_readSync', data);
}
encoded = native_.getResultObject(result);
if (encoded.length) {
- str += Base64.decodeString(encoded);
+ buffers.push( Base64.decode(encoded) );
data.offset += data.length;
}
} while (encoded.length);
+ var buffer = Array.prototype.concat.apply([], buffers);
+
setTimeout(function() {
- native_.callIfPossible(args.onsuccess, str);
+ native_.callIfPossible(args.onsuccess, Base64._utf8_decode(buffer) );
}, 0);
}