From: Pawel Andruszkiewicz Date: Mon, 8 Jun 2015 12:14:42 +0000 (+0200) Subject: [Filesystem] Fixed implementation of readAsText(). X-Git-Tag: submit/tizen_mobile/20150612.133019^2~2^2~34^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=26f624eb1dacf112729580f45fd21858ac489ca7;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Filesystem] Fixed implementation of readAsText(). Read operation is now performed asynchronously on main thread. Recursive call removed. [Verification] Pass rate: 289/289. Warning: Due to nature of implementation and current architecture, the test File_readAsText_with_encoding may block. If there are large files present in /opt/usr/media/Documents/ folder (i.e. created by Download test suite) the test will not be able to finish in time. Change-Id: I031ac1d7c6d3ab223a0f93a0788938d5067b8a8c Signed-off-by: Pawel Andruszkiewicz --- diff --git a/src/filesystem/js/file.js b/src/filesystem/js/file.js index 34b5f76a..1e031ab3 100755 --- a/src/filesystem/js/file.js +++ b/src/filesystem/js/file.js @@ -311,26 +311,30 @@ File.prototype.readAsText = function(onsuccess, onerror, encoding) { encoding: args.encoding }; - var result, encoded, str = ''; - function readFile() { - result = native_.callSync('File_readSync', data); - if (native_.isFailure(result)) { - native_.callIfPossible(args.onerror, native_.getErrorObject(result)); - return; - } - encoded = native_.getResultObject(result); - if (!encoded.length) { - setTimeout(function() { - native_.callIfPossible(args.onsuccess, Base64.decode(str)); - }, 0); - } else { - str += encoded; - data.offset += data.length; - readFile(); - } + var result, encoded, str = ''; + + do { + result = native_.callSync('File_readSync', data); + if (native_.isFailure(result)) { + setTimeout(function() { + native_.callIfPossible(args.onerror, native_.getErrorObject(result)); + }, 0); + return; + } + encoded = native_.getResultObject(result); + if (encoded.length) { + str += Base64.decode(encoded); + data.offset += data.length; + } + } while (encoded.length); + + setTimeout(function() { + native_.callIfPossible(args.onsuccess, str); + }, 0); } - readFile(); + + setTimeout(readFile, 0); }; File.prototype.copyTo = function(originFilePath, destinationFilePath, overwrite, onsuccess, onerror) {