[Filesystem] Fixed Blob to Uint8Array conversion 86/260886/1
authorPiotr Kosko/Tizen API (PLT) /SRPOL/Engineer/Samsung Electronics <p.kosko@samsung.com>
Mon, 5 Jul 2021 11:10:54 +0000 (13:10 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Tue, 6 Jul 2021 08:24:27 +0000 (08:24 +0000)
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

index 47ab983..84760c1 100644 (file)
@@ -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);
     }