Advertisement
informaticage

fagottello

Sep 2nd, 2021
1,136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const getB64FileSize = (b64Data, contentType='', sliceSize=512) => {
  2.   const byteCharacters = atob(b64Data);
  3.   const byteArrays = [];
  4.  
  5.   for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
  6.     const slice = byteCharacters.slice(offset, offset + sliceSize);
  7.  
  8.     const byteNumbers = new Array(slice.length);
  9.     for (let i = 0; i < slice.length; i++) {
  10.       byteNumbers[i] = slice.charCodeAt(i);
  11.     }
  12.  
  13.     const byteArray = new Uint8Array(byteNumbers);
  14.     byteArrays.push(byteArray);
  15.   }
  16.  
  17.   const blob = new Blob(byteArrays, {type: contentType});
  18.   return blob.size;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement