Skip to content

Commit

Permalink
Opt: blobToUin8Array
Browse files Browse the repository at this point in the history
  • Loading branch information
zijiren233 committed Oct 11, 2023
1 parent af8347b commit fa5a754
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ export const strLengthLimit = (str: any, num: number) => {

export const blobToUin8Array = (blob: Blob): Promise<Uint8Array> => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => {
resolve(new Uint8Array(reader.result as ArrayBuffer));
};
reader.onerror = reject;
reader.readAsArrayBuffer(blob);
blob
.arrayBuffer()
.then((res) => {
resolve(new Uint8Array(res));
})
.catch((err) => {
reject(err);
});
});
};

0 comments on commit fa5a754

Please sign in to comment.