MCPcopy Index your code
hub / github.com/plotly/plotly.js / toByteArray

Function toByteArray

stackgl_modules/index.js:2007–2051  ·  view source on GitHub ↗
(b64)

Source from the content-addressed store, hash-verified

2005}
2006
2007function toByteArray (b64) {
2008 var tmp
2009 var lens = getLens(b64)
2010 var validLen = lens[0]
2011 var placeHoldersLen = lens[1]
2012
2013 var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
2014
2015 var curByte = 0
2016
2017 // if there are placeholders, only get up to the last complete 4 chars
2018 var len = placeHoldersLen > 0
2019 ? validLen - 4
2020 : validLen
2021
2022 var i
2023 for (i = 0; i < len; i += 4) {
2024 tmp =
2025 (revLookup[b64.charCodeAt(i)] << 18) |
2026 (revLookup[b64.charCodeAt(i + 1)] << 12) |
2027 (revLookup[b64.charCodeAt(i + 2)] << 6) |
2028 revLookup[b64.charCodeAt(i + 3)]
2029 arr[curByte++] = (tmp >> 16) & 0xFF
2030 arr[curByte++] = (tmp >> 8) & 0xFF
2031 arr[curByte++] = tmp & 0xFF
2032 }
2033
2034 if (placeHoldersLen === 2) {
2035 tmp =
2036 (revLookup[b64.charCodeAt(i)] << 2) |
2037 (revLookup[b64.charCodeAt(i + 1)] >> 4)
2038 arr[curByte++] = tmp & 0xFF
2039 }
2040
2041 if (placeHoldersLen === 1) {
2042 tmp =
2043 (revLookup[b64.charCodeAt(i)] << 10) |
2044 (revLookup[b64.charCodeAt(i + 1)] << 4) |
2045 (revLookup[b64.charCodeAt(i + 2)] >> 2)
2046 arr[curByte++] = (tmp >> 8) & 0xFF
2047 arr[curByte++] = tmp & 0xFF
2048 }
2049
2050 return arr
2051}
2052
2053function tripletToBase64 (num) {
2054 return lookup[num >> 18 & 0x3F] +

Callers

nothing calls this directly

Calls 2

getLensFunction · 0.85
_byteLengthFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…