3 Copyright (c) 2014 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
7 <link rel="import" href="/base.html">
11 tv.exportTo('tv', function() {
16 function b64ToUint6(nChr) {
17 if (nChr > 64 && nChr < 91)
19 if (nChr > 96 && nChr < 123)
21 if (nChr > 47 && nChr < 58)
30 Base64.getDecodedBufferLength = function(input) {
31 return input.length * 3 + 1 >> 2;
34 Base64.DecodeToTypedArray = function(input, output) {
36 var nInLen = input.length;
37 var nOutLen = nInLen * 3 + 1 >> 2;
43 if (nOutLen > output.byteLength)
44 throw new Error('Output buffer too small to decode.');
46 for (var nInIdx = 0; nInIdx < nInLen; nInIdx++) {
48 nUint24 |= b64ToUint6(input.charCodeAt(nInIdx)) << 18 - 6 * nMod4;
49 if (nMod4 === 3 || nInLen - nInIdx === 1) {
50 for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) {
51 output.setUint8(nOutIdx, nUint24 >>> (16 >>> nMod3 & 24) & 255);