From: Piotr Kosko/Tizen API (PLT) /SRPOL/Engineer/Samsung Electronics Date: Mon, 5 Jul 2021 11:10:54 +0000 (+0200) Subject: [Filesystem] Fixed Blob to Uint8Array conversion X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d48596dbb1ffcefd483d995999b5589ae600e862;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Filesystem] Fixed Blob to Uint8Array conversion Fix inspired by this answer: https://stackoverflow.com/a/63920556/11502478 [Verification] in Chrome console: // assume having wav file on the device input = tizen.filesystem.openFile("documents/sample1.wav", "r") blob = input.readBlob() /// BlobĀ {size: 1073218, type: ""} output = tizen.filesystem.openFile("documents/sample1_output.wav", "w") output.writeBlob(blob) output.close() output_test = tizen.filesystem.openFile("documents/sample1_output.wav", "r") blob_test = output_test.readBlob() /// Blob {size: 1073218, type: ""} console.log("Verification passed: " + (blob.size === blob_test.size)) input.close() output_test.close() TCT (filesystem, deprecated) passrate 100% Change-Id: I5e4beea31d69430e9dbe44a7899cf675e779c7f8 --- diff --git a/src/filesystem/js/file_handle.js b/src/filesystem/js/file_handle.js index 47ab9836..84760c1e 100644 --- a/src/filesystem/js/file_handle.js +++ b/src/filesystem/js/file_handle.js @@ -354,11 +354,14 @@ function blobToUint8Array(b) { xhr = new XMLHttpRequest(), i, ui8; + xhr.overrideMimeType('text/plain; charset=x-user-defined'); xhr.open('GET', uri, false); xhr.send(); URL.revokeObjectURL(uri); - var stringUtf8 = unescape(encodeURIComponent(xhr.response)); + + var stringUtf8 = xhr.response; ui8 = new Uint8Array(stringUtf8.length); + for (i = 0; i < stringUtf8.length; ++i) { ui8[i] = stringUtf8.charCodeAt(i); }