MCPcopy Index your code
hub / github.com/SocketCluster/socketcluster / toByteArray

Function toByteArray

app/public/socketcluster-client.js:2515–2559  ·  view source on GitHub ↗
(b64)

Source from the content-addressed store, hash-verified

2513}
2514
2515function toByteArray (b64) {
2516 var tmp
2517 var lens = getLens(b64)
2518 var validLen = lens[0]
2519 var placeHoldersLen = lens[1]
2520
2521 var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
2522
2523 var curByte = 0
2524
2525 // if there are placeholders, only get up to the last complete 4 chars
2526 var len = placeHoldersLen > 0
2527 ? validLen - 4
2528 : validLen
2529
2530 var i
2531 for (i = 0; i < len; i += 4) {
2532 tmp =
2533 (revLookup[b64.charCodeAt(i)] << 18) |
2534 (revLookup[b64.charCodeAt(i + 1)] << 12) |
2535 (revLookup[b64.charCodeAt(i + 2)] << 6) |
2536 revLookup[b64.charCodeAt(i + 3)]
2537 arr[curByte++] = (tmp >> 16) & 0xFF
2538 arr[curByte++] = (tmp >> 8) & 0xFF
2539 arr[curByte++] = tmp & 0xFF
2540 }
2541
2542 if (placeHoldersLen === 2) {
2543 tmp =
2544 (revLookup[b64.charCodeAt(i)] << 2) |
2545 (revLookup[b64.charCodeAt(i + 1)] >> 4)
2546 arr[curByte++] = tmp & 0xFF
2547 }
2548
2549 if (placeHoldersLen === 1) {
2550 tmp =
2551 (revLookup[b64.charCodeAt(i)] << 10) |
2552 (revLookup[b64.charCodeAt(i + 1)] << 4) |
2553 (revLookup[b64.charCodeAt(i + 2)] >> 2)
2554 arr[curByte++] = (tmp >> 8) & 0xFF
2555 arr[curByte++] = tmp & 0xFF
2556 }
2557
2558 return arr
2559}
2560
2561function tripletToBase64 (num) {
2562 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…