| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <!-- | 2 <!-- |
| 3 Copyright (c) 2014 The Chromium Authors. All rights reserved. | 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 | 4 Use of this source code is governed by a BSD-style license that can be |
| 5 found in the LICENSE file. | 5 found in the LICENSE file. |
| 6 --> | 6 --> |
| 7 <link rel="import" href="/tracing/base/base.html"> | 7 <link rel="import" href="/tracing/base/base.html"> |
| 8 <script> | 8 <script> |
| 9 'use strict'; | 9 'use strict'; |
| 10 | 10 |
| 11 tr.exportTo('tr.b', function() { | 11 tr.exportTo('tr.b', function() { |
| 12 function Base64() { | 12 function Base64() { |
| 13 } | 13 } |
| 14 | 14 |
| 15 function b64ToUint6(nChr) { | 15 function b64ToUint6(nChr) { |
| 16 if (nChr > 64 && nChr < 91) | 16 if (nChr > 64 && nChr < 91) return nChr - 65; |
| 17 return nChr - 65; | 17 if (nChr > 96 && nChr < 123) return nChr - 71; |
| 18 if (nChr > 96 && nChr < 123) | 18 if (nChr > 47 && nChr < 58) return nChr + 4; |
| 19 return nChr - 71; | 19 if (nChr === 43) return 62; |
| 20 if (nChr > 47 && nChr < 58) | 20 if (nChr === 47) return 63; |
| 21 return nChr + 4; | |
| 22 if (nChr === 43) | |
| 23 return 62; | |
| 24 if (nChr === 47) | |
| 25 return 63; | |
| 26 return 0; | 21 return 0; |
| 27 } | 22 } |
| 28 | 23 |
| 29 Base64.getDecodedBufferLength = function(input) { | 24 Base64.getDecodedBufferLength = function(input) { |
| 30 return input.length * 3 + 1 >> 2; | 25 return input.length * 3 + 1 >> 2; |
| 31 }; | 26 }; |
| 32 | 27 |
| 33 Base64.EncodeArrayBufferToString = function(input) { | 28 Base64.EncodeArrayBufferToString = function(input) { |
| 34 // http://stackoverflow.com/questions/9267899/ | 29 // http://stackoverflow.com/questions/9267899/ |
| 35 var binary = ''; | 30 var binary = ''; |
| 36 var bytes = new Uint8Array(input); | 31 var bytes = new Uint8Array(input); |
| 37 var len = bytes.byteLength; | 32 var len = bytes.byteLength; |
| 38 for (var i = 0; i < len; i++) | 33 for (var i = 0; i < len; i++) { |
| 39 binary += String.fromCharCode(bytes[i]); | 34 binary += String.fromCharCode(bytes[i]); |
| 35 } |
| 40 return btoa(binary); | 36 return btoa(binary); |
| 41 }; | 37 }; |
| 42 | 38 |
| 43 Base64.DecodeToTypedArray = function(input, output) { | 39 Base64.DecodeToTypedArray = function(input, output) { |
| 44 var nInLen = input.length; | 40 var nInLen = input.length; |
| 45 var nOutLen = nInLen * 3 + 1 >> 2; | 41 var nOutLen = nInLen * 3 + 1 >> 2; |
| 46 var nMod3 = 0; | 42 var nMod3 = 0; |
| 47 var nMod4 = 0; | 43 var nMod4 = 0; |
| 48 var nUint24 = 0; | 44 var nUint24 = 0; |
| 49 var nOutIdx = 0; | 45 var nOutIdx = 0; |
| 50 | 46 |
| 51 if (nOutLen > output.byteLength) | 47 if (nOutLen > output.byteLength) { |
| 52 throw new Error('Output buffer too small to decode.'); | 48 throw new Error('Output buffer too small to decode.'); |
| 49 } |
| 53 | 50 |
| 54 for (var nInIdx = 0; nInIdx < nInLen; nInIdx++) { | 51 for (var nInIdx = 0; nInIdx < nInLen; nInIdx++) { |
| 55 nMod4 = nInIdx & 3; | 52 nMod4 = nInIdx & 3; |
| 56 nUint24 |= b64ToUint6(input.charCodeAt(nInIdx)) << 18 - 6 * nMod4; | 53 nUint24 |= b64ToUint6(input.charCodeAt(nInIdx)) << 18 - 6 * nMod4; |
| 57 if (nMod4 === 3 || nInLen - nInIdx === 1) { | 54 if (nMod4 === 3 || nInLen - nInIdx === 1) { |
| 58 for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) { | 55 for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) { |
| 59 output.setUint8(nOutIdx, nUint24 >>> (16 >>> nMod3 & 24) & 255); | 56 output.setUint8(nOutIdx, nUint24 >>> (16 >>> nMod3 & 24) & 255); |
| 60 } | 57 } |
| 61 nUint24 = 0; | 58 nUint24 = 0; |
| 62 } | 59 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 82 */ | 79 */ |
| 83 Base64.atob = function(input) { | 80 Base64.atob = function(input) { |
| 84 return atob(input); | 81 return atob(input); |
| 85 }; | 82 }; |
| 86 | 83 |
| 87 return { | 84 return { |
| 88 Base64, | 85 Base64, |
| 89 }; | 86 }; |
| 90 }); | 87 }); |
| 91 </script> | 88 </script> |
| OLD | NEW |