Page MenuHomePhabricator

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

Authored by bartek on May 25 2023, 5:10 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Mar 5, 9:20 PM
Unknown Object (File)
Feb 26 2024, 9:39 PM
Unknown Object (File)
Feb 26 2024, 9:38 PM
Unknown Object (File)
Feb 26 2024, 9:38 PM
Unknown Object (File)
Feb 26 2024, 9:38 PM
Unknown Object (File)
Feb 26 2024, 9:34 PM
Unknown Object (File)
Feb 5 2024, 2:43 AM
Unknown Object (File)
Jan 11 2024, 1:48 PM
Subscribers

Details

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

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bartek held this revision as a draft.
bartek published this revision for review.May 25 2023, 5:52 AM
atul added inline comments.
native/expo-modules/comm-expo-package/ios/BlobUtilsModule.swift
5 ↗(On Diff #27049)

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

native/utils/blob-utils-module.js
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.May 26 2023, 8:34 AM
native/expo-modules/comm-expo-package/ios/BlobUtilsModule.swift
5 ↗(On Diff #27049)

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

native/utils/blob-utils-module.js
30 ↗(On Diff #27049)

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

39 ↗(On Diff #27049)

Yeah 😅 lost it somehow

native/expo-modules/comm-expo-package/ios/BlobUtilsModule.swift
5 ↗(On Diff #27049)

Ah understood, disregard then

marcin added inline comments.
native/expo-modules/comm-expo-package/ios/BlobUtilsModule.swift
16 ↗(On Diff #27049)

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

native/expo-modules/comm-expo-package/ios/BlobUtilsModule.swift
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