Created
September 11, 2019 08:10
-
-
Save M1TKO/dfec9dfe0e91f840a0c8c0b08178985f to your computer and use it in GitHub Desktop.
Calculate base64 string size in bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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