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.
 
 
 
 
 
 

8562 regels
244 KiB

  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.LessPass = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. 'use strict'
  3. exports.byteLength = byteLength
  4. exports.toByteArray = toByteArray
  5. exports.fromByteArray = fromByteArray
  6. var lookup = []
  7. var revLookup = []
  8. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  9. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  10. for (var i = 0, len = code.length; i < len; ++i) {
  11. lookup[i] = code[i]
  12. revLookup[code.charCodeAt(i)] = i
  13. }
  14. revLookup['-'.charCodeAt(0)] = 62
  15. revLookup['_'.charCodeAt(0)] = 63
  16. function placeHoldersCount (b64) {
  17. var len = b64.length
  18. if (len % 4 > 0) {
  19. throw new Error('Invalid string. Length must be a multiple of 4')
  20. }
  21. // the number of equal signs (place holders)
  22. // if there are two placeholders, than the two characters before it
  23. // represent one byte
  24. // if there is only one, then the three characters before it represent 2 bytes
  25. // this is just a cheap hack to not do indexOf twice
  26. return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
  27. }
  28. function byteLength (b64) {
  29. // base64 is 4/3 + up to two characters of the original data
  30. return b64.length * 3 / 4 - placeHoldersCount(b64)
  31. }
  32. function toByteArray (b64) {
  33. var i, j, l, tmp, placeHolders, arr
  34. var len = b64.length
  35. placeHolders = placeHoldersCount(b64)
  36. arr = new Arr(len * 3 / 4 - placeHolders)
  37. // if there are placeholders, only get up to the last complete 4 chars
  38. l = placeHolders > 0 ? len - 4 : len
  39. var L = 0
  40. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  41. tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
  42. arr[L++] = (tmp >> 16) & 0xFF
  43. arr[L++] = (tmp >> 8) & 0xFF
  44. arr[L++] = tmp & 0xFF
  45. }
  46. if (placeHolders === 2) {
  47. tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
  48. arr[L++] = tmp & 0xFF
  49. } else if (placeHolders === 1) {
  50. tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
  51. arr[L++] = (tmp >> 8) & 0xFF
  52. arr[L++] = tmp & 0xFF
  53. }
  54. return arr
  55. }
  56. function tripletToBase64 (num) {
  57. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
  58. }
  59. function encodeChunk (uint8, start, end) {
  60. var tmp
  61. var output = []
  62. for (var i = start; i < end; i += 3) {
  63. tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
  64. output.push(tripletToBase64(tmp))
  65. }
  66. return output.join('')
  67. }
  68. function fromByteArray (uint8) {
  69. var tmp
  70. var len = uint8.length
  71. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  72. var output = ''
  73. var parts = []
  74. var maxChunkLength = 16383 // must be multiple of 3
  75. // go through the array every three bytes, we'll deal with trailing stuff later
  76. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  77. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
  78. }
  79. // pad the end with zeros, but make sure to not forget the extra bytes
  80. if (extraBytes === 1) {
  81. tmp = uint8[len - 1]
  82. output += lookup[tmp >> 2]
  83. output += lookup[(tmp << 4) & 0x3F]
  84. output += '=='
  85. } else if (extraBytes === 2) {
  86. tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
  87. output += lookup[tmp >> 10]
  88. output += lookup[(tmp >> 4) & 0x3F]
  89. output += lookup[(tmp << 2) & 0x3F]
  90. output += '='
  91. }
  92. parts.push(output)
  93. return parts.join('')
  94. }
  95. },{}],2:[function(require,module,exports){
  96. var bigInt = (function (undefined) {
  97. "use strict";
  98. var BASE = 1e7,
  99. LOG_BASE = 7,
  100. MAX_INT = 9007199254740992,
  101. MAX_INT_ARR = smallToArray(MAX_INT),
  102. LOG_MAX_INT = Math.log(MAX_INT);
  103. function Integer(v, radix) {
  104. if (typeof v === "undefined") return Integer[0];
  105. if (typeof radix !== "undefined") return +radix === 10 ? parseValue(v) : parseBase(v, radix);
  106. return parseValue(v);
  107. }
  108. function BigInteger(value, sign) {
  109. this.value = value;
  110. this.sign = sign;
  111. this.isSmall = false;
  112. }
  113. BigInteger.prototype = Object.create(Integer.prototype);
  114. function SmallInteger(value) {
  115. this.value = value;
  116. this.sign = value < 0;
  117. this.isSmall = true;
  118. }
  119. SmallInteger.prototype = Object.create(Integer.prototype);
  120. function isPrecise(n) {
  121. return -MAX_INT < n && n < MAX_INT;
  122. }
  123. function smallToArray(n) { // For performance reasons doesn't reference BASE, need to change this function if BASE changes
  124. if (n < 1e7)
  125. return [n];
  126. if (n < 1e14)
  127. return [n % 1e7, Math.floor(n / 1e7)];
  128. return [n % 1e7, Math.floor(n / 1e7) % 1e7, Math.floor(n / 1e14)];
  129. }
  130. function arrayToSmall(arr) { // If BASE changes this function may need to change
  131. trim(arr);
  132. var length = arr.length;
  133. if (length < 4 && compareAbs(arr, MAX_INT_ARR) < 0) {
  134. switch (length) {
  135. case 0: return 0;
  136. case 1: return arr[0];
  137. case 2: return arr[0] + arr[1] * BASE;
  138. default: return arr[0] + (arr[1] + arr[2] * BASE) * BASE;
  139. }
  140. }
  141. return arr;
  142. }
  143. function trim(v) {
  144. var i = v.length;
  145. while (v[--i] === 0);
  146. v.length = i + 1;
  147. }
  148. function createArray(length) { // function shamelessly stolen from Yaffle's library https://github.com/Yaffle/BigInteger
  149. var x = new Array(length);
  150. var i = -1;
  151. while (++i < length) {
  152. x[i] = 0;
  153. }
  154. return x;
  155. }
  156. function truncate(n) {
  157. if (n > 0) return Math.floor(n);
  158. return Math.ceil(n);
  159. }
  160. function add(a, b) { // assumes a and b are arrays with a.length >= b.length
  161. var l_a = a.length,
  162. l_b = b.length,
  163. r = new Array(l_a),
  164. carry = 0,
  165. base = BASE,
  166. sum, i;
  167. for (i = 0; i < l_b; i++) {
  168. sum = a[i] + b[i] + carry;
  169. carry = sum >= base ? 1 : 0;
  170. r[i] = sum - carry * base;
  171. }
  172. while (i < l_a) {
  173. sum = a[i] + carry;
  174. carry = sum === base ? 1 : 0;
  175. r[i++] = sum - carry * base;
  176. }
  177. if (carry > 0) r.push(carry);
  178. return r;
  179. }
  180. function addAny(a, b) {
  181. if (a.length >= b.length) return add(a, b);
  182. return add(b, a);
  183. }
  184. function addSmall(a, carry) { // assumes a is array, carry is number with 0 <= carry < MAX_INT
  185. var l = a.length,
  186. r = new Array(l),
  187. base = BASE,
  188. sum, i;
  189. for (i = 0; i < l; i++) {
  190. sum = a[i] - base + carry;
  191. carry = Math.floor(sum / base);
  192. r[i] = sum - carry * base;
  193. carry += 1;
  194. }
  195. while (carry > 0) {
  196. r[i++] = carry % base;
  197. carry = Math.floor(carry / base);
  198. }
  199. return r;
  200. }
  201. BigInteger.prototype.add = function (v) {
  202. var value, n = parseValue(v);
  203. if (this.sign !== n.sign) {
  204. return this.subtract(n.negate());
  205. }
  206. var a = this.value, b = n.value;
  207. if (n.isSmall) {
  208. return new BigInteger(addSmall(a, Math.abs(b)), this.sign);
  209. }
  210. return new BigInteger(addAny(a, b), this.sign);
  211. };
  212. BigInteger.prototype.plus = BigInteger.prototype.add;
  213. SmallInteger.prototype.add = function (v) {
  214. var n = parseValue(v);
  215. var a = this.value;
  216. if (a < 0 !== n.sign) {
  217. return this.subtract(n.negate());
  218. }
  219. var b = n.value;
  220. if (n.isSmall) {
  221. if (isPrecise(a + b)) return new SmallInteger(a + b);
  222. b = smallToArray(Math.abs(b));
  223. }
  224. return new BigInteger(addSmall(b, Math.abs(a)), a < 0);
  225. };
  226. SmallInteger.prototype.plus = SmallInteger.prototype.add;
  227. function subtract(a, b) { // assumes a and b are arrays with a >= b
  228. var a_l = a.length,
  229. b_l = b.length,
  230. r = new Array(a_l),
  231. borrow = 0,
  232. base = BASE,
  233. i, difference;
  234. for (i = 0; i < b_l; i++) {
  235. difference = a[i] - borrow - b[i];
  236. if (difference < 0) {
  237. difference += base;
  238. borrow = 1;
  239. } else borrow = 0;
  240. r[i] = difference;
  241. }
  242. for (i = b_l; i < a_l; i++) {
  243. difference = a[i] - borrow;
  244. if (difference < 0) difference += base;
  245. else {
  246. r[i++] = difference;
  247. break;
  248. }
  249. r[i] = difference;
  250. }
  251. for (; i < a_l; i++) {
  252. r[i] = a[i];
  253. }
  254. trim(r);
  255. return r;
  256. }
  257. function subtractAny(a, b, sign) {
  258. var value, isSmall;
  259. if (compareAbs(a, b) >= 0) {
  260. value = subtract(a,b);
  261. } else {
  262. value = subtract(b, a);
  263. sign = !sign;
  264. }
  265. value = arrayToSmall(value);
  266. if (typeof value === "number") {
  267. if (sign) value = -value;
  268. return new SmallInteger(value);
  269. }
  270. return new BigInteger(value, sign);
  271. }
  272. function subtractSmall(a, b, sign) { // assumes a is array, b is number with 0 <= b < MAX_INT
  273. var l = a.length,
  274. r = new Array(l),
  275. carry = -b,
  276. base = BASE,
  277. i, difference;
  278. for (i = 0; i < l; i++) {
  279. difference = a[i] + carry;
  280. carry = Math.floor(difference / base);
  281. difference %= base;
  282. r[i] = difference < 0 ? difference + base : difference;
  283. }
  284. r = arrayToSmall(r);
  285. if (typeof r === "number") {
  286. if (sign) r = -r;
  287. return new SmallInteger(r);
  288. } return new BigInteger(r, sign);
  289. }
  290. BigInteger.prototype.subtract = function (v) {
  291. var n = parseValue(v);
  292. if (this.sign !== n.sign) {
  293. return this.add(n.negate());
  294. }
  295. var a = this.value, b = n.value;
  296. if (n.isSmall)
  297. return subtractSmall(a, Math.abs(b), this.sign);
  298. return subtractAny(a, b, this.sign);
  299. };
  300. BigInteger.prototype.minus = BigInteger.prototype.subtract;
  301. SmallInteger.prototype.subtract = function (v) {
  302. var n = parseValue(v);
  303. var a = this.value;
  304. if (a < 0 !== n.sign) {
  305. return this.add(n.negate());
  306. }
  307. var b = n.value;
  308. if (n.isSmall) {
  309. return new SmallInteger(a - b);
  310. }
  311. return subtractSmall(b, Math.abs(a), a >= 0);
  312. };
  313. SmallInteger.prototype.minus = SmallInteger.prototype.subtract;
  314. BigInteger.prototype.negate = function () {
  315. return new BigInteger(this.value, !this.sign);
  316. };
  317. SmallInteger.prototype.negate = function () {
  318. var sign = this.sign;
  319. var small = new SmallInteger(-this.value);
  320. small.sign = !sign;
  321. return small;
  322. };
  323. BigInteger.prototype.abs = function () {
  324. return new BigInteger(this.value, false);
  325. };
  326. SmallInteger.prototype.abs = function () {
  327. return new SmallInteger(Math.abs(this.value));
  328. };
  329. function multiplyLong(a, b) {
  330. var a_l = a.length,
  331. b_l = b.length,
  332. l = a_l + b_l,
  333. r = createArray(l),
  334. base = BASE,
  335. product, carry, i, a_i, b_j;
  336. for (i = 0; i < a_l; ++i) {
  337. a_i = a[i];
  338. for (var j = 0; j < b_l; ++j) {
  339. b_j = b[j];
  340. product = a_i * b_j + r[i + j];
  341. carry = Math.floor(product / base);
  342. r[i + j] = product - carry * base;
  343. r[i + j + 1] += carry;
  344. }
  345. }
  346. trim(r);
  347. return r;
  348. }
  349. function multiplySmall(a, b) { // assumes a is array, b is number with |b| < BASE
  350. var l = a.length,
  351. r = new Array(l),
  352. base = BASE,
  353. carry = 0,
  354. product, i;
  355. for (i = 0; i < l; i++) {
  356. product = a[i] * b + carry;
  357. carry = Math.floor(product / base);
  358. r[i] = product - carry * base;
  359. }
  360. while (carry > 0) {
  361. r[i++] = carry % base;
  362. carry = Math.floor(carry / base);
  363. }
  364. return r;
  365. }
  366. function shiftLeft(x, n) {
  367. var r = [];
  368. while (n-- > 0) r.push(0);
  369. return r.concat(x);
  370. }
  371. function multiplyKaratsuba(x, y) {
  372. var n = Math.max(x.length, y.length);
  373. if (n <= 30) return multiplyLong(x, y);
  374. n = Math.ceil(n / 2);
  375. var b = x.slice(n),
  376. a = x.slice(0, n),
  377. d = y.slice(n),
  378. c = y.slice(0, n);
  379. var ac = multiplyKaratsuba(a, c),
  380. bd = multiplyKaratsuba(b, d),
  381. abcd = multiplyKaratsuba(addAny(a, b), addAny(c, d));
  382. var product = addAny(addAny(ac, shiftLeft(subtract(subtract(abcd, ac), bd), n)), shiftLeft(bd, 2 * n));
  383. trim(product);
  384. return product;
  385. }
  386. // The following function is derived from a surface fit of a graph plotting the performance difference
  387. // between long multiplication and karatsuba multiplication versus the lengths of the two arrays.
  388. function useKaratsuba(l1, l2) {
  389. return -0.012 * l1 - 0.012 * l2 + 0.000015 * l1 * l2 > 0;
  390. }
  391. BigInteger.prototype.multiply = function (v) {
  392. var value, n = parseValue(v),
  393. a = this.value, b = n.value,
  394. sign = this.sign !== n.sign,
  395. abs;
  396. if (n.isSmall) {
  397. if (b === 0) return Integer[0];
  398. if (b === 1) return this;
  399. if (b === -1) return this.negate();
  400. abs = Math.abs(b);
  401. if (abs < BASE) {
  402. return new BigInteger(multiplySmall(a, abs), sign);
  403. }
  404. b = smallToArray(abs);
  405. }
  406. if (useKaratsuba(a.length, b.length)) // Karatsuba is only faster for certain array sizes
  407. return new BigInteger(multiplyKaratsuba(a, b), sign);
  408. return new BigInteger(multiplyLong(a, b), sign);
  409. };
  410. BigInteger.prototype.times = BigInteger.prototype.multiply;
  411. function multiplySmallAndArray(a, b, sign) { // a >= 0
  412. if (a < BASE) {
  413. return new BigInteger(multiplySmall(b, a), sign);
  414. }
  415. return new BigInteger(multiplyLong(b, smallToArray(a)), sign);
  416. }
  417. SmallInteger.prototype._multiplyBySmall = function (a) {
  418. if (isPrecise(a.value * this.value)) {
  419. return new SmallInteger(a.value * this.value);
  420. }
  421. return multiplySmallAndArray(Math.abs(a.value), smallToArray(Math.abs(this.value)), this.sign !== a.sign);
  422. };
  423. BigInteger.prototype._multiplyBySmall = function (a) {
  424. if (a.value === 0) return Integer[0];
  425. if (a.value === 1) return this;
  426. if (a.value === -1) return this.negate();
  427. return multiplySmallAndArray(Math.abs(a.value), this.value, this.sign !== a.sign);
  428. };
  429. SmallInteger.prototype.multiply = function (v) {
  430. return parseValue(v)._multiplyBySmall(this);
  431. };
  432. SmallInteger.prototype.times = SmallInteger.prototype.multiply;
  433. function square(a) {
  434. var l = a.length,
  435. r = createArray(l + l),
  436. base = BASE,
  437. product, carry, i, a_i, a_j;
  438. for (i = 0; i < l; i++) {
  439. a_i = a[i];
  440. for (var j = 0; j < l; j++) {
  441. a_j = a[j];
  442. product = a_i * a_j + r[i + j];
  443. carry = Math.floor(product / base);
  444. r[i + j] = product - carry * base;
  445. r[i + j + 1] += carry;
  446. }
  447. }
  448. trim(r);
  449. return r;
  450. }
  451. BigInteger.prototype.square = function () {
  452. return new BigInteger(square(this.value), false);
  453. };
  454. SmallInteger.prototype.square = function () {
  455. var value = this.value * this.value;
  456. if (isPrecise(value)) return new SmallInteger(value);
  457. return new BigInteger(square(smallToArray(Math.abs(this.value))), false);
  458. };
  459. function divMod1(a, b) { // Left over from previous version. Performs faster than divMod2 on smaller input sizes.
  460. var a_l = a.length,
  461. b_l = b.length,
  462. base = BASE,
  463. result = createArray(b.length),
  464. divisorMostSignificantDigit = b[b_l - 1],
  465. // normalization
  466. lambda = Math.ceil(base / (2 * divisorMostSignificantDigit)),
  467. remainder = multiplySmall(a, lambda),
  468. divisor = multiplySmall(b, lambda),
  469. quotientDigit, shift, carry, borrow, i, l, q;
  470. if (remainder.length <= a_l) remainder.push(0);
  471. divisor.push(0);
  472. divisorMostSignificantDigit = divisor[b_l - 1];
  473. for (shift = a_l - b_l; shift >= 0; shift--) {
  474. quotientDigit = base - 1;
  475. if (remainder[shift + b_l] !== divisorMostSignificantDigit) {
  476. quotientDigit = Math.floor((remainder[shift + b_l] * base + remainder[shift + b_l - 1]) / divisorMostSignificantDigit);
  477. }
  478. // quotientDigit <= base - 1
  479. carry = 0;
  480. borrow = 0;
  481. l = divisor.length;
  482. for (i = 0; i < l; i++) {
  483. carry += quotientDigit * divisor[i];
  484. q = Math.floor(carry / base);
  485. borrow += remainder[shift + i] - (carry - q * base);
  486. carry = q;
  487. if (borrow < 0) {
  488. remainder[shift + i] = borrow + base;
  489. borrow = -1;
  490. } else {
  491. remainder[shift + i] = borrow;
  492. borrow = 0;
  493. }
  494. }
  495. while (borrow !== 0) {
  496. quotientDigit -= 1;
  497. carry = 0;
  498. for (i = 0; i < l; i++) {
  499. carry += remainder[shift + i] - base + divisor[i];
  500. if (carry < 0) {
  501. remainder[shift + i] = carry + base;
  502. carry = 0;
  503. } else {
  504. remainder[shift + i] = carry;
  505. carry = 1;
  506. }
  507. }
  508. borrow += carry;
  509. }
  510. result[shift] = quotientDigit;
  511. }
  512. // denormalization
  513. remainder = divModSmall(remainder, lambda)[0];
  514. return [arrayToSmall(result), arrayToSmall(remainder)];
  515. }
  516. function divMod2(a, b) { // Implementation idea shamelessly stolen from Silent Matt's library http://silentmatt.com/biginteger/
  517. // Performs faster than divMod1 on larger input sizes.
  518. var a_l = a.length,
  519. b_l = b.length,
  520. result = [],
  521. part = [],
  522. base = BASE,
  523. guess, xlen, highx, highy, check;
  524. while (a_l) {
  525. part.unshift(a[--a_l]);
  526. if (compareAbs(part, b) < 0) {
  527. result.push(0);
  528. continue;
  529. }
  530. xlen = part.length;
  531. highx = part[xlen - 1] * base + part[xlen - 2];
  532. highy = b[b_l - 1] * base + b[b_l - 2];
  533. if (xlen > b_l) {
  534. highx = (highx + 1) * base;
  535. }
  536. guess = Math.ceil(highx / highy);
  537. do {
  538. check = multiplySmall(b, guess);
  539. if (compareAbs(check, part) <= 0) break;
  540. guess--;
  541. } while (guess);
  542. result.push(guess);
  543. part = subtract(part, check);
  544. }
  545. result.reverse();
  546. return [arrayToSmall(result), arrayToSmall(part)];
  547. }
  548. function divModSmall(value, lambda) {
  549. var length = value.length,
  550. quotient = createArray(length),
  551. base = BASE,
  552. i, q, remainder, divisor;
  553. remainder = 0;
  554. for (i = length - 1; i >= 0; --i) {
  555. divisor = remainder * base + value[i];
  556. q = truncate(divisor / lambda);
  557. remainder = divisor - q * lambda;
  558. quotient[i] = q | 0;
  559. }
  560. return [quotient, remainder | 0];
  561. }
  562. function divModAny(self, v) {
  563. var value, n = parseValue(v);
  564. var a = self.value, b = n.value;
  565. var quotient;
  566. if (b === 0) throw new Error("Cannot divide by zero");
  567. if (self.isSmall) {
  568. if (n.isSmall) {
  569. return [new SmallInteger(truncate(a / b)), new SmallInteger(a % b)];
  570. }
  571. return [Integer[0], self];
  572. }
  573. if (n.isSmall) {
  574. if (b === 1) return [self, Integer[0]];
  575. if (b == -1) return [self.negate(), Integer[0]];
  576. var abs = Math.abs(b);
  577. if (abs < BASE) {
  578. value = divModSmall(a, abs);
  579. quotient = arrayToSmall(value[0]);
  580. var remainder = value[1];
  581. if (self.sign) remainder = -remainder;
  582. if (typeof quotient === "number") {
  583. if (self.sign !== n.sign) quotient = -quotient;
  584. return [new SmallInteger(quotient), new SmallInteger(remainder)];
  585. }
  586. return [new BigInteger(quotient, self.sign !== n.sign), new SmallInteger(remainder)];
  587. }
  588. b = smallToArray(abs);
  589. }
  590. var comparison = compareAbs(a, b);
  591. if (comparison === -1) return [Integer[0], self];
  592. if (comparison === 0) return [Integer[self.sign === n.sign ? 1 : -1], Integer[0]];
  593. // divMod1 is faster on smaller input sizes
  594. if (a.length + b.length <= 200)
  595. value = divMod1(a, b);
  596. else value = divMod2(a, b);
  597. quotient = value[0];
  598. var qSign = self.sign !== n.sign,
  599. mod = value[1],
  600. mSign = self.sign;
  601. if (typeof quotient === "number") {
  602. if (qSign) quotient = -quotient;
  603. quotient = new SmallInteger(quotient);
  604. } else quotient = new BigInteger(quotient, qSign);
  605. if (typeof mod === "number") {
  606. if (mSign) mod = -mod;
  607. mod = new SmallInteger(mod);
  608. } else mod = new BigInteger(mod, mSign);
  609. return [quotient, mod];
  610. }
  611. BigInteger.prototype.divmod = function (v) {
  612. var result = divModAny(this, v);
  613. return {
  614. quotient: result[0],
  615. remainder: result[1]
  616. };
  617. };
  618. SmallInteger.prototype.divmod = BigInteger.prototype.divmod;
  619. BigInteger.prototype.divide = function (v) {
  620. return divModAny(this, v)[0];
  621. };
  622. SmallInteger.prototype.over = SmallInteger.prototype.divide = BigInteger.prototype.over = BigInteger.prototype.divide;
  623. BigInteger.prototype.mod = function (v) {
  624. return divModAny(this, v)[1];
  625. };
  626. SmallInteger.prototype.remainder = SmallInteger.prototype.mod = BigInteger.prototype.remainder = BigInteger.prototype.mod;
  627. BigInteger.prototype.pow = function (v) {
  628. var n = parseValue(v),
  629. a = this.value,
  630. b = n.value,
  631. value, x, y;
  632. if (b === 0) return Integer[1];
  633. if (a === 0) return Integer[0];
  634. if (a === 1) return Integer[1];
  635. if (a === -1) return n.isEven() ? Integer[1] : Integer[-1];
  636. if (n.sign) {
  637. return Integer[0];
  638. }
  639. if (!n.isSmall) throw new Error("The exponent " + n.toString() + " is too large.");
  640. if (this.isSmall) {
  641. if (isPrecise(value = Math.pow(a, b)))
  642. return new SmallInteger(truncate(value));
  643. }
  644. x = this;
  645. y = Integer[1];
  646. while (true) {
  647. if (b & 1 === 1) {
  648. y = y.times(x);
  649. --b;
  650. }
  651. if (b === 0) break;
  652. b /= 2;
  653. x = x.square();
  654. }
  655. return y;
  656. };
  657. SmallInteger.prototype.pow = BigInteger.prototype.pow;
  658. BigInteger.prototype.modPow = function (exp, mod) {
  659. exp = parseValue(exp);
  660. mod = parseValue(mod);
  661. if (mod.isZero()) throw new Error("Cannot take modPow with modulus 0");
  662. var r = Integer[1],
  663. base = this.mod(mod);
  664. while (exp.isPositive()) {
  665. if (base.isZero()) return Integer[0];
  666. if (exp.isOdd()) r = r.multiply(base).mod(mod);
  667. exp = exp.divide(2);
  668. base = base.square().mod(mod);
  669. }
  670. return r;
  671. };
  672. SmallInteger.prototype.modPow = BigInteger.prototype.modPow;
  673. function compareAbs(a, b) {
  674. if (a.length !== b.length) {
  675. return a.length > b.length ? 1 : -1;
  676. }
  677. for (var i = a.length - 1; i >= 0; i--) {
  678. if (a[i] !== b[i]) return a[i] > b[i] ? 1 : -1;
  679. }
  680. return 0;
  681. }
  682. BigInteger.prototype.compareAbs = function (v) {
  683. var n = parseValue(v),
  684. a = this.value,
  685. b = n.value;
  686. if (n.isSmall) return 1;
  687. return compareAbs(a, b);
  688. };
  689. SmallInteger.prototype.compareAbs = function (v) {
  690. var n = parseValue(v),
  691. a = Math.abs(this.value),
  692. b = n.value;
  693. if (n.isSmall) {
  694. b = Math.abs(b);
  695. return a === b ? 0 : a > b ? 1 : -1;
  696. }
  697. return -1;
  698. };
  699. BigInteger.prototype.compare = function (v) {
  700. // See discussion about comparison with Infinity:
  701. // https://github.com/peterolson/BigInteger.js/issues/61
  702. if (v === Infinity) {
  703. return -1;
  704. }
  705. if (v === -Infinity) {
  706. return 1;
  707. }
  708. var n = parseValue(v),
  709. a = this.value,
  710. b = n.value;
  711. if (this.sign !== n.sign) {
  712. return n.sign ? 1 : -1;
  713. }
  714. if (n.isSmall) {
  715. return this.sign ? -1 : 1;
  716. }
  717. return compareAbs(a, b) * (this.sign ? -1 : 1);
  718. };
  719. BigInteger.prototype.compareTo = BigInteger.prototype.compare;
  720. SmallInteger.prototype.compare = function (v) {
  721. if (v === Infinity) {
  722. return -1;
  723. }
  724. if (v === -Infinity) {
  725. return 1;
  726. }
  727. var n = parseValue(v),
  728. a = this.value,
  729. b = n.value;
  730. if (n.isSmall) {
  731. return a == b ? 0 : a > b ? 1 : -1;
  732. }
  733. if (a < 0 !== n.sign) {
  734. return a < 0 ? -1 : 1;
  735. }
  736. return a < 0 ? 1 : -1;
  737. };
  738. SmallInteger.prototype.compareTo = SmallInteger.prototype.compare;
  739. BigInteger.prototype.equals = function (v) {
  740. return this.compare(v) === 0;
  741. };
  742. SmallInteger.prototype.eq = SmallInteger.prototype.equals = BigInteger.prototype.eq = BigInteger.prototype.equals;
  743. BigInteger.prototype.notEquals = function (v) {
  744. return this.compare(v) !== 0;
  745. };
  746. SmallInteger.prototype.neq = SmallInteger.prototype.notEquals = BigInteger.prototype.neq = BigInteger.prototype.notEquals;
  747. BigInteger.prototype.greater = function (v) {
  748. return this.compare(v) > 0;
  749. };
  750. SmallInteger.prototype.gt = SmallInteger.prototype.greater = BigInteger.prototype.gt = BigInteger.prototype.greater;
  751. BigInteger.prototype.lesser = function (v) {
  752. return this.compare(v) < 0;
  753. };
  754. SmallInteger.prototype.lt = SmallInteger.prototype.lesser = BigInteger.prototype.lt = BigInteger.prototype.lesser;
  755. BigInteger.prototype.greaterOrEquals = function (v) {
  756. return this.compare(v) >= 0;
  757. };
  758. SmallInteger.prototype.geq = SmallInteger.prototype.greaterOrEquals = BigInteger.prototype.geq = BigInteger.prototype.greaterOrEquals;
  759. BigInteger.prototype.lesserOrEquals = function (v) {
  760. return this.compare(v) <= 0;
  761. };
  762. SmallInteger.prototype.leq = SmallInteger.prototype.lesserOrEquals = BigInteger.prototype.leq = BigInteger.prototype.lesserOrEquals;
  763. BigInteger.prototype.isEven = function () {
  764. return (this.value[0] & 1) === 0;
  765. };
  766. SmallInteger.prototype.isEven = function () {
  767. return (this.value & 1) === 0;
  768. };
  769. BigInteger.prototype.isOdd = function () {
  770. return (this.value[0] & 1) === 1;
  771. };
  772. SmallInteger.prototype.isOdd = function () {
  773. return (this.value & 1) === 1;
  774. };
  775. BigInteger.prototype.isPositive = function () {
  776. return !this.sign;
  777. };
  778. SmallInteger.prototype.isPositive = function () {
  779. return this.value > 0;
  780. };
  781. BigInteger.prototype.isNegative = function () {
  782. return this.sign;
  783. };
  784. SmallInteger.prototype.isNegative = function () {
  785. return this.value < 0;
  786. };
  787. BigInteger.prototype.isUnit = function () {
  788. return false;
  789. };
  790. SmallInteger.prototype.isUnit = function () {
  791. return Math.abs(this.value) === 1;
  792. };
  793. BigInteger.prototype.isZero = function () {
  794. return false;
  795. };
  796. SmallInteger.prototype.isZero = function () {
  797. return this.value === 0;
  798. };
  799. BigInteger.prototype.isDivisibleBy = function (v) {
  800. var n = parseValue(v);
  801. var value = n.value;
  802. if (value === 0) return false;
  803. if (value === 1) return true;
  804. if (value === 2) return this.isEven();
  805. return this.mod(n).equals(Integer[0]);
  806. };
  807. SmallInteger.prototype.isDivisibleBy = BigInteger.prototype.isDivisibleBy;
  808. function isBasicPrime(v) {
  809. var n = v.abs();
  810. if (n.isUnit()) return false;
  811. if (n.equals(2) || n.equals(3) || n.equals(5)) return true;
  812. if (n.isEven() || n.isDivisibleBy(3) || n.isDivisibleBy(5)) return false;
  813. if (n.lesser(25)) return true;
  814. // we don't know if it's prime: let the other functions figure it out
  815. }
  816. BigInteger.prototype.isPrime = function () {
  817. var isPrime = isBasicPrime(this);
  818. if (isPrime !== undefined) return isPrime;
  819. var n = this.abs(),
  820. nPrev = n.prev();
  821. var a = [2, 3, 5, 7, 11, 13, 17, 19],
  822. b = nPrev,
  823. d, t, i, x;
  824. while (b.isEven()) b = b.divide(2);
  825. for (i = 0; i < a.length; i++) {
  826. x = bigInt(a[i]).modPow(b, n);
  827. if (x.equals(Integer[1]) || x.equals(nPrev)) continue;
  828. for (t = true, d = b; t && d.lesser(nPrev) ; d = d.multiply(2)) {
  829. x = x.square().mod(n);
  830. if (x.equals(nPrev)) t = false;
  831. }
  832. if (t) return false;
  833. }
  834. return true;
  835. };
  836. SmallInteger.prototype.isPrime = BigInteger.prototype.isPrime;
  837. BigInteger.prototype.isProbablePrime = function (iterations) {
  838. var isPrime = isBasicPrime(this);
  839. if (isPrime !== undefined) return isPrime;
  840. var n = this.abs();
  841. var t = iterations === undefined ? 5 : iterations;
  842. // use the Fermat primality test
  843. for (var i = 0; i < t; i++) {
  844. var a = bigInt.randBetween(2, n.minus(2));
  845. if (!a.modPow(n.prev(), n).isUnit()) return false; // definitely composite
  846. }
  847. return true; // large chance of being prime
  848. };
  849. SmallInteger.prototype.isProbablePrime = BigInteger.prototype.isProbablePrime;
  850. BigInteger.prototype.modInv = function (n) {
  851. var t = bigInt.zero, newT = bigInt.one, r = parseValue(n), newR = this.abs(), q, lastT, lastR;
  852. while (!newR.equals(bigInt.zero)) {
  853. q = r.divide(newR);
  854. lastT = t;
  855. lastR = r;
  856. t = newT;
  857. r = newR;
  858. newT = lastT.subtract(q.multiply(newT));
  859. newR = lastR.subtract(q.multiply(newR));
  860. }
  861. if (!r.equals(1)) throw new Error(this.toString() + " and " + n.toString() + " are not co-prime");
  862. if (t.compare(0) === -1) {
  863. t = t.add(n);
  864. }
  865. return t;
  866. }
  867. SmallInteger.prototype.modInv = BigInteger.prototype.modInv;
  868. BigInteger.prototype.next = function () {
  869. var value = this.value;
  870. if (this.sign) {
  871. return subtractSmall(value, 1, this.sign);
  872. }
  873. return new BigInteger(addSmall(value, 1), this.sign);
  874. };
  875. SmallInteger.prototype.next = function () {
  876. var value = this.value;
  877. if (value + 1 < MAX_INT) return new SmallInteger(value + 1);
  878. return new BigInteger(MAX_INT_ARR, false);
  879. };
  880. BigInteger.prototype.prev = function () {
  881. var value = this.value;
  882. if (this.sign) {
  883. return new BigInteger(addSmall(value, 1), true);
  884. }
  885. return subtractSmall(value, 1, this.sign);
  886. };
  887. SmallInteger.prototype.prev = function () {
  888. var value = this.value;
  889. if (value - 1 > -MAX_INT) return new SmallInteger(value - 1);
  890. return new BigInteger(MAX_INT_ARR, true);
  891. };
  892. var powersOfTwo = [1];
  893. while (powersOfTwo[powersOfTwo.length - 1] <= BASE) powersOfTwo.push(2 * powersOfTwo[powersOfTwo.length - 1]);
  894. var powers2Length = powersOfTwo.length, highestPower2 = powersOfTwo[powers2Length - 1];
  895. function shift_isSmall(n) {
  896. return ((typeof n === "number" || typeof n === "string") && +Math.abs(n) <= BASE) ||
  897. (n instanceof BigInteger && n.value.length <= 1);
  898. }
  899. BigInteger.prototype.shiftLeft = function (n) {
  900. if (!shift_isSmall(n)) {
  901. throw new Error(String(n) + " is too large for shifting.");
  902. }
  903. n = +n;
  904. if (n < 0) return this.shiftRight(-n);
  905. var result = this;
  906. while (n >= powers2Length) {
  907. result = result.multiply(highestPower2);
  908. n -= powers2Length - 1;
  909. }
  910. return result.multiply(powersOfTwo[n]);
  911. };
  912. SmallInteger.prototype.shiftLeft = BigInteger.prototype.shiftLeft;
  913. BigInteger.prototype.shiftRight = function (n) {
  914. var remQuo;
  915. if (!shift_isSmall(n)) {
  916. throw new Error(String(n) + " is too large for shifting.");
  917. }
  918. n = +n;
  919. if (n < 0) return this.shiftLeft(-n);
  920. var result = this;
  921. while (n >= powers2Length) {
  922. if (result.isZero()) return result;
  923. remQuo = divModAny(result, highestPower2);
  924. result = remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];
  925. n -= powers2Length - 1;
  926. }
  927. remQuo = divModAny(result, powersOfTwo[n]);
  928. return remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];
  929. };
  930. SmallInteger.prototype.shiftRight = BigInteger.prototype.shiftRight;
  931. function bitwise(x, y, fn) {
  932. y = parseValue(y);
  933. var xSign = x.isNegative(), ySign = y.isNegative();
  934. var xRem = xSign ? x.not() : x,
  935. yRem = ySign ? y.not() : y;
  936. var xBits = [], yBits = [];
  937. var xStop = false, yStop = false;
  938. while (!xStop || !yStop) {
  939. if (xRem.isZero()) { // virtual sign extension for simulating two's complement
  940. xStop = true;
  941. xBits.push(xSign ? 1 : 0);
  942. }
  943. else if (xSign) xBits.push(xRem.isEven() ? 1 : 0); // two's complement for negative numbers
  944. else xBits.push(xRem.isEven() ? 0 : 1);
  945. if (yRem.isZero()) {
  946. yStop = true;
  947. yBits.push(ySign ? 1 : 0);
  948. }
  949. else if (ySign) yBits.push(yRem.isEven() ? 1 : 0);
  950. else yBits.push(yRem.isEven() ? 0 : 1);
  951. xRem = xRem.over(2);
  952. yRem = yRem.over(2);
  953. }
  954. var result = [];
  955. for (var i = 0; i < xBits.length; i++) result.push(fn(xBits[i], yBits[i]));
  956. var sum = bigInt(result.pop()).negate().times(bigInt(2).pow(result.length));
  957. while (result.length) {
  958. sum = sum.add(bigInt(result.pop()).times(bigInt(2).pow(result.length)));
  959. }
  960. return sum;
  961. }
  962. BigInteger.prototype.not = function () {
  963. return this.negate().prev();
  964. };
  965. SmallInteger.prototype.not = BigInteger.prototype.not;
  966. BigInteger.prototype.and = function (n) {
  967. return bitwise(this, n, function (a, b) { return a & b; });
  968. };
  969. SmallInteger.prototype.and = BigInteger.prototype.and;
  970. BigInteger.prototype.or = function (n) {
  971. return bitwise(this, n, function (a, b) { return a | b; });
  972. };
  973. SmallInteger.prototype.or = BigInteger.prototype.or;
  974. BigInteger.prototype.xor = function (n) {
  975. return bitwise(this, n, function (a, b) { return a ^ b; });
  976. };
  977. SmallInteger.prototype.xor = BigInteger.prototype.xor;
  978. var LOBMASK_I = 1 << 30, LOBMASK_BI = (BASE & -BASE) * (BASE & -BASE) | LOBMASK_I;
  979. function roughLOB(n) { // get lowestOneBit (rough)
  980. // SmallInteger: return Min(lowestOneBit(n), 1 << 30)
  981. // BigInteger: return Min(lowestOneBit(n), 1 << 14) [BASE=1e7]
  982. var v = n.value, x = typeof v === "number" ? v | LOBMASK_I : v[0] + v[1] * BASE | LOBMASK_BI;
  983. return x & -x;
  984. }
  985. function max(a, b) {
  986. a = parseValue(a);
  987. b = parseValue(b);
  988. return a.greater(b) ? a : b;
  989. }
  990. function min(a,b) {
  991. a = parseValue(a);
  992. b = parseValue(b);
  993. return a.lesser(b) ? a : b;
  994. }
  995. function gcd(a, b) {
  996. a = parseValue(a).abs();
  997. b = parseValue(b).abs();
  998. if (a.equals(b)) return a;
  999. if (a.isZero()) return b;
  1000. if (b.isZero()) return a;
  1001. var c = Integer[1], d, t;
  1002. while (a.isEven() && b.isEven()) {
  1003. d = Math.min(roughLOB(a), roughLOB(b));
  1004. a = a.divide(d);
  1005. b = b.divide(d);
  1006. c = c.multiply(d);
  1007. }
  1008. while (a.isEven()) {
  1009. a = a.divide(roughLOB(a));
  1010. }
  1011. do {
  1012. while (b.isEven()) {
  1013. b = b.divide(roughLOB(b));
  1014. }
  1015. if (a.greater(b)) {
  1016. t = b; b = a; a = t;
  1017. }
  1018. b = b.subtract(a);
  1019. } while (!b.isZero());
  1020. return c.isUnit() ? a : a.multiply(c);
  1021. }
  1022. function lcm(a, b) {
  1023. a = parseValue(a).abs();
  1024. b = parseValue(b).abs();
  1025. return a.divide(gcd(a, b)).multiply(b);
  1026. }
  1027. function randBetween(a, b) {
  1028. a = parseValue(a);
  1029. b = parseValue(b);
  1030. var low = min(a, b), high = max(a, b);
  1031. var range = high.subtract(low);
  1032. if (range.isSmall) return low.add(Math.round(Math.random() * range));
  1033. var length = range.value.length - 1;
  1034. var result = [], restricted = true;
  1035. for (var i = length; i >= 0; i--) {
  1036. var top = restricted ? range.value[i] : BASE;
  1037. var digit = truncate(Math.random() * top);
  1038. result.unshift(digit);
  1039. if (digit < top) restricted = false;
  1040. }
  1041. result = arrayToSmall(result);
  1042. return low.add(typeof result === "number" ? new SmallInteger(result) : new BigInteger(result, false));
  1043. }
  1044. var parseBase = function (text, base) {
  1045. var val = Integer[0], pow = Integer[1],
  1046. length = text.length;
  1047. if (2 <= base && base <= 36) {
  1048. if (length <= LOG_MAX_INT / Math.log(base)) {
  1049. return new SmallInteger(parseInt(text, base));
  1050. }
  1051. }
  1052. base = parseValue(base);
  1053. var digits = [];
  1054. var i;
  1055. var isNegative = text[0] === "-";
  1056. for (i = isNegative ? 1 : 0; i < text.length; i++) {
  1057. var c = text[i].toLowerCase(),
  1058. charCode = c.charCodeAt(0);
  1059. if (48 <= charCode && charCode <= 57) digits.push(parseValue(c));
  1060. else if (97 <= charCode && charCode <= 122) digits.push(parseValue(c.charCodeAt(0) - 87));
  1061. else if (c === "<") {
  1062. var start = i;
  1063. do { i++; } while (text[i] !== ">");
  1064. digits.push(parseValue(text.slice(start + 1, i)));
  1065. }
  1066. else throw new Error(c + " is not a valid character");
  1067. }
  1068. digits.reverse();
  1069. for (i = 0; i < digits.length; i++) {
  1070. val = val.add(digits[i].times(pow));
  1071. pow = pow.times(base);
  1072. }
  1073. return isNegative ? val.negate() : val;
  1074. };
  1075. function stringify(digit) {
  1076. var v = digit.value;
  1077. if (typeof v === "number") v = [v];
  1078. if (v.length === 1 && v[0] <= 35) {
  1079. return "0123456789abcdefghijklmnopqrstuvwxyz".charAt(v[0]);
  1080. }
  1081. return "<" + v + ">";
  1082. }
  1083. function toBase(n, base) {
  1084. base = bigInt(base);
  1085. if (base.isZero()) {
  1086. if (n.isZero()) return "0";
  1087. throw new Error("Cannot convert nonzero numbers to base 0.");
  1088. }
  1089. if (base.equals(-1)) {
  1090. if (n.isZero()) return "0";
  1091. if (n.isNegative()) return new Array(1 - n).join("10");
  1092. return "1" + new Array(+n).join("01");
  1093. }
  1094. var minusSign = "";
  1095. if (n.isNegative() && base.isPositive()) {
  1096. minusSign = "-";
  1097. n = n.abs();
  1098. }
  1099. if (base.equals(1)) {
  1100. if (n.isZero()) return "0";
  1101. return minusSign + new Array(+n + 1).join(1);
  1102. }
  1103. var out = [];
  1104. var left = n, divmod;
  1105. while (left.isNegative() || left.compareAbs(base) >= 0) {
  1106. divmod = left.divmod(base);
  1107. left = divmod.quotient;
  1108. var digit = divmod.remainder;
  1109. if (digit.isNegative()) {
  1110. digit = base.minus(digit).abs();
  1111. left = left.next();
  1112. }
  1113. out.push(stringify(digit));
  1114. }
  1115. out.push(stringify(left));
  1116. return minusSign + out.reverse().join("");
  1117. }
  1118. BigInteger.prototype.toString = function (radix) {
  1119. if (radix === undefined) radix = 10;
  1120. if (radix !== 10) return toBase(this, radix);
  1121. var v = this.value, l = v.length, str = String(v[--l]), zeros = "0000000", digit;
  1122. while (--l >= 0) {
  1123. digit = String(v[l]);
  1124. str += zeros.slice(digit.length) + digit;
  1125. }
  1126. var sign = this.sign ? "-" : "";
  1127. return sign + str;
  1128. };
  1129. SmallInteger.prototype.toString = function (radix) {
  1130. if (radix === undefined) radix = 10;
  1131. if (radix != 10) return toBase(this, radix);
  1132. return String(this.value);
  1133. };
  1134. BigInteger.prototype.valueOf = function () {
  1135. return +this.toString();
  1136. };
  1137. BigInteger.prototype.toJSNumber = BigInteger.prototype.valueOf;
  1138. SmallInteger.prototype.valueOf = function () {
  1139. return this.value;
  1140. };
  1141. SmallInteger.prototype.toJSNumber = SmallInteger.prototype.valueOf;
  1142. function parseStringValue(v) {
  1143. if (isPrecise(+v)) {
  1144. var x = +v;
  1145. if (x === truncate(x))
  1146. return new SmallInteger(x);
  1147. throw "Invalid integer: " + v;
  1148. }
  1149. var sign = v[0] === "-";
  1150. if (sign) v = v.slice(1);
  1151. var split = v.split(/e/i);
  1152. if (split.length > 2) throw new Error("Invalid integer: " + split.join("e"));
  1153. if (split.length === 2) {
  1154. var exp = split[1];
  1155. if (exp[0] === "+") exp = exp.slice(1);
  1156. exp = +exp;
  1157. if (exp !== truncate(exp) || !isPrecise(exp)) throw new Error("Invalid integer: " + exp + " is not a valid exponent.");
  1158. var text = split[0];
  1159. var decimalPlace = text.indexOf(".");
  1160. if (decimalPlace >= 0) {
  1161. exp -= text.length - decimalPlace - 1;
  1162. text = text.slice(0, decimalPlace) + text.slice(decimalPlace + 1);
  1163. }
  1164. if (exp < 0) throw new Error("Cannot include negative exponent part for integers");
  1165. text += (new Array(exp + 1)).join("0");
  1166. v = text;
  1167. }
  1168. var isValid = /^([0-9][0-9]*)$/.test(v);
  1169. if (!isValid) throw new Error("Invalid integer: " + v);
  1170. var r = [], max = v.length, l = LOG_BASE, min = max - l;
  1171. while (max > 0) {
  1172. r.push(+v.slice(min, max));
  1173. min -= l;
  1174. if (min < 0) min = 0;
  1175. max -= l;
  1176. }
  1177. trim(r);
  1178. return new BigInteger(r, sign);
  1179. }
  1180. function parseNumberValue(v) {
  1181. if (isPrecise(v)) {
  1182. if (v !== truncate(v)) throw new Error(v + " is not an integer.");
  1183. return new SmallInteger(v);
  1184. }
  1185. return parseStringValue(v.toString());
  1186. }
  1187. function parseValue(v) {
  1188. if (typeof v === "number") {
  1189. return parseNumberValue(v);
  1190. }
  1191. if (typeof v === "string") {
  1192. return parseStringValue(v);
  1193. }
  1194. return v;
  1195. }
  1196. // Pre-define numbers in range [-999,999]
  1197. for (var i = 0; i < 1000; i++) {
  1198. Integer[i] = new SmallInteger(i);
  1199. if (i > 0) Integer[-i] = new SmallInteger(-i);
  1200. }
  1201. // Backwards compatibility
  1202. Integer.one = Integer[1];
  1203. Integer.zero = Integer[0];
  1204. Integer.minusOne = Integer[-1];
  1205. Integer.max = max;
  1206. Integer.min = min;
  1207. Integer.gcd = gcd;
  1208. Integer.lcm = lcm;
  1209. Integer.isInstance = function (x) { return x instanceof BigInteger || x instanceof SmallInteger; };
  1210. Integer.randBetween = randBetween;
  1211. return Integer;
  1212. })();
  1213. // Node.js check
  1214. if (typeof module !== "undefined" && module.hasOwnProperty("exports")) {
  1215. module.exports = bigInt;
  1216. }
  1217. },{}],3:[function(require,module,exports){
  1218. },{}],4:[function(require,module,exports){
  1219. (function (global){
  1220. 'use strict';
  1221. var buffer = require('buffer');
  1222. var Buffer = buffer.Buffer;
  1223. var SlowBuffer = buffer.SlowBuffer;
  1224. var MAX_LEN = buffer.kMaxLength || 2147483647;
  1225. exports.alloc = function alloc(size, fill, encoding) {
  1226. if (typeof Buffer.alloc === 'function') {
  1227. return Buffer.alloc(size, fill, encoding);
  1228. }
  1229. if (typeof encoding === 'number') {
  1230. throw new TypeError('encoding must not be number');
  1231. }
  1232. if (typeof size !== 'number') {
  1233. throw new TypeError('size must be a number');
  1234. }
  1235. if (size > MAX_LEN) {
  1236. throw new RangeError('size is too large');
  1237. }
  1238. var enc = encoding;
  1239. var _fill = fill;
  1240. if (_fill === undefined) {
  1241. enc = undefined;
  1242. _fill = 0;
  1243. }
  1244. var buf = new Buffer(size);
  1245. if (typeof _fill === 'string') {
  1246. var fillBuf = new Buffer(_fill, enc);
  1247. var flen = fillBuf.length;
  1248. var i = -1;
  1249. while (++i < size) {
  1250. buf[i] = fillBuf[i % flen];
  1251. }
  1252. } else {
  1253. buf.fill(_fill);
  1254. }
  1255. return buf;
  1256. }
  1257. exports.allocUnsafe = function allocUnsafe(size) {
  1258. if (typeof Buffer.allocUnsafe === 'function') {
  1259. return Buffer.allocUnsafe(size);
  1260. }
  1261. if (typeof size !== 'number') {
  1262. throw new TypeError('size must be a number');
  1263. }
  1264. if (size > MAX_LEN) {
  1265. throw new RangeError('size is too large');
  1266. }
  1267. return new Buffer(size);
  1268. }
  1269. exports.from = function from(value, encodingOrOffset, length) {
  1270. if (typeof Buffer.from === 'function' && (!global.Uint8Array || Uint8Array.from !== Buffer.from)) {
  1271. return Buffer.from(value, encodingOrOffset, length);
  1272. }
  1273. if (typeof value === 'number') {
  1274. throw new TypeError('"value" argument must not be a number');
  1275. }
  1276. if (typeof value === 'string') {
  1277. return new Buffer(value, encodingOrOffset);
  1278. }
  1279. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  1280. var offset = encodingOrOffset;
  1281. if (arguments.length === 1) {
  1282. return new Buffer(value);
  1283. }
  1284. if (typeof offset === 'undefined') {
  1285. offset = 0;
  1286. }
  1287. var len = length;
  1288. if (typeof len === 'undefined') {
  1289. len = value.byteLength - offset;
  1290. }
  1291. if (offset >= value.byteLength) {
  1292. throw new RangeError('\'offset\' is out of bounds');
  1293. }
  1294. if (len > value.byteLength - offset) {
  1295. throw new RangeError('\'length\' is out of bounds');
  1296. }
  1297. return new Buffer(value.slice(offset, offset + len));
  1298. }
  1299. if (Buffer.isBuffer(value)) {
  1300. var out = new Buffer(value.length);
  1301. value.copy(out, 0, 0, value.length);
  1302. return out;
  1303. }
  1304. if (value) {
  1305. if (Array.isArray(value) || (typeof ArrayBuffer !== 'undefined' && value.buffer instanceof ArrayBuffer) || 'length' in value) {
  1306. return new Buffer(value);
  1307. }
  1308. if (value.type === 'Buffer' && Array.isArray(value.data)) {
  1309. return new Buffer(value.data);
  1310. }
  1311. }
  1312. throw new TypeError('First argument must be a string, Buffer, ' + 'ArrayBuffer, Array, or array-like object.');
  1313. }
  1314. exports.allocUnsafeSlow = function allocUnsafeSlow(size) {
  1315. if (typeof Buffer.allocUnsafeSlow === 'function') {
  1316. return Buffer.allocUnsafeSlow(size);
  1317. }
  1318. if (typeof size !== 'number') {
  1319. throw new TypeError('size must be a number');
  1320. }
  1321. if (size >= MAX_LEN) {
  1322. throw new RangeError('size is too large');
  1323. }
  1324. return new SlowBuffer(size);
  1325. }
  1326. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1327. },{"buffer":5}],5:[function(require,module,exports){
  1328. (function (global){
  1329. /*!
  1330. * The buffer module from node.js, for the browser.
  1331. *
  1332. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  1333. * @license MIT
  1334. */
  1335. /* eslint-disable no-proto */
  1336. 'use strict'
  1337. var base64 = require('base64-js')
  1338. var ieee754 = require('ieee754')
  1339. var isArray = require('isarray')
  1340. exports.Buffer = Buffer
  1341. exports.SlowBuffer = SlowBuffer
  1342. exports.INSPECT_MAX_BYTES = 50
  1343. /**
  1344. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  1345. * === true Use Uint8Array implementation (fastest)
  1346. * === false Use Object implementation (most compatible, even IE6)
  1347. *
  1348. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  1349. * Opera 11.6+, iOS 4.2+.
  1350. *
  1351. * Due to various browser bugs, sometimes the Object implementation will be used even
  1352. * when the browser supports typed arrays.
  1353. *
  1354. * Note:
  1355. *
  1356. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  1357. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  1358. *
  1359. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  1360. *
  1361. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  1362. * incorrect length in some situations.
  1363. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  1364. * get the Object implementation, which is slower but behaves correctly.
  1365. */
  1366. Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
  1367. ? global.TYPED_ARRAY_SUPPORT
  1368. : typedArraySupport()
  1369. /*
  1370. * Export kMaxLength after typed array support is determined.
  1371. */
  1372. exports.kMaxLength = kMaxLength()
  1373. function typedArraySupport () {
  1374. try {
  1375. var arr = new Uint8Array(1)
  1376. arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
  1377. return arr.foo() === 42 && // typed array instances can be augmented
  1378. typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
  1379. arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
  1380. } catch (e) {
  1381. return false
  1382. }
  1383. }
  1384. function kMaxLength () {
  1385. return Buffer.TYPED_ARRAY_SUPPORT
  1386. ? 0x7fffffff
  1387. : 0x3fffffff
  1388. }
  1389. function createBuffer (that, length) {
  1390. if (kMaxLength() < length) {
  1391. throw new RangeError('Invalid typed array length')
  1392. }
  1393. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1394. // Return an augmented `Uint8Array` instance, for best performance
  1395. that = new Uint8Array(length)
  1396. that.__proto__ = Buffer.prototype
  1397. } else {
  1398. // Fallback: Return an object instance of the Buffer class
  1399. if (that === null) {
  1400. that = new Buffer(length)
  1401. }
  1402. that.length = length
  1403. }
  1404. return that
  1405. }
  1406. /**
  1407. * The Buffer constructor returns instances of `Uint8Array` that have their
  1408. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  1409. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  1410. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  1411. * returns a single octet.
  1412. *
  1413. * The `Uint8Array` prototype remains unmodified.
  1414. */
  1415. function Buffer (arg, encodingOrOffset, length) {
  1416. if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
  1417. return new Buffer(arg, encodingOrOffset, length)
  1418. }
  1419. // Common case.
  1420. if (typeof arg === 'number') {
  1421. if (typeof encodingOrOffset === 'string') {
  1422. throw new Error(
  1423. 'If encoding is specified then the first argument must be a string'
  1424. )
  1425. }
  1426. return allocUnsafe(this, arg)
  1427. }
  1428. return from(this, arg, encodingOrOffset, length)
  1429. }
  1430. Buffer.poolSize = 8192 // not used by this implementation
  1431. // TODO: Legacy, not needed anymore. Remove in next major version.
  1432. Buffer._augment = function (arr) {
  1433. arr.__proto__ = Buffer.prototype
  1434. return arr
  1435. }
  1436. function from (that, value, encodingOrOffset, length) {
  1437. if (typeof value === 'number') {
  1438. throw new TypeError('"value" argument must not be a number')
  1439. }
  1440. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  1441. return fromArrayBuffer(that, value, encodingOrOffset, length)
  1442. }
  1443. if (typeof value === 'string') {
  1444. return fromString(that, value, encodingOrOffset)
  1445. }
  1446. return fromObject(that, value)
  1447. }
  1448. /**
  1449. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  1450. * if value is a number.
  1451. * Buffer.from(str[, encoding])
  1452. * Buffer.from(array)
  1453. * Buffer.from(buffer)
  1454. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  1455. **/
  1456. Buffer.from = function (value, encodingOrOffset, length) {
  1457. return from(null, value, encodingOrOffset, length)
  1458. }
  1459. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1460. Buffer.prototype.__proto__ = Uint8Array.prototype
  1461. Buffer.__proto__ = Uint8Array
  1462. if (typeof Symbol !== 'undefined' && Symbol.species &&
  1463. Buffer[Symbol.species] === Buffer) {
  1464. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  1465. Object.defineProperty(Buffer, Symbol.species, {
  1466. value: null,
  1467. configurable: true
  1468. })
  1469. }
  1470. }
  1471. function assertSize (size) {
  1472. if (typeof size !== 'number') {
  1473. throw new TypeError('"size" argument must be a number')
  1474. } else if (size < 0) {
  1475. throw new RangeError('"size" argument must not be negative')
  1476. }
  1477. }
  1478. function alloc (that, size, fill, encoding) {
  1479. assertSize(size)
  1480. if (size <= 0) {
  1481. return createBuffer(that, size)
  1482. }
  1483. if (fill !== undefined) {
  1484. // Only pay attention to encoding if it's a string. This
  1485. // prevents accidentally sending in a number that would
  1486. // be interpretted as a start offset.
  1487. return typeof encoding === 'string'
  1488. ? createBuffer(that, size).fill(fill, encoding)
  1489. : createBuffer(that, size).fill(fill)
  1490. }
  1491. return createBuffer(that, size)
  1492. }
  1493. /**
  1494. * Creates a new filled Buffer instance.
  1495. * alloc(size[, fill[, encoding]])
  1496. **/
  1497. Buffer.alloc = function (size, fill, encoding) {
  1498. return alloc(null, size, fill, encoding)
  1499. }
  1500. function allocUnsafe (that, size) {
  1501. assertSize(size)
  1502. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
  1503. if (!Buffer.TYPED_ARRAY_SUPPORT) {
  1504. for (var i = 0; i < size; ++i) {
  1505. that[i] = 0
  1506. }
  1507. }
  1508. return that
  1509. }
  1510. /**
  1511. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  1512. * */
  1513. Buffer.allocUnsafe = function (size) {
  1514. return allocUnsafe(null, size)
  1515. }
  1516. /**
  1517. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  1518. */
  1519. Buffer.allocUnsafeSlow = function (size) {
  1520. return allocUnsafe(null, size)
  1521. }
  1522. function fromString (that, string, encoding) {
  1523. if (typeof encoding !== 'string' || encoding === '') {
  1524. encoding = 'utf8'
  1525. }
  1526. if (!Buffer.isEncoding(encoding)) {
  1527. throw new TypeError('"encoding" must be a valid string encoding')
  1528. }
  1529. var length = byteLength(string, encoding) | 0
  1530. that = createBuffer(that, length)
  1531. var actual = that.write(string, encoding)
  1532. if (actual !== length) {
  1533. // Writing a hex string, for example, that contains invalid characters will
  1534. // cause everything after the first invalid character to be ignored. (e.g.
  1535. // 'abxxcd' will be treated as 'ab')
  1536. that = that.slice(0, actual)
  1537. }
  1538. return that
  1539. }
  1540. function fromArrayLike (that, array) {
  1541. var length = array.length < 0 ? 0 : checked(array.length) | 0
  1542. that = createBuffer(that, length)
  1543. for (var i = 0; i < length; i += 1) {
  1544. that[i] = array[i] & 255
  1545. }
  1546. return that
  1547. }
  1548. function fromArrayBuffer (that, array, byteOffset, length) {
  1549. array.byteLength // this throws if `array` is not a valid ArrayBuffer
  1550. if (byteOffset < 0 || array.byteLength < byteOffset) {
  1551. throw new RangeError('\'offset\' is out of bounds')
  1552. }
  1553. if (array.byteLength < byteOffset + (length || 0)) {
  1554. throw new RangeError('\'length\' is out of bounds')
  1555. }
  1556. if (byteOffset === undefined && length === undefined) {
  1557. array = new Uint8Array(array)
  1558. } else if (length === undefined) {
  1559. array = new Uint8Array(array, byteOffset)
  1560. } else {
  1561. array = new Uint8Array(array, byteOffset, length)
  1562. }
  1563. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1564. // Return an augmented `Uint8Array` instance, for best performance
  1565. that = array
  1566. that.__proto__ = Buffer.prototype
  1567. } else {
  1568. // Fallback: Return an object instance of the Buffer class
  1569. that = fromArrayLike(that, array)
  1570. }
  1571. return that
  1572. }
  1573. function fromObject (that, obj) {
  1574. if (Buffer.isBuffer(obj)) {
  1575. var len = checked(obj.length) | 0
  1576. that = createBuffer(that, len)
  1577. if (that.length === 0) {
  1578. return that
  1579. }
  1580. obj.copy(that, 0, 0, len)
  1581. return that
  1582. }
  1583. if (obj) {
  1584. if ((typeof ArrayBuffer !== 'undefined' &&
  1585. obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
  1586. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  1587. return createBuffer(that, 0)
  1588. }
  1589. return fromArrayLike(that, obj)
  1590. }
  1591. if (obj.type === 'Buffer' && isArray(obj.data)) {
  1592. return fromArrayLike(that, obj.data)
  1593. }
  1594. }
  1595. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  1596. }
  1597. function checked (length) {
  1598. // Note: cannot use `length < kMaxLength()` here because that fails when
  1599. // length is NaN (which is otherwise coerced to zero.)
  1600. if (length >= kMaxLength()) {
  1601. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  1602. 'size: 0x' + kMaxLength().toString(16) + ' bytes')
  1603. }
  1604. return length | 0
  1605. }
  1606. function SlowBuffer (length) {
  1607. if (+length != length) { // eslint-disable-line eqeqeq
  1608. length = 0
  1609. }
  1610. return Buffer.alloc(+length)
  1611. }
  1612. Buffer.isBuffer = function isBuffer (b) {
  1613. return !!(b != null && b._isBuffer)
  1614. }
  1615. Buffer.compare = function compare (a, b) {
  1616. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  1617. throw new TypeError('Arguments must be Buffers')
  1618. }
  1619. if (a === b) return 0
  1620. var x = a.length
  1621. var y = b.length
  1622. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  1623. if (a[i] !== b[i]) {
  1624. x = a[i]
  1625. y = b[i]
  1626. break
  1627. }
  1628. }
  1629. if (x < y) return -1
  1630. if (y < x) return 1
  1631. return 0
  1632. }
  1633. Buffer.isEncoding = function isEncoding (encoding) {
  1634. switch (String(encoding).toLowerCase()) {
  1635. case 'hex':
  1636. case 'utf8':
  1637. case 'utf-8':
  1638. case 'ascii':
  1639. case 'latin1':
  1640. case 'binary':
  1641. case 'base64':
  1642. case 'ucs2':
  1643. case 'ucs-2':
  1644. case 'utf16le':
  1645. case 'utf-16le':
  1646. return true
  1647. default:
  1648. return false
  1649. }
  1650. }
  1651. Buffer.concat = function concat (list, length) {
  1652. if (!isArray(list)) {
  1653. throw new TypeError('"list" argument must be an Array of Buffers')
  1654. }
  1655. if (list.length === 0) {
  1656. return Buffer.alloc(0)
  1657. }
  1658. var i
  1659. if (length === undefined) {
  1660. length = 0
  1661. for (i = 0; i < list.length; ++i) {
  1662. length += list[i].length
  1663. }
  1664. }
  1665. var buffer = Buffer.allocUnsafe(length)
  1666. var pos = 0
  1667. for (i = 0; i < list.length; ++i) {
  1668. var buf = list[i]
  1669. if (!Buffer.isBuffer(buf)) {
  1670. throw new TypeError('"list" argument must be an Array of Buffers')
  1671. }
  1672. buf.copy(buffer, pos)
  1673. pos += buf.length
  1674. }
  1675. return buffer
  1676. }
  1677. function byteLength (string, encoding) {
  1678. if (Buffer.isBuffer(string)) {
  1679. return string.length
  1680. }
  1681. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
  1682. (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  1683. return string.byteLength
  1684. }
  1685. if (typeof string !== 'string') {
  1686. string = '' + string
  1687. }
  1688. var len = string.length
  1689. if (len === 0) return 0
  1690. // Use a for loop to avoid recursion
  1691. var loweredCase = false
  1692. for (;;) {
  1693. switch (encoding) {
  1694. case 'ascii':
  1695. case 'latin1':
  1696. case 'binary':
  1697. return len
  1698. case 'utf8':
  1699. case 'utf-8':
  1700. case undefined:
  1701. return utf8ToBytes(string).length
  1702. case 'ucs2':
  1703. case 'ucs-2':
  1704. case 'utf16le':
  1705. case 'utf-16le':
  1706. return len * 2
  1707. case 'hex':
  1708. return len >>> 1
  1709. case 'base64':
  1710. return base64ToBytes(string).length
  1711. default:
  1712. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  1713. encoding = ('' + encoding).toLowerCase()
  1714. loweredCase = true
  1715. }
  1716. }
  1717. }
  1718. Buffer.byteLength = byteLength
  1719. function slowToString (encoding, start, end) {
  1720. var loweredCase = false
  1721. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  1722. // property of a typed array.
  1723. // This behaves neither like String nor Uint8Array in that we set start/end
  1724. // to their upper/lower bounds if the value passed is out of range.
  1725. // undefined is handled specially as per ECMA-262 6th Edition,
  1726. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  1727. if (start === undefined || start < 0) {
  1728. start = 0
  1729. }
  1730. // Return early if start > this.length. Done here to prevent potential uint32
  1731. // coercion fail below.
  1732. if (start > this.length) {
  1733. return ''
  1734. }
  1735. if (end === undefined || end > this.length) {
  1736. end = this.length
  1737. }
  1738. if (end <= 0) {
  1739. return ''
  1740. }
  1741. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  1742. end >>>= 0
  1743. start >>>= 0
  1744. if (end <= start) {
  1745. return ''
  1746. }
  1747. if (!encoding) encoding = 'utf8'
  1748. while (true) {
  1749. switch (encoding) {
  1750. case 'hex':
  1751. return hexSlice(this, start, end)
  1752. case 'utf8':
  1753. case 'utf-8':
  1754. return utf8Slice(this, start, end)
  1755. case 'ascii':
  1756. return asciiSlice(this, start, end)
  1757. case 'latin1':
  1758. case 'binary':
  1759. return latin1Slice(this, start, end)
  1760. case 'base64':
  1761. return base64Slice(this, start, end)
  1762. case 'ucs2':
  1763. case 'ucs-2':
  1764. case 'utf16le':
  1765. case 'utf-16le':
  1766. return utf16leSlice(this, start, end)
  1767. default:
  1768. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  1769. encoding = (encoding + '').toLowerCase()
  1770. loweredCase = true
  1771. }
  1772. }
  1773. }
  1774. // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  1775. // Buffer instances.
  1776. Buffer.prototype._isBuffer = true
  1777. function swap (b, n, m) {
  1778. var i = b[n]
  1779. b[n] = b[m]
  1780. b[m] = i
  1781. }
  1782. Buffer.prototype.swap16 = function swap16 () {
  1783. var len = this.length
  1784. if (len % 2 !== 0) {
  1785. throw new RangeError('Buffer size must be a multiple of 16-bits')
  1786. }
  1787. for (var i = 0; i < len; i += 2) {
  1788. swap(this, i, i + 1)
  1789. }
  1790. return this
  1791. }
  1792. Buffer.prototype.swap32 = function swap32 () {
  1793. var len = this.length
  1794. if (len % 4 !== 0) {
  1795. throw new RangeError('Buffer size must be a multiple of 32-bits')
  1796. }
  1797. for (var i = 0; i < len; i += 4) {
  1798. swap(this, i, i + 3)
  1799. swap(this, i + 1, i + 2)
  1800. }
  1801. return this
  1802. }
  1803. Buffer.prototype.swap64 = function swap64 () {
  1804. var len = this.length
  1805. if (len % 8 !== 0) {
  1806. throw new RangeError('Buffer size must be a multiple of 64-bits')
  1807. }
  1808. for (var i = 0; i < len; i += 8) {
  1809. swap(this, i, i + 7)
  1810. swap(this, i + 1, i + 6)
  1811. swap(this, i + 2, i + 5)
  1812. swap(this, i + 3, i + 4)
  1813. }
  1814. return this
  1815. }
  1816. Buffer.prototype.toString = function toString () {
  1817. var length = this.length | 0
  1818. if (length === 0) return ''
  1819. if (arguments.length === 0) return utf8Slice(this, 0, length)
  1820. return slowToString.apply(this, arguments)
  1821. }
  1822. Buffer.prototype.equals = function equals (b) {
  1823. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  1824. if (this === b) return true
  1825. return Buffer.compare(this, b) === 0
  1826. }
  1827. Buffer.prototype.inspect = function inspect () {
  1828. var str = ''
  1829. var max = exports.INSPECT_MAX_BYTES
  1830. if (this.length > 0) {
  1831. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
  1832. if (this.length > max) str += ' ... '
  1833. }
  1834. return '<Buffer ' + str + '>'
  1835. }
  1836. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  1837. if (!Buffer.isBuffer(target)) {
  1838. throw new TypeError('Argument must be a Buffer')
  1839. }
  1840. if (start === undefined) {
  1841. start = 0
  1842. }
  1843. if (end === undefined) {
  1844. end = target ? target.length : 0
  1845. }
  1846. if (thisStart === undefined) {
  1847. thisStart = 0
  1848. }
  1849. if (thisEnd === undefined) {
  1850. thisEnd = this.length
  1851. }
  1852. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  1853. throw new RangeError('out of range index')
  1854. }
  1855. if (thisStart >= thisEnd && start >= end) {
  1856. return 0
  1857. }
  1858. if (thisStart >= thisEnd) {
  1859. return -1
  1860. }
  1861. if (start >= end) {
  1862. return 1
  1863. }
  1864. start >>>= 0
  1865. end >>>= 0
  1866. thisStart >>>= 0
  1867. thisEnd >>>= 0
  1868. if (this === target) return 0
  1869. var x = thisEnd - thisStart
  1870. var y = end - start
  1871. var len = Math.min(x, y)
  1872. var thisCopy = this.slice(thisStart, thisEnd)
  1873. var targetCopy = target.slice(start, end)
  1874. for (var i = 0; i < len; ++i) {
  1875. if (thisCopy[i] !== targetCopy[i]) {
  1876. x = thisCopy[i]
  1877. y = targetCopy[i]
  1878. break
  1879. }
  1880. }
  1881. if (x < y) return -1
  1882. if (y < x) return 1
  1883. return 0
  1884. }
  1885. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  1886. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  1887. //
  1888. // Arguments:
  1889. // - buffer - a Buffer to search
  1890. // - val - a string, Buffer, or number
  1891. // - byteOffset - an index into `buffer`; will be clamped to an int32
  1892. // - encoding - an optional encoding, relevant is val is a string
  1893. // - dir - true for indexOf, false for lastIndexOf
  1894. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  1895. // Empty buffer means no match
  1896. if (buffer.length === 0) return -1
  1897. // Normalize byteOffset
  1898. if (typeof byteOffset === 'string') {
  1899. encoding = byteOffset
  1900. byteOffset = 0
  1901. } else if (byteOffset > 0x7fffffff) {
  1902. byteOffset = 0x7fffffff
  1903. } else if (byteOffset < -0x80000000) {
  1904. byteOffset = -0x80000000
  1905. }
  1906. byteOffset = +byteOffset // Coerce to Number.
  1907. if (isNaN(byteOffset)) {
  1908. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  1909. byteOffset = dir ? 0 : (buffer.length - 1)
  1910. }
  1911. // Normalize byteOffset: negative offsets start from the end of the buffer
  1912. if (byteOffset < 0) byteOffset = buffer.length + byteOffset
  1913. if (byteOffset >= buffer.length) {
  1914. if (dir) return -1
  1915. else byteOffset = buffer.length - 1
  1916. } else if (byteOffset < 0) {
  1917. if (dir) byteOffset = 0
  1918. else return -1
  1919. }
  1920. // Normalize val
  1921. if (typeof val === 'string') {
  1922. val = Buffer.from(val, encoding)
  1923. }
  1924. // Finally, search either indexOf (if dir is true) or lastIndexOf
  1925. if (Buffer.isBuffer(val)) {
  1926. // Special case: looking for empty string/buffer always fails
  1927. if (val.length === 0) {
  1928. return -1
  1929. }
  1930. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  1931. } else if (typeof val === 'number') {
  1932. val = val & 0xFF // Search for a byte value [0-255]
  1933. if (Buffer.TYPED_ARRAY_SUPPORT &&
  1934. typeof Uint8Array.prototype.indexOf === 'function') {
  1935. if (dir) {
  1936. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  1937. } else {
  1938. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  1939. }
  1940. }
  1941. return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
  1942. }
  1943. throw new TypeError('val must be string, number or Buffer')
  1944. }
  1945. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  1946. var indexSize = 1
  1947. var arrLength = arr.length
  1948. var valLength = val.length
  1949. if (encoding !== undefined) {
  1950. encoding = String(encoding).toLowerCase()
  1951. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  1952. encoding === 'utf16le' || encoding === 'utf-16le') {
  1953. if (arr.length < 2 || val.length < 2) {
  1954. return -1
  1955. }
  1956. indexSize = 2
  1957. arrLength /= 2
  1958. valLength /= 2
  1959. byteOffset /= 2
  1960. }
  1961. }
  1962. function read (buf, i) {
  1963. if (indexSize === 1) {
  1964. return buf[i]
  1965. } else {
  1966. return buf.readUInt16BE(i * indexSize)
  1967. }
  1968. }
  1969. var i
  1970. if (dir) {
  1971. var foundIndex = -1
  1972. for (i = byteOffset; i < arrLength; i++) {
  1973. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  1974. if (foundIndex === -1) foundIndex = i
  1975. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  1976. } else {
  1977. if (foundIndex !== -1) i -= i - foundIndex
  1978. foundIndex = -1
  1979. }
  1980. }
  1981. } else {
  1982. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
  1983. for (i = byteOffset; i >= 0; i--) {
  1984. var found = true
  1985. for (var j = 0; j < valLength; j++) {
  1986. if (read(arr, i + j) !== read(val, j)) {
  1987. found = false
  1988. break
  1989. }
  1990. }
  1991. if (found) return i
  1992. }
  1993. }
  1994. return -1
  1995. }
  1996. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  1997. return this.indexOf(val, byteOffset, encoding) !== -1
  1998. }
  1999. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  2000. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  2001. }
  2002. Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  2003. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  2004. }
  2005. function hexWrite (buf, string, offset, length) {
  2006. offset = Number(offset) || 0
  2007. var remaining = buf.length - offset
  2008. if (!length) {
  2009. length = remaining
  2010. } else {
  2011. length = Number(length)
  2012. if (length > remaining) {
  2013. length = remaining
  2014. }
  2015. }
  2016. // must be an even number of digits
  2017. var strLen = string.length
  2018. if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
  2019. if (length > strLen / 2) {
  2020. length = strLen / 2
  2021. }
  2022. for (var i = 0; i < length; ++i) {
  2023. var parsed = parseInt(string.substr(i * 2, 2), 16)
  2024. if (isNaN(parsed)) return i
  2025. buf[offset + i] = parsed
  2026. }
  2027. return i
  2028. }
  2029. function utf8Write (buf, string, offset, length) {
  2030. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  2031. }
  2032. function asciiWrite (buf, string, offset, length) {
  2033. return blitBuffer(asciiToBytes(string), buf, offset, length)
  2034. }
  2035. function latin1Write (buf, string, offset, length) {
  2036. return asciiWrite(buf, string, offset, length)
  2037. }
  2038. function base64Write (buf, string, offset, length) {
  2039. return blitBuffer(base64ToBytes(string), buf, offset, length)
  2040. }
  2041. function ucs2Write (buf, string, offset, length) {
  2042. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  2043. }
  2044. Buffer.prototype.write = function write (string, offset, length, encoding) {
  2045. // Buffer#write(string)
  2046. if (offset === undefined) {
  2047. encoding = 'utf8'
  2048. length = this.length
  2049. offset = 0
  2050. // Buffer#write(string, encoding)
  2051. } else if (length === undefined && typeof offset === 'string') {
  2052. encoding = offset
  2053. length = this.length
  2054. offset = 0
  2055. // Buffer#write(string, offset[, length][, encoding])
  2056. } else if (isFinite(offset)) {
  2057. offset = offset | 0
  2058. if (isFinite(length)) {
  2059. length = length | 0
  2060. if (encoding === undefined) encoding = 'utf8'
  2061. } else {
  2062. encoding = length
  2063. length = undefined
  2064. }
  2065. // legacy write(string, encoding, offset, length) - remove in v0.13
  2066. } else {
  2067. throw new Error(
  2068. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  2069. )
  2070. }
  2071. var remaining = this.length - offset
  2072. if (length === undefined || length > remaining) length = remaining
  2073. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  2074. throw new RangeError('Attempt to write outside buffer bounds')
  2075. }
  2076. if (!encoding) encoding = 'utf8'
  2077. var loweredCase = false
  2078. for (;;) {
  2079. switch (encoding) {
  2080. case 'hex':
  2081. return hexWrite(this, string, offset, length)
  2082. case 'utf8':
  2083. case 'utf-8':
  2084. return utf8Write(this, string, offset, length)
  2085. case 'ascii':
  2086. return asciiWrite(this, string, offset, length)
  2087. case 'latin1':
  2088. case 'binary':
  2089. return latin1Write(this, string, offset, length)
  2090. case 'base64':
  2091. // Warning: maxLength not taken into account in base64Write
  2092. return base64Write(this, string, offset, length)
  2093. case 'ucs2':
  2094. case 'ucs-2':
  2095. case 'utf16le':
  2096. case 'utf-16le':
  2097. return ucs2Write(this, string, offset, length)
  2098. default:
  2099. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  2100. encoding = ('' + encoding).toLowerCase()
  2101. loweredCase = true
  2102. }
  2103. }
  2104. }
  2105. Buffer.prototype.toJSON = function toJSON () {
  2106. return {
  2107. type: 'Buffer',
  2108. data: Array.prototype.slice.call(this._arr || this, 0)
  2109. }
  2110. }
  2111. function base64Slice (buf, start, end) {
  2112. if (start === 0 && end === buf.length) {
  2113. return base64.fromByteArray(buf)
  2114. } else {
  2115. return base64.fromByteArray(buf.slice(start, end))
  2116. }
  2117. }
  2118. function utf8Slice (buf, start, end) {
  2119. end = Math.min(buf.length, end)
  2120. var res = []
  2121. var i = start
  2122. while (i < end) {
  2123. var firstByte = buf[i]
  2124. var codePoint = null
  2125. var bytesPerSequence = (firstByte > 0xEF) ? 4
  2126. : (firstByte > 0xDF) ? 3
  2127. : (firstByte > 0xBF) ? 2
  2128. : 1
  2129. if (i + bytesPerSequence <= end) {
  2130. var secondByte, thirdByte, fourthByte, tempCodePoint
  2131. switch (bytesPerSequence) {
  2132. case 1:
  2133. if (firstByte < 0x80) {
  2134. codePoint = firstByte
  2135. }
  2136. break
  2137. case 2:
  2138. secondByte = buf[i + 1]
  2139. if ((secondByte & 0xC0) === 0x80) {
  2140. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  2141. if (tempCodePoint > 0x7F) {
  2142. codePoint = tempCodePoint
  2143. }
  2144. }
  2145. break
  2146. case 3:
  2147. secondByte = buf[i + 1]
  2148. thirdByte = buf[i + 2]
  2149. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  2150. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  2151. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  2152. codePoint = tempCodePoint
  2153. }
  2154. }
  2155. break
  2156. case 4:
  2157. secondByte = buf[i + 1]
  2158. thirdByte = buf[i + 2]
  2159. fourthByte = buf[i + 3]
  2160. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  2161. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  2162. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  2163. codePoint = tempCodePoint
  2164. }
  2165. }
  2166. }
  2167. }
  2168. if (codePoint === null) {
  2169. // we did not generate a valid codePoint so insert a
  2170. // replacement char (U+FFFD) and advance only 1 byte
  2171. codePoint = 0xFFFD
  2172. bytesPerSequence = 1
  2173. } else if (codePoint > 0xFFFF) {
  2174. // encode to utf16 (surrogate pair dance)
  2175. codePoint -= 0x10000
  2176. res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  2177. codePoint = 0xDC00 | codePoint & 0x3FF
  2178. }
  2179. res.push(codePoint)
  2180. i += bytesPerSequence
  2181. }
  2182. return decodeCodePointsArray(res)
  2183. }
  2184. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  2185. // the lowest limit is Chrome, with 0x10000 args.
  2186. // We go 1 magnitude less, for safety
  2187. var MAX_ARGUMENTS_LENGTH = 0x1000
  2188. function decodeCodePointsArray (codePoints) {
  2189. var len = codePoints.length
  2190. if (len <= MAX_ARGUMENTS_LENGTH) {
  2191. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  2192. }
  2193. // Decode in chunks to avoid "call stack size exceeded".
  2194. var res = ''
  2195. var i = 0
  2196. while (i < len) {
  2197. res += String.fromCharCode.apply(
  2198. String,
  2199. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  2200. )
  2201. }
  2202. return res
  2203. }
  2204. function asciiSlice (buf, start, end) {
  2205. var ret = ''
  2206. end = Math.min(buf.length, end)
  2207. for (var i = start; i < end; ++i) {
  2208. ret += String.fromCharCode(buf[i] & 0x7F)
  2209. }
  2210. return ret
  2211. }
  2212. function latin1Slice (buf, start, end) {
  2213. var ret = ''
  2214. end = Math.min(buf.length, end)
  2215. for (var i = start; i < end; ++i) {
  2216. ret += String.fromCharCode(buf[i])
  2217. }
  2218. return ret
  2219. }
  2220. function hexSlice (buf, start, end) {
  2221. var len = buf.length
  2222. if (!start || start < 0) start = 0
  2223. if (!end || end < 0 || end > len) end = len
  2224. var out = ''
  2225. for (var i = start; i < end; ++i) {
  2226. out += toHex(buf[i])
  2227. }
  2228. return out
  2229. }
  2230. function utf16leSlice (buf, start, end) {
  2231. var bytes = buf.slice(start, end)
  2232. var res = ''
  2233. for (var i = 0; i < bytes.length; i += 2) {
  2234. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
  2235. }
  2236. return res
  2237. }
  2238. Buffer.prototype.slice = function slice (start, end) {
  2239. var len = this.length
  2240. start = ~~start
  2241. end = end === undefined ? len : ~~end
  2242. if (start < 0) {
  2243. start += len
  2244. if (start < 0) start = 0
  2245. } else if (start > len) {
  2246. start = len
  2247. }
  2248. if (end < 0) {
  2249. end += len
  2250. if (end < 0) end = 0
  2251. } else if (end > len) {
  2252. end = len
  2253. }
  2254. if (end < start) end = start
  2255. var newBuf
  2256. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2257. newBuf = this.subarray(start, end)
  2258. newBuf.__proto__ = Buffer.prototype
  2259. } else {
  2260. var sliceLen = end - start
  2261. newBuf = new Buffer(sliceLen, undefined)
  2262. for (var i = 0; i < sliceLen; ++i) {
  2263. newBuf[i] = this[i + start]
  2264. }
  2265. }
  2266. return newBuf
  2267. }
  2268. /*
  2269. * Need to make sure that buffer isn't trying to write out of bounds.
  2270. */
  2271. function checkOffset (offset, ext, length) {
  2272. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  2273. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  2274. }
  2275. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  2276. offset = offset | 0
  2277. byteLength = byteLength | 0
  2278. if (!noAssert) checkOffset(offset, byteLength, this.length)
  2279. var val = this[offset]
  2280. var mul = 1
  2281. var i = 0
  2282. while (++i < byteLength && (mul *= 0x100)) {
  2283. val += this[offset + i] * mul
  2284. }
  2285. return val
  2286. }
  2287. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  2288. offset = offset | 0
  2289. byteLength = byteLength | 0
  2290. if (!noAssert) {
  2291. checkOffset(offset, byteLength, this.length)
  2292. }
  2293. var val = this[offset + --byteLength]
  2294. var mul = 1
  2295. while (byteLength > 0 && (mul *= 0x100)) {
  2296. val += this[offset + --byteLength] * mul
  2297. }
  2298. return val
  2299. }
  2300. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  2301. if (!noAssert) checkOffset(offset, 1, this.length)
  2302. return this[offset]
  2303. }
  2304. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  2305. if (!noAssert) checkOffset(offset, 2, this.length)
  2306. return this[offset] | (this[offset + 1] << 8)
  2307. }
  2308. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  2309. if (!noAssert) checkOffset(offset, 2, this.length)
  2310. return (this[offset] << 8) | this[offset + 1]
  2311. }
  2312. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  2313. if (!noAssert) checkOffset(offset, 4, this.length)
  2314. return ((this[offset]) |
  2315. (this[offset + 1] << 8) |
  2316. (this[offset + 2] << 16)) +
  2317. (this[offset + 3] * 0x1000000)
  2318. }
  2319. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  2320. if (!noAssert) checkOffset(offset, 4, this.length)
  2321. return (this[offset] * 0x1000000) +
  2322. ((this[offset + 1] << 16) |
  2323. (this[offset + 2] << 8) |
  2324. this[offset + 3])
  2325. }
  2326. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  2327. offset = offset | 0
  2328. byteLength = byteLength | 0
  2329. if (!noAssert) checkOffset(offset, byteLength, this.length)
  2330. var val = this[offset]
  2331. var mul = 1
  2332. var i = 0
  2333. while (++i < byteLength && (mul *= 0x100)) {
  2334. val += this[offset + i] * mul
  2335. }
  2336. mul *= 0x80
  2337. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  2338. return val
  2339. }
  2340. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  2341. offset = offset | 0
  2342. byteLength = byteLength | 0
  2343. if (!noAssert) checkOffset(offset, byteLength, this.length)
  2344. var i = byteLength
  2345. var mul = 1
  2346. var val = this[offset + --i]
  2347. while (i > 0 && (mul *= 0x100)) {
  2348. val += this[offset + --i] * mul
  2349. }
  2350. mul *= 0x80
  2351. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  2352. return val
  2353. }
  2354. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  2355. if (!noAssert) checkOffset(offset, 1, this.length)
  2356. if (!(this[offset] & 0x80)) return (this[offset])
  2357. return ((0xff - this[offset] + 1) * -1)
  2358. }
  2359. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  2360. if (!noAssert) checkOffset(offset, 2, this.length)
  2361. var val = this[offset] | (this[offset + 1] << 8)
  2362. return (val & 0x8000) ? val | 0xFFFF0000 : val
  2363. }
  2364. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  2365. if (!noAssert) checkOffset(offset, 2, this.length)
  2366. var val = this[offset + 1] | (this[offset] << 8)
  2367. return (val & 0x8000) ? val | 0xFFFF0000 : val
  2368. }
  2369. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  2370. if (!noAssert) checkOffset(offset, 4, this.length)
  2371. return (this[offset]) |
  2372. (this[offset + 1] << 8) |
  2373. (this[offset + 2] << 16) |
  2374. (this[offset + 3] << 24)
  2375. }
  2376. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  2377. if (!noAssert) checkOffset(offset, 4, this.length)
  2378. return (this[offset] << 24) |
  2379. (this[offset + 1] << 16) |
  2380. (this[offset + 2] << 8) |
  2381. (this[offset + 3])
  2382. }
  2383. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  2384. if (!noAssert) checkOffset(offset, 4, this.length)
  2385. return ieee754.read(this, offset, true, 23, 4)
  2386. }
  2387. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  2388. if (!noAssert) checkOffset(offset, 4, this.length)
  2389. return ieee754.read(this, offset, false, 23, 4)
  2390. }
  2391. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  2392. if (!noAssert) checkOffset(offset, 8, this.length)
  2393. return ieee754.read(this, offset, true, 52, 8)
  2394. }
  2395. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  2396. if (!noAssert) checkOffset(offset, 8, this.length)
  2397. return ieee754.read(this, offset, false, 52, 8)
  2398. }
  2399. function checkInt (buf, value, offset, ext, max, min) {
  2400. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  2401. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  2402. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  2403. }
  2404. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  2405. value = +value
  2406. offset = offset | 0
  2407. byteLength = byteLength | 0
  2408. if (!noAssert) {
  2409. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  2410. checkInt(this, value, offset, byteLength, maxBytes, 0)
  2411. }
  2412. var mul = 1
  2413. var i = 0
  2414. this[offset] = value & 0xFF
  2415. while (++i < byteLength && (mul *= 0x100)) {
  2416. this[offset + i] = (value / mul) & 0xFF
  2417. }
  2418. return offset + byteLength
  2419. }
  2420. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  2421. value = +value
  2422. offset = offset | 0
  2423. byteLength = byteLength | 0
  2424. if (!noAssert) {
  2425. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  2426. checkInt(this, value, offset, byteLength, maxBytes, 0)
  2427. }
  2428. var i = byteLength - 1
  2429. var mul = 1
  2430. this[offset + i] = value & 0xFF
  2431. while (--i >= 0 && (mul *= 0x100)) {
  2432. this[offset + i] = (value / mul) & 0xFF
  2433. }
  2434. return offset + byteLength
  2435. }
  2436. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  2437. value = +value
  2438. offset = offset | 0
  2439. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  2440. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  2441. this[offset] = (value & 0xff)
  2442. return offset + 1
  2443. }
  2444. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  2445. if (value < 0) value = 0xffff + value + 1
  2446. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
  2447. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  2448. (littleEndian ? i : 1 - i) * 8
  2449. }
  2450. }
  2451. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  2452. value = +value
  2453. offset = offset | 0
  2454. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  2455. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2456. this[offset] = (value & 0xff)
  2457. this[offset + 1] = (value >>> 8)
  2458. } else {
  2459. objectWriteUInt16(this, value, offset, true)
  2460. }
  2461. return offset + 2
  2462. }
  2463. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  2464. value = +value
  2465. offset = offset | 0
  2466. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  2467. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2468. this[offset] = (value >>> 8)
  2469. this[offset + 1] = (value & 0xff)
  2470. } else {
  2471. objectWriteUInt16(this, value, offset, false)
  2472. }
  2473. return offset + 2
  2474. }
  2475. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  2476. if (value < 0) value = 0xffffffff + value + 1
  2477. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
  2478. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
  2479. }
  2480. }
  2481. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  2482. value = +value
  2483. offset = offset | 0
  2484. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  2485. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2486. this[offset + 3] = (value >>> 24)
  2487. this[offset + 2] = (value >>> 16)
  2488. this[offset + 1] = (value >>> 8)
  2489. this[offset] = (value & 0xff)
  2490. } else {
  2491. objectWriteUInt32(this, value, offset, true)
  2492. }
  2493. return offset + 4
  2494. }
  2495. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  2496. value = +value
  2497. offset = offset | 0
  2498. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  2499. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2500. this[offset] = (value >>> 24)
  2501. this[offset + 1] = (value >>> 16)
  2502. this[offset + 2] = (value >>> 8)
  2503. this[offset + 3] = (value & 0xff)
  2504. } else {
  2505. objectWriteUInt32(this, value, offset, false)
  2506. }
  2507. return offset + 4
  2508. }
  2509. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  2510. value = +value
  2511. offset = offset | 0
  2512. if (!noAssert) {
  2513. var limit = Math.pow(2, 8 * byteLength - 1)
  2514. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  2515. }
  2516. var i = 0
  2517. var mul = 1
  2518. var sub = 0
  2519. this[offset] = value & 0xFF
  2520. while (++i < byteLength && (mul *= 0x100)) {
  2521. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  2522. sub = 1
  2523. }
  2524. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  2525. }
  2526. return offset + byteLength
  2527. }
  2528. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  2529. value = +value
  2530. offset = offset | 0
  2531. if (!noAssert) {
  2532. var limit = Math.pow(2, 8 * byteLength - 1)
  2533. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  2534. }
  2535. var i = byteLength - 1
  2536. var mul = 1
  2537. var sub = 0
  2538. this[offset + i] = value & 0xFF
  2539. while (--i >= 0 && (mul *= 0x100)) {
  2540. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  2541. sub = 1
  2542. }
  2543. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  2544. }
  2545. return offset + byteLength
  2546. }
  2547. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  2548. value = +value
  2549. offset = offset | 0
  2550. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  2551. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  2552. if (value < 0) value = 0xff + value + 1
  2553. this[offset] = (value & 0xff)
  2554. return offset + 1
  2555. }
  2556. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  2557. value = +value
  2558. offset = offset | 0
  2559. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  2560. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2561. this[offset] = (value & 0xff)
  2562. this[offset + 1] = (value >>> 8)
  2563. } else {
  2564. objectWriteUInt16(this, value, offset, true)
  2565. }
  2566. return offset + 2
  2567. }
  2568. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  2569. value = +value
  2570. offset = offset | 0
  2571. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  2572. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2573. this[offset] = (value >>> 8)
  2574. this[offset + 1] = (value & 0xff)
  2575. } else {
  2576. objectWriteUInt16(this, value, offset, false)
  2577. }
  2578. return offset + 2
  2579. }
  2580. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  2581. value = +value
  2582. offset = offset | 0
  2583. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  2584. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2585. this[offset] = (value & 0xff)
  2586. this[offset + 1] = (value >>> 8)
  2587. this[offset + 2] = (value >>> 16)
  2588. this[offset + 3] = (value >>> 24)
  2589. } else {
  2590. objectWriteUInt32(this, value, offset, true)
  2591. }
  2592. return offset + 4
  2593. }
  2594. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  2595. value = +value
  2596. offset = offset | 0
  2597. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  2598. if (value < 0) value = 0xffffffff + value + 1
  2599. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2600. this[offset] = (value >>> 24)
  2601. this[offset + 1] = (value >>> 16)
  2602. this[offset + 2] = (value >>> 8)
  2603. this[offset + 3] = (value & 0xff)
  2604. } else {
  2605. objectWriteUInt32(this, value, offset, false)
  2606. }
  2607. return offset + 4
  2608. }
  2609. function checkIEEE754 (buf, value, offset, ext, max, min) {
  2610. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  2611. if (offset < 0) throw new RangeError('Index out of range')
  2612. }
  2613. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  2614. if (!noAssert) {
  2615. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  2616. }
  2617. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  2618. return offset + 4
  2619. }
  2620. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  2621. return writeFloat(this, value, offset, true, noAssert)
  2622. }
  2623. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  2624. return writeFloat(this, value, offset, false, noAssert)
  2625. }
  2626. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  2627. if (!noAssert) {
  2628. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  2629. }
  2630. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  2631. return offset + 8
  2632. }
  2633. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  2634. return writeDouble(this, value, offset, true, noAssert)
  2635. }
  2636. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  2637. return writeDouble(this, value, offset, false, noAssert)
  2638. }
  2639. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  2640. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  2641. if (!start) start = 0
  2642. if (!end && end !== 0) end = this.length
  2643. if (targetStart >= target.length) targetStart = target.length
  2644. if (!targetStart) targetStart = 0
  2645. if (end > 0 && end < start) end = start
  2646. // Copy 0 bytes; we're done
  2647. if (end === start) return 0
  2648. if (target.length === 0 || this.length === 0) return 0
  2649. // Fatal error conditions
  2650. if (targetStart < 0) {
  2651. throw new RangeError('targetStart out of bounds')
  2652. }
  2653. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  2654. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  2655. // Are we oob?
  2656. if (end > this.length) end = this.length
  2657. if (target.length - targetStart < end - start) {
  2658. end = target.length - targetStart + start
  2659. }
  2660. var len = end - start
  2661. var i
  2662. if (this === target && start < targetStart && targetStart < end) {
  2663. // descending copy from end
  2664. for (i = len - 1; i >= 0; --i) {
  2665. target[i + targetStart] = this[i + start]
  2666. }
  2667. } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
  2668. // ascending copy from start
  2669. for (i = 0; i < len; ++i) {
  2670. target[i + targetStart] = this[i + start]
  2671. }
  2672. } else {
  2673. Uint8Array.prototype.set.call(
  2674. target,
  2675. this.subarray(start, start + len),
  2676. targetStart
  2677. )
  2678. }
  2679. return len
  2680. }
  2681. // Usage:
  2682. // buffer.fill(number[, offset[, end]])
  2683. // buffer.fill(buffer[, offset[, end]])
  2684. // buffer.fill(string[, offset[, end]][, encoding])
  2685. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  2686. // Handle string cases:
  2687. if (typeof val === 'string') {
  2688. if (typeof start === 'string') {
  2689. encoding = start
  2690. start = 0
  2691. end = this.length
  2692. } else if (typeof end === 'string') {
  2693. encoding = end
  2694. end = this.length
  2695. }
  2696. if (val.length === 1) {
  2697. var code = val.charCodeAt(0)
  2698. if (code < 256) {
  2699. val = code
  2700. }
  2701. }
  2702. if (encoding !== undefined && typeof encoding !== 'string') {
  2703. throw new TypeError('encoding must be a string')
  2704. }
  2705. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  2706. throw new TypeError('Unknown encoding: ' + encoding)
  2707. }
  2708. } else if (typeof val === 'number') {
  2709. val = val & 255
  2710. }
  2711. // Invalid ranges are not set to a default, so can range check early.
  2712. if (start < 0 || this.length < start || this.length < end) {
  2713. throw new RangeError('Out of range index')
  2714. }
  2715. if (end <= start) {
  2716. return this
  2717. }
  2718. start = start >>> 0
  2719. end = end === undefined ? this.length : end >>> 0
  2720. if (!val) val = 0
  2721. var i
  2722. if (typeof val === 'number') {
  2723. for (i = start; i < end; ++i) {
  2724. this[i] = val
  2725. }
  2726. } else {
  2727. var bytes = Buffer.isBuffer(val)
  2728. ? val
  2729. : utf8ToBytes(new Buffer(val, encoding).toString())
  2730. var len = bytes.length
  2731. for (i = 0; i < end - start; ++i) {
  2732. this[i + start] = bytes[i % len]
  2733. }
  2734. }
  2735. return this
  2736. }
  2737. // HELPER FUNCTIONS
  2738. // ================
  2739. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
  2740. function base64clean (str) {
  2741. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  2742. str = stringtrim(str).replace(INVALID_BASE64_RE, '')
  2743. // Node converts strings with length < 2 to ''
  2744. if (str.length < 2) return ''
  2745. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  2746. while (str.length % 4 !== 0) {
  2747. str = str + '='
  2748. }
  2749. return str
  2750. }
  2751. function stringtrim (str) {
  2752. if (str.trim) return str.trim()
  2753. return str.replace(/^\s+|\s+$/g, '')
  2754. }
  2755. function toHex (n) {
  2756. if (n < 16) return '0' + n.toString(16)
  2757. return n.toString(16)
  2758. }
  2759. function utf8ToBytes (string, units) {
  2760. units = units || Infinity
  2761. var codePoint
  2762. var length = string.length
  2763. var leadSurrogate = null
  2764. var bytes = []
  2765. for (var i = 0; i < length; ++i) {
  2766. codePoint = string.charCodeAt(i)
  2767. // is surrogate component
  2768. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  2769. // last char was a lead
  2770. if (!leadSurrogate) {
  2771. // no lead yet
  2772. if (codePoint > 0xDBFF) {
  2773. // unexpected trail
  2774. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  2775. continue
  2776. } else if (i + 1 === length) {
  2777. // unpaired lead
  2778. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  2779. continue
  2780. }
  2781. // valid lead
  2782. leadSurrogate = codePoint
  2783. continue
  2784. }
  2785. // 2 leads in a row
  2786. if (codePoint < 0xDC00) {
  2787. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  2788. leadSurrogate = codePoint
  2789. continue
  2790. }
  2791. // valid surrogate pair
  2792. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  2793. } else if (leadSurrogate) {
  2794. // valid bmp char, but last char was a lead
  2795. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  2796. }
  2797. leadSurrogate = null
  2798. // encode utf8
  2799. if (codePoint < 0x80) {
  2800. if ((units -= 1) < 0) break
  2801. bytes.push(codePoint)
  2802. } else if (codePoint < 0x800) {
  2803. if ((units -= 2) < 0) break
  2804. bytes.push(
  2805. codePoint >> 0x6 | 0xC0,
  2806. codePoint & 0x3F | 0x80
  2807. )
  2808. } else if (codePoint < 0x10000) {
  2809. if ((units -= 3) < 0) break
  2810. bytes.push(
  2811. codePoint >> 0xC | 0xE0,
  2812. codePoint >> 0x6 & 0x3F | 0x80,
  2813. codePoint & 0x3F | 0x80
  2814. )
  2815. } else if (codePoint < 0x110000) {
  2816. if ((units -= 4) < 0) break
  2817. bytes.push(
  2818. codePoint >> 0x12 | 0xF0,
  2819. codePoint >> 0xC & 0x3F | 0x80,
  2820. codePoint >> 0x6 & 0x3F | 0x80,
  2821. codePoint & 0x3F | 0x80
  2822. )
  2823. } else {
  2824. throw new Error('Invalid code point')
  2825. }
  2826. }
  2827. return bytes
  2828. }
  2829. function asciiToBytes (str) {
  2830. var byteArray = []
  2831. for (var i = 0; i < str.length; ++i) {
  2832. // Node's code seems to be doing this and not & 0x7F..
  2833. byteArray.push(str.charCodeAt(i) & 0xFF)
  2834. }
  2835. return byteArray
  2836. }
  2837. function utf16leToBytes (str, units) {
  2838. var c, hi, lo
  2839. var byteArray = []
  2840. for (var i = 0; i < str.length; ++i) {
  2841. if ((units -= 2) < 0) break
  2842. c = str.charCodeAt(i)
  2843. hi = c >> 8
  2844. lo = c % 256
  2845. byteArray.push(lo)
  2846. byteArray.push(hi)
  2847. }
  2848. return byteArray
  2849. }
  2850. function base64ToBytes (str) {
  2851. return base64.toByteArray(base64clean(str))
  2852. }
  2853. function blitBuffer (src, dst, offset, length) {
  2854. for (var i = 0; i < length; ++i) {
  2855. if ((i + offset >= dst.length) || (i >= src.length)) break
  2856. dst[i + offset] = src[i]
  2857. }
  2858. return i
  2859. }
  2860. function isnan (val) {
  2861. return val !== val // eslint-disable-line no-self-compare
  2862. }
  2863. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2864. },{"base64-js":1,"ieee754":13,"isarray":16}],6:[function(require,module,exports){
  2865. (function (Buffer){
  2866. var Transform = require('stream').Transform
  2867. var inherits = require('inherits')
  2868. var StringDecoder = require('string_decoder').StringDecoder
  2869. module.exports = CipherBase
  2870. inherits(CipherBase, Transform)
  2871. function CipherBase (hashMode) {
  2872. Transform.call(this)
  2873. this.hashMode = typeof hashMode === 'string'
  2874. if (this.hashMode) {
  2875. this[hashMode] = this._finalOrDigest
  2876. } else {
  2877. this.final = this._finalOrDigest
  2878. }
  2879. this._decoder = null
  2880. this._encoding = null
  2881. }
  2882. CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
  2883. if (typeof data === 'string') {
  2884. data = new Buffer(data, inputEnc)
  2885. }
  2886. var outData = this._update(data)
  2887. if (this.hashMode) {
  2888. return this
  2889. }
  2890. if (outputEnc) {
  2891. outData = this._toString(outData, outputEnc)
  2892. }
  2893. return outData
  2894. }
  2895. CipherBase.prototype.setAutoPadding = function () {}
  2896. CipherBase.prototype.getAuthTag = function () {
  2897. throw new Error('trying to get auth tag in unsupported state')
  2898. }
  2899. CipherBase.prototype.setAuthTag = function () {
  2900. throw new Error('trying to set auth tag in unsupported state')
  2901. }
  2902. CipherBase.prototype.setAAD = function () {
  2903. throw new Error('trying to set aad in unsupported state')
  2904. }
  2905. CipherBase.prototype._transform = function (data, _, next) {
  2906. var err
  2907. try {
  2908. if (this.hashMode) {
  2909. this._update(data)
  2910. } else {
  2911. this.push(this._update(data))
  2912. }
  2913. } catch (e) {
  2914. err = e
  2915. } finally {
  2916. next(err)
  2917. }
  2918. }
  2919. CipherBase.prototype._flush = function (done) {
  2920. var err
  2921. try {
  2922. this.push(this._final())
  2923. } catch (e) {
  2924. err = e
  2925. } finally {
  2926. done(err)
  2927. }
  2928. }
  2929. CipherBase.prototype._finalOrDigest = function (outputEnc) {
  2930. var outData = this._final() || new Buffer('')
  2931. if (outputEnc) {
  2932. outData = this._toString(outData, outputEnc, true)
  2933. }
  2934. return outData
  2935. }
  2936. CipherBase.prototype._toString = function (value, enc, fin) {
  2937. if (!this._decoder) {
  2938. this._decoder = new StringDecoder(enc)
  2939. this._encoding = enc
  2940. }
  2941. if (this._encoding !== enc) {
  2942. throw new Error('can\'t switch encodings')
  2943. }
  2944. var out = this._decoder.write(value)
  2945. if (fin) {
  2946. out += this._decoder.end()
  2947. }
  2948. return out
  2949. }
  2950. }).call(this,require("buffer").Buffer)
  2951. },{"buffer":5,"inherits":14,"stream":44,"string_decoder":45}],7:[function(require,module,exports){
  2952. (function (Buffer){
  2953. // Copyright Joyent, Inc. and other Node contributors.
  2954. //
  2955. // Permission is hereby granted, free of charge, to any person obtaining a
  2956. // copy of this software and associated documentation files (the
  2957. // "Software"), to deal in the Software without restriction, including
  2958. // without limitation the rights to use, copy, modify, merge, publish,
  2959. // distribute, sublicense, and/or sell copies of the Software, and to permit
  2960. // persons to whom the Software is furnished to do so, subject to the
  2961. // following conditions:
  2962. //
  2963. // The above copyright notice and this permission notice shall be included
  2964. // in all copies or substantial portions of the Software.
  2965. //
  2966. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2967. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2968. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  2969. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  2970. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  2971. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  2972. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  2973. // NOTE: These type checking functions intentionally don't use `instanceof`
  2974. // because it is fragile and can be easily faked with `Object.create()`.
  2975. function isArray(arg) {
  2976. if (Array.isArray) {
  2977. return Array.isArray(arg);
  2978. }
  2979. return objectToString(arg) === '[object Array]';
  2980. }
  2981. exports.isArray = isArray;
  2982. function isBoolean(arg) {
  2983. return typeof arg === 'boolean';
  2984. }
  2985. exports.isBoolean = isBoolean;
  2986. function isNull(arg) {
  2987. return arg === null;
  2988. }
  2989. exports.isNull = isNull;
  2990. function isNullOrUndefined(arg) {
  2991. return arg == null;
  2992. }
  2993. exports.isNullOrUndefined = isNullOrUndefined;
  2994. function isNumber(arg) {
  2995. return typeof arg === 'number';
  2996. }
  2997. exports.isNumber = isNumber;
  2998. function isString(arg) {
  2999. return typeof arg === 'string';
  3000. }
  3001. exports.isString = isString;
  3002. function isSymbol(arg) {
  3003. return typeof arg === 'symbol';
  3004. }
  3005. exports.isSymbol = isSymbol;
  3006. function isUndefined(arg) {
  3007. return arg === void 0;
  3008. }
  3009. exports.isUndefined = isUndefined;
  3010. function isRegExp(re) {
  3011. return objectToString(re) === '[object RegExp]';
  3012. }
  3013. exports.isRegExp = isRegExp;
  3014. function isObject(arg) {
  3015. return typeof arg === 'object' && arg !== null;
  3016. }
  3017. exports.isObject = isObject;
  3018. function isDate(d) {
  3019. return objectToString(d) === '[object Date]';
  3020. }
  3021. exports.isDate = isDate;
  3022. function isError(e) {
  3023. return (objectToString(e) === '[object Error]' || e instanceof Error);
  3024. }
  3025. exports.isError = isError;
  3026. function isFunction(arg) {
  3027. return typeof arg === 'function';
  3028. }
  3029. exports.isFunction = isFunction;
  3030. function isPrimitive(arg) {
  3031. return arg === null ||
  3032. typeof arg === 'boolean' ||
  3033. typeof arg === 'number' ||
  3034. typeof arg === 'string' ||
  3035. typeof arg === 'symbol' || // ES6 symbol
  3036. typeof arg === 'undefined';
  3037. }
  3038. exports.isPrimitive = isPrimitive;
  3039. exports.isBuffer = Buffer.isBuffer;
  3040. function objectToString(o) {
  3041. return Object.prototype.toString.call(o);
  3042. }
  3043. }).call(this,{"isBuffer":require("../../is-buffer/index.js")})
  3044. },{"../../is-buffer/index.js":15}],8:[function(require,module,exports){
  3045. (function (Buffer){
  3046. 'use strict';
  3047. var inherits = require('inherits')
  3048. var md5 = require('./md5')
  3049. var rmd160 = require('ripemd160')
  3050. var sha = require('sha.js')
  3051. var Base = require('cipher-base')
  3052. function HashNoConstructor(hash) {
  3053. Base.call(this, 'digest')
  3054. this._hash = hash
  3055. this.buffers = []
  3056. }
  3057. inherits(HashNoConstructor, Base)
  3058. HashNoConstructor.prototype._update = function (data) {
  3059. this.buffers.push(data)
  3060. }
  3061. HashNoConstructor.prototype._final = function () {
  3062. var buf = Buffer.concat(this.buffers)
  3063. var r = this._hash(buf)
  3064. this.buffers = null
  3065. return r
  3066. }
  3067. function Hash(hash) {
  3068. Base.call(this, 'digest')
  3069. this._hash = hash
  3070. }
  3071. inherits(Hash, Base)
  3072. Hash.prototype._update = function (data) {
  3073. this._hash.update(data)
  3074. }
  3075. Hash.prototype._final = function () {
  3076. return this._hash.digest()
  3077. }
  3078. module.exports = function createHash (alg) {
  3079. alg = alg.toLowerCase()
  3080. if ('md5' === alg) return new HashNoConstructor(md5)
  3081. if ('rmd160' === alg || 'ripemd160' === alg) return new HashNoConstructor(rmd160)
  3082. return new Hash(sha(alg))
  3083. }
  3084. }).call(this,require("buffer").Buffer)
  3085. },{"./md5":10,"buffer":5,"cipher-base":6,"inherits":14,"ripemd160":35,"sha.js":37}],9:[function(require,module,exports){
  3086. (function (Buffer){
  3087. 'use strict';
  3088. var intSize = 4;
  3089. var zeroBuffer = new Buffer(intSize); zeroBuffer.fill(0);
  3090. var chrsz = 8;
  3091. function toArray(buf, bigEndian) {
  3092. if ((buf.length % intSize) !== 0) {
  3093. var len = buf.length + (intSize - (buf.length % intSize));
  3094. buf = Buffer.concat([buf, zeroBuffer], len);
  3095. }
  3096. var arr = [];
  3097. var fn = bigEndian ? buf.readInt32BE : buf.readInt32LE;
  3098. for (var i = 0; i < buf.length; i += intSize) {
  3099. arr.push(fn.call(buf, i));
  3100. }
  3101. return arr;
  3102. }
  3103. function toBuffer(arr, size, bigEndian) {
  3104. var buf = new Buffer(size);
  3105. var fn = bigEndian ? buf.writeInt32BE : buf.writeInt32LE;
  3106. for (var i = 0; i < arr.length; i++) {
  3107. fn.call(buf, arr[i], i * 4, true);
  3108. }
  3109. return buf;
  3110. }
  3111. function hash(buf, fn, hashSize, bigEndian) {
  3112. if (!Buffer.isBuffer(buf)) buf = new Buffer(buf);
  3113. var arr = fn(toArray(buf, bigEndian), buf.length * chrsz);
  3114. return toBuffer(arr, hashSize, bigEndian);
  3115. }
  3116. exports.hash = hash;
  3117. }).call(this,require("buffer").Buffer)
  3118. },{"buffer":5}],10:[function(require,module,exports){
  3119. 'use strict';
  3120. /*
  3121. * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
  3122. * Digest Algorithm, as defined in RFC 1321.
  3123. * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
  3124. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  3125. * Distributed under the BSD License
  3126. * See http://pajhome.org.uk/crypt/md5 for more info.
  3127. */
  3128. var helpers = require('./helpers');
  3129. /*
  3130. * Calculate the MD5 of an array of little-endian words, and a bit length
  3131. */
  3132. function core_md5(x, len)
  3133. {
  3134. /* append padding */
  3135. x[len >> 5] |= 0x80 << ((len) % 32);
  3136. x[(((len + 64) >>> 9) << 4) + 14] = len;
  3137. var a = 1732584193;
  3138. var b = -271733879;
  3139. var c = -1732584194;
  3140. var d = 271733878;
  3141. for(var i = 0; i < x.length; i += 16)
  3142. {
  3143. var olda = a;
  3144. var oldb = b;
  3145. var oldc = c;
  3146. var oldd = d;
  3147. a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
  3148. d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
  3149. c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
  3150. b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
  3151. a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
  3152. d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
  3153. c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
  3154. b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
  3155. a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
  3156. d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
  3157. c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
  3158. b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
  3159. a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
  3160. d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
  3161. c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
  3162. b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
  3163. a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
  3164. d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
  3165. c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
  3166. b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
  3167. a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
  3168. d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
  3169. c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
  3170. b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
  3171. a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
  3172. d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
  3173. c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
  3174. b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
  3175. a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
  3176. d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
  3177. c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
  3178. b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
  3179. a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
  3180. d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
  3181. c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
  3182. b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
  3183. a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
  3184. d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
  3185. c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
  3186. b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
  3187. a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
  3188. d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
  3189. c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
  3190. b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
  3191. a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
  3192. d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
  3193. c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
  3194. b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
  3195. a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
  3196. d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
  3197. c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
  3198. b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
  3199. a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
  3200. d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
  3201. c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
  3202. b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
  3203. a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
  3204. d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
  3205. c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
  3206. b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
  3207. a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
  3208. d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
  3209. c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
  3210. b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
  3211. a = safe_add(a, olda);
  3212. b = safe_add(b, oldb);
  3213. c = safe_add(c, oldc);
  3214. d = safe_add(d, oldd);
  3215. }
  3216. return Array(a, b, c, d);
  3217. }
  3218. /*
  3219. * These functions implement the four basic operations the algorithm uses.
  3220. */
  3221. function md5_cmn(q, a, b, x, s, t)
  3222. {
  3223. return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
  3224. }
  3225. function md5_ff(a, b, c, d, x, s, t)
  3226. {
  3227. return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
  3228. }
  3229. function md5_gg(a, b, c, d, x, s, t)
  3230. {
  3231. return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
  3232. }
  3233. function md5_hh(a, b, c, d, x, s, t)
  3234. {
  3235. return md5_cmn(b ^ c ^ d, a, b, x, s, t);
  3236. }
  3237. function md5_ii(a, b, c, d, x, s, t)
  3238. {
  3239. return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
  3240. }
  3241. /*
  3242. * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  3243. * to work around bugs in some JS interpreters.
  3244. */
  3245. function safe_add(x, y)
  3246. {
  3247. var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  3248. var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  3249. return (msw << 16) | (lsw & 0xFFFF);
  3250. }
  3251. /*
  3252. * Bitwise rotate a 32-bit number to the left.
  3253. */
  3254. function bit_rol(num, cnt)
  3255. {
  3256. return (num << cnt) | (num >>> (32 - cnt));
  3257. }
  3258. module.exports = function md5(buf) {
  3259. return helpers.hash(buf, core_md5, 16);
  3260. };
  3261. },{"./helpers":9}],11:[function(require,module,exports){
  3262. (function (Buffer){
  3263. 'use strict';
  3264. var createHash = require('create-hash/browser');
  3265. var inherits = require('inherits')
  3266. var Transform = require('stream').Transform
  3267. var ZEROS = new Buffer(128)
  3268. ZEROS.fill(0)
  3269. function Hmac(alg, key) {
  3270. Transform.call(this)
  3271. alg = alg.toLowerCase()
  3272. if (typeof key === 'string') {
  3273. key = new Buffer(key)
  3274. }
  3275. var blocksize = (alg === 'sha512' || alg === 'sha384') ? 128 : 64
  3276. this._alg = alg
  3277. this._key = key
  3278. if (key.length > blocksize) {
  3279. key = createHash(alg).update(key).digest()
  3280. } else if (key.length < blocksize) {
  3281. key = Buffer.concat([key, ZEROS], blocksize)
  3282. }
  3283. var ipad = this._ipad = new Buffer(blocksize)
  3284. var opad = this._opad = new Buffer(blocksize)
  3285. for (var i = 0; i < blocksize; i++) {
  3286. ipad[i] = key[i] ^ 0x36
  3287. opad[i] = key[i] ^ 0x5C
  3288. }
  3289. this._hash = createHash(alg).update(ipad)
  3290. }
  3291. inherits(Hmac, Transform)
  3292. Hmac.prototype.update = function (data, enc) {
  3293. this._hash.update(data, enc)
  3294. return this
  3295. }
  3296. Hmac.prototype._transform = function (data, _, next) {
  3297. this._hash.update(data)
  3298. next()
  3299. }
  3300. Hmac.prototype._flush = function (next) {
  3301. this.push(this.digest())
  3302. next()
  3303. }
  3304. Hmac.prototype.digest = function (enc) {
  3305. var h = this._hash.digest()
  3306. return createHash(this._alg).update(this._opad).update(h).digest(enc)
  3307. }
  3308. module.exports = function createHmac(alg, key) {
  3309. return new Hmac(alg, key)
  3310. }
  3311. }).call(this,require("buffer").Buffer)
  3312. },{"buffer":5,"create-hash/browser":8,"inherits":14,"stream":44}],12:[function(require,module,exports){
  3313. // Copyright Joyent, Inc. and other Node contributors.
  3314. //
  3315. // Permission is hereby granted, free of charge, to any person obtaining a
  3316. // copy of this software and associated documentation files (the
  3317. // "Software"), to deal in the Software without restriction, including
  3318. // without limitation the rights to use, copy, modify, merge, publish,
  3319. // distribute, sublicense, and/or sell copies of the Software, and to permit
  3320. // persons to whom the Software is furnished to do so, subject to the
  3321. // following conditions:
  3322. //
  3323. // The above copyright notice and this permission notice shall be included
  3324. // in all copies or substantial portions of the Software.
  3325. //
  3326. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  3327. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3328. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  3329. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  3330. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  3331. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  3332. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  3333. function EventEmitter() {
  3334. this._events = this._events || {};
  3335. this._maxListeners = this._maxListeners || undefined;
  3336. }
  3337. module.exports = EventEmitter;
  3338. // Backwards-compat with node 0.10.x
  3339. EventEmitter.EventEmitter = EventEmitter;
  3340. EventEmitter.prototype._events = undefined;
  3341. EventEmitter.prototype._maxListeners = undefined;
  3342. // By default EventEmitters will print a warning if more than 10 listeners are
  3343. // added to it. This is a useful default which helps finding memory leaks.
  3344. EventEmitter.defaultMaxListeners = 10;
  3345. // Obviously not all Emitters should be limited to 10. This function allows
  3346. // that to be increased. Set to zero for unlimited.
  3347. EventEmitter.prototype.setMaxListeners = function(n) {
  3348. if (!isNumber(n) || n < 0 || isNaN(n))
  3349. throw TypeError('n must be a positive number');
  3350. this._maxListeners = n;
  3351. return this;
  3352. };
  3353. EventEmitter.prototype.emit = function(type) {
  3354. var er, handler, len, args, i, listeners;
  3355. if (!this._events)
  3356. this._events = {};
  3357. // If there is no 'error' event listener then throw.
  3358. if (type === 'error') {
  3359. if (!this._events.error ||
  3360. (isObject(this._events.error) && !this._events.error.length)) {
  3361. er = arguments[1];
  3362. if (er instanceof Error) {
  3363. throw er; // Unhandled 'error' event
  3364. } else {
  3365. // At least give some kind of context to the user
  3366. var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
  3367. err.context = er;
  3368. throw err;
  3369. }
  3370. }
  3371. }
  3372. handler = this._events[type];
  3373. if (isUndefined(handler))
  3374. return false;
  3375. if (isFunction(handler)) {
  3376. switch (arguments.length) {
  3377. // fast cases
  3378. case 1:
  3379. handler.call(this);
  3380. break;
  3381. case 2:
  3382. handler.call(this, arguments[1]);
  3383. break;
  3384. case 3:
  3385. handler.call(this, arguments[1], arguments[2]);
  3386. break;
  3387. // slower
  3388. default:
  3389. args = Array.prototype.slice.call(arguments, 1);
  3390. handler.apply(this, args);
  3391. }
  3392. } else if (isObject(handler)) {
  3393. args = Array.prototype.slice.call(arguments, 1);
  3394. listeners = handler.slice();
  3395. len = listeners.length;
  3396. for (i = 0; i < len; i++)
  3397. listeners[i].apply(this, args);
  3398. }
  3399. return true;
  3400. };
  3401. EventEmitter.prototype.addListener = function(type, listener) {
  3402. var m;
  3403. if (!isFunction(listener))
  3404. throw TypeError('listener must be a function');
  3405. if (!this._events)
  3406. this._events = {};
  3407. // To avoid recursion in the case that type === "newListener"! Before
  3408. // adding it to the listeners, first emit "newListener".
  3409. if (this._events.newListener)
  3410. this.emit('newListener', type,
  3411. isFunction(listener.listener) ?
  3412. listener.listener : listener);
  3413. if (!this._events[type])
  3414. // Optimize the case of one listener. Don't need the extra array object.
  3415. this._events[type] = listener;
  3416. else if (isObject(this._events[type]))
  3417. // If we've already got an array, just append.
  3418. this._events[type].push(listener);
  3419. else
  3420. // Adding the second element, need to change to array.
  3421. this._events[type] = [this._events[type], listener];
  3422. // Check for listener leak
  3423. if (isObject(this._events[type]) && !this._events[type].warned) {
  3424. if (!isUndefined(this._maxListeners)) {
  3425. m = this._maxListeners;
  3426. } else {
  3427. m = EventEmitter.defaultMaxListeners;
  3428. }
  3429. if (m && m > 0 && this._events[type].length > m) {
  3430. this._events[type].warned = true;
  3431. console.error('(node) warning: possible EventEmitter memory ' +
  3432. 'leak detected. %d listeners added. ' +
  3433. 'Use emitter.setMaxListeners() to increase limit.',
  3434. this._events[type].length);
  3435. if (typeof console.trace === 'function') {
  3436. // not supported in IE 10
  3437. console.trace();
  3438. }
  3439. }
  3440. }
  3441. return this;
  3442. };
  3443. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  3444. EventEmitter.prototype.once = function(type, listener) {
  3445. if (!isFunction(listener))
  3446. throw TypeError('listener must be a function');
  3447. var fired = false;
  3448. function g() {
  3449. this.removeListener(type, g);
  3450. if (!fired) {
  3451. fired = true;
  3452. listener.apply(this, arguments);
  3453. }
  3454. }
  3455. g.listener = listener;
  3456. this.on(type, g);
  3457. return this;
  3458. };
  3459. // emits a 'removeListener' event iff the listener was removed
  3460. EventEmitter.prototype.removeListener = function(type, listener) {
  3461. var list, position, length, i;
  3462. if (!isFunction(listener))
  3463. throw TypeError('listener must be a function');
  3464. if (!this._events || !this._events[type])
  3465. return this;
  3466. list = this._events[type];
  3467. length = list.length;
  3468. position = -1;
  3469. if (list === listener ||
  3470. (isFunction(list.listener) && list.listener === listener)) {
  3471. delete this._events[type];
  3472. if (this._events.removeListener)
  3473. this.emit('removeListener', type, listener);
  3474. } else if (isObject(list)) {
  3475. for (i = length; i-- > 0;) {
  3476. if (list[i] === listener ||
  3477. (list[i].listener && list[i].listener === listener)) {
  3478. position = i;
  3479. break;
  3480. }
  3481. }
  3482. if (position < 0)
  3483. return this;
  3484. if (list.length === 1) {
  3485. list.length = 0;
  3486. delete this._events[type];
  3487. } else {
  3488. list.splice(position, 1);
  3489. }
  3490. if (this._events.removeListener)
  3491. this.emit('removeListener', type, listener);
  3492. }
  3493. return this;
  3494. };
  3495. EventEmitter.prototype.removeAllListeners = function(type) {
  3496. var key, listeners;
  3497. if (!this._events)
  3498. return this;
  3499. // not listening for removeListener, no need to emit
  3500. if (!this._events.removeListener) {
  3501. if (arguments.length === 0)
  3502. this._events = {};
  3503. else if (this._events[type])
  3504. delete this._events[type];
  3505. return this;
  3506. }
  3507. // emit removeListener for all listeners on all events
  3508. if (arguments.length === 0) {
  3509. for (key in this._events) {
  3510. if (key === 'removeListener') continue;
  3511. this.removeAllListeners(key);
  3512. }
  3513. this.removeAllListeners('removeListener');
  3514. this._events = {};
  3515. return this;
  3516. }
  3517. listeners = this._events[type];
  3518. if (isFunction(listeners)) {
  3519. this.removeListener(type, listeners);
  3520. } else if (listeners) {
  3521. // LIFO order
  3522. while (listeners.length)
  3523. this.removeListener(type, listeners[listeners.length - 1]);
  3524. }
  3525. delete this._events[type];
  3526. return this;
  3527. };
  3528. EventEmitter.prototype.listeners = function(type) {
  3529. var ret;
  3530. if (!this._events || !this._events[type])
  3531. ret = [];
  3532. else if (isFunction(this._events[type]))
  3533. ret = [this._events[type]];
  3534. else
  3535. ret = this._events[type].slice();
  3536. return ret;
  3537. };
  3538. EventEmitter.prototype.listenerCount = function(type) {
  3539. if (this._events) {
  3540. var evlistener = this._events[type];
  3541. if (isFunction(evlistener))
  3542. return 1;
  3543. else if (evlistener)
  3544. return evlistener.length;
  3545. }
  3546. return 0;
  3547. };
  3548. EventEmitter.listenerCount = function(emitter, type) {
  3549. return emitter.listenerCount(type);
  3550. };
  3551. function isFunction(arg) {
  3552. return typeof arg === 'function';
  3553. }
  3554. function isNumber(arg) {
  3555. return typeof arg === 'number';
  3556. }
  3557. function isObject(arg) {
  3558. return typeof arg === 'object' && arg !== null;
  3559. }
  3560. function isUndefined(arg) {
  3561. return arg === void 0;
  3562. }
  3563. },{}],13:[function(require,module,exports){
  3564. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  3565. var e, m
  3566. var eLen = nBytes * 8 - mLen - 1
  3567. var eMax = (1 << eLen) - 1
  3568. var eBias = eMax >> 1
  3569. var nBits = -7
  3570. var i = isLE ? (nBytes - 1) : 0
  3571. var d = isLE ? -1 : 1
  3572. var s = buffer[offset + i]
  3573. i += d
  3574. e = s & ((1 << (-nBits)) - 1)
  3575. s >>= (-nBits)
  3576. nBits += eLen
  3577. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  3578. m = e & ((1 << (-nBits)) - 1)
  3579. e >>= (-nBits)
  3580. nBits += mLen
  3581. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  3582. if (e === 0) {
  3583. e = 1 - eBias
  3584. } else if (e === eMax) {
  3585. return m ? NaN : ((s ? -1 : 1) * Infinity)
  3586. } else {
  3587. m = m + Math.pow(2, mLen)
  3588. e = e - eBias
  3589. }
  3590. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  3591. }
  3592. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  3593. var e, m, c
  3594. var eLen = nBytes * 8 - mLen - 1
  3595. var eMax = (1 << eLen) - 1
  3596. var eBias = eMax >> 1
  3597. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  3598. var i = isLE ? 0 : (nBytes - 1)
  3599. var d = isLE ? 1 : -1
  3600. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  3601. value = Math.abs(value)
  3602. if (isNaN(value) || value === Infinity) {
  3603. m = isNaN(value) ? 1 : 0
  3604. e = eMax
  3605. } else {
  3606. e = Math.floor(Math.log(value) / Math.LN2)
  3607. if (value * (c = Math.pow(2, -e)) < 1) {
  3608. e--
  3609. c *= 2
  3610. }
  3611. if (e + eBias >= 1) {
  3612. value += rt / c
  3613. } else {
  3614. value += rt * Math.pow(2, 1 - eBias)
  3615. }
  3616. if (value * c >= 2) {
  3617. e++
  3618. c /= 2
  3619. }
  3620. if (e + eBias >= eMax) {
  3621. m = 0
  3622. e = eMax
  3623. } else if (e + eBias >= 1) {
  3624. m = (value * c - 1) * Math.pow(2, mLen)
  3625. e = e + eBias
  3626. } else {
  3627. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  3628. e = 0
  3629. }
  3630. }
  3631. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  3632. e = (e << mLen) | m
  3633. eLen += mLen
  3634. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  3635. buffer[offset + i - d] |= s * 128
  3636. }
  3637. },{}],14:[function(require,module,exports){
  3638. if (typeof Object.create === 'function') {
  3639. // implementation from standard node.js 'util' module
  3640. module.exports = function inherits(ctor, superCtor) {
  3641. ctor.super_ = superCtor
  3642. ctor.prototype = Object.create(superCtor.prototype, {
  3643. constructor: {
  3644. value: ctor,
  3645. enumerable: false,
  3646. writable: true,
  3647. configurable: true
  3648. }
  3649. });
  3650. };
  3651. } else {
  3652. // old school shim for old browsers
  3653. module.exports = function inherits(ctor, superCtor) {
  3654. ctor.super_ = superCtor
  3655. var TempCtor = function () {}
  3656. TempCtor.prototype = superCtor.prototype
  3657. ctor.prototype = new TempCtor()
  3658. ctor.prototype.constructor = ctor
  3659. }
  3660. }
  3661. },{}],15:[function(require,module,exports){
  3662. /*!
  3663. * Determine if an object is a Buffer
  3664. *
  3665. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  3666. * @license MIT
  3667. */
  3668. // The _isBuffer check is for Safari 5-7 support, because it's missing
  3669. // Object.prototype.constructor. Remove this eventually
  3670. module.exports = function (obj) {
  3671. return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
  3672. }
  3673. function isBuffer (obj) {
  3674. return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
  3675. }
  3676. // For Node v0.10 support. Remove this eventually.
  3677. function isSlowBuffer (obj) {
  3678. return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
  3679. }
  3680. },{}],16:[function(require,module,exports){
  3681. var toString = {}.toString;
  3682. module.exports = Array.isArray || function (arr) {
  3683. return toString.call(arr) == '[object Array]';
  3684. };
  3685. },{}],17:[function(require,module,exports){
  3686. 'use strict';
  3687. /* eslint-disable no-unused-vars */
  3688. var hasOwnProperty = Object.prototype.hasOwnProperty;
  3689. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  3690. function toObject(val) {
  3691. if (val === null || val === undefined) {
  3692. throw new TypeError('Object.assign cannot be called with null or undefined');
  3693. }
  3694. return Object(val);
  3695. }
  3696. function shouldUseNative() {
  3697. try {
  3698. if (!Object.assign) {
  3699. return false;
  3700. }
  3701. // Detect buggy property enumeration order in older V8 versions.
  3702. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  3703. var test1 = new String('abc'); // eslint-disable-line
  3704. test1[5] = 'de';
  3705. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  3706. return false;
  3707. }
  3708. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  3709. var test2 = {};
  3710. for (var i = 0; i < 10; i++) {
  3711. test2['_' + String.fromCharCode(i)] = i;
  3712. }
  3713. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  3714. return test2[n];
  3715. });
  3716. if (order2.join('') !== '0123456789') {
  3717. return false;
  3718. }
  3719. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  3720. var test3 = {};
  3721. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  3722. test3[letter] = letter;
  3723. });
  3724. if (Object.keys(Object.assign({}, test3)).join('') !==
  3725. 'abcdefghijklmnopqrst') {
  3726. return false;
  3727. }
  3728. return true;
  3729. } catch (e) {
  3730. // We don't expect any of the above to throw, but better to be safe.
  3731. return false;
  3732. }
  3733. }
  3734. module.exports = shouldUseNative() ? Object.assign : function (target, source) {
  3735. var from;
  3736. var to = toObject(target);
  3737. var symbols;
  3738. for (var s = 1; s < arguments.length; s++) {
  3739. from = Object(arguments[s]);
  3740. for (var key in from) {
  3741. if (hasOwnProperty.call(from, key)) {
  3742. to[key] = from[key];
  3743. }
  3744. }
  3745. if (Object.getOwnPropertySymbols) {
  3746. symbols = Object.getOwnPropertySymbols(from);
  3747. for (var i = 0; i < symbols.length; i++) {
  3748. if (propIsEnumerable.call(from, symbols[i])) {
  3749. to[symbols[i]] = from[symbols[i]];
  3750. }
  3751. }
  3752. }
  3753. }
  3754. return to;
  3755. };
  3756. },{}],18:[function(require,module,exports){
  3757. (function (process,Buffer){
  3758. var createHmac = require('create-hmac')
  3759. var checkParameters = require('./precondition')
  3760. exports.pbkdf2 = function (password, salt, iterations, keylen, digest, callback) {
  3761. if (typeof digest === 'function') {
  3762. callback = digest
  3763. digest = undefined
  3764. }
  3765. checkParameters(iterations, keylen)
  3766. if (typeof callback !== 'function') throw new Error('No callback provided to pbkdf2')
  3767. setTimeout(function () {
  3768. callback(null, exports.pbkdf2Sync(password, salt, iterations, keylen, digest))
  3769. })
  3770. }
  3771. var defaultEncoding
  3772. if (process.browser) {
  3773. defaultEncoding = 'utf-8'
  3774. } else {
  3775. var pVersionMajor = parseInt(process.version.split('.')[0].slice(1), 10)
  3776. defaultEncoding = pVersionMajor >= 6 ? 'utf-8' : 'binary'
  3777. }
  3778. exports.pbkdf2Sync = function (password, salt, iterations, keylen, digest) {
  3779. if (!Buffer.isBuffer(password)) password = new Buffer(password, defaultEncoding)
  3780. if (!Buffer.isBuffer(salt)) salt = new Buffer(salt, defaultEncoding)
  3781. checkParameters(iterations, keylen)
  3782. digest = digest || 'sha1'
  3783. var hLen
  3784. var l = 1
  3785. var DK = new Buffer(keylen)
  3786. var block1 = new Buffer(salt.length + 4)
  3787. salt.copy(block1, 0, 0, salt.length)
  3788. var r
  3789. var T
  3790. for (var i = 1; i <= l; i++) {
  3791. block1.writeUInt32BE(i, salt.length)
  3792. var U = createHmac(digest, password).update(block1).digest()
  3793. if (!hLen) {
  3794. hLen = U.length
  3795. T = new Buffer(hLen)
  3796. l = Math.ceil(keylen / hLen)
  3797. r = keylen - (l - 1) * hLen
  3798. }
  3799. U.copy(T, 0, 0, hLen)
  3800. for (var j = 1; j < iterations; j++) {
  3801. U = createHmac(digest, password).update(U).digest()
  3802. for (var k = 0; k < hLen; k++) T[k] ^= U[k]
  3803. }
  3804. var destPos = (i - 1) * hLen
  3805. var len = (i === l ? r : hLen)
  3806. T.copy(DK, destPos, 0, len)
  3807. }
  3808. return DK
  3809. }
  3810. }).call(this,require('_process'),require("buffer").Buffer)
  3811. },{"./precondition":19,"_process":23,"buffer":5,"create-hmac":11}],19:[function(require,module,exports){
  3812. var MAX_ALLOC = Math.pow(2, 30) - 1 // default in iojs
  3813. module.exports = function (iterations, keylen) {
  3814. if (typeof iterations !== 'number') {
  3815. throw new TypeError('Iterations not a number')
  3816. }
  3817. if (iterations < 0) {
  3818. throw new TypeError('Bad iterations')
  3819. }
  3820. if (typeof keylen !== 'number') {
  3821. throw new TypeError('Key length not a number')
  3822. }
  3823. if (keylen < 0 || keylen > MAX_ALLOC || keylen !== keylen) { /* eslint no-self-compare: 0 */
  3824. throw new TypeError('Bad key length')
  3825. }
  3826. }
  3827. },{}],20:[function(require,module,exports){
  3828. 'use strict';
  3829. module.exports = typeof Promise === 'function' ? Promise : require('pinkie');
  3830. },{"pinkie":21}],21:[function(require,module,exports){
  3831. (function (global){
  3832. 'use strict';
  3833. var PENDING = 'pending';
  3834. var SETTLED = 'settled';
  3835. var FULFILLED = 'fulfilled';
  3836. var REJECTED = 'rejected';
  3837. var NOOP = function () {};
  3838. var isNode = typeof global !== 'undefined' && typeof global.process !== 'undefined' && typeof global.process.emit === 'function';
  3839. var asyncSetTimer = typeof setImmediate === 'undefined' ? setTimeout : setImmediate;
  3840. var asyncQueue = [];
  3841. var asyncTimer;
  3842. function asyncFlush() {
  3843. // run promise callbacks
  3844. for (var i = 0; i < asyncQueue.length; i++) {
  3845. asyncQueue[i][0](asyncQueue[i][1]);
  3846. }
  3847. // reset async asyncQueue
  3848. asyncQueue = [];
  3849. asyncTimer = false;
  3850. }
  3851. function asyncCall(callback, arg) {
  3852. asyncQueue.push([callback, arg]);
  3853. if (!asyncTimer) {
  3854. asyncTimer = true;
  3855. asyncSetTimer(asyncFlush, 0);
  3856. }
  3857. }
  3858. function invokeResolver(resolver, promise) {
  3859. function resolvePromise(value) {
  3860. resolve(promise, value);
  3861. }
  3862. function rejectPromise(reason) {
  3863. reject(promise, reason);
  3864. }
  3865. try {
  3866. resolver(resolvePromise, rejectPromise);
  3867. } catch (e) {
  3868. rejectPromise(e);
  3869. }
  3870. }
  3871. function invokeCallback(subscriber) {
  3872. var owner = subscriber.owner;
  3873. var settled = owner._state;
  3874. var value = owner._data;
  3875. var callback = subscriber[settled];
  3876. var promise = subscriber.then;
  3877. if (typeof callback === 'function') {
  3878. settled = FULFILLED;
  3879. try {
  3880. value = callback(value);
  3881. } catch (e) {
  3882. reject(promise, e);
  3883. }
  3884. }
  3885. if (!handleThenable(promise, value)) {
  3886. if (settled === FULFILLED) {
  3887. resolve(promise, value);
  3888. }
  3889. if (settled === REJECTED) {
  3890. reject(promise, value);
  3891. }
  3892. }
  3893. }
  3894. function handleThenable(promise, value) {
  3895. var resolved;
  3896. try {
  3897. if (promise === value) {
  3898. throw new TypeError('A promises callback cannot return that same promise.');
  3899. }
  3900. if (value && (typeof value === 'function' || typeof value === 'object')) {
  3901. // then should be retrieved only once
  3902. var then = value.then;
  3903. if (typeof then === 'function') {
  3904. then.call(value, function (val) {
  3905. if (!resolved) {
  3906. resolved = true;
  3907. if (value === val) {
  3908. fulfill(promise, val);
  3909. } else {
  3910. resolve(promise, val);
  3911. }
  3912. }
  3913. }, function (reason) {
  3914. if (!resolved) {
  3915. resolved = true;
  3916. reject(promise, reason);
  3917. }
  3918. });
  3919. return true;
  3920. }
  3921. }
  3922. } catch (e) {
  3923. if (!resolved) {
  3924. reject(promise, e);
  3925. }
  3926. return true;
  3927. }
  3928. return false;
  3929. }
  3930. function resolve(promise, value) {
  3931. if (promise === value || !handleThenable(promise, value)) {
  3932. fulfill(promise, value);
  3933. }
  3934. }
  3935. function fulfill(promise, value) {
  3936. if (promise._state === PENDING) {
  3937. promise._state = SETTLED;
  3938. promise._data = value;
  3939. asyncCall(publishFulfillment, promise);
  3940. }
  3941. }
  3942. function reject(promise, reason) {
  3943. if (promise._state === PENDING) {
  3944. promise._state = SETTLED;
  3945. promise._data = reason;
  3946. asyncCall(publishRejection, promise);
  3947. }
  3948. }
  3949. function publish(promise) {
  3950. promise._then = promise._then.forEach(invokeCallback);
  3951. }
  3952. function publishFulfillment(promise) {
  3953. promise._state = FULFILLED;
  3954. publish(promise);
  3955. }
  3956. function publishRejection(promise) {
  3957. promise._state = REJECTED;
  3958. publish(promise);
  3959. if (!promise._handled && isNode) {
  3960. global.process.emit('unhandledRejection', promise._data, promise);
  3961. }
  3962. }
  3963. function notifyRejectionHandled(promise) {
  3964. global.process.emit('rejectionHandled', promise);
  3965. }
  3966. /**
  3967. * @class
  3968. */
  3969. function Promise(resolver) {
  3970. if (typeof resolver !== 'function') {
  3971. throw new TypeError('Promise resolver ' + resolver + ' is not a function');
  3972. }
  3973. if (this instanceof Promise === false) {
  3974. throw new TypeError('Failed to construct \'Promise\': Please use the \'new\' operator, this object constructor cannot be called as a function.');
  3975. }
  3976. this._then = [];
  3977. invokeResolver(resolver, this);
  3978. }
  3979. Promise.prototype = {
  3980. constructor: Promise,
  3981. _state: PENDING,
  3982. _then: null,
  3983. _data: undefined,
  3984. _handled: false,
  3985. then: function (onFulfillment, onRejection) {
  3986. var subscriber = {
  3987. owner: this,
  3988. then: new this.constructor(NOOP),
  3989. fulfilled: onFulfillment,
  3990. rejected: onRejection
  3991. };
  3992. if ((onRejection || onFulfillment) && !this._handled) {
  3993. this._handled = true;
  3994. if (this._state === REJECTED && isNode) {
  3995. asyncCall(notifyRejectionHandled, this);
  3996. }
  3997. }
  3998. if (this._state === FULFILLED || this._state === REJECTED) {
  3999. // already resolved, call callback async
  4000. asyncCall(invokeCallback, subscriber);
  4001. } else {
  4002. // subscribe
  4003. this._then.push(subscriber);
  4004. }
  4005. return subscriber.then;
  4006. },
  4007. catch: function (onRejection) {
  4008. return this.then(null, onRejection);
  4009. }
  4010. };
  4011. Promise.all = function (promises) {
  4012. if (!Array.isArray(promises)) {
  4013. throw new TypeError('You must pass an array to Promise.all().');
  4014. }
  4015. return new Promise(function (resolve, reject) {
  4016. var results = [];
  4017. var remaining = 0;
  4018. function resolver(index) {
  4019. remaining++;
  4020. return function (value) {
  4021. results[index] = value;
  4022. if (!--remaining) {
  4023. resolve(results);
  4024. }
  4025. };
  4026. }
  4027. for (var i = 0, promise; i < promises.length; i++) {
  4028. promise = promises[i];
  4029. if (promise && typeof promise.then === 'function') {
  4030. promise.then(resolver(i), reject);
  4031. } else {
  4032. results[i] = promise;
  4033. }
  4034. }
  4035. if (!remaining) {
  4036. resolve(results);
  4037. }
  4038. });
  4039. };
  4040. Promise.race = function (promises) {
  4041. if (!Array.isArray(promises)) {
  4042. throw new TypeError('You must pass an array to Promise.race().');
  4043. }
  4044. return new Promise(function (resolve, reject) {
  4045. for (var i = 0, promise; i < promises.length; i++) {
  4046. promise = promises[i];
  4047. if (promise && typeof promise.then === 'function') {
  4048. promise.then(resolve, reject);
  4049. } else {
  4050. resolve(promise);
  4051. }
  4052. }
  4053. });
  4054. };
  4055. Promise.resolve = function (value) {
  4056. if (value && typeof value === 'object' && value.constructor === Promise) {
  4057. return value;
  4058. }
  4059. return new Promise(function (resolve) {
  4060. resolve(value);
  4061. });
  4062. };
  4063. Promise.reject = function (reason) {
  4064. return new Promise(function (resolve, reject) {
  4065. reject(reason);
  4066. });
  4067. };
  4068. module.exports = Promise;
  4069. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  4070. },{}],22:[function(require,module,exports){
  4071. (function (process){
  4072. 'use strict';
  4073. if (!process.version ||
  4074. process.version.indexOf('v0.') === 0 ||
  4075. process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
  4076. module.exports = nextTick;
  4077. } else {
  4078. module.exports = process.nextTick;
  4079. }
  4080. function nextTick(fn, arg1, arg2, arg3) {
  4081. if (typeof fn !== 'function') {
  4082. throw new TypeError('"callback" argument must be a function');
  4083. }
  4084. var len = arguments.length;
  4085. var args, i;
  4086. switch (len) {
  4087. case 0:
  4088. case 1:
  4089. return process.nextTick(fn);
  4090. case 2:
  4091. return process.nextTick(function afterTickOne() {
  4092. fn.call(null, arg1);
  4093. });
  4094. case 3:
  4095. return process.nextTick(function afterTickTwo() {
  4096. fn.call(null, arg1, arg2);
  4097. });
  4098. case 4:
  4099. return process.nextTick(function afterTickThree() {
  4100. fn.call(null, arg1, arg2, arg3);
  4101. });
  4102. default:
  4103. args = new Array(len - 1);
  4104. i = 0;
  4105. while (i < args.length) {
  4106. args[i++] = arguments[i];
  4107. }
  4108. return process.nextTick(function afterTick() {
  4109. fn.apply(null, args);
  4110. });
  4111. }
  4112. }
  4113. }).call(this,require('_process'))
  4114. },{"_process":23}],23:[function(require,module,exports){
  4115. // shim for using process in browser
  4116. var process = module.exports = {};
  4117. // cached from whatever global is present so that test runners that stub it
  4118. // don't break things. But we need to wrap it in a try catch in case it is
  4119. // wrapped in strict mode code which doesn't define any globals. It's inside a
  4120. // function because try/catches deoptimize in certain engines.
  4121. var cachedSetTimeout;
  4122. var cachedClearTimeout;
  4123. function defaultSetTimout() {
  4124. throw new Error('setTimeout has not been defined');
  4125. }
  4126. function defaultClearTimeout () {
  4127. throw new Error('clearTimeout has not been defined');
  4128. }
  4129. (function () {
  4130. try {
  4131. if (typeof setTimeout === 'function') {
  4132. cachedSetTimeout = setTimeout;
  4133. } else {
  4134. cachedSetTimeout = defaultSetTimout;
  4135. }
  4136. } catch (e) {
  4137. cachedSetTimeout = defaultSetTimout;
  4138. }
  4139. try {
  4140. if (typeof clearTimeout === 'function') {
  4141. cachedClearTimeout = clearTimeout;
  4142. } else {
  4143. cachedClearTimeout = defaultClearTimeout;
  4144. }
  4145. } catch (e) {
  4146. cachedClearTimeout = defaultClearTimeout;
  4147. }
  4148. } ())
  4149. function runTimeout(fun) {
  4150. if (cachedSetTimeout === setTimeout) {
  4151. //normal enviroments in sane situations
  4152. return setTimeout(fun, 0);
  4153. }
  4154. // if setTimeout wasn't available but was latter defined
  4155. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  4156. cachedSetTimeout = setTimeout;
  4157. return setTimeout(fun, 0);
  4158. }
  4159. try {
  4160. // when when somebody has screwed with setTimeout but no I.E. maddness
  4161. return cachedSetTimeout(fun, 0);
  4162. } catch(e){
  4163. try {
  4164. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  4165. return cachedSetTimeout.call(null, fun, 0);
  4166. } catch(e){
  4167. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  4168. return cachedSetTimeout.call(this, fun, 0);
  4169. }
  4170. }
  4171. }
  4172. function runClearTimeout(marker) {
  4173. if (cachedClearTimeout === clearTimeout) {
  4174. //normal enviroments in sane situations
  4175. return clearTimeout(marker);
  4176. }
  4177. // if clearTimeout wasn't available but was latter defined
  4178. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  4179. cachedClearTimeout = clearTimeout;
  4180. return clearTimeout(marker);
  4181. }
  4182. try {
  4183. // when when somebody has screwed with setTimeout but no I.E. maddness
  4184. return cachedClearTimeout(marker);
  4185. } catch (e){
  4186. try {
  4187. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  4188. return cachedClearTimeout.call(null, marker);
  4189. } catch (e){
  4190. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  4191. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  4192. return cachedClearTimeout.call(this, marker);
  4193. }
  4194. }
  4195. }
  4196. var queue = [];
  4197. var draining = false;
  4198. var currentQueue;
  4199. var queueIndex = -1;
  4200. function cleanUpNextTick() {
  4201. if (!draining || !currentQueue) {
  4202. return;
  4203. }
  4204. draining = false;
  4205. if (currentQueue.length) {
  4206. queue = currentQueue.concat(queue);
  4207. } else {
  4208. queueIndex = -1;
  4209. }
  4210. if (queue.length) {
  4211. drainQueue();
  4212. }
  4213. }
  4214. function drainQueue() {
  4215. if (draining) {
  4216. return;
  4217. }
  4218. var timeout = runTimeout(cleanUpNextTick);
  4219. draining = true;
  4220. var len = queue.length;
  4221. while(len) {
  4222. currentQueue = queue;
  4223. queue = [];
  4224. while (++queueIndex < len) {
  4225. if (currentQueue) {
  4226. currentQueue[queueIndex].run();
  4227. }
  4228. }
  4229. queueIndex = -1;
  4230. len = queue.length;
  4231. }
  4232. currentQueue = null;
  4233. draining = false;
  4234. runClearTimeout(timeout);
  4235. }
  4236. process.nextTick = function (fun) {
  4237. var args = new Array(arguments.length - 1);
  4238. if (arguments.length > 1) {
  4239. for (var i = 1; i < arguments.length; i++) {
  4240. args[i - 1] = arguments[i];
  4241. }
  4242. }
  4243. queue.push(new Item(fun, args));
  4244. if (queue.length === 1 && !draining) {
  4245. runTimeout(drainQueue);
  4246. }
  4247. };
  4248. // v8 likes predictible objects
  4249. function Item(fun, array) {
  4250. this.fun = fun;
  4251. this.array = array;
  4252. }
  4253. Item.prototype.run = function () {
  4254. this.fun.apply(null, this.array);
  4255. };
  4256. process.title = 'browser';
  4257. process.browser = true;
  4258. process.env = {};
  4259. process.argv = [];
  4260. process.version = ''; // empty string to avoid regexp issues
  4261. process.versions = {};
  4262. function noop() {}
  4263. process.on = noop;
  4264. process.addListener = noop;
  4265. process.once = noop;
  4266. process.off = noop;
  4267. process.removeListener = noop;
  4268. process.removeAllListeners = noop;
  4269. process.emit = noop;
  4270. process.binding = function (name) {
  4271. throw new Error('process.binding is not supported');
  4272. };
  4273. process.cwd = function () { return '/' };
  4274. process.chdir = function (dir) {
  4275. throw new Error('process.chdir is not supported');
  4276. };
  4277. process.umask = function() { return 0; };
  4278. },{}],24:[function(require,module,exports){
  4279. module.exports = require("./lib/_stream_duplex.js")
  4280. },{"./lib/_stream_duplex.js":25}],25:[function(require,module,exports){
  4281. // a duplex stream is just a stream that is both readable and writable.
  4282. // Since JS doesn't have multiple prototypal inheritance, this class
  4283. // prototypally inherits from Readable, and then parasitically from
  4284. // Writable.
  4285. 'use strict';
  4286. /*<replacement>*/
  4287. var objectKeys = Object.keys || function (obj) {
  4288. var keys = [];
  4289. for (var key in obj) {
  4290. keys.push(key);
  4291. }return keys;
  4292. };
  4293. /*</replacement>*/
  4294. module.exports = Duplex;
  4295. /*<replacement>*/
  4296. var processNextTick = require('process-nextick-args');
  4297. /*</replacement>*/
  4298. /*<replacement>*/
  4299. var util = require('core-util-is');
  4300. util.inherits = require('inherits');
  4301. /*</replacement>*/
  4302. var Readable = require('./_stream_readable');
  4303. var Writable = require('./_stream_writable');
  4304. util.inherits(Duplex, Readable);
  4305. var keys = objectKeys(Writable.prototype);
  4306. for (var v = 0; v < keys.length; v++) {
  4307. var method = keys[v];
  4308. if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
  4309. }
  4310. function Duplex(options) {
  4311. if (!(this instanceof Duplex)) return new Duplex(options);
  4312. Readable.call(this, options);
  4313. Writable.call(this, options);
  4314. if (options && options.readable === false) this.readable = false;
  4315. if (options && options.writable === false) this.writable = false;
  4316. this.allowHalfOpen = true;
  4317. if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
  4318. this.once('end', onend);
  4319. }
  4320. // the no-half-open enforcer
  4321. function onend() {
  4322. // if we allow half-open state, or if the writable side ended,
  4323. // then we're ok.
  4324. if (this.allowHalfOpen || this._writableState.ended) return;
  4325. // no more data can be written.
  4326. // But allow more writes to happen in this tick.
  4327. processNextTick(onEndNT, this);
  4328. }
  4329. function onEndNT(self) {
  4330. self.end();
  4331. }
  4332. function forEach(xs, f) {
  4333. for (var i = 0, l = xs.length; i < l; i++) {
  4334. f(xs[i], i);
  4335. }
  4336. }
  4337. },{"./_stream_readable":27,"./_stream_writable":29,"core-util-is":7,"inherits":14,"process-nextick-args":22}],26:[function(require,module,exports){
  4338. // a passthrough stream.
  4339. // basically just the most minimal sort of Transform stream.
  4340. // Every written chunk gets output as-is.
  4341. 'use strict';
  4342. module.exports = PassThrough;
  4343. var Transform = require('./_stream_transform');
  4344. /*<replacement>*/
  4345. var util = require('core-util-is');
  4346. util.inherits = require('inherits');
  4347. /*</replacement>*/
  4348. util.inherits(PassThrough, Transform);
  4349. function PassThrough(options) {
  4350. if (!(this instanceof PassThrough)) return new PassThrough(options);
  4351. Transform.call(this, options);
  4352. }
  4353. PassThrough.prototype._transform = function (chunk, encoding, cb) {
  4354. cb(null, chunk);
  4355. };
  4356. },{"./_stream_transform":28,"core-util-is":7,"inherits":14}],27:[function(require,module,exports){
  4357. (function (process){
  4358. 'use strict';
  4359. module.exports = Readable;
  4360. /*<replacement>*/
  4361. var processNextTick = require('process-nextick-args');
  4362. /*</replacement>*/
  4363. /*<replacement>*/
  4364. var isArray = require('isarray');
  4365. /*</replacement>*/
  4366. /*<replacement>*/
  4367. var Duplex;
  4368. /*</replacement>*/
  4369. Readable.ReadableState = ReadableState;
  4370. /*<replacement>*/
  4371. var EE = require('events').EventEmitter;
  4372. var EElistenerCount = function (emitter, type) {
  4373. return emitter.listeners(type).length;
  4374. };
  4375. /*</replacement>*/
  4376. /*<replacement>*/
  4377. var Stream;
  4378. (function () {
  4379. try {
  4380. Stream = require('st' + 'ream');
  4381. } catch (_) {} finally {
  4382. if (!Stream) Stream = require('events').EventEmitter;
  4383. }
  4384. })();
  4385. /*</replacement>*/
  4386. var Buffer = require('buffer').Buffer;
  4387. /*<replacement>*/
  4388. var bufferShim = require('buffer-shims');
  4389. /*</replacement>*/
  4390. /*<replacement>*/
  4391. var util = require('core-util-is');
  4392. util.inherits = require('inherits');
  4393. /*</replacement>*/
  4394. /*<replacement>*/
  4395. var debugUtil = require('util');
  4396. var debug = void 0;
  4397. if (debugUtil && debugUtil.debuglog) {
  4398. debug = debugUtil.debuglog('stream');
  4399. } else {
  4400. debug = function () {};
  4401. }
  4402. /*</replacement>*/
  4403. var BufferList = require('./internal/streams/BufferList');
  4404. var StringDecoder;
  4405. util.inherits(Readable, Stream);
  4406. function prependListener(emitter, event, fn) {
  4407. // Sadly this is not cacheable as some libraries bundle their own
  4408. // event emitter implementation with them.
  4409. if (typeof emitter.prependListener === 'function') {
  4410. return emitter.prependListener(event, fn);
  4411. } else {
  4412. // This is a hack to make sure that our error handler is attached before any
  4413. // userland ones. NEVER DO THIS. This is here only because this code needs
  4414. // to continue to work with older versions of Node.js that do not include
  4415. // the prependListener() method. The goal is to eventually remove this hack.
  4416. if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
  4417. }
  4418. }
  4419. function ReadableState(options, stream) {
  4420. Duplex = Duplex || require('./_stream_duplex');
  4421. options = options || {};
  4422. // object stream flag. Used to make read(n) ignore n and to
  4423. // make all the buffer merging and length checks go away
  4424. this.objectMode = !!options.objectMode;
  4425. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
  4426. // the point at which it stops calling _read() to fill the buffer
  4427. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  4428. var hwm = options.highWaterMark;
  4429. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  4430. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  4431. // cast to ints.
  4432. this.highWaterMark = ~ ~this.highWaterMark;
  4433. // A linked list is used to store data chunks instead of an array because the
  4434. // linked list can remove elements from the beginning faster than
  4435. // array.shift()
  4436. this.buffer = new BufferList();
  4437. this.length = 0;
  4438. this.pipes = null;
  4439. this.pipesCount = 0;
  4440. this.flowing = null;
  4441. this.ended = false;
  4442. this.endEmitted = false;
  4443. this.reading = false;
  4444. // a flag to be able to tell if the onwrite cb is called immediately,
  4445. // or on a later tick. We set this to true at first, because any
  4446. // actions that shouldn't happen until "later" should generally also
  4447. // not happen before the first write call.
  4448. this.sync = true;
  4449. // whenever we return null, then we set a flag to say
  4450. // that we're awaiting a 'readable' event emission.
  4451. this.needReadable = false;
  4452. this.emittedReadable = false;
  4453. this.readableListening = false;
  4454. this.resumeScheduled = false;
  4455. // Crypto is kind of old and crusty. Historically, its default string
  4456. // encoding is 'binary' so we have to make this configurable.
  4457. // Everything else in the universe uses 'utf8', though.
  4458. this.defaultEncoding = options.defaultEncoding || 'utf8';
  4459. // when piping, we only care about 'readable' events that happen
  4460. // after read()ing all the bytes and not getting any pushback.
  4461. this.ranOut = false;
  4462. // the number of writers that are awaiting a drain event in .pipe()s
  4463. this.awaitDrain = 0;
  4464. // if true, a maybeReadMore has been scheduled
  4465. this.readingMore = false;
  4466. this.decoder = null;
  4467. this.encoding = null;
  4468. if (options.encoding) {
  4469. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  4470. this.decoder = new StringDecoder(options.encoding);
  4471. this.encoding = options.encoding;
  4472. }
  4473. }
  4474. function Readable(options) {
  4475. Duplex = Duplex || require('./_stream_duplex');
  4476. if (!(this instanceof Readable)) return new Readable(options);
  4477. this._readableState = new ReadableState(options, this);
  4478. // legacy
  4479. this.readable = true;
  4480. if (options && typeof options.read === 'function') this._read = options.read;
  4481. Stream.call(this);
  4482. }
  4483. // Manually shove something into the read() buffer.
  4484. // This returns true if the highWaterMark has not been hit yet,
  4485. // similar to how Writable.write() returns true if you should
  4486. // write() some more.
  4487. Readable.prototype.push = function (chunk, encoding) {
  4488. var state = this._readableState;
  4489. if (!state.objectMode && typeof chunk === 'string') {
  4490. encoding = encoding || state.defaultEncoding;
  4491. if (encoding !== state.encoding) {
  4492. chunk = bufferShim.from(chunk, encoding);
  4493. encoding = '';
  4494. }
  4495. }
  4496. return readableAddChunk(this, state, chunk, encoding, false);
  4497. };
  4498. // Unshift should *always* be something directly out of read()
  4499. Readable.prototype.unshift = function (chunk) {
  4500. var state = this._readableState;
  4501. return readableAddChunk(this, state, chunk, '', true);
  4502. };
  4503. Readable.prototype.isPaused = function () {
  4504. return this._readableState.flowing === false;
  4505. };
  4506. function readableAddChunk(stream, state, chunk, encoding, addToFront) {
  4507. var er = chunkInvalid(state, chunk);
  4508. if (er) {
  4509. stream.emit('error', er);
  4510. } else if (chunk === null) {
  4511. state.reading = false;
  4512. onEofChunk(stream, state);
  4513. } else if (state.objectMode || chunk && chunk.length > 0) {
  4514. if (state.ended && !addToFront) {
  4515. var e = new Error('stream.push() after EOF');
  4516. stream.emit('error', e);
  4517. } else if (state.endEmitted && addToFront) {
  4518. var _e = new Error('stream.unshift() after end event');
  4519. stream.emit('error', _e);
  4520. } else {
  4521. var skipAdd;
  4522. if (state.decoder && !addToFront && !encoding) {
  4523. chunk = state.decoder.write(chunk);
  4524. skipAdd = !state.objectMode && chunk.length === 0;
  4525. }
  4526. if (!addToFront) state.reading = false;
  4527. // Don't add to the buffer if we've decoded to an empty string chunk and
  4528. // we're not in object mode
  4529. if (!skipAdd) {
  4530. // if we want the data now, just emit it.
  4531. if (state.flowing && state.length === 0 && !state.sync) {
  4532. stream.emit('data', chunk);
  4533. stream.read(0);
  4534. } else {
  4535. // update the buffer info.
  4536. state.length += state.objectMode ? 1 : chunk.length;
  4537. if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
  4538. if (state.needReadable) emitReadable(stream);
  4539. }
  4540. }
  4541. maybeReadMore(stream, state);
  4542. }
  4543. } else if (!addToFront) {
  4544. state.reading = false;
  4545. }
  4546. return needMoreData(state);
  4547. }
  4548. // if it's past the high water mark, we can push in some more.
  4549. // Also, if we have no data yet, we can stand some
  4550. // more bytes. This is to work around cases where hwm=0,
  4551. // such as the repl. Also, if the push() triggered a
  4552. // readable event, and the user called read(largeNumber) such that
  4553. // needReadable was set, then we ought to push more, so that another
  4554. // 'readable' event will be triggered.
  4555. function needMoreData(state) {
  4556. return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
  4557. }
  4558. // backwards compatibility.
  4559. Readable.prototype.setEncoding = function (enc) {
  4560. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  4561. this._readableState.decoder = new StringDecoder(enc);
  4562. this._readableState.encoding = enc;
  4563. return this;
  4564. };
  4565. // Don't raise the hwm > 8MB
  4566. var MAX_HWM = 0x800000;
  4567. function computeNewHighWaterMark(n) {
  4568. if (n >= MAX_HWM) {
  4569. n = MAX_HWM;
  4570. } else {
  4571. // Get the next highest power of 2 to prevent increasing hwm excessively in
  4572. // tiny amounts
  4573. n--;
  4574. n |= n >>> 1;
  4575. n |= n >>> 2;
  4576. n |= n >>> 4;
  4577. n |= n >>> 8;
  4578. n |= n >>> 16;
  4579. n++;
  4580. }
  4581. return n;
  4582. }
  4583. // This function is designed to be inlinable, so please take care when making
  4584. // changes to the function body.
  4585. function howMuchToRead(n, state) {
  4586. if (n <= 0 || state.length === 0 && state.ended) return 0;
  4587. if (state.objectMode) return 1;
  4588. if (n !== n) {
  4589. // Only flow one buffer at a time
  4590. if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
  4591. }
  4592. // If we're asking for more than the current hwm, then raise the hwm.
  4593. if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  4594. if (n <= state.length) return n;
  4595. // Don't have enough
  4596. if (!state.ended) {
  4597. state.needReadable = true;
  4598. return 0;
  4599. }
  4600. return state.length;
  4601. }
  4602. // you can override either this method, or the async _read(n) below.
  4603. Readable.prototype.read = function (n) {
  4604. debug('read', n);
  4605. n = parseInt(n, 10);
  4606. var state = this._readableState;
  4607. var nOrig = n;
  4608. if (n !== 0) state.emittedReadable = false;
  4609. // if we're doing read(0) to trigger a readable event, but we
  4610. // already have a bunch of data in the buffer, then just trigger
  4611. // the 'readable' event and move on.
  4612. if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
  4613. debug('read: emitReadable', state.length, state.ended);
  4614. if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
  4615. return null;
  4616. }
  4617. n = howMuchToRead(n, state);
  4618. // if we've ended, and we're now clear, then finish it up.
  4619. if (n === 0 && state.ended) {
  4620. if (state.length === 0) endReadable(this);
  4621. return null;
  4622. }
  4623. // All the actual chunk generation logic needs to be
  4624. // *below* the call to _read. The reason is that in certain
  4625. // synthetic stream cases, such as passthrough streams, _read
  4626. // may be a completely synchronous operation which may change
  4627. // the state of the read buffer, providing enough data when
  4628. // before there was *not* enough.
  4629. //
  4630. // So, the steps are:
  4631. // 1. Figure out what the state of things will be after we do
  4632. // a read from the buffer.
  4633. //
  4634. // 2. If that resulting state will trigger a _read, then call _read.
  4635. // Note that this may be asynchronous, or synchronous. Yes, it is
  4636. // deeply ugly to write APIs this way, but that still doesn't mean
  4637. // that the Readable class should behave improperly, as streams are
  4638. // designed to be sync/async agnostic.
  4639. // Take note if the _read call is sync or async (ie, if the read call
  4640. // has returned yet), so that we know whether or not it's safe to emit
  4641. // 'readable' etc.
  4642. //
  4643. // 3. Actually pull the requested chunks out of the buffer and return.
  4644. // if we need a readable event, then we need to do some reading.
  4645. var doRead = state.needReadable;
  4646. debug('need readable', doRead);
  4647. // if we currently have less than the highWaterMark, then also read some
  4648. if (state.length === 0 || state.length - n < state.highWaterMark) {
  4649. doRead = true;
  4650. debug('length less than watermark', doRead);
  4651. }
  4652. // however, if we've ended, then there's no point, and if we're already
  4653. // reading, then it's unnecessary.
  4654. if (state.ended || state.reading) {
  4655. doRead = false;
  4656. debug('reading or ended', doRead);
  4657. } else if (doRead) {
  4658. debug('do read');
  4659. state.reading = true;
  4660. state.sync = true;
  4661. // if the length is currently zero, then we *need* a readable event.
  4662. if (state.length === 0) state.needReadable = true;
  4663. // call internal read method
  4664. this._read(state.highWaterMark);
  4665. state.sync = false;
  4666. // If _read pushed data synchronously, then `reading` will be false,
  4667. // and we need to re-evaluate how much data we can return to the user.
  4668. if (!state.reading) n = howMuchToRead(nOrig, state);
  4669. }
  4670. var ret;
  4671. if (n > 0) ret = fromList(n, state);else ret = null;
  4672. if (ret === null) {
  4673. state.needReadable = true;
  4674. n = 0;
  4675. } else {
  4676. state.length -= n;
  4677. }
  4678. if (state.length === 0) {
  4679. // If we have nothing in the buffer, then we want to know
  4680. // as soon as we *do* get something into the buffer.
  4681. if (!state.ended) state.needReadable = true;
  4682. // If we tried to read() past the EOF, then emit end on the next tick.
  4683. if (nOrig !== n && state.ended) endReadable(this);
  4684. }
  4685. if (ret !== null) this.emit('data', ret);
  4686. return ret;
  4687. };
  4688. function chunkInvalid(state, chunk) {
  4689. var er = null;
  4690. if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) {
  4691. er = new TypeError('Invalid non-string/buffer chunk');
  4692. }
  4693. return er;
  4694. }
  4695. function onEofChunk(stream, state) {
  4696. if (state.ended) return;
  4697. if (state.decoder) {
  4698. var chunk = state.decoder.end();
  4699. if (chunk && chunk.length) {
  4700. state.buffer.push(chunk);
  4701. state.length += state.objectMode ? 1 : chunk.length;
  4702. }
  4703. }
  4704. state.ended = true;
  4705. // emit 'readable' now to make sure it gets picked up.
  4706. emitReadable(stream);
  4707. }
  4708. // Don't emit readable right away in sync mode, because this can trigger
  4709. // another read() call => stack overflow. This way, it might trigger
  4710. // a nextTick recursion warning, but that's not so bad.
  4711. function emitReadable(stream) {
  4712. var state = stream._readableState;
  4713. state.needReadable = false;
  4714. if (!state.emittedReadable) {
  4715. debug('emitReadable', state.flowing);
  4716. state.emittedReadable = true;
  4717. if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream);
  4718. }
  4719. }
  4720. function emitReadable_(stream) {
  4721. debug('emit readable');
  4722. stream.emit('readable');
  4723. flow(stream);
  4724. }
  4725. // at this point, the user has presumably seen the 'readable' event,
  4726. // and called read() to consume some data. that may have triggered
  4727. // in turn another _read(n) call, in which case reading = true if
  4728. // it's in progress.
  4729. // However, if we're not ended, or reading, and the length < hwm,
  4730. // then go ahead and try to read some more preemptively.
  4731. function maybeReadMore(stream, state) {
  4732. if (!state.readingMore) {
  4733. state.readingMore = true;
  4734. processNextTick(maybeReadMore_, stream, state);
  4735. }
  4736. }
  4737. function maybeReadMore_(stream, state) {
  4738. var len = state.length;
  4739. while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
  4740. debug('maybeReadMore read 0');
  4741. stream.read(0);
  4742. if (len === state.length)
  4743. // didn't get any data, stop spinning.
  4744. break;else len = state.length;
  4745. }
  4746. state.readingMore = false;
  4747. }
  4748. // abstract method. to be overridden in specific implementation classes.
  4749. // call cb(er, data) where data is <= n in length.
  4750. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  4751. // arbitrary, and perhaps not very meaningful.
  4752. Readable.prototype._read = function (n) {
  4753. this.emit('error', new Error('_read() is not implemented'));
  4754. };
  4755. Readable.prototype.pipe = function (dest, pipeOpts) {
  4756. var src = this;
  4757. var state = this._readableState;
  4758. switch (state.pipesCount) {
  4759. case 0:
  4760. state.pipes = dest;
  4761. break;
  4762. case 1:
  4763. state.pipes = [state.pipes, dest];
  4764. break;
  4765. default:
  4766. state.pipes.push(dest);
  4767. break;
  4768. }
  4769. state.pipesCount += 1;
  4770. debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
  4771. var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
  4772. var endFn = doEnd ? onend : cleanup;
  4773. if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn);
  4774. dest.on('unpipe', onunpipe);
  4775. function onunpipe(readable) {
  4776. debug('onunpipe');
  4777. if (readable === src) {
  4778. cleanup();
  4779. }
  4780. }
  4781. function onend() {
  4782. debug('onend');
  4783. dest.end();
  4784. }
  4785. // when the dest drains, it reduces the awaitDrain counter
  4786. // on the source. This would be more elegant with a .once()
  4787. // handler in flow(), but adding and removing repeatedly is
  4788. // too slow.
  4789. var ondrain = pipeOnDrain(src);
  4790. dest.on('drain', ondrain);
  4791. var cleanedUp = false;
  4792. function cleanup() {
  4793. debug('cleanup');
  4794. // cleanup event handlers once the pipe is broken
  4795. dest.removeListener('close', onclose);
  4796. dest.removeListener('finish', onfinish);
  4797. dest.removeListener('drain', ondrain);
  4798. dest.removeListener('error', onerror);
  4799. dest.removeListener('unpipe', onunpipe);
  4800. src.removeListener('end', onend);
  4801. src.removeListener('end', cleanup);
  4802. src.removeListener('data', ondata);
  4803. cleanedUp = true;
  4804. // if the reader is waiting for a drain event from this
  4805. // specific writer, then it would cause it to never start
  4806. // flowing again.
  4807. // So, if this is awaiting a drain, then we just call it now.
  4808. // If we don't know, then assume that we are waiting for one.
  4809. if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
  4810. }
  4811. // If the user pushes more data while we're writing to dest then we'll end up
  4812. // in ondata again. However, we only want to increase awaitDrain once because
  4813. // dest will only emit one 'drain' event for the multiple writes.
  4814. // => Introduce a guard on increasing awaitDrain.
  4815. var increasedAwaitDrain = false;
  4816. src.on('data', ondata);
  4817. function ondata(chunk) {
  4818. debug('ondata');
  4819. increasedAwaitDrain = false;
  4820. var ret = dest.write(chunk);
  4821. if (false === ret && !increasedAwaitDrain) {
  4822. // If the user unpiped during `dest.write()`, it is possible
  4823. // to get stuck in a permanently paused state if that write
  4824. // also returned false.
  4825. // => Check whether `dest` is still a piping destination.
  4826. if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
  4827. debug('false write response, pause', src._readableState.awaitDrain);
  4828. src._readableState.awaitDrain++;
  4829. increasedAwaitDrain = true;
  4830. }
  4831. src.pause();
  4832. }
  4833. }
  4834. // if the dest has an error, then stop piping into it.
  4835. // however, don't suppress the throwing behavior for this.
  4836. function onerror(er) {
  4837. debug('onerror', er);
  4838. unpipe();
  4839. dest.removeListener('error', onerror);
  4840. if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
  4841. }
  4842. // Make sure our error handler is attached before userland ones.
  4843. prependListener(dest, 'error', onerror);
  4844. // Both close and finish should trigger unpipe, but only once.
  4845. function onclose() {
  4846. dest.removeListener('finish', onfinish);
  4847. unpipe();
  4848. }
  4849. dest.once('close', onclose);
  4850. function onfinish() {
  4851. debug('onfinish');
  4852. dest.removeListener('close', onclose);
  4853. unpipe();
  4854. }
  4855. dest.once('finish', onfinish);
  4856. function unpipe() {
  4857. debug('unpipe');
  4858. src.unpipe(dest);
  4859. }
  4860. // tell the dest that it's being piped to
  4861. dest.emit('pipe', src);
  4862. // start the flow if it hasn't been started already.
  4863. if (!state.flowing) {
  4864. debug('pipe resume');
  4865. src.resume();
  4866. }
  4867. return dest;
  4868. };
  4869. function pipeOnDrain(src) {
  4870. return function () {
  4871. var state = src._readableState;
  4872. debug('pipeOnDrain', state.awaitDrain);
  4873. if (state.awaitDrain) state.awaitDrain--;
  4874. if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
  4875. state.flowing = true;
  4876. flow(src);
  4877. }
  4878. };
  4879. }
  4880. Readable.prototype.unpipe = function (dest) {
  4881. var state = this._readableState;
  4882. // if we're not piping anywhere, then do nothing.
  4883. if (state.pipesCount === 0) return this;
  4884. // just one destination. most common case.
  4885. if (state.pipesCount === 1) {
  4886. // passed in one, but it's not the right one.
  4887. if (dest && dest !== state.pipes) return this;
  4888. if (!dest) dest = state.pipes;
  4889. // got a match.
  4890. state.pipes = null;
  4891. state.pipesCount = 0;
  4892. state.flowing = false;
  4893. if (dest) dest.emit('unpipe', this);
  4894. return this;
  4895. }
  4896. // slow case. multiple pipe destinations.
  4897. if (!dest) {
  4898. // remove all.
  4899. var dests = state.pipes;
  4900. var len = state.pipesCount;
  4901. state.pipes = null;
  4902. state.pipesCount = 0;
  4903. state.flowing = false;
  4904. for (var i = 0; i < len; i++) {
  4905. dests[i].emit('unpipe', this);
  4906. }return this;
  4907. }
  4908. // try to find the right one.
  4909. var index = indexOf(state.pipes, dest);
  4910. if (index === -1) return this;
  4911. state.pipes.splice(index, 1);
  4912. state.pipesCount -= 1;
  4913. if (state.pipesCount === 1) state.pipes = state.pipes[0];
  4914. dest.emit('unpipe', this);
  4915. return this;
  4916. };
  4917. // set up data events if they are asked for
  4918. // Ensure readable listeners eventually get something
  4919. Readable.prototype.on = function (ev, fn) {
  4920. var res = Stream.prototype.on.call(this, ev, fn);
  4921. if (ev === 'data') {
  4922. // Start flowing on next tick if stream isn't explicitly paused
  4923. if (this._readableState.flowing !== false) this.resume();
  4924. } else if (ev === 'readable') {
  4925. var state = this._readableState;
  4926. if (!state.endEmitted && !state.readableListening) {
  4927. state.readableListening = state.needReadable = true;
  4928. state.emittedReadable = false;
  4929. if (!state.reading) {
  4930. processNextTick(nReadingNextTick, this);
  4931. } else if (state.length) {
  4932. emitReadable(this, state);
  4933. }
  4934. }
  4935. }
  4936. return res;
  4937. };
  4938. Readable.prototype.addListener = Readable.prototype.on;
  4939. function nReadingNextTick(self) {
  4940. debug('readable nexttick read 0');
  4941. self.read(0);
  4942. }
  4943. // pause() and resume() are remnants of the legacy readable stream API
  4944. // If the user uses them, then switch into old mode.
  4945. Readable.prototype.resume = function () {
  4946. var state = this._readableState;
  4947. if (!state.flowing) {
  4948. debug('resume');
  4949. state.flowing = true;
  4950. resume(this, state);
  4951. }
  4952. return this;
  4953. };
  4954. function resume(stream, state) {
  4955. if (!state.resumeScheduled) {
  4956. state.resumeScheduled = true;
  4957. processNextTick(resume_, stream, state);
  4958. }
  4959. }
  4960. function resume_(stream, state) {
  4961. if (!state.reading) {
  4962. debug('resume read 0');
  4963. stream.read(0);
  4964. }
  4965. state.resumeScheduled = false;
  4966. state.awaitDrain = 0;
  4967. stream.emit('resume');
  4968. flow(stream);
  4969. if (state.flowing && !state.reading) stream.read(0);
  4970. }
  4971. Readable.prototype.pause = function () {
  4972. debug('call pause flowing=%j', this._readableState.flowing);
  4973. if (false !== this._readableState.flowing) {
  4974. debug('pause');
  4975. this._readableState.flowing = false;
  4976. this.emit('pause');
  4977. }
  4978. return this;
  4979. };
  4980. function flow(stream) {
  4981. var state = stream._readableState;
  4982. debug('flow', state.flowing);
  4983. while (state.flowing && stream.read() !== null) {}
  4984. }
  4985. // wrap an old-style stream as the async data source.
  4986. // This is *not* part of the readable stream interface.
  4987. // It is an ugly unfortunate mess of history.
  4988. Readable.prototype.wrap = function (stream) {
  4989. var state = this._readableState;
  4990. var paused = false;
  4991. var self = this;
  4992. stream.on('end', function () {
  4993. debug('wrapped end');
  4994. if (state.decoder && !state.ended) {
  4995. var chunk = state.decoder.end();
  4996. if (chunk && chunk.length) self.push(chunk);
  4997. }
  4998. self.push(null);
  4999. });
  5000. stream.on('data', function (chunk) {
  5001. debug('wrapped data');
  5002. if (state.decoder) chunk = state.decoder.write(chunk);
  5003. // don't skip over falsy values in objectMode
  5004. if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
  5005. var ret = self.push(chunk);
  5006. if (!ret) {
  5007. paused = true;
  5008. stream.pause();
  5009. }
  5010. });
  5011. // proxy all the other methods.
  5012. // important when wrapping filters and duplexes.
  5013. for (var i in stream) {
  5014. if (this[i] === undefined && typeof stream[i] === 'function') {
  5015. this[i] = function (method) {
  5016. return function () {
  5017. return stream[method].apply(stream, arguments);
  5018. };
  5019. }(i);
  5020. }
  5021. }
  5022. // proxy certain important events.
  5023. var events = ['error', 'close', 'destroy', 'pause', 'resume'];
  5024. forEach(events, function (ev) {
  5025. stream.on(ev, self.emit.bind(self, ev));
  5026. });
  5027. // when we try to consume some more bytes, simply unpause the
  5028. // underlying stream.
  5029. self._read = function (n) {
  5030. debug('wrapped _read', n);
  5031. if (paused) {
  5032. paused = false;
  5033. stream.resume();
  5034. }
  5035. };
  5036. return self;
  5037. };
  5038. // exposed for testing purposes only.
  5039. Readable._fromList = fromList;
  5040. // Pluck off n bytes from an array of buffers.
  5041. // Length is the combined lengths of all the buffers in the list.
  5042. // This function is designed to be inlinable, so please take care when making
  5043. // changes to the function body.
  5044. function fromList(n, state) {
  5045. // nothing buffered
  5046. if (state.length === 0) return null;
  5047. var ret;
  5048. if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
  5049. // read it all, truncate the list
  5050. if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length);
  5051. state.buffer.clear();
  5052. } else {
  5053. // read part of list
  5054. ret = fromListPartial(n, state.buffer, state.decoder);
  5055. }
  5056. return ret;
  5057. }
  5058. // Extracts only enough buffered data to satisfy the amount requested.
  5059. // This function is designed to be inlinable, so please take care when making
  5060. // changes to the function body.
  5061. function fromListPartial(n, list, hasStrings) {
  5062. var ret;
  5063. if (n < list.head.data.length) {
  5064. // slice is the same for buffers and strings
  5065. ret = list.head.data.slice(0, n);
  5066. list.head.data = list.head.data.slice(n);
  5067. } else if (n === list.head.data.length) {
  5068. // first chunk is a perfect match
  5069. ret = list.shift();
  5070. } else {
  5071. // result spans more than one buffer
  5072. ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
  5073. }
  5074. return ret;
  5075. }
  5076. // Copies a specified amount of characters from the list of buffered data
  5077. // chunks.
  5078. // This function is designed to be inlinable, so please take care when making
  5079. // changes to the function body.
  5080. function copyFromBufferString(n, list) {
  5081. var p = list.head;
  5082. var c = 1;
  5083. var ret = p.data;
  5084. n -= ret.length;
  5085. while (p = p.next) {
  5086. var str = p.data;
  5087. var nb = n > str.length ? str.length : n;
  5088. if (nb === str.length) ret += str;else ret += str.slice(0, n);
  5089. n -= nb;
  5090. if (n === 0) {
  5091. if (nb === str.length) {
  5092. ++c;
  5093. if (p.next) list.head = p.next;else list.head = list.tail = null;
  5094. } else {
  5095. list.head = p;
  5096. p.data = str.slice(nb);
  5097. }
  5098. break;
  5099. }
  5100. ++c;
  5101. }
  5102. list.length -= c;
  5103. return ret;
  5104. }
  5105. // Copies a specified amount of bytes from the list of buffered data chunks.
  5106. // This function is designed to be inlinable, so please take care when making
  5107. // changes to the function body.
  5108. function copyFromBuffer(n, list) {
  5109. var ret = bufferShim.allocUnsafe(n);
  5110. var p = list.head;
  5111. var c = 1;
  5112. p.data.copy(ret);
  5113. n -= p.data.length;
  5114. while (p = p.next) {
  5115. var buf = p.data;
  5116. var nb = n > buf.length ? buf.length : n;
  5117. buf.copy(ret, ret.length - n, 0, nb);
  5118. n -= nb;
  5119. if (n === 0) {
  5120. if (nb === buf.length) {
  5121. ++c;
  5122. if (p.next) list.head = p.next;else list.head = list.tail = null;
  5123. } else {
  5124. list.head = p;
  5125. p.data = buf.slice(nb);
  5126. }
  5127. break;
  5128. }
  5129. ++c;
  5130. }
  5131. list.length -= c;
  5132. return ret;
  5133. }
  5134. function endReadable(stream) {
  5135. var state = stream._readableState;
  5136. // If we get here before consuming all the bytes, then that is a
  5137. // bug in node. Should never happen.
  5138. if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
  5139. if (!state.endEmitted) {
  5140. state.ended = true;
  5141. processNextTick(endReadableNT, state, stream);
  5142. }
  5143. }
  5144. function endReadableNT(state, stream) {
  5145. // Check that we didn't get one last unshift.
  5146. if (!state.endEmitted && state.length === 0) {
  5147. state.endEmitted = true;
  5148. stream.readable = false;
  5149. stream.emit('end');
  5150. }
  5151. }
  5152. function forEach(xs, f) {
  5153. for (var i = 0, l = xs.length; i < l; i++) {
  5154. f(xs[i], i);
  5155. }
  5156. }
  5157. function indexOf(xs, x) {
  5158. for (var i = 0, l = xs.length; i < l; i++) {
  5159. if (xs[i] === x) return i;
  5160. }
  5161. return -1;
  5162. }
  5163. }).call(this,require('_process'))
  5164. },{"./_stream_duplex":25,"./internal/streams/BufferList":30,"_process":23,"buffer":5,"buffer-shims":4,"core-util-is":7,"events":12,"inherits":14,"isarray":16,"process-nextick-args":22,"string_decoder/":45,"util":3}],28:[function(require,module,exports){
  5165. // a transform stream is a readable/writable stream where you do
  5166. // something with the data. Sometimes it's called a "filter",
  5167. // but that's not a great name for it, since that implies a thing where
  5168. // some bits pass through, and others are simply ignored. (That would
  5169. // be a valid example of a transform, of course.)
  5170. //
  5171. // While the output is causally related to the input, it's not a
  5172. // necessarily symmetric or synchronous transformation. For example,
  5173. // a zlib stream might take multiple plain-text writes(), and then
  5174. // emit a single compressed chunk some time in the future.
  5175. //
  5176. // Here's how this works:
  5177. //
  5178. // The Transform stream has all the aspects of the readable and writable
  5179. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  5180. // internally, and returns false if there's a lot of pending writes
  5181. // buffered up. When you call read(), that calls _read(n) until
  5182. // there's enough pending readable data buffered up.
  5183. //
  5184. // In a transform stream, the written data is placed in a buffer. When
  5185. // _read(n) is called, it transforms the queued up data, calling the
  5186. // buffered _write cb's as it consumes chunks. If consuming a single
  5187. // written chunk would result in multiple output chunks, then the first
  5188. // outputted bit calls the readcb, and subsequent chunks just go into
  5189. // the read buffer, and will cause it to emit 'readable' if necessary.
  5190. //
  5191. // This way, back-pressure is actually determined by the reading side,
  5192. // since _read has to be called to start processing a new chunk. However,
  5193. // a pathological inflate type of transform can cause excessive buffering
  5194. // here. For example, imagine a stream where every byte of input is
  5195. // interpreted as an integer from 0-255, and then results in that many
  5196. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  5197. // 1kb of data being output. In this case, you could write a very small
  5198. // amount of input, and end up with a very large amount of output. In
  5199. // such a pathological inflating mechanism, there'd be no way to tell
  5200. // the system to stop doing the transform. A single 4MB write could
  5201. // cause the system to run out of memory.
  5202. //
  5203. // However, even in such a pathological case, only a single written chunk
  5204. // would be consumed, and then the rest would wait (un-transformed) until
  5205. // the results of the previous transformed chunk were consumed.
  5206. 'use strict';
  5207. module.exports = Transform;
  5208. var Duplex = require('./_stream_duplex');
  5209. /*<replacement>*/
  5210. var util = require('core-util-is');
  5211. util.inherits = require('inherits');
  5212. /*</replacement>*/
  5213. util.inherits(Transform, Duplex);
  5214. function TransformState(stream) {
  5215. this.afterTransform = function (er, data) {
  5216. return afterTransform(stream, er, data);
  5217. };
  5218. this.needTransform = false;
  5219. this.transforming = false;
  5220. this.writecb = null;
  5221. this.writechunk = null;
  5222. this.writeencoding = null;
  5223. }
  5224. function afterTransform(stream, er, data) {
  5225. var ts = stream._transformState;
  5226. ts.transforming = false;
  5227. var cb = ts.writecb;
  5228. if (!cb) return stream.emit('error', new Error('no writecb in Transform class'));
  5229. ts.writechunk = null;
  5230. ts.writecb = null;
  5231. if (data !== null && data !== undefined) stream.push(data);
  5232. cb(er);
  5233. var rs = stream._readableState;
  5234. rs.reading = false;
  5235. if (rs.needReadable || rs.length < rs.highWaterMark) {
  5236. stream._read(rs.highWaterMark);
  5237. }
  5238. }
  5239. function Transform(options) {
  5240. if (!(this instanceof Transform)) return new Transform(options);
  5241. Duplex.call(this, options);
  5242. this._transformState = new TransformState(this);
  5243. var stream = this;
  5244. // start out asking for a readable event once data is transformed.
  5245. this._readableState.needReadable = true;
  5246. // we have implemented the _read method, and done the other things
  5247. // that Readable wants before the first _read call, so unset the
  5248. // sync guard flag.
  5249. this._readableState.sync = false;
  5250. if (options) {
  5251. if (typeof options.transform === 'function') this._transform = options.transform;
  5252. if (typeof options.flush === 'function') this._flush = options.flush;
  5253. }
  5254. // When the writable side finishes, then flush out anything remaining.
  5255. this.once('prefinish', function () {
  5256. if (typeof this._flush === 'function') this._flush(function (er, data) {
  5257. done(stream, er, data);
  5258. });else done(stream);
  5259. });
  5260. }
  5261. Transform.prototype.push = function (chunk, encoding) {
  5262. this._transformState.needTransform = false;
  5263. return Duplex.prototype.push.call(this, chunk, encoding);
  5264. };
  5265. // This is the part where you do stuff!
  5266. // override this function in implementation classes.
  5267. // 'chunk' is an input chunk.
  5268. //
  5269. // Call `push(newChunk)` to pass along transformed output
  5270. // to the readable side. You may call 'push' zero or more times.
  5271. //
  5272. // Call `cb(err)` when you are done with this chunk. If you pass
  5273. // an error, then that'll put the hurt on the whole operation. If you
  5274. // never call cb(), then you'll never get another chunk.
  5275. Transform.prototype._transform = function (chunk, encoding, cb) {
  5276. throw new Error('_transform() is not implemented');
  5277. };
  5278. Transform.prototype._write = function (chunk, encoding, cb) {
  5279. var ts = this._transformState;
  5280. ts.writecb = cb;
  5281. ts.writechunk = chunk;
  5282. ts.writeencoding = encoding;
  5283. if (!ts.transforming) {
  5284. var rs = this._readableState;
  5285. if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
  5286. }
  5287. };
  5288. // Doesn't matter what the args are here.
  5289. // _transform does all the work.
  5290. // That we got here means that the readable side wants more data.
  5291. Transform.prototype._read = function (n) {
  5292. var ts = this._transformState;
  5293. if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
  5294. ts.transforming = true;
  5295. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  5296. } else {
  5297. // mark that we need a transform, so that any data that comes in
  5298. // will get processed, now that we've asked for it.
  5299. ts.needTransform = true;
  5300. }
  5301. };
  5302. function done(stream, er, data) {
  5303. if (er) return stream.emit('error', er);
  5304. if (data !== null && data !== undefined) stream.push(data);
  5305. // if there's nothing in the write buffer, then that means
  5306. // that nothing more will ever be provided
  5307. var ws = stream._writableState;
  5308. var ts = stream._transformState;
  5309. if (ws.length) throw new Error('Calling transform done when ws.length != 0');
  5310. if (ts.transforming) throw new Error('Calling transform done when still transforming');
  5311. return stream.push(null);
  5312. }
  5313. },{"./_stream_duplex":25,"core-util-is":7,"inherits":14}],29:[function(require,module,exports){
  5314. (function (process){
  5315. // A bit simpler than readable streams.
  5316. // Implement an async ._write(chunk, encoding, cb), and it'll handle all
  5317. // the drain event emission and buffering.
  5318. 'use strict';
  5319. module.exports = Writable;
  5320. /*<replacement>*/
  5321. var processNextTick = require('process-nextick-args');
  5322. /*</replacement>*/
  5323. /*<replacement>*/
  5324. var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick;
  5325. /*</replacement>*/
  5326. /*<replacement>*/
  5327. var Duplex;
  5328. /*</replacement>*/
  5329. Writable.WritableState = WritableState;
  5330. /*<replacement>*/
  5331. var util = require('core-util-is');
  5332. util.inherits = require('inherits');
  5333. /*</replacement>*/
  5334. /*<replacement>*/
  5335. var internalUtil = {
  5336. deprecate: require('util-deprecate')
  5337. };
  5338. /*</replacement>*/
  5339. /*<replacement>*/
  5340. var Stream;
  5341. (function () {
  5342. try {
  5343. Stream = require('st' + 'ream');
  5344. } catch (_) {} finally {
  5345. if (!Stream) Stream = require('events').EventEmitter;
  5346. }
  5347. })();
  5348. /*</replacement>*/
  5349. var Buffer = require('buffer').Buffer;
  5350. /*<replacement>*/
  5351. var bufferShim = require('buffer-shims');
  5352. /*</replacement>*/
  5353. util.inherits(Writable, Stream);
  5354. function nop() {}
  5355. function WriteReq(chunk, encoding, cb) {
  5356. this.chunk = chunk;
  5357. this.encoding = encoding;
  5358. this.callback = cb;
  5359. this.next = null;
  5360. }
  5361. function WritableState(options, stream) {
  5362. Duplex = Duplex || require('./_stream_duplex');
  5363. options = options || {};
  5364. // object stream flag to indicate whether or not this stream
  5365. // contains buffers or objects.
  5366. this.objectMode = !!options.objectMode;
  5367. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
  5368. // the point at which write() starts returning false
  5369. // Note: 0 is a valid value, means that we always return false if
  5370. // the entire buffer is not flushed immediately on write()
  5371. var hwm = options.highWaterMark;
  5372. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  5373. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  5374. // cast to ints.
  5375. this.highWaterMark = ~ ~this.highWaterMark;
  5376. // drain event flag.
  5377. this.needDrain = false;
  5378. // at the start of calling end()
  5379. this.ending = false;
  5380. // when end() has been called, and returned
  5381. this.ended = false;
  5382. // when 'finish' is emitted
  5383. this.finished = false;
  5384. // should we decode strings into buffers before passing to _write?
  5385. // this is here so that some node-core streams can optimize string
  5386. // handling at a lower level.
  5387. var noDecode = options.decodeStrings === false;
  5388. this.decodeStrings = !noDecode;
  5389. // Crypto is kind of old and crusty. Historically, its default string
  5390. // encoding is 'binary' so we have to make this configurable.
  5391. // Everything else in the universe uses 'utf8', though.
  5392. this.defaultEncoding = options.defaultEncoding || 'utf8';
  5393. // not an actual buffer we keep track of, but a measurement
  5394. // of how much we're waiting to get pushed to some underlying
  5395. // socket or file.
  5396. this.length = 0;
  5397. // a flag to see when we're in the middle of a write.
  5398. this.writing = false;
  5399. // when true all writes will be buffered until .uncork() call
  5400. this.corked = 0;
  5401. // a flag to be able to tell if the onwrite cb is called immediately,
  5402. // or on a later tick. We set this to true at first, because any
  5403. // actions that shouldn't happen until "later" should generally also
  5404. // not happen before the first write call.
  5405. this.sync = true;
  5406. // a flag to know if we're processing previously buffered items, which
  5407. // may call the _write() callback in the same tick, so that we don't
  5408. // end up in an overlapped onwrite situation.
  5409. this.bufferProcessing = false;
  5410. // the callback that's passed to _write(chunk,cb)
  5411. this.onwrite = function (er) {
  5412. onwrite(stream, er);
  5413. };
  5414. // the callback that the user supplies to write(chunk,encoding,cb)
  5415. this.writecb = null;
  5416. // the amount that is being written when _write is called.
  5417. this.writelen = 0;
  5418. this.bufferedRequest = null;
  5419. this.lastBufferedRequest = null;
  5420. // number of pending user-supplied write callbacks
  5421. // this must be 0 before 'finish' can be emitted
  5422. this.pendingcb = 0;
  5423. // emit prefinish if the only thing we're waiting for is _write cbs
  5424. // This is relevant for synchronous Transform streams
  5425. this.prefinished = false;
  5426. // True if the error was already emitted and should not be thrown again
  5427. this.errorEmitted = false;
  5428. // count buffered requests
  5429. this.bufferedRequestCount = 0;
  5430. // allocate the first CorkedRequest, there is always
  5431. // one allocated and free to use, and we maintain at most two
  5432. this.corkedRequestsFree = new CorkedRequest(this);
  5433. }
  5434. WritableState.prototype.getBuffer = function getBuffer() {
  5435. var current = this.bufferedRequest;
  5436. var out = [];
  5437. while (current) {
  5438. out.push(current);
  5439. current = current.next;
  5440. }
  5441. return out;
  5442. };
  5443. (function () {
  5444. try {
  5445. Object.defineProperty(WritableState.prototype, 'buffer', {
  5446. get: internalUtil.deprecate(function () {
  5447. return this.getBuffer();
  5448. }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.')
  5449. });
  5450. } catch (_) {}
  5451. })();
  5452. // Test _writableState for inheritance to account for Duplex streams,
  5453. // whose prototype chain only points to Readable.
  5454. var realHasInstance;
  5455. if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
  5456. realHasInstance = Function.prototype[Symbol.hasInstance];
  5457. Object.defineProperty(Writable, Symbol.hasInstance, {
  5458. value: function (object) {
  5459. if (realHasInstance.call(this, object)) return true;
  5460. return object && object._writableState instanceof WritableState;
  5461. }
  5462. });
  5463. } else {
  5464. realHasInstance = function (object) {
  5465. return object instanceof this;
  5466. };
  5467. }
  5468. function Writable(options) {
  5469. Duplex = Duplex || require('./_stream_duplex');
  5470. // Writable ctor is applied to Duplexes, too.
  5471. // `realHasInstance` is necessary because using plain `instanceof`
  5472. // would return false, as no `_writableState` property is attached.
  5473. // Trying to use the custom `instanceof` for Writable here will also break the
  5474. // Node.js LazyTransform implementation, which has a non-trivial getter for
  5475. // `_writableState` that would lead to infinite recursion.
  5476. if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
  5477. return new Writable(options);
  5478. }
  5479. this._writableState = new WritableState(options, this);
  5480. // legacy.
  5481. this.writable = true;
  5482. if (options) {
  5483. if (typeof options.write === 'function') this._write = options.write;
  5484. if (typeof options.writev === 'function') this._writev = options.writev;
  5485. }
  5486. Stream.call(this);
  5487. }
  5488. // Otherwise people can pipe Writable streams, which is just wrong.
  5489. Writable.prototype.pipe = function () {
  5490. this.emit('error', new Error('Cannot pipe, not readable'));
  5491. };
  5492. function writeAfterEnd(stream, cb) {
  5493. var er = new Error('write after end');
  5494. // TODO: defer error events consistently everywhere, not just the cb
  5495. stream.emit('error', er);
  5496. processNextTick(cb, er);
  5497. }
  5498. // If we get something that is not a buffer, string, null, or undefined,
  5499. // and we're not in objectMode, then that's an error.
  5500. // Otherwise stream chunks are all considered to be of length=1, and the
  5501. // watermarks determine how many objects to keep in the buffer, rather than
  5502. // how many bytes or characters.
  5503. function validChunk(stream, state, chunk, cb) {
  5504. var valid = true;
  5505. var er = false;
  5506. // Always throw error if a null is written
  5507. // if we are not in object mode then throw
  5508. // if it is not a buffer, string, or undefined.
  5509. if (chunk === null) {
  5510. er = new TypeError('May not write null values to stream');
  5511. } else if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  5512. er = new TypeError('Invalid non-string/buffer chunk');
  5513. }
  5514. if (er) {
  5515. stream.emit('error', er);
  5516. processNextTick(cb, er);
  5517. valid = false;
  5518. }
  5519. return valid;
  5520. }
  5521. Writable.prototype.write = function (chunk, encoding, cb) {
  5522. var state = this._writableState;
  5523. var ret = false;
  5524. if (typeof encoding === 'function') {
  5525. cb = encoding;
  5526. encoding = null;
  5527. }
  5528. if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
  5529. if (typeof cb !== 'function') cb = nop;
  5530. if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) {
  5531. state.pendingcb++;
  5532. ret = writeOrBuffer(this, state, chunk, encoding, cb);
  5533. }
  5534. return ret;
  5535. };
  5536. Writable.prototype.cork = function () {
  5537. var state = this._writableState;
  5538. state.corked++;
  5539. };
  5540. Writable.prototype.uncork = function () {
  5541. var state = this._writableState;
  5542. if (state.corked) {
  5543. state.corked--;
  5544. if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
  5545. }
  5546. };
  5547. Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
  5548. // node::ParseEncoding() requires lower case.
  5549. if (typeof encoding === 'string') encoding = encoding.toLowerCase();
  5550. if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding);
  5551. this._writableState.defaultEncoding = encoding;
  5552. return this;
  5553. };
  5554. function decodeChunk(state, chunk, encoding) {
  5555. if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
  5556. chunk = bufferShim.from(chunk, encoding);
  5557. }
  5558. return chunk;
  5559. }
  5560. // if we're already writing something, then just put this
  5561. // in the queue, and wait our turn. Otherwise, call _write
  5562. // If we return false, then we need a drain event, so set that flag.
  5563. function writeOrBuffer(stream, state, chunk, encoding, cb) {
  5564. chunk = decodeChunk(state, chunk, encoding);
  5565. if (Buffer.isBuffer(chunk)) encoding = 'buffer';
  5566. var len = state.objectMode ? 1 : chunk.length;
  5567. state.length += len;
  5568. var ret = state.length < state.highWaterMark;
  5569. // we must ensure that previous needDrain will not be reset to false.
  5570. if (!ret) state.needDrain = true;
  5571. if (state.writing || state.corked) {
  5572. var last = state.lastBufferedRequest;
  5573. state.lastBufferedRequest = new WriteReq(chunk, encoding, cb);
  5574. if (last) {
  5575. last.next = state.lastBufferedRequest;
  5576. } else {
  5577. state.bufferedRequest = state.lastBufferedRequest;
  5578. }
  5579. state.bufferedRequestCount += 1;
  5580. } else {
  5581. doWrite(stream, state, false, len, chunk, encoding, cb);
  5582. }
  5583. return ret;
  5584. }
  5585. function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  5586. state.writelen = len;
  5587. state.writecb = cb;
  5588. state.writing = true;
  5589. state.sync = true;
  5590. if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
  5591. state.sync = false;
  5592. }
  5593. function onwriteError(stream, state, sync, er, cb) {
  5594. --state.pendingcb;
  5595. if (sync) processNextTick(cb, er);else cb(er);
  5596. stream._writableState.errorEmitted = true;
  5597. stream.emit('error', er);
  5598. }
  5599. function onwriteStateUpdate(state) {
  5600. state.writing = false;
  5601. state.writecb = null;
  5602. state.length -= state.writelen;
  5603. state.writelen = 0;
  5604. }
  5605. function onwrite(stream, er) {
  5606. var state = stream._writableState;
  5607. var sync = state.sync;
  5608. var cb = state.writecb;
  5609. onwriteStateUpdate(state);
  5610. if (er) onwriteError(stream, state, sync, er, cb);else {
  5611. // Check if we're actually ready to finish, but don't emit yet
  5612. var finished = needFinish(state);
  5613. if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
  5614. clearBuffer(stream, state);
  5615. }
  5616. if (sync) {
  5617. /*<replacement>*/
  5618. asyncWrite(afterWrite, stream, state, finished, cb);
  5619. /*</replacement>*/
  5620. } else {
  5621. afterWrite(stream, state, finished, cb);
  5622. }
  5623. }
  5624. }
  5625. function afterWrite(stream, state, finished, cb) {
  5626. if (!finished) onwriteDrain(stream, state);
  5627. state.pendingcb--;
  5628. cb();
  5629. finishMaybe(stream, state);
  5630. }
  5631. // Must force callback to be called on nextTick, so that we don't
  5632. // emit 'drain' before the write() consumer gets the 'false' return
  5633. // value, and has a chance to attach a 'drain' listener.
  5634. function onwriteDrain(stream, state) {
  5635. if (state.length === 0 && state.needDrain) {
  5636. state.needDrain = false;
  5637. stream.emit('drain');
  5638. }
  5639. }
  5640. // if there's something in the buffer waiting, then process it
  5641. function clearBuffer(stream, state) {
  5642. state.bufferProcessing = true;
  5643. var entry = state.bufferedRequest;
  5644. if (stream._writev && entry && entry.next) {
  5645. // Fast case, write everything using _writev()
  5646. var l = state.bufferedRequestCount;
  5647. var buffer = new Array(l);
  5648. var holder = state.corkedRequestsFree;
  5649. holder.entry = entry;
  5650. var count = 0;
  5651. while (entry) {
  5652. buffer[count] = entry;
  5653. entry = entry.next;
  5654. count += 1;
  5655. }
  5656. doWrite(stream, state, true, state.length, buffer, '', holder.finish);
  5657. // doWrite is almost always async, defer these to save a bit of time
  5658. // as the hot path ends with doWrite
  5659. state.pendingcb++;
  5660. state.lastBufferedRequest = null;
  5661. if (holder.next) {
  5662. state.corkedRequestsFree = holder.next;
  5663. holder.next = null;
  5664. } else {
  5665. state.corkedRequestsFree = new CorkedRequest(state);
  5666. }
  5667. } else {
  5668. // Slow case, write chunks one-by-one
  5669. while (entry) {
  5670. var chunk = entry.chunk;
  5671. var encoding = entry.encoding;
  5672. var cb = entry.callback;
  5673. var len = state.objectMode ? 1 : chunk.length;
  5674. doWrite(stream, state, false, len, chunk, encoding, cb);
  5675. entry = entry.next;
  5676. // if we didn't call the onwrite immediately, then
  5677. // it means that we need to wait until it does.
  5678. // also, that means that the chunk and cb are currently
  5679. // being processed, so move the buffer counter past them.
  5680. if (state.writing) {
  5681. break;
  5682. }
  5683. }
  5684. if (entry === null) state.lastBufferedRequest = null;
  5685. }
  5686. state.bufferedRequestCount = 0;
  5687. state.bufferedRequest = entry;
  5688. state.bufferProcessing = false;
  5689. }
  5690. Writable.prototype._write = function (chunk, encoding, cb) {
  5691. cb(new Error('_write() is not implemented'));
  5692. };
  5693. Writable.prototype._writev = null;
  5694. Writable.prototype.end = function (chunk, encoding, cb) {
  5695. var state = this._writableState;
  5696. if (typeof chunk === 'function') {
  5697. cb = chunk;
  5698. chunk = null;
  5699. encoding = null;
  5700. } else if (typeof encoding === 'function') {
  5701. cb = encoding;
  5702. encoding = null;
  5703. }
  5704. if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
  5705. // .end() fully uncorks
  5706. if (state.corked) {
  5707. state.corked = 1;
  5708. this.uncork();
  5709. }
  5710. // ignore unnecessary end() calls.
  5711. if (!state.ending && !state.finished) endWritable(this, state, cb);
  5712. };
  5713. function needFinish(state) {
  5714. return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
  5715. }
  5716. function prefinish(stream, state) {
  5717. if (!state.prefinished) {
  5718. state.prefinished = true;
  5719. stream.emit('prefinish');
  5720. }
  5721. }
  5722. function finishMaybe(stream, state) {
  5723. var need = needFinish(state);
  5724. if (need) {
  5725. if (state.pendingcb === 0) {
  5726. prefinish(stream, state);
  5727. state.finished = true;
  5728. stream.emit('finish');
  5729. } else {
  5730. prefinish(stream, state);
  5731. }
  5732. }
  5733. return need;
  5734. }
  5735. function endWritable(stream, state, cb) {
  5736. state.ending = true;
  5737. finishMaybe(stream, state);
  5738. if (cb) {
  5739. if (state.finished) processNextTick(cb);else stream.once('finish', cb);
  5740. }
  5741. state.ended = true;
  5742. stream.writable = false;
  5743. }
  5744. // It seems a linked list but it is not
  5745. // there will be only 2 of these for each stream
  5746. function CorkedRequest(state) {
  5747. var _this = this;
  5748. this.next = null;
  5749. this.entry = null;
  5750. this.finish = function (err) {
  5751. var entry = _this.entry;
  5752. _this.entry = null;
  5753. while (entry) {
  5754. var cb = entry.callback;
  5755. state.pendingcb--;
  5756. cb(err);
  5757. entry = entry.next;
  5758. }
  5759. if (state.corkedRequestsFree) {
  5760. state.corkedRequestsFree.next = _this;
  5761. } else {
  5762. state.corkedRequestsFree = _this;
  5763. }
  5764. };
  5765. }
  5766. }).call(this,require('_process'))
  5767. },{"./_stream_duplex":25,"_process":23,"buffer":5,"buffer-shims":4,"core-util-is":7,"events":12,"inherits":14,"process-nextick-args":22,"util-deprecate":46}],30:[function(require,module,exports){
  5768. 'use strict';
  5769. var Buffer = require('buffer').Buffer;
  5770. /*<replacement>*/
  5771. var bufferShim = require('buffer-shims');
  5772. /*</replacement>*/
  5773. module.exports = BufferList;
  5774. function BufferList() {
  5775. this.head = null;
  5776. this.tail = null;
  5777. this.length = 0;
  5778. }
  5779. BufferList.prototype.push = function (v) {
  5780. var entry = { data: v, next: null };
  5781. if (this.length > 0) this.tail.next = entry;else this.head = entry;
  5782. this.tail = entry;
  5783. ++this.length;
  5784. };
  5785. BufferList.prototype.unshift = function (v) {
  5786. var entry = { data: v, next: this.head };
  5787. if (this.length === 0) this.tail = entry;
  5788. this.head = entry;
  5789. ++this.length;
  5790. };
  5791. BufferList.prototype.shift = function () {
  5792. if (this.length === 0) return;
  5793. var ret = this.head.data;
  5794. if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
  5795. --this.length;
  5796. return ret;
  5797. };
  5798. BufferList.prototype.clear = function () {
  5799. this.head = this.tail = null;
  5800. this.length = 0;
  5801. };
  5802. BufferList.prototype.join = function (s) {
  5803. if (this.length === 0) return '';
  5804. var p = this.head;
  5805. var ret = '' + p.data;
  5806. while (p = p.next) {
  5807. ret += s + p.data;
  5808. }return ret;
  5809. };
  5810. BufferList.prototype.concat = function (n) {
  5811. if (this.length === 0) return bufferShim.alloc(0);
  5812. if (this.length === 1) return this.head.data;
  5813. var ret = bufferShim.allocUnsafe(n >>> 0);
  5814. var p = this.head;
  5815. var i = 0;
  5816. while (p) {
  5817. p.data.copy(ret, i);
  5818. i += p.data.length;
  5819. p = p.next;
  5820. }
  5821. return ret;
  5822. };
  5823. },{"buffer":5,"buffer-shims":4}],31:[function(require,module,exports){
  5824. module.exports = require("./lib/_stream_passthrough.js")
  5825. },{"./lib/_stream_passthrough.js":26}],32:[function(require,module,exports){
  5826. (function (process){
  5827. var Stream = (function (){
  5828. try {
  5829. return require('st' + 'ream'); // hack to fix a circular dependency issue when used with browserify
  5830. } catch(_){}
  5831. }());
  5832. exports = module.exports = require('./lib/_stream_readable.js');
  5833. exports.Stream = Stream || exports;
  5834. exports.Readable = exports;
  5835. exports.Writable = require('./lib/_stream_writable.js');
  5836. exports.Duplex = require('./lib/_stream_duplex.js');
  5837. exports.Transform = require('./lib/_stream_transform.js');
  5838. exports.PassThrough = require('./lib/_stream_passthrough.js');
  5839. if (!process.browser && process.env.READABLE_STREAM === 'disable' && Stream) {
  5840. module.exports = Stream;
  5841. }
  5842. }).call(this,require('_process'))
  5843. },{"./lib/_stream_duplex.js":25,"./lib/_stream_passthrough.js":26,"./lib/_stream_readable.js":27,"./lib/_stream_transform.js":28,"./lib/_stream_writable.js":29,"_process":23}],33:[function(require,module,exports){
  5844. module.exports = require("./lib/_stream_transform.js")
  5845. },{"./lib/_stream_transform.js":28}],34:[function(require,module,exports){
  5846. module.exports = require("./lib/_stream_writable.js")
  5847. },{"./lib/_stream_writable.js":29}],35:[function(require,module,exports){
  5848. (function (Buffer){
  5849. /*
  5850. CryptoJS v3.1.2
  5851. code.google.com/p/crypto-js
  5852. (c) 2009-2013 by Jeff Mott. All rights reserved.
  5853. code.google.com/p/crypto-js/wiki/License
  5854. */
  5855. /** @preserve
  5856. (c) 2012 by Cédric Mesnil. All rights reserved.
  5857. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  5858. - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  5859. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  5860. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5861. */
  5862. // constants table
  5863. var zl = [
  5864. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  5865. 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
  5866. 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
  5867. 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
  5868. 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
  5869. ]
  5870. var zr = [
  5871. 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
  5872. 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
  5873. 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
  5874. 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
  5875. 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
  5876. ]
  5877. var sl = [
  5878. 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
  5879. 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
  5880. 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
  5881. 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
  5882. 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
  5883. ]
  5884. var sr = [
  5885. 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
  5886. 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
  5887. 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
  5888. 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
  5889. 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
  5890. ]
  5891. var hl = [0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]
  5892. var hr = [0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]
  5893. function bytesToWords (bytes) {
  5894. var words = []
  5895. for (var i = 0, b = 0; i < bytes.length; i++, b += 8) {
  5896. words[b >>> 5] |= bytes[i] << (24 - b % 32)
  5897. }
  5898. return words
  5899. }
  5900. function wordsToBytes (words) {
  5901. var bytes = []
  5902. for (var b = 0; b < words.length * 32; b += 8) {
  5903. bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF)
  5904. }
  5905. return bytes
  5906. }
  5907. function processBlock (H, M, offset) {
  5908. // swap endian
  5909. for (var i = 0; i < 16; i++) {
  5910. var offset_i = offset + i
  5911. var M_offset_i = M[offset_i]
  5912. // Swap
  5913. M[offset_i] = (
  5914. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  5915. (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
  5916. )
  5917. }
  5918. // Working variables
  5919. var al, bl, cl, dl, el
  5920. var ar, br, cr, dr, er
  5921. ar = al = H[0]
  5922. br = bl = H[1]
  5923. cr = cl = H[2]
  5924. dr = dl = H[3]
  5925. er = el = H[4]
  5926. // computation
  5927. var t
  5928. for (i = 0; i < 80; i += 1) {
  5929. t = (al + M[offset + zl[i]]) | 0
  5930. if (i < 16) {
  5931. t += f1(bl, cl, dl) + hl[0]
  5932. } else if (i < 32) {
  5933. t += f2(bl, cl, dl) + hl[1]
  5934. } else if (i < 48) {
  5935. t += f3(bl, cl, dl) + hl[2]
  5936. } else if (i < 64) {
  5937. t += f4(bl, cl, dl) + hl[3]
  5938. } else {// if (i<80) {
  5939. t += f5(bl, cl, dl) + hl[4]
  5940. }
  5941. t = t | 0
  5942. t = rotl(t, sl[i])
  5943. t = (t + el) | 0
  5944. al = el
  5945. el = dl
  5946. dl = rotl(cl, 10)
  5947. cl = bl
  5948. bl = t
  5949. t = (ar + M[offset + zr[i]]) | 0
  5950. if (i < 16) {
  5951. t += f5(br, cr, dr) + hr[0]
  5952. } else if (i < 32) {
  5953. t += f4(br, cr, dr) + hr[1]
  5954. } else if (i < 48) {
  5955. t += f3(br, cr, dr) + hr[2]
  5956. } else if (i < 64) {
  5957. t += f2(br, cr, dr) + hr[3]
  5958. } else {// if (i<80) {
  5959. t += f1(br, cr, dr) + hr[4]
  5960. }
  5961. t = t | 0
  5962. t = rotl(t, sr[i])
  5963. t = (t + er) | 0
  5964. ar = er
  5965. er = dr
  5966. dr = rotl(cr, 10)
  5967. cr = br
  5968. br = t
  5969. }
  5970. // intermediate hash value
  5971. t = (H[1] + cl + dr) | 0
  5972. H[1] = (H[2] + dl + er) | 0
  5973. H[2] = (H[3] + el + ar) | 0
  5974. H[3] = (H[4] + al + br) | 0
  5975. H[4] = (H[0] + bl + cr) | 0
  5976. H[0] = t
  5977. }
  5978. function f1 (x, y, z) {
  5979. return ((x) ^ (y) ^ (z))
  5980. }
  5981. function f2 (x, y, z) {
  5982. return (((x) & (y)) | ((~x) & (z)))
  5983. }
  5984. function f3 (x, y, z) {
  5985. return (((x) | (~(y))) ^ (z))
  5986. }
  5987. function f4 (x, y, z) {
  5988. return (((x) & (z)) | ((y) & (~(z))))
  5989. }
  5990. function f5 (x, y, z) {
  5991. return ((x) ^ ((y) | (~(z))))
  5992. }
  5993. function rotl (x, n) {
  5994. return (x << n) | (x >>> (32 - n))
  5995. }
  5996. function ripemd160 (message) {
  5997. var H = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]
  5998. if (typeof message === 'string') {
  5999. message = new Buffer(message, 'utf8')
  6000. }
  6001. var m = bytesToWords(message)
  6002. var nBitsLeft = message.length * 8
  6003. var nBitsTotal = message.length * 8
  6004. // Add padding
  6005. m[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32)
  6006. m[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  6007. (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) |
  6008. (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00)
  6009. )
  6010. for (var i = 0; i < m.length; i += 16) {
  6011. processBlock(H, m, i)
  6012. }
  6013. // swap endian
  6014. for (i = 0; i < 5; i++) {
  6015. // shortcut
  6016. var H_i = H[i]
  6017. // Swap
  6018. H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  6019. (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00)
  6020. }
  6021. var digestbytes = wordsToBytes(H)
  6022. return new Buffer(digestbytes)
  6023. }
  6024. module.exports = ripemd160
  6025. }).call(this,require("buffer").Buffer)
  6026. },{"buffer":5}],36:[function(require,module,exports){
  6027. (function (Buffer){
  6028. // prototype class for hash functions
  6029. function Hash (blockSize, finalSize) {
  6030. this._block = new Buffer(blockSize)
  6031. this._finalSize = finalSize
  6032. this._blockSize = blockSize
  6033. this._len = 0
  6034. this._s = 0
  6035. }
  6036. Hash.prototype.update = function (data, enc) {
  6037. if (typeof data === 'string') {
  6038. enc = enc || 'utf8'
  6039. data = new Buffer(data, enc)
  6040. }
  6041. var l = this._len += data.length
  6042. var s = this._s || 0
  6043. var f = 0
  6044. var buffer = this._block
  6045. while (s < l) {
  6046. var t = Math.min(data.length, f + this._blockSize - (s % this._blockSize))
  6047. var ch = (t - f)
  6048. for (var i = 0; i < ch; i++) {
  6049. buffer[(s % this._blockSize) + i] = data[i + f]
  6050. }
  6051. s += ch
  6052. f += ch
  6053. if ((s % this._blockSize) === 0) {
  6054. this._update(buffer)
  6055. }
  6056. }
  6057. this._s = s
  6058. return this
  6059. }
  6060. Hash.prototype.digest = function (enc) {
  6061. // Suppose the length of the message M, in bits, is l
  6062. var l = this._len * 8
  6063. // Append the bit 1 to the end of the message
  6064. this._block[this._len % this._blockSize] = 0x80
  6065. // and then k zero bits, where k is the smallest non-negative solution to the equation (l + 1 + k) === finalSize mod blockSize
  6066. this._block.fill(0, this._len % this._blockSize + 1)
  6067. if (l % (this._blockSize * 8) >= this._finalSize * 8) {
  6068. this._update(this._block)
  6069. this._block.fill(0)
  6070. }
  6071. // to this append the block which is equal to the number l written in binary
  6072. // TODO: handle case where l is > Math.pow(2, 29)
  6073. this._block.writeInt32BE(l, this._blockSize - 4)
  6074. var hash = this._update(this._block) || this._hash()
  6075. return enc ? hash.toString(enc) : hash
  6076. }
  6077. Hash.prototype._update = function () {
  6078. throw new Error('_update must be implemented by subclass')
  6079. }
  6080. module.exports = Hash
  6081. }).call(this,require("buffer").Buffer)
  6082. },{"buffer":5}],37:[function(require,module,exports){
  6083. var exports = module.exports = function SHA (algorithm) {
  6084. algorithm = algorithm.toLowerCase()
  6085. var Algorithm = exports[algorithm]
  6086. if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)')
  6087. return new Algorithm()
  6088. }
  6089. exports.sha = require('./sha')
  6090. exports.sha1 = require('./sha1')
  6091. exports.sha224 = require('./sha224')
  6092. exports.sha256 = require('./sha256')
  6093. exports.sha384 = require('./sha384')
  6094. exports.sha512 = require('./sha512')
  6095. },{"./sha":38,"./sha1":39,"./sha224":40,"./sha256":41,"./sha384":42,"./sha512":43}],38:[function(require,module,exports){
  6096. (function (Buffer){
  6097. /*
  6098. * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined
  6099. * in FIPS PUB 180-1
  6100. * This source code is derived from sha1.js of the same repository.
  6101. * The difference between SHA-0 and SHA-1 is just a bitwise rotate left
  6102. * operation was added.
  6103. */
  6104. var inherits = require('inherits')
  6105. var Hash = require('./hash')
  6106. var K = [
  6107. 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
  6108. ]
  6109. var W = new Array(80)
  6110. function Sha () {
  6111. this.init()
  6112. this._w = W
  6113. Hash.call(this, 64, 56)
  6114. }
  6115. inherits(Sha, Hash)
  6116. Sha.prototype.init = function () {
  6117. this._a = 0x67452301
  6118. this._b = 0xefcdab89
  6119. this._c = 0x98badcfe
  6120. this._d = 0x10325476
  6121. this._e = 0xc3d2e1f0
  6122. return this
  6123. }
  6124. function rotl5 (num) {
  6125. return (num << 5) | (num >>> 27)
  6126. }
  6127. function rotl30 (num) {
  6128. return (num << 30) | (num >>> 2)
  6129. }
  6130. function ft (s, b, c, d) {
  6131. if (s === 0) return (b & c) | ((~b) & d)
  6132. if (s === 2) return (b & c) | (b & d) | (c & d)
  6133. return b ^ c ^ d
  6134. }
  6135. Sha.prototype._update = function (M) {
  6136. var W = this._w
  6137. var a = this._a | 0
  6138. var b = this._b | 0
  6139. var c = this._c | 0
  6140. var d = this._d | 0
  6141. var e = this._e | 0
  6142. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
  6143. for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]
  6144. for (var j = 0; j < 80; ++j) {
  6145. var s = ~~(j / 20)
  6146. var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
  6147. e = d
  6148. d = c
  6149. c = rotl30(b)
  6150. b = a
  6151. a = t
  6152. }
  6153. this._a = (a + this._a) | 0
  6154. this._b = (b + this._b) | 0
  6155. this._c = (c + this._c) | 0
  6156. this._d = (d + this._d) | 0
  6157. this._e = (e + this._e) | 0
  6158. }
  6159. Sha.prototype._hash = function () {
  6160. var H = new Buffer(20)
  6161. H.writeInt32BE(this._a | 0, 0)
  6162. H.writeInt32BE(this._b | 0, 4)
  6163. H.writeInt32BE(this._c | 0, 8)
  6164. H.writeInt32BE(this._d | 0, 12)
  6165. H.writeInt32BE(this._e | 0, 16)
  6166. return H
  6167. }
  6168. module.exports = Sha
  6169. }).call(this,require("buffer").Buffer)
  6170. },{"./hash":36,"buffer":5,"inherits":14}],39:[function(require,module,exports){
  6171. (function (Buffer){
  6172. /*
  6173. * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
  6174. * in FIPS PUB 180-1
  6175. * Version 2.1a Copyright Paul Johnston 2000 - 2002.
  6176. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  6177. * Distributed under the BSD License
  6178. * See http://pajhome.org.uk/crypt/md5 for details.
  6179. */
  6180. var inherits = require('inherits')
  6181. var Hash = require('./hash')
  6182. var K = [
  6183. 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
  6184. ]
  6185. var W = new Array(80)
  6186. function Sha1 () {
  6187. this.init()
  6188. this._w = W
  6189. Hash.call(this, 64, 56)
  6190. }
  6191. inherits(Sha1, Hash)
  6192. Sha1.prototype.init = function () {
  6193. this._a = 0x67452301
  6194. this._b = 0xefcdab89
  6195. this._c = 0x98badcfe
  6196. this._d = 0x10325476
  6197. this._e = 0xc3d2e1f0
  6198. return this
  6199. }
  6200. function rotl1 (num) {
  6201. return (num << 1) | (num >>> 31)
  6202. }
  6203. function rotl5 (num) {
  6204. return (num << 5) | (num >>> 27)
  6205. }
  6206. function rotl30 (num) {
  6207. return (num << 30) | (num >>> 2)
  6208. }
  6209. function ft (s, b, c, d) {
  6210. if (s === 0) return (b & c) | ((~b) & d)
  6211. if (s === 2) return (b & c) | (b & d) | (c & d)
  6212. return b ^ c ^ d
  6213. }
  6214. Sha1.prototype._update = function (M) {
  6215. var W = this._w
  6216. var a = this._a | 0
  6217. var b = this._b | 0
  6218. var c = this._c | 0
  6219. var d = this._d | 0
  6220. var e = this._e | 0
  6221. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
  6222. for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16])
  6223. for (var j = 0; j < 80; ++j) {
  6224. var s = ~~(j / 20)
  6225. var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
  6226. e = d
  6227. d = c
  6228. c = rotl30(b)
  6229. b = a
  6230. a = t
  6231. }
  6232. this._a = (a + this._a) | 0
  6233. this._b = (b + this._b) | 0
  6234. this._c = (c + this._c) | 0
  6235. this._d = (d + this._d) | 0
  6236. this._e = (e + this._e) | 0
  6237. }
  6238. Sha1.prototype._hash = function () {
  6239. var H = new Buffer(20)
  6240. H.writeInt32BE(this._a | 0, 0)
  6241. H.writeInt32BE(this._b | 0, 4)
  6242. H.writeInt32BE(this._c | 0, 8)
  6243. H.writeInt32BE(this._d | 0, 12)
  6244. H.writeInt32BE(this._e | 0, 16)
  6245. return H
  6246. }
  6247. module.exports = Sha1
  6248. }).call(this,require("buffer").Buffer)
  6249. },{"./hash":36,"buffer":5,"inherits":14}],40:[function(require,module,exports){
  6250. (function (Buffer){
  6251. /**
  6252. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  6253. * in FIPS 180-2
  6254. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  6255. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  6256. *
  6257. */
  6258. var inherits = require('inherits')
  6259. var Sha256 = require('./sha256')
  6260. var Hash = require('./hash')
  6261. var W = new Array(64)
  6262. function Sha224 () {
  6263. this.init()
  6264. this._w = W // new Array(64)
  6265. Hash.call(this, 64, 56)
  6266. }
  6267. inherits(Sha224, Sha256)
  6268. Sha224.prototype.init = function () {
  6269. this._a = 0xc1059ed8
  6270. this._b = 0x367cd507
  6271. this._c = 0x3070dd17
  6272. this._d = 0xf70e5939
  6273. this._e = 0xffc00b31
  6274. this._f = 0x68581511
  6275. this._g = 0x64f98fa7
  6276. this._h = 0xbefa4fa4
  6277. return this
  6278. }
  6279. Sha224.prototype._hash = function () {
  6280. var H = new Buffer(28)
  6281. H.writeInt32BE(this._a, 0)
  6282. H.writeInt32BE(this._b, 4)
  6283. H.writeInt32BE(this._c, 8)
  6284. H.writeInt32BE(this._d, 12)
  6285. H.writeInt32BE(this._e, 16)
  6286. H.writeInt32BE(this._f, 20)
  6287. H.writeInt32BE(this._g, 24)
  6288. return H
  6289. }
  6290. module.exports = Sha224
  6291. }).call(this,require("buffer").Buffer)
  6292. },{"./hash":36,"./sha256":41,"buffer":5,"inherits":14}],41:[function(require,module,exports){
  6293. (function (Buffer){
  6294. /**
  6295. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  6296. * in FIPS 180-2
  6297. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  6298. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  6299. *
  6300. */
  6301. var inherits = require('inherits')
  6302. var Hash = require('./hash')
  6303. var K = [
  6304. 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
  6305. 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
  6306. 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
  6307. 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
  6308. 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
  6309. 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
  6310. 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
  6311. 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
  6312. 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
  6313. 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
  6314. 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
  6315. 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
  6316. 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
  6317. 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
  6318. 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
  6319. 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
  6320. ]
  6321. var W = new Array(64)
  6322. function Sha256 () {
  6323. this.init()
  6324. this._w = W // new Array(64)
  6325. Hash.call(this, 64, 56)
  6326. }
  6327. inherits(Sha256, Hash)
  6328. Sha256.prototype.init = function () {
  6329. this._a = 0x6a09e667
  6330. this._b = 0xbb67ae85
  6331. this._c = 0x3c6ef372
  6332. this._d = 0xa54ff53a
  6333. this._e = 0x510e527f
  6334. this._f = 0x9b05688c
  6335. this._g = 0x1f83d9ab
  6336. this._h = 0x5be0cd19
  6337. return this
  6338. }
  6339. function ch (x, y, z) {
  6340. return z ^ (x & (y ^ z))
  6341. }
  6342. function maj (x, y, z) {
  6343. return (x & y) | (z & (x | y))
  6344. }
  6345. function sigma0 (x) {
  6346. return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10)
  6347. }
  6348. function sigma1 (x) {
  6349. return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7)
  6350. }
  6351. function gamma0 (x) {
  6352. return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ (x >>> 3)
  6353. }
  6354. function gamma1 (x) {
  6355. return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ (x >>> 10)
  6356. }
  6357. Sha256.prototype._update = function (M) {
  6358. var W = this._w
  6359. var a = this._a | 0
  6360. var b = this._b | 0
  6361. var c = this._c | 0
  6362. var d = this._d | 0
  6363. var e = this._e | 0
  6364. var f = this._f | 0
  6365. var g = this._g | 0
  6366. var h = this._h | 0
  6367. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
  6368. for (; i < 64; ++i) W[i] = (gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0
  6369. for (var j = 0; j < 64; ++j) {
  6370. var T1 = (h + sigma1(e) + ch(e, f, g) + K[j] + W[j]) | 0
  6371. var T2 = (sigma0(a) + maj(a, b, c)) | 0
  6372. h = g
  6373. g = f
  6374. f = e
  6375. e = (d + T1) | 0
  6376. d = c
  6377. c = b
  6378. b = a
  6379. a = (T1 + T2) | 0
  6380. }
  6381. this._a = (a + this._a) | 0
  6382. this._b = (b + this._b) | 0
  6383. this._c = (c + this._c) | 0
  6384. this._d = (d + this._d) | 0
  6385. this._e = (e + this._e) | 0
  6386. this._f = (f + this._f) | 0
  6387. this._g = (g + this._g) | 0
  6388. this._h = (h + this._h) | 0
  6389. }
  6390. Sha256.prototype._hash = function () {
  6391. var H = new Buffer(32)
  6392. H.writeInt32BE(this._a, 0)
  6393. H.writeInt32BE(this._b, 4)
  6394. H.writeInt32BE(this._c, 8)
  6395. H.writeInt32BE(this._d, 12)
  6396. H.writeInt32BE(this._e, 16)
  6397. H.writeInt32BE(this._f, 20)
  6398. H.writeInt32BE(this._g, 24)
  6399. H.writeInt32BE(this._h, 28)
  6400. return H
  6401. }
  6402. module.exports = Sha256
  6403. }).call(this,require("buffer").Buffer)
  6404. },{"./hash":36,"buffer":5,"inherits":14}],42:[function(require,module,exports){
  6405. (function (Buffer){
  6406. var inherits = require('inherits')
  6407. var SHA512 = require('./sha512')
  6408. var Hash = require('./hash')
  6409. var W = new Array(160)
  6410. function Sha384 () {
  6411. this.init()
  6412. this._w = W
  6413. Hash.call(this, 128, 112)
  6414. }
  6415. inherits(Sha384, SHA512)
  6416. Sha384.prototype.init = function () {
  6417. this._ah = 0xcbbb9d5d
  6418. this._bh = 0x629a292a
  6419. this._ch = 0x9159015a
  6420. this._dh = 0x152fecd8
  6421. this._eh = 0x67332667
  6422. this._fh = 0x8eb44a87
  6423. this._gh = 0xdb0c2e0d
  6424. this._hh = 0x47b5481d
  6425. this._al = 0xc1059ed8
  6426. this._bl = 0x367cd507
  6427. this._cl = 0x3070dd17
  6428. this._dl = 0xf70e5939
  6429. this._el = 0xffc00b31
  6430. this._fl = 0x68581511
  6431. this._gl = 0x64f98fa7
  6432. this._hl = 0xbefa4fa4
  6433. return this
  6434. }
  6435. Sha384.prototype._hash = function () {
  6436. var H = new Buffer(48)
  6437. function writeInt64BE (h, l, offset) {
  6438. H.writeInt32BE(h, offset)
  6439. H.writeInt32BE(l, offset + 4)
  6440. }
  6441. writeInt64BE(this._ah, this._al, 0)
  6442. writeInt64BE(this._bh, this._bl, 8)
  6443. writeInt64BE(this._ch, this._cl, 16)
  6444. writeInt64BE(this._dh, this._dl, 24)
  6445. writeInt64BE(this._eh, this._el, 32)
  6446. writeInt64BE(this._fh, this._fl, 40)
  6447. return H
  6448. }
  6449. module.exports = Sha384
  6450. }).call(this,require("buffer").Buffer)
  6451. },{"./hash":36,"./sha512":43,"buffer":5,"inherits":14}],43:[function(require,module,exports){
  6452. (function (Buffer){
  6453. var inherits = require('inherits')
  6454. var Hash = require('./hash')
  6455. var K = [
  6456. 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
  6457. 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
  6458. 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
  6459. 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
  6460. 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
  6461. 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
  6462. 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
  6463. 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
  6464. 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
  6465. 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
  6466. 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
  6467. 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
  6468. 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
  6469. 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
  6470. 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
  6471. 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
  6472. 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
  6473. 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
  6474. 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
  6475. 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
  6476. 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
  6477. 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
  6478. 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
  6479. 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
  6480. 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
  6481. 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
  6482. 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
  6483. 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
  6484. 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
  6485. 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
  6486. 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
  6487. 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
  6488. 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
  6489. 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
  6490. 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
  6491. 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
  6492. 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
  6493. 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
  6494. 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
  6495. 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
  6496. ]
  6497. var W = new Array(160)
  6498. function Sha512 () {
  6499. this.init()
  6500. this._w = W
  6501. Hash.call(this, 128, 112)
  6502. }
  6503. inherits(Sha512, Hash)
  6504. Sha512.prototype.init = function () {
  6505. this._ah = 0x6a09e667
  6506. this._bh = 0xbb67ae85
  6507. this._ch = 0x3c6ef372
  6508. this._dh = 0xa54ff53a
  6509. this._eh = 0x510e527f
  6510. this._fh = 0x9b05688c
  6511. this._gh = 0x1f83d9ab
  6512. this._hh = 0x5be0cd19
  6513. this._al = 0xf3bcc908
  6514. this._bl = 0x84caa73b
  6515. this._cl = 0xfe94f82b
  6516. this._dl = 0x5f1d36f1
  6517. this._el = 0xade682d1
  6518. this._fl = 0x2b3e6c1f
  6519. this._gl = 0xfb41bd6b
  6520. this._hl = 0x137e2179
  6521. return this
  6522. }
  6523. function Ch (x, y, z) {
  6524. return z ^ (x & (y ^ z))
  6525. }
  6526. function maj (x, y, z) {
  6527. return (x & y) | (z & (x | y))
  6528. }
  6529. function sigma0 (x, xl) {
  6530. return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25)
  6531. }
  6532. function sigma1 (x, xl) {
  6533. return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23)
  6534. }
  6535. function Gamma0 (x, xl) {
  6536. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7)
  6537. }
  6538. function Gamma0l (x, xl) {
  6539. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25)
  6540. }
  6541. function Gamma1 (x, xl) {
  6542. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6)
  6543. }
  6544. function Gamma1l (x, xl) {
  6545. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26)
  6546. }
  6547. function getCarry (a, b) {
  6548. return (a >>> 0) < (b >>> 0) ? 1 : 0
  6549. }
  6550. Sha512.prototype._update = function (M) {
  6551. var W = this._w
  6552. var ah = this._ah | 0
  6553. var bh = this._bh | 0
  6554. var ch = this._ch | 0
  6555. var dh = this._dh | 0
  6556. var eh = this._eh | 0
  6557. var fh = this._fh | 0
  6558. var gh = this._gh | 0
  6559. var hh = this._hh | 0
  6560. var al = this._al | 0
  6561. var bl = this._bl | 0
  6562. var cl = this._cl | 0
  6563. var dl = this._dl | 0
  6564. var el = this._el | 0
  6565. var fl = this._fl | 0
  6566. var gl = this._gl | 0
  6567. var hl = this._hl | 0
  6568. for (var i = 0; i < 32; i += 2) {
  6569. W[i] = M.readInt32BE(i * 4)
  6570. W[i + 1] = M.readInt32BE(i * 4 + 4)
  6571. }
  6572. for (; i < 160; i += 2) {
  6573. var xh = W[i - 15 * 2]
  6574. var xl = W[i - 15 * 2 + 1]
  6575. var gamma0 = Gamma0(xh, xl)
  6576. var gamma0l = Gamma0l(xl, xh)
  6577. xh = W[i - 2 * 2]
  6578. xl = W[i - 2 * 2 + 1]
  6579. var gamma1 = Gamma1(xh, xl)
  6580. var gamma1l = Gamma1l(xl, xh)
  6581. // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
  6582. var Wi7h = W[i - 7 * 2]
  6583. var Wi7l = W[i - 7 * 2 + 1]
  6584. var Wi16h = W[i - 16 * 2]
  6585. var Wi16l = W[i - 16 * 2 + 1]
  6586. var Wil = (gamma0l + Wi7l) | 0
  6587. var Wih = (gamma0 + Wi7h + getCarry(Wil, gamma0l)) | 0
  6588. Wil = (Wil + gamma1l) | 0
  6589. Wih = (Wih + gamma1 + getCarry(Wil, gamma1l)) | 0
  6590. Wil = (Wil + Wi16l) | 0
  6591. Wih = (Wih + Wi16h + getCarry(Wil, Wi16l)) | 0
  6592. W[i] = Wih
  6593. W[i + 1] = Wil
  6594. }
  6595. for (var j = 0; j < 160; j += 2) {
  6596. Wih = W[j]
  6597. Wil = W[j + 1]
  6598. var majh = maj(ah, bh, ch)
  6599. var majl = maj(al, bl, cl)
  6600. var sigma0h = sigma0(ah, al)
  6601. var sigma0l = sigma0(al, ah)
  6602. var sigma1h = sigma1(eh, el)
  6603. var sigma1l = sigma1(el, eh)
  6604. // t1 = h + sigma1 + ch + K[j] + W[j]
  6605. var Kih = K[j]
  6606. var Kil = K[j + 1]
  6607. var chh = Ch(eh, fh, gh)
  6608. var chl = Ch(el, fl, gl)
  6609. var t1l = (hl + sigma1l) | 0
  6610. var t1h = (hh + sigma1h + getCarry(t1l, hl)) | 0
  6611. t1l = (t1l + chl) | 0
  6612. t1h = (t1h + chh + getCarry(t1l, chl)) | 0
  6613. t1l = (t1l + Kil) | 0
  6614. t1h = (t1h + Kih + getCarry(t1l, Kil)) | 0
  6615. t1l = (t1l + Wil) | 0
  6616. t1h = (t1h + Wih + getCarry(t1l, Wil)) | 0
  6617. // t2 = sigma0 + maj
  6618. var t2l = (sigma0l + majl) | 0
  6619. var t2h = (sigma0h + majh + getCarry(t2l, sigma0l)) | 0
  6620. hh = gh
  6621. hl = gl
  6622. gh = fh
  6623. gl = fl
  6624. fh = eh
  6625. fl = el
  6626. el = (dl + t1l) | 0
  6627. eh = (dh + t1h + getCarry(el, dl)) | 0
  6628. dh = ch
  6629. dl = cl
  6630. ch = bh
  6631. cl = bl
  6632. bh = ah
  6633. bl = al
  6634. al = (t1l + t2l) | 0
  6635. ah = (t1h + t2h + getCarry(al, t1l)) | 0
  6636. }
  6637. this._al = (this._al + al) | 0
  6638. this._bl = (this._bl + bl) | 0
  6639. this._cl = (this._cl + cl) | 0
  6640. this._dl = (this._dl + dl) | 0
  6641. this._el = (this._el + el) | 0
  6642. this._fl = (this._fl + fl) | 0
  6643. this._gl = (this._gl + gl) | 0
  6644. this._hl = (this._hl + hl) | 0
  6645. this._ah = (this._ah + ah + getCarry(this._al, al)) | 0
  6646. this._bh = (this._bh + bh + getCarry(this._bl, bl)) | 0
  6647. this._ch = (this._ch + ch + getCarry(this._cl, cl)) | 0
  6648. this._dh = (this._dh + dh + getCarry(this._dl, dl)) | 0
  6649. this._eh = (this._eh + eh + getCarry(this._el, el)) | 0
  6650. this._fh = (this._fh + fh + getCarry(this._fl, fl)) | 0
  6651. this._gh = (this._gh + gh + getCarry(this._gl, gl)) | 0
  6652. this._hh = (this._hh + hh + getCarry(this._hl, hl)) | 0
  6653. }
  6654. Sha512.prototype._hash = function () {
  6655. var H = new Buffer(64)
  6656. function writeInt64BE (h, l, offset) {
  6657. H.writeInt32BE(h, offset)
  6658. H.writeInt32BE(l, offset + 4)
  6659. }
  6660. writeInt64BE(this._ah, this._al, 0)
  6661. writeInt64BE(this._bh, this._bl, 8)
  6662. writeInt64BE(this._ch, this._cl, 16)
  6663. writeInt64BE(this._dh, this._dl, 24)
  6664. writeInt64BE(this._eh, this._el, 32)
  6665. writeInt64BE(this._fh, this._fl, 40)
  6666. writeInt64BE(this._gh, this._gl, 48)
  6667. writeInt64BE(this._hh, this._hl, 56)
  6668. return H
  6669. }
  6670. module.exports = Sha512
  6671. }).call(this,require("buffer").Buffer)
  6672. },{"./hash":36,"buffer":5,"inherits":14}],44:[function(require,module,exports){
  6673. // Copyright Joyent, Inc. and other Node contributors.
  6674. //
  6675. // Permission is hereby granted, free of charge, to any person obtaining a
  6676. // copy of this software and associated documentation files (the
  6677. // "Software"), to deal in the Software without restriction, including
  6678. // without limitation the rights to use, copy, modify, merge, publish,
  6679. // distribute, sublicense, and/or sell copies of the Software, and to permit
  6680. // persons to whom the Software is furnished to do so, subject to the
  6681. // following conditions:
  6682. //
  6683. // The above copyright notice and this permission notice shall be included
  6684. // in all copies or substantial portions of the Software.
  6685. //
  6686. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  6687. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  6688. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  6689. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  6690. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  6691. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  6692. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  6693. module.exports = Stream;
  6694. var EE = require('events').EventEmitter;
  6695. var inherits = require('inherits');
  6696. inherits(Stream, EE);
  6697. Stream.Readable = require('readable-stream/readable.js');
  6698. Stream.Writable = require('readable-stream/writable.js');
  6699. Stream.Duplex = require('readable-stream/duplex.js');
  6700. Stream.Transform = require('readable-stream/transform.js');
  6701. Stream.PassThrough = require('readable-stream/passthrough.js');
  6702. // Backwards-compat with node 0.4.x
  6703. Stream.Stream = Stream;
  6704. // old-style streams. Note that the pipe method (the only relevant
  6705. // part of this class) is overridden in the Readable class.
  6706. function Stream() {
  6707. EE.call(this);
  6708. }
  6709. Stream.prototype.pipe = function(dest, options) {
  6710. var source = this;
  6711. function ondata(chunk) {
  6712. if (dest.writable) {
  6713. if (false === dest.write(chunk) && source.pause) {
  6714. source.pause();
  6715. }
  6716. }
  6717. }
  6718. source.on('data', ondata);
  6719. function ondrain() {
  6720. if (source.readable && source.resume) {
  6721. source.resume();
  6722. }
  6723. }
  6724. dest.on('drain', ondrain);
  6725. // If the 'end' option is not supplied, dest.end() will be called when
  6726. // source gets the 'end' or 'close' events. Only dest.end() once.
  6727. if (!dest._isStdio && (!options || options.end !== false)) {
  6728. source.on('end', onend);
  6729. source.on('close', onclose);
  6730. }
  6731. var didOnEnd = false;
  6732. function onend() {
  6733. if (didOnEnd) return;
  6734. didOnEnd = true;
  6735. dest.end();
  6736. }
  6737. function onclose() {
  6738. if (didOnEnd) return;
  6739. didOnEnd = true;
  6740. if (typeof dest.destroy === 'function') dest.destroy();
  6741. }
  6742. // don't leave dangling pipes when there are errors.
  6743. function onerror(er) {
  6744. cleanup();
  6745. if (EE.listenerCount(this, 'error') === 0) {
  6746. throw er; // Unhandled stream error in pipe.
  6747. }
  6748. }
  6749. source.on('error', onerror);
  6750. dest.on('error', onerror);
  6751. // remove all the event listeners that were added.
  6752. function cleanup() {
  6753. source.removeListener('data', ondata);
  6754. dest.removeListener('drain', ondrain);
  6755. source.removeListener('end', onend);
  6756. source.removeListener('close', onclose);
  6757. source.removeListener('error', onerror);
  6758. dest.removeListener('error', onerror);
  6759. source.removeListener('end', cleanup);
  6760. source.removeListener('close', cleanup);
  6761. dest.removeListener('close', cleanup);
  6762. }
  6763. source.on('end', cleanup);
  6764. source.on('close', cleanup);
  6765. dest.on('close', cleanup);
  6766. dest.emit('pipe', source);
  6767. // Allow for unix-like usage: A.pipe(B).pipe(C)
  6768. return dest;
  6769. };
  6770. },{"events":12,"inherits":14,"readable-stream/duplex.js":24,"readable-stream/passthrough.js":31,"readable-stream/readable.js":32,"readable-stream/transform.js":33,"readable-stream/writable.js":34}],45:[function(require,module,exports){
  6771. // Copyright Joyent, Inc. and other Node contributors.
  6772. //
  6773. // Permission is hereby granted, free of charge, to any person obtaining a
  6774. // copy of this software and associated documentation files (the
  6775. // "Software"), to deal in the Software without restriction, including
  6776. // without limitation the rights to use, copy, modify, merge, publish,
  6777. // distribute, sublicense, and/or sell copies of the Software, and to permit
  6778. // persons to whom the Software is furnished to do so, subject to the
  6779. // following conditions:
  6780. //
  6781. // The above copyright notice and this permission notice shall be included
  6782. // in all copies or substantial portions of the Software.
  6783. //
  6784. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  6785. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  6786. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  6787. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  6788. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  6789. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  6790. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  6791. var Buffer = require('buffer').Buffer;
  6792. var isBufferEncoding = Buffer.isEncoding
  6793. || function(encoding) {
  6794. switch (encoding && encoding.toLowerCase()) {
  6795. case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw': return true;
  6796. default: return false;
  6797. }
  6798. }
  6799. function assertEncoding(encoding) {
  6800. if (encoding && !isBufferEncoding(encoding)) {
  6801. throw new Error('Unknown encoding: ' + encoding);
  6802. }
  6803. }
  6804. // StringDecoder provides an interface for efficiently splitting a series of
  6805. // buffers into a series of JS strings without breaking apart multi-byte
  6806. // characters. CESU-8 is handled as part of the UTF-8 encoding.
  6807. //
  6808. // @TODO Handling all encodings inside a single object makes it very difficult
  6809. // to reason about this code, so it should be split up in the future.
  6810. // @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code
  6811. // points as used by CESU-8.
  6812. var StringDecoder = exports.StringDecoder = function(encoding) {
  6813. this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
  6814. assertEncoding(encoding);
  6815. switch (this.encoding) {
  6816. case 'utf8':
  6817. // CESU-8 represents each of Surrogate Pair by 3-bytes
  6818. this.surrogateSize = 3;
  6819. break;
  6820. case 'ucs2':
  6821. case 'utf16le':
  6822. // UTF-16 represents each of Surrogate Pair by 2-bytes
  6823. this.surrogateSize = 2;
  6824. this.detectIncompleteChar = utf16DetectIncompleteChar;
  6825. break;
  6826. case 'base64':
  6827. // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
  6828. this.surrogateSize = 3;
  6829. this.detectIncompleteChar = base64DetectIncompleteChar;
  6830. break;
  6831. default:
  6832. this.write = passThroughWrite;
  6833. return;
  6834. }
  6835. // Enough space to store all bytes of a single character. UTF-8 needs 4
  6836. // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate).
  6837. this.charBuffer = new Buffer(6);
  6838. // Number of bytes received for the current incomplete multi-byte character.
  6839. this.charReceived = 0;
  6840. // Number of bytes expected for the current incomplete multi-byte character.
  6841. this.charLength = 0;
  6842. };
  6843. // write decodes the given buffer and returns it as JS string that is
  6844. // guaranteed to not contain any partial multi-byte characters. Any partial
  6845. // character found at the end of the buffer is buffered up, and will be
  6846. // returned when calling write again with the remaining bytes.
  6847. //
  6848. // Note: Converting a Buffer containing an orphan surrogate to a String
  6849. // currently works, but converting a String to a Buffer (via `new Buffer`, or
  6850. // Buffer#write) will replace incomplete surrogates with the unicode
  6851. // replacement character. See https://codereview.chromium.org/121173009/ .
  6852. StringDecoder.prototype.write = function(buffer) {
  6853. var charStr = '';
  6854. // if our last write ended with an incomplete multibyte character
  6855. while (this.charLength) {
  6856. // determine how many remaining bytes this buffer has to offer for this char
  6857. var available = (buffer.length >= this.charLength - this.charReceived) ?
  6858. this.charLength - this.charReceived :
  6859. buffer.length;
  6860. // add the new bytes to the char buffer
  6861. buffer.copy(this.charBuffer, this.charReceived, 0, available);
  6862. this.charReceived += available;
  6863. if (this.charReceived < this.charLength) {
  6864. // still not enough chars in this buffer? wait for more ...
  6865. return '';
  6866. }
  6867. // remove bytes belonging to the current character from the buffer
  6868. buffer = buffer.slice(available, buffer.length);
  6869. // get the character that was split
  6870. charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
  6871. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  6872. var charCode = charStr.charCodeAt(charStr.length - 1);
  6873. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  6874. this.charLength += this.surrogateSize;
  6875. charStr = '';
  6876. continue;
  6877. }
  6878. this.charReceived = this.charLength = 0;
  6879. // if there are no more bytes in this buffer, just emit our char
  6880. if (buffer.length === 0) {
  6881. return charStr;
  6882. }
  6883. break;
  6884. }
  6885. // determine and set charLength / charReceived
  6886. this.detectIncompleteChar(buffer);
  6887. var end = buffer.length;
  6888. if (this.charLength) {
  6889. // buffer the incomplete character bytes we got
  6890. buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
  6891. end -= this.charReceived;
  6892. }
  6893. charStr += buffer.toString(this.encoding, 0, end);
  6894. var end = charStr.length - 1;
  6895. var charCode = charStr.charCodeAt(end);
  6896. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  6897. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  6898. var size = this.surrogateSize;
  6899. this.charLength += size;
  6900. this.charReceived += size;
  6901. this.charBuffer.copy(this.charBuffer, size, 0, size);
  6902. buffer.copy(this.charBuffer, 0, 0, size);
  6903. return charStr.substring(0, end);
  6904. }
  6905. // or just emit the charStr
  6906. return charStr;
  6907. };
  6908. // detectIncompleteChar determines if there is an incomplete UTF-8 character at
  6909. // the end of the given buffer. If so, it sets this.charLength to the byte
  6910. // length that character, and sets this.charReceived to the number of bytes
  6911. // that are available for this character.
  6912. StringDecoder.prototype.detectIncompleteChar = function(buffer) {
  6913. // determine how many bytes we have to check at the end of this buffer
  6914. var i = (buffer.length >= 3) ? 3 : buffer.length;
  6915. // Figure out if one of the last i bytes of our buffer announces an
  6916. // incomplete char.
  6917. for (; i > 0; i--) {
  6918. var c = buffer[buffer.length - i];
  6919. // See http://en.wikipedia.org/wiki/UTF-8#Description
  6920. // 110XXXXX
  6921. if (i == 1 && c >> 5 == 0x06) {
  6922. this.charLength = 2;
  6923. break;
  6924. }
  6925. // 1110XXXX
  6926. if (i <= 2 && c >> 4 == 0x0E) {
  6927. this.charLength = 3;
  6928. break;
  6929. }
  6930. // 11110XXX
  6931. if (i <= 3 && c >> 3 == 0x1E) {
  6932. this.charLength = 4;
  6933. break;
  6934. }
  6935. }
  6936. this.charReceived = i;
  6937. };
  6938. StringDecoder.prototype.end = function(buffer) {
  6939. var res = '';
  6940. if (buffer && buffer.length)
  6941. res = this.write(buffer);
  6942. if (this.charReceived) {
  6943. var cr = this.charReceived;
  6944. var buf = this.charBuffer;
  6945. var enc = this.encoding;
  6946. res += buf.slice(0, cr).toString(enc);
  6947. }
  6948. return res;
  6949. };
  6950. function passThroughWrite(buffer) {
  6951. return buffer.toString(this.encoding);
  6952. }
  6953. function utf16DetectIncompleteChar(buffer) {
  6954. this.charReceived = buffer.length % 2;
  6955. this.charLength = this.charReceived ? 2 : 0;
  6956. }
  6957. function base64DetectIncompleteChar(buffer) {
  6958. this.charReceived = buffer.length % 3;
  6959. this.charLength = this.charReceived ? 3 : 0;
  6960. }
  6961. },{"buffer":5}],46:[function(require,module,exports){
  6962. (function (global){
  6963. /**
  6964. * Module exports.
  6965. */
  6966. module.exports = deprecate;
  6967. /**
  6968. * Mark that a method should not be used.
  6969. * Returns a modified function which warns once by default.
  6970. *
  6971. * If `localStorage.noDeprecation = true` is set, then it is a no-op.
  6972. *
  6973. * If `localStorage.throwDeprecation = true` is set, then deprecated functions
  6974. * will throw an Error when invoked.
  6975. *
  6976. * If `localStorage.traceDeprecation = true` is set, then deprecated functions
  6977. * will invoke `console.trace()` instead of `console.error()`.
  6978. *
  6979. * @param {Function} fn - the function to deprecate
  6980. * @param {String} msg - the string to print to the console when `fn` is invoked
  6981. * @returns {Function} a new "deprecated" version of `fn`
  6982. * @api public
  6983. */
  6984. function deprecate (fn, msg) {
  6985. if (config('noDeprecation')) {
  6986. return fn;
  6987. }
  6988. var warned = false;
  6989. function deprecated() {
  6990. if (!warned) {
  6991. if (config('throwDeprecation')) {
  6992. throw new Error(msg);
  6993. } else if (config('traceDeprecation')) {
  6994. console.trace(msg);
  6995. } else {
  6996. console.warn(msg);
  6997. }
  6998. warned = true;
  6999. }
  7000. return fn.apply(this, arguments);
  7001. }
  7002. return deprecated;
  7003. }
  7004. /**
  7005. * Checks `localStorage` for boolean values for the given `name`.
  7006. *
  7007. * @param {String} name
  7008. * @returns {Boolean}
  7009. * @api private
  7010. */
  7011. function config (name) {
  7012. // accessing global.localStorage can trigger a DOMException in sandboxed iframes
  7013. try {
  7014. if (!global.localStorage) return false;
  7015. } catch (_) {
  7016. return false;
  7017. }
  7018. var val = global.localStorage[name];
  7019. if (null == val) return false;
  7020. return String(val).toLowerCase() === 'true';
  7021. }
  7022. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  7023. },{}],47:[function(require,module,exports){
  7024. var v1 = require('./v1');
  7025. var v2 = require('./v2');
  7026. var pbkdf2 = require('./pbkdf2');
  7027. var objectAssign = require('object-assign');
  7028. module.exports = {
  7029. encryptLogin: v1.encryptLogin,
  7030. renderPassword: v1.renderPassword,
  7031. createFingerprint: v1.createFingerprint,
  7032. _deriveEncryptedLogin: v1._deriveEncryptedLogin,
  7033. _getPasswordTemplate: v1._getPasswordTemplate,
  7034. _prettyPrint: v1._prettyPrint,
  7035. _string2charCodes: v1._string2charCodes,
  7036. _getCharType: v1._getCharType,
  7037. _getPasswordChar: v1._getPasswordChar,
  7038. _createHmac: v1._createHmac,
  7039. generatePassword: generatePassword,
  7040. _calcEntropy: v2._calcEntropy,
  7041. _consumeEntropy: v2._consumeEntropy,
  7042. _getSetOfCharacters: v2._getSetOfCharacters,
  7043. _getConfiguredRules: v2._getConfiguredRules,
  7044. _insertStringPseudoRandomly: v2._insertStringPseudoRandomly,
  7045. _getOneCharPerRule: v2._getOneCharPerRule,
  7046. _renderPassword: v2._renderPassword,
  7047. pbkdf2: pbkdf2
  7048. };
  7049. var defaultPasswordProfile = {
  7050. version: 2,
  7051. lowercase: true,
  7052. numbers: true,
  7053. uppercase: true,
  7054. symbols: true,
  7055. keylen: 32,
  7056. digest: 'sha256',
  7057. length: 16,
  7058. index: 1,
  7059. iterations: 100000
  7060. };
  7061. function generatePassword(site, login, masterPassword, passwordProfile) {
  7062. var _passwordProfile = objectAssign({}, defaultPasswordProfile, passwordProfile);
  7063. if (_passwordProfile.version === 1) {
  7064. var options = {
  7065. counter: _passwordProfile.counter,
  7066. length: _passwordProfile.length,
  7067. lowercase: _passwordProfile.lowercase,
  7068. uppercase: _passwordProfile.uppercase,
  7069. numbers: _passwordProfile.numbers,
  7070. symbols: _passwordProfile.symbols
  7071. };
  7072. return v1.encryptLogin(login, masterPassword)
  7073. .then(function (encryptedLogin) {
  7074. return v1.renderPassword(encryptedLogin, site, options).then(function (generatedPassword) {
  7075. return generatedPassword
  7076. });
  7077. });
  7078. }
  7079. return v2.generatePassword(site, login, masterPassword, _passwordProfile);
  7080. }
  7081. },{"./pbkdf2":48,"./v1":49,"./v2":50,"object-assign":17}],48:[function(require,module,exports){
  7082. (function (Buffer){
  7083. var pbkdf2 = require('pbkdf2');
  7084. var Promise = require('pinkie-promise');
  7085. function shouldUseNative() {
  7086. return !!(typeof window !== 'undefined' && window.crypto && window.crypto.subtle);
  7087. }
  7088. function pbkdf2Native(password, salt, iterations, keylen, digest) {
  7089. var algorithms = {
  7090. 'sha1': 'SHA-1',
  7091. 'sha-1': 'SHA-1',
  7092. 'sha256': 'SHA-256',
  7093. 'sha-256': 'SHA-256',
  7094. 'sha512': 'SHA-512',
  7095. 'sha-512': 'SHA-512',
  7096. };
  7097. return window.crypto.subtle.importKey('raw', new Buffer(password), 'PBKDF2', false, ['deriveKey'])
  7098. .then(function (key) {
  7099. var algo = {
  7100. name: 'PBKDF2',
  7101. salt: new Buffer(salt),
  7102. iterations: iterations,
  7103. hash: algorithms[digest.toLowerCase()],
  7104. };
  7105. return window.crypto.subtle.deriveKey(algo, key, {
  7106. name: 'AES-CTR',
  7107. length: keylen * 8
  7108. }, true, ['encrypt', 'decrypt']);
  7109. })
  7110. .then(function (derivedKey) {
  7111. return window.crypto.subtle.exportKey('raw', derivedKey).then(function (keyArray) {
  7112. return new Buffer(keyArray).toString('hex');
  7113. });
  7114. });
  7115. }
  7116. function pbkdf2Browserified(password, salt, iterations, keylen, digest) {
  7117. return new Promise(function (resolve, reject) {
  7118. pbkdf2.pbkdf2(password, salt, iterations, keylen, digest, function (error, key) {
  7119. if (error) {
  7120. reject('error in pbkdf2');
  7121. } else {
  7122. resolve(key.toString('hex'));
  7123. }
  7124. });
  7125. });
  7126. }
  7127. module.exports = shouldUseNative() ? pbkdf2Native : pbkdf2Browserified;
  7128. }).call(this,require("buffer").Buffer)
  7129. },{"buffer":5,"pbkdf2":18,"pinkie-promise":20}],49:[function(require,module,exports){
  7130. (function (Buffer){
  7131. var pbkdf2 = require('./pbkdf2');
  7132. var createHMAC = require('create-hmac');
  7133. var Promise = require('pinkie-promise');
  7134. module.exports = {
  7135. encryptLogin: encryptLogin,
  7136. renderPassword: renderPassword,
  7137. createFingerprint: createFingerprint,
  7138. _deriveEncryptedLogin: deriveEncryptedLogin,
  7139. _getPasswordTemplate: getPasswordTemplate,
  7140. _prettyPrint: prettyPrint,
  7141. _string2charCodes: string2charCodes,
  7142. _getCharType: getCharType,
  7143. _getPasswordChar: getPasswordChar,
  7144. _createHmac: createHmac,
  7145. };
  7146. function encryptLogin(login, masterPassword, options) {
  7147. var _options = options !== undefined ? options : {};
  7148. var iterations = _options.iterations || 8192;
  7149. var keylen = _options.keylen || 32;
  7150. return pbkdf2(masterPassword, login, iterations, keylen, 'sha256');
  7151. }
  7152. function renderPassword(encryptedLogin, site, passwordOptions) {
  7153. return deriveEncryptedLogin(encryptedLogin, site, passwordOptions).then(function (derivedEncryptedLogin) {
  7154. var template = passwordOptions.template || getPasswordTemplate(passwordOptions);
  7155. return prettyPrint(derivedEncryptedLogin, template);
  7156. });
  7157. }
  7158. function createHmac(encryptedLogin, salt) {
  7159. return new Promise(function (resolve) {
  7160. resolve(createHMAC('sha256', new Buffer(encryptedLogin)).update(salt).digest('hex'));
  7161. });
  7162. }
  7163. function deriveEncryptedLogin(encryptedLogin, site, options) {
  7164. var _options = options !== undefined ? options : {};
  7165. var length = _options.length || 12;
  7166. var counter = _options.counter || 1;
  7167. var salt = site + counter.toString();
  7168. return createHmac(encryptedLogin, salt).then(function (derivedHash) {
  7169. return derivedHash.substring(0, length);
  7170. });
  7171. }
  7172. function getPasswordTemplate(passwordTypes) {
  7173. var templates = {
  7174. lowercase: 'vc',
  7175. uppercase: 'VC',
  7176. numbers: 'n',
  7177. symbols: 's',
  7178. };
  7179. var returnedTemplate = '';
  7180. Object.keys(templates).forEach(function (template) {
  7181. if (passwordTypes.hasOwnProperty(template) && passwordTypes[template]) {
  7182. returnedTemplate += templates[template]
  7183. }
  7184. });
  7185. return returnedTemplate;
  7186. }
  7187. function prettyPrint(hash, template) {
  7188. var password = '';
  7189. string2charCodes(hash).forEach(function (charCode, index) {
  7190. var charType = getCharType(template, index);
  7191. password += getPasswordChar(charType, charCode);
  7192. });
  7193. return password;
  7194. }
  7195. function string2charCodes(text) {
  7196. var charCodes = [];
  7197. for (var i = 0; i < text.length; i++) {
  7198. charCodes.push(text.charCodeAt(i));
  7199. }
  7200. return charCodes;
  7201. }
  7202. function getCharType(template, index) {
  7203. return template[index % template.length];
  7204. }
  7205. function getPasswordChar(charType, index) {
  7206. var passwordsChars = {
  7207. V: 'AEIOUY',
  7208. C: 'BCDFGHJKLMNPQRSTVWXZ',
  7209. v: 'aeiouy',
  7210. c: 'bcdfghjklmnpqrstvwxz',
  7211. A: 'AEIOUYBCDFGHJKLMNPQRSTVWXZ',
  7212. a: 'AEIOUYaeiouyBCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz',
  7213. n: '0123456789',
  7214. s: '@&%?,=[]_:-+*$#!\'^~;()/.',
  7215. x: 'AEIOUYaeiouyBCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz0123456789@&%?,=[]_:-+*$#!\'^~;()/.'
  7216. };
  7217. var passwordChar = passwordsChars[charType];
  7218. return passwordChar[index % passwordChar.length];
  7219. }
  7220. function createFingerprint(str) {
  7221. return new Promise(function (resolve) {
  7222. resolve(createHMAC('sha256', new Buffer(str)).digest('hex'))
  7223. });
  7224. }
  7225. }).call(this,require("buffer").Buffer)
  7226. },{"./pbkdf2":48,"buffer":5,"create-hmac":11,"pinkie-promise":20}],50:[function(require,module,exports){
  7227. var pbkdf2 = require('./pbkdf2');
  7228. var bigInt = require("big-integer");
  7229. module.exports = {
  7230. generatePassword: generatePassword,
  7231. _calcEntropy: calcEntropy,
  7232. _consumeEntropy: consumeEntropy,
  7233. _getSetOfCharacters: getSetOfCharacters,
  7234. _getConfiguredRules: getConfiguredRules,
  7235. _insertStringPseudoRandomly: insertStringPseudoRandomly,
  7236. _getOneCharPerRule: getOneCharPerRule,
  7237. _renderPassword: renderPassword
  7238. };
  7239. function generatePassword(site, login, masterPassword, passwordProfile) {
  7240. return calcEntropy(site, login, masterPassword, passwordProfile).then(function (entropy) {
  7241. return renderPassword(entropy, passwordProfile);
  7242. });
  7243. }
  7244. function calcEntropy(site, login, masterPassword, passwordProfile) {
  7245. var salt = site + login + passwordProfile.counter.toString(16);
  7246. return pbkdf2(masterPassword, salt, passwordProfile.iterations, passwordProfile.keylen, passwordProfile.digest);
  7247. }
  7248. var characterSubsets = {
  7249. lowercase: 'abcdefghijklmnopqrstuvwxyz',
  7250. uppercase: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
  7251. numbers: '0123456789',
  7252. symbols: '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
  7253. };
  7254. function getSetOfCharacters(rules) {
  7255. if (typeof rules === 'undefined') {
  7256. return characterSubsets.lowercase + characterSubsets.uppercase + characterSubsets.numbers + characterSubsets.symbols;
  7257. }
  7258. var setOfChars = '';
  7259. rules.forEach(function (rule) {
  7260. setOfChars += characterSubsets[rule];
  7261. });
  7262. return setOfChars;
  7263. }
  7264. function consumeEntropy(generatedPassword, quotient, setOfCharacters, maxLength) {
  7265. if (generatedPassword.length >= maxLength) {
  7266. return {value: generatedPassword, entropy: quotient};
  7267. }
  7268. var longDivision = quotient.divmod(setOfCharacters.length);
  7269. generatedPassword += setOfCharacters[longDivision.remainder];
  7270. return consumeEntropy(generatedPassword, longDivision.quotient, setOfCharacters, maxLength);
  7271. }
  7272. function insertStringPseudoRandomly(generatedPassword, entropy, string) {
  7273. for (var i = 0; i < string.length; i++) {
  7274. var longDivision = entropy.divmod(generatedPassword.length);
  7275. generatedPassword = generatedPassword.slice(0, longDivision.remainder) + string[i] + generatedPassword.slice(longDivision.remainder);
  7276. entropy = longDivision.quotient;
  7277. }
  7278. return generatedPassword;
  7279. }
  7280. function getOneCharPerRule(entropy, rules) {
  7281. var oneCharPerRules = '';
  7282. rules.forEach(function (rule) {
  7283. var password = consumeEntropy('', entropy, characterSubsets[rule], 1);
  7284. oneCharPerRules += password.value;
  7285. entropy = password.entropy;
  7286. });
  7287. return {value: oneCharPerRules, entropy: entropy};
  7288. }
  7289. function getConfiguredRules(passwordProfile) {
  7290. return ['lowercase', 'uppercase', 'numbers', 'symbols'].filter(function (rule) {
  7291. return passwordProfile[rule];
  7292. });
  7293. }
  7294. function renderPassword(entropy, passwordProfile) {
  7295. var rules = getConfiguredRules(passwordProfile);
  7296. var setOfCharacters = getSetOfCharacters(rules);
  7297. var password = consumeEntropy('', bigInt(entropy, 16), setOfCharacters, passwordProfile.length - rules.length);
  7298. var charactersToAdd = getOneCharPerRule(password.entropy, rules);
  7299. return insertStringPseudoRandomly(password.value, charactersToAdd.entropy, charactersToAdd.value);
  7300. }
  7301. },{"./pbkdf2":48,"big-integer":2}]},{},[47])(47)
  7302. });