From bdd189947f9bd69e4238978c753740a9575d1225 Mon Sep 17 00:00:00 2001 From: "Piotr Kosko/Tizen API (PLT) /SRPOL/Engineer/Samsung Electronics" Date: Mon, 5 Jul 2021 13:10:54 +0200 Subject: [PATCH] [Filesystem] Fixed Blob to Uint8Array conversion MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- src/filesystem/js/file_handle.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/filesystem/js/file_handle.js b/src/filesystem/js/file_handle.js index 33563503..63a93721 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); } -- 2.34.1