* Decodes a base64 encoded string to up to len bytes of output. * @param {string} s String to decode * @param {number} len Maximum output length * @returns {!Array. } * @inner
(s, len)
| 460 | * @inner |
| 461 | */ |
| 462 | function base64_decode(s, len) { |
| 463 | var off = 0, |
| 464 | slen = s.length, |
| 465 | olen = 0, |
| 466 | rs = [], |
| 467 | c1, |
| 468 | c2, |
| 469 | c3, |
| 470 | c4, |
| 471 | o, |
| 472 | code; |
| 473 | if (len <= 0) throw Error("Illegal len: " + len); |
| 474 | while (off < slen - 1 && olen < len) { |
| 475 | code = s.charCodeAt(off++); |
| 476 | c1 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1; |
| 477 | code = s.charCodeAt(off++); |
| 478 | c2 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1; |
| 479 | if (c1 == -1 || c2 == -1) break; |
| 480 | o = (c1 << 2) >>> 0; |
| 481 | o |= (c2 & 0x30) >> 4; |
| 482 | rs.push(String.fromCharCode(o)); |
| 483 | if (++olen >= len || off >= slen) break; |
| 484 | code = s.charCodeAt(off++); |
| 485 | c3 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1; |
| 486 | if (c3 == -1) break; |
| 487 | o = ((c2 & 0x0f) << 4) >>> 0; |
| 488 | o |= (c3 & 0x3c) >> 2; |
| 489 | rs.push(String.fromCharCode(o)); |
| 490 | if (++olen >= len || off >= slen) break; |
| 491 | code = s.charCodeAt(off++); |
| 492 | c4 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1; |
| 493 | o = ((c3 & 0x03) << 6) >>> 0; |
| 494 | o |= c4; |
| 495 | rs.push(String.fromCharCode(o)); |
| 496 | ++olen; |
| 497 | } |
| 498 | var res = []; |
| 499 | for (off = 0; off < olen; off++) res.push(rs[off].charCodeAt(0)); |
| 500 | return res; |
| 501 | } |
| 502 | |
| 503 | /** |
| 504 | * @type {number} |
no outgoing calls
no test coverage detected