HomePhabricator
Diffusion Comm 42bca7921375

[native] Add BlobUtils expo-module and add iOS implementation

Description

[native] Add BlobUtils expo-module and add iOS implementation

Summary:
The core part of ENG-3718. The issue description is important to understand the context of this diff.
In short: Implemented two functions that provide a way to directly convert Blob <--> ArrayBuffer without going through base64 encoding/decoding which is extremely inefficient.

Other helpful resources:

Test Plan:
Built the iOS, tested using the following snippet:

const array1 = new Uint8Array([1, 2, 3, 4, 5]);
const blob1 = blobFromArrayBuffer(array1.buffer);
console.log('blob1', blob1);

const decoded = new Uint8Array(arrayBufferFromBlob(blob1));
console.log('decoded', decoded);

const blob2 = await fetch(
  'data:application/octet-stream;base64,AQIDBAUKCw==',
).then(it => {
  console.log('response', it);
  return it.blob();
});
console.log('blob2', blob2);

const decoded2 = new Uint8Array(arrayBufferFromBlob(blob2));
console.log('decoded2', decoded2);

const blob3 = blobFromArrayBuffer(decoded2.buffer);
console.log('blob3', blob3);
// line below requires amending exports in native/media/blob-utils.js
console.log('Another way:', await blobToDataURI(blob3).then(dataURIToIntArray));

Reviewers: atul, marcin

Reviewed By: atul, marcin

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D7973

Details