Page MenuHomePhabricator

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

Authored by bartek on Thu, May 25, 5:10 AM.



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(
).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));

Diff Detail

rCOMM Comm
Lint Not Applicable
Tests Not Applicable

Event Timeline

bartek held this revision as a draft.
bartek published this revision for review.Thu, May 25, 5:52 AM
atul added inline comments.
5 ↗(On Diff #27049)

Super minor nit but we usually would do something like blobID instead of blobId

30 ↗(On Diff #27049)

Same as above, we usually would name this blobID instead of blobId

39 ↗(On Diff #27049)

I think you intended to include "incompatible" between "is" and "with"?

This revision is now accepted and ready to land.Fri, May 26, 8:34 AM
5 ↗(On Diff #27049)

Yes, but we need to be in sync with RN internal names here (linked in issue description)

30 ↗(On Diff #27049)

In contrast to above, this name can be fixed. Will do

39 ↗(On Diff #27049)

Yeah 😅 lost it somehow

5 ↗(On Diff #27049)

Ah understood, disregard then

marcin added inline comments.
16 ↗(On Diff #27049)

Might be missing swift knowledge but I am under the impression that potential error here is not caught anywhere.

16 ↗(On Diff #27049)

One line above, the closure is marked as throws (the same meaning as for Java functions). Exceptions are then handled automatically by expo-modules and their message and stack trace is converted to promise rejection / throwing new Error() in JS.
These automatic messages are pretty clean and meaningful so I prefer relying on them.

Rebase, blobId -> blobID, fix typo