Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

base64.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*! http://mths.be/base64 v0.1.0 by @mathias | MIT license */
  2. ;(function(root) {
  3. // Detect free variables `exports`.
  4. var freeExports = typeof exports == 'object' && exports;
  5. // Detect free variable `module`.
  6. var freeModule = typeof module == 'object' && module &&
  7. module.exports == freeExports && module;
  8. // Detect free variable `global`, from Node.js or Browserified code, and use
  9. // it as `root`.
  10. var freeGlobal = typeof global == 'object' && global;
  11. if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
  12. root = freeGlobal;
  13. }
  14. /*--------------------------------------------------------------------------*/
  15. var InvalidCharacterError = function(message) {
  16. this.message = message;
  17. };
  18. InvalidCharacterError.prototype = new Error;
  19. InvalidCharacterError.prototype.name = 'InvalidCharacterError';
  20. var error = function(message) {
  21. // Note: the error messages used throughout this file match those used by
  22. // the native `atob`/`btoa` implementation in Chromium.
  23. throw new InvalidCharacterError(message);
  24. };
  25. var TABLE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  26. // http://whatwg.org/html/common-microsyntaxes.html#space-character
  27. var REGEX_SPACE_CHARACTERS = /[\t\n\f\r ]/g;
  28. // `decode` is designed to be fully compatible with `atob` as described in the
  29. // HTML Standard. http://whatwg.org/html/webappapis.html#dom-windowbase64-atob
  30. // The optimized base64-decoding algorithm used is based on @atk’s excellent
  31. // implementation. https://gist.github.com/atk/1020396
  32. var decode = function(input) {
  33. input = String(input)
  34. .replace(REGEX_SPACE_CHARACTERS, '');
  35. var length = input.length;
  36. if (length % 4 == 0) {
  37. input = input.replace(/==?$/, '');
  38. length = input.length;
  39. }
  40. if (
  41. length % 4 == 1 ||
  42. // http://whatwg.org/C#alphanumeric-ascii-characters
  43. /[^+a-zA-Z0-9/]/.test(input)
  44. ) {
  45. error(
  46. 'Invalid character: the string to be decoded is not correctly encoded.'
  47. );
  48. }
  49. var bitCounter = 0;
  50. var bitStorage;
  51. var buffer;
  52. var output = '';
  53. var position = -1;
  54. while (++position < length) {
  55. buffer = TABLE.indexOf(input.charAt(position));
  56. bitStorage = bitCounter % 4 ? bitStorage * 64 + buffer : buffer;
  57. // Unless this is the first of a group of 4 characters…
  58. if (bitCounter++ % 4) {
  59. // …convert the first 8 bits to a single ASCII character.
  60. output += String.fromCharCode(
  61. 0xFF & bitStorage >> (-2 * bitCounter & 6)
  62. );
  63. }
  64. }
  65. return output;
  66. };
  67. // `encode` is designed to be fully compatible with `btoa` as described in the
  68. // HTML Standard: http://whatwg.org/html/webappapis.html#dom-windowbase64-btoa
  69. var encode = function(input) {
  70. input = String(input);
  71. if (/[^\0-\xFF]/.test(input)) {
  72. // Note: no need to special-case astral symbols here, as surrogates are
  73. // matched, and the input is supposed to only contain ASCII anyway.
  74. error(
  75. 'The string to be encoded contains characters outside of the ' +
  76. 'Latin1 range.'
  77. );
  78. }
  79. var padding = input.length % 3;
  80. var output = '';
  81. var position = -1;
  82. var a;
  83. var b;
  84. var c;
  85. var d;
  86. var buffer;
  87. // Make sure any padding is handled outside of the loop.
  88. var length = input.length - padding;
  89. while (++position < length) {
  90. // Read three bytes, i.e. 24 bits.
  91. a = input.charCodeAt(position) << 16;
  92. b = input.charCodeAt(++position) << 8;
  93. c = input.charCodeAt(++position);
  94. buffer = a + b + c;
  95. // Turn the 24 bits into four chunks of 6 bits each, and append the
  96. // matching character for each of them to the output.
  97. output += (
  98. TABLE.charAt(buffer >> 18 & 0x3F) +
  99. TABLE.charAt(buffer >> 12 & 0x3F) +
  100. TABLE.charAt(buffer >> 6 & 0x3F) +
  101. TABLE.charAt(buffer & 0x3F)
  102. );
  103. }
  104. if (padding == 2) {
  105. a = input.charCodeAt(position) << 8;
  106. b = input.charCodeAt(++position);
  107. buffer = a + b;
  108. output += (
  109. TABLE.charAt(buffer >> 10) +
  110. TABLE.charAt((buffer >> 4) & 0x3F) +
  111. TABLE.charAt((buffer << 2) & 0x3F) +
  112. '='
  113. );
  114. } else if (padding == 1) {
  115. buffer = input.charCodeAt(position);
  116. output += (
  117. TABLE.charAt(buffer >> 2) +
  118. TABLE.charAt((buffer << 4) & 0x3F) +
  119. '=='
  120. );
  121. }
  122. return output;
  123. };
  124. var base64 = {
  125. 'encode': encode,
  126. 'decode': decode,
  127. 'version': '0.1.0'
  128. };
  129. // Some AMD build optimizers, like r.js, check for specific condition patterns
  130. // like the following:
  131. if (
  132. typeof define == 'function' &&
  133. typeof define.amd == 'object' &&
  134. define.amd
  135. ) {
  136. define(function() {
  137. return base64;
  138. });
  139. } else if (freeExports && !freeExports.nodeType) {
  140. if (freeModule) { // in Node.js or RingoJS v0.8.0+
  141. freeModule.exports = base64;
  142. } else { // in Narwhal or RingoJS v0.7.0-
  143. for (var key in base64) {
  144. base64.hasOwnProperty(key) && (freeExports[key] = base64[key]);
  145. }
  146. }
  147. } else { // in Rhino or a web browser
  148. root.base64 = base64;
  149. }
  150. }(this));