Skip to content

Commit

Permalink
feat: allow reading "arraybuffer" using content URI
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-wd committed Oct 9, 2024
1 parent 1538ee6 commit c13d48e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,24 @@ function decodeContents(b64: string, encoding: Encoding): string {
}

function getArrayBuffer(filePath: string): Promise<ArrayBuffer> {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
if (!blobJSIHelper) {
reject(new Error('react-native-blob-jsi-helper is not installed'));
return;
}

fetch(filePath)
let originalFilepath = filePath;
if (filePath.includes('content://')) {
const stat = await RNFSManager.stat(normalizeFilePath(filePath));

if (stat.originalFilepath.includes('file://')) {
originalFilepath = stat.originalFilepath;
} else {
originalFilepath = `file://${stat.originalFilepath}`;
}
}

fetch(originalFilepath)
.then((response) => response.blob())
.then((blob) => {
resolve(blobJSIHelper.getArrayBufferForBlob(blob));
Expand Down

0 comments on commit c13d48e

Please sign in to comment.