Skip to content

Instantly share code, notes, and snippets.

@M1TKO
Created September 11, 2019 08:10
Show Gist options
  • Save M1TKO/dfec9dfe0e91f840a0c8c0b08178985f to your computer and use it in GitHub Desktop.
Save M1TKO/dfec9dfe0e91f840a0c8c0b08178985f to your computer and use it in GitHub Desktop.
Calculate base64 string size in bytes
var calculateBase64Size = function (base64, mimeType){
var b64Length = base64.length;
var base64Padding = 0;
if (base64.substring(b64Length - 1) === '=') base64Padding = 1;
else if (base64.substring(b64Length - 2) === '==') base64Padding = 2;
b64Length = base64.length - ('data:' + mimeType + ';base64,').length;
return (b64Length / 4) * 3 - base64Padding;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment