[Edit]
+
0
-
0
JavaScript - convert Blob object to Uint8Array object (to bytes array)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24// Warning: Blob arrayBuffer() method appeared in the major web browser around 2019-2020 (in Deno v1.0 (2020), in Node.js v15.7.0 (2021)). const toArray = (blob, callback) => { const promise = blob.arrayBuffer(); promise.then((buffer) => callback(new Uint8Array(buffer))); }; // Usage example: const blob = ...; // Blob object toArray(blob, (array) => { console.log(`array.length=${array.length}`); console.log(`array[0]=${array[0]}`); console.log(`array[1]=${array[1]}`); console.log(`array[2]=${array[2]}`); console.log(`...`); }); // See also: // 1. https://dirask.com/snippets/JavaScript-convert-Blob-object-to-Uint8Array-object-to-bytes-array-1GMYbp