From c71a91f72fb28a1b24f225ad98ab437f54ebc730 Mon Sep 17 00:00:00 2001 From: David Humphrey Date: Tue, 29 May 2018 14:03:59 -0400 Subject: [PATCH] Update dist/ with newest stuff --- dist/buffer.js | 650 ++-- dist/buffer.min.js | 4 +- dist/filer-perf.js | 4685 +++++++++++++------------ dist/filer-test.js | 8204 +++++++++++++++++++++++--------------------- dist/filer.js | 2124 +++++++----- dist/filer.min.js | 8 +- dist/path.js | 2 +- dist/path.min.js | 4 +- 8 files changed, 8291 insertions(+), 7390 deletions(-) diff --git a/dist/buffer.js b/dist/buffer.js index dd34e77..71460df 100644 --- a/dist/buffer.js +++ b/dist/buffer.js @@ -1,21 +1,150 @@ (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.FilerBuffer = 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 0) { + throw new Error('Invalid string. Length must be a multiple of 4') + } + + // the number of equal signs (place holders) + // if there are two placeholders, than the two characters before it + // represent one byte + // if there is only one, then the three characters before it represent 2 bytes + // this is just a cheap hack to not do indexOf twice + var len = b64.length + placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0 + + // base64 is 4/3 + up to two characters of the original data + arr = new Arr(b64.length * 3 / 4 - placeHolders) + + // if there are placeholders, only get up to the last complete 4 chars + l = placeHolders > 0 ? b64.length - 4 : b64.length + + var L = 0 + + function push (v) { + arr[L++] = v + } + + for (i = 0, j = 0; i < l; i += 4, j += 3) { + tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3)) + push((tmp & 0xFF0000) >> 16) + push((tmp & 0xFF00) >> 8) + push(tmp & 0xFF) + } + + if (placeHolders === 2) { + tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4) + push(tmp & 0xFF) + } else if (placeHolders === 1) { + tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2) + push((tmp >> 8) & 0xFF) + push(tmp & 0xFF) + } + + return arr + } + + function uint8ToBase64 (uint8) { + var i, + extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes + output = "", + temp, length + + function encode (num) { + return lookup.charAt(num) + } + + function tripletToBase64 (num) { + return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F) + } + + // go through the array every three bytes, we'll deal with trailing stuff later + for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { + temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) + output += tripletToBase64(temp) + } + + // pad the end with zeros, but make sure to not forget the extra bytes + switch (extraBytes) { + case 1: + temp = uint8[uint8.length - 1] + output += encode(temp >> 2) + output += encode((temp << 4) & 0x3F) + output += '==' + break + case 2: + temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]) + output += encode(temp >> 10) + output += encode((temp >> 4) & 0x3F) + output += encode((temp << 2) & 0x3F) + output += '=' + break + } + + return output + } + + exports.toByteArray = b64ToByteArray + exports.fromByteArray = uint8ToBase64 +}(typeof exports === 'undefined' ? (this.base64js = {}) : exports)) + +},{}],2:[function(require,module,exports){ +(function (global){ /*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh * @license MIT */ +/* eslint-disable no-proto */ + +'use strict' var base64 = require('base64-js') var ieee754 = require('ieee754') -var isArray = require('is-array') +var isArray = require('isarray') exports.Buffer = Buffer exports.SlowBuffer = SlowBuffer exports.INSPECT_MAX_BYTES = 50 Buffer.poolSize = 8192 // not used by this implementation -var kMaxLength = 0x3fffffff var rootParent = {} /** @@ -26,32 +155,49 @@ var rootParent = {} * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, * Opera 11.6+, iOS 4.2+. * + * Due to various browser bugs, sometimes the Object implementation will be used even + * when the browser supports typed arrays. + * * Note: * - * - Implementation must support adding new properties to `Uint8Array` instances. - * Firefox 4-29 lacked support, fixed in Firefox 30+. - * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. + * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, + * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. * - * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. + * - Safari 5-7 lacks support for changing the `Object.prototype.constructor` property + * on objects. * - * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of - * incorrect length in some situations. + * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. * - * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they will - * get the Object implementation, which is slower but will work correctly. + * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of + * incorrect length in some situations. + + * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they + * get the Object implementation, which is slower but behaves correctly. */ -Buffer.TYPED_ARRAY_SUPPORT = (function () { +Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined + ? global.TYPED_ARRAY_SUPPORT + : typedArraySupport() + +function typedArraySupport () { + function Bar () {} try { - var buf = new ArrayBuffer(0) - var arr = new Uint8Array(buf) + var arr = new Uint8Array(1) arr.foo = function () { return 42 } + arr.constructor = Bar return arr.foo() === 42 && // typed array instances can be augmented + arr.constructor === Bar && // constructor can be set typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` - new Uint8Array(1).subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` + arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` } catch (e) { return false } -})() +} + +function kMaxLength () { + return Buffer.TYPED_ARRAY_SUPPORT + ? 0x7fffffff + : 0x3fffffff +} /** * Class: Buffer @@ -72,8 +218,10 @@ function Buffer (arg) { return new Buffer(arg) } - this.length = 0 - this.parent = undefined + if (!Buffer.TYPED_ARRAY_SUPPORT) { + this.length = 0 + this.parent = undefined + } // Common case. if (typeof arg === 'number') { @@ -119,8 +267,13 @@ function fromObject (that, object) { throw new TypeError('must start with number, buffer, array or string') } - if (typeof ArrayBuffer !== 'undefined' && object.buffer instanceof ArrayBuffer) { - return fromTypedArray(that, object) + if (typeof ArrayBuffer !== 'undefined') { + if (object.buffer instanceof ArrayBuffer) { + return fromTypedArray(that, object) + } + if (object instanceof ArrayBuffer) { + return fromArrayBuffer(that, object) + } } if (object.length) return fromArrayLike(that, object) @@ -157,6 +310,18 @@ function fromTypedArray (that, array) { return that } +function fromArrayBuffer (that, array) { + if (Buffer.TYPED_ARRAY_SUPPORT) { + // Return an augmented `Uint8Array` instance, for best performance + array.byteLength + that = Buffer._augment(new Uint8Array(array)) + } else { + // Fallback: Return an object instance of the Buffer class + that = fromTypedArray(that, new Uint8Array(array)) + } + return that +} + function fromArrayLike (that, array) { var length = checked(array.length) | 0 that = allocate(that, length) @@ -184,10 +349,20 @@ function fromJsonObject (that, object) { return that } +if (Buffer.TYPED_ARRAY_SUPPORT) { + Buffer.prototype.__proto__ = Uint8Array.prototype + Buffer.__proto__ = Uint8Array +} else { + // pre-set for values that may exist in the future + Buffer.prototype.length = undefined + Buffer.prototype.parent = undefined +} + function allocate (that, length) { if (Buffer.TYPED_ARRAY_SUPPORT) { // Return an augmented `Uint8Array` instance, for best performance that = Buffer._augment(new Uint8Array(length)) + that.__proto__ = Buffer.prototype } else { // Fallback: Return an object instance of the Buffer class that.length = length @@ -203,9 +378,9 @@ function allocate (that, length) { function checked (length) { // Note: cannot use `length < kMaxLength` here because that fails when // length is NaN (which is otherwise coerced to zero.) - if (length >= kMaxLength) { + if (length >= kMaxLength()) { throw new RangeError('Attempt to allocate Buffer larger than maximum ' + - 'size: 0x' + kMaxLength.toString(16) + ' bytes') + 'size: 0x' + kMaxLength().toString(16) + ' bytes') } return length | 0 } @@ -274,8 +449,6 @@ Buffer.concat = function concat (list, length) { if (list.length === 0) { return new Buffer(0) - } else if (list.length === 1) { - return list[0] } var i @@ -297,39 +470,43 @@ Buffer.concat = function concat (list, length) { } function byteLength (string, encoding) { - if (typeof string !== 'string') string = String(string) + if (typeof string !== 'string') string = '' + string - if (string.length === 0) return 0 + var len = string.length + if (len === 0) return 0 - switch (encoding || 'utf8') { - case 'ascii': - case 'binary': - case 'raw': - return string.length - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return string.length * 2 - case 'hex': - return string.length >>> 1 - case 'utf8': - case 'utf-8': - return utf8ToBytes(string).length - case 'base64': - return base64ToBytes(string).length - default: - return string.length + // Use a for loop to avoid recursion + var loweredCase = false + for (;;) { + switch (encoding) { + case 'ascii': + case 'binary': + // Deprecated + case 'raw': + case 'raws': + return len + case 'utf8': + case 'utf-8': + return utf8ToBytes(string).length + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return len * 2 + case 'hex': + return len >>> 1 + case 'base64': + return base64ToBytes(string).length + default: + if (loweredCase) return utf8ToBytes(string).length // assume utf8 + encoding = ('' + encoding).toLowerCase() + loweredCase = true + } } } Buffer.byteLength = byteLength -// pre-set for values that may exist in the future -Buffer.prototype.length = undefined -Buffer.prototype.parent = undefined - -// toString(encoding, start=0, end=buffer.length) -Buffer.prototype.toString = function toString (encoding, start, end) { +function slowToString (encoding, start, end) { var loweredCase = false start = start | 0 @@ -372,6 +549,13 @@ Buffer.prototype.toString = function toString (encoding, start, end) { } } +Buffer.prototype.toString = function toString () { + var length = this.length | 0 + if (length === 0) return '' + if (arguments.length === 0) return utf8Slice(this, 0, length) + return slowToString.apply(this, arguments) +} + Buffer.prototype.equals = function equals (b) { if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') if (this === b) return true @@ -435,13 +619,13 @@ Buffer.prototype.indexOf = function indexOf (val, byteOffset) { throw new TypeError('val must be string, number or Buffer') } -// `get` will be removed in Node 0.13+ +// `get` is deprecated Buffer.prototype.get = function get (offset) { console.log('.get() is deprecated. Access using array indexes instead.') return this.readUInt8(offset) } -// `set` will be removed in Node 0.13+ +// `set` is deprecated Buffer.prototype.set = function set (v, offset) { console.log('.set() is deprecated. Access using array indexes instead.') return this.writeUInt8(v, offset) @@ -582,20 +766,99 @@ function base64Slice (buf, start, end) { } function utf8Slice (buf, start, end) { - var res = '' - var tmp = '' end = Math.min(buf.length, end) + var res = [] - for (var i = start; i < end; i++) { - if (buf[i] <= 0x7F) { - res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i]) - tmp = '' - } else { - tmp += '%' + buf[i].toString(16) + var i = start + while (i < end) { + var firstByte = buf[i] + var codePoint = null + var bytesPerSequence = (firstByte > 0xEF) ? 4 + : (firstByte > 0xDF) ? 3 + : (firstByte > 0xBF) ? 2 + : 1 + + if (i + bytesPerSequence <= end) { + var secondByte, thirdByte, fourthByte, tempCodePoint + + switch (bytesPerSequence) { + case 1: + if (firstByte < 0x80) { + codePoint = firstByte + } + break + case 2: + secondByte = buf[i + 1] + if ((secondByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) + if (tempCodePoint > 0x7F) { + codePoint = tempCodePoint + } + } + break + case 3: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) + if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { + codePoint = tempCodePoint + } + } + break + case 4: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + fourthByte = buf[i + 3] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) + if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { + codePoint = tempCodePoint + } + } + } } + + if (codePoint === null) { + // we did not generate a valid codePoint so insert a + // replacement char (U+FFFD) and advance only 1 byte + codePoint = 0xFFFD + bytesPerSequence = 1 + } else if (codePoint > 0xFFFF) { + // encode to utf16 (surrogate pair dance) + codePoint -= 0x10000 + res.push(codePoint >>> 10 & 0x3FF | 0xD800) + codePoint = 0xDC00 | codePoint & 0x3FF + } + + res.push(codePoint) + i += bytesPerSequence } - return res + decodeUtf8Char(tmp) + return decodeCodePointsArray(res) +} + +// Based on http://stackoverflow.com/a/22747272/680742, the browser with +// the lowest limit is Chrome, with 0x10000 args. +// We go 1 magnitude less, for safety +var MAX_ARGUMENTS_LENGTH = 0x1000 + +function decodeCodePointsArray (codePoints) { + var len = codePoints.length + if (len <= MAX_ARGUMENTS_LENGTH) { + return String.fromCharCode.apply(String, codePoints) // avoid extra slice() + } + + // Decode in chunks to avoid "call stack size exceeded". + var res = '' + var i = 0 + while (i < len) { + res += String.fromCharCode.apply( + String, + codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) + ) + } + return res } function asciiSlice (buf, start, end) { @@ -884,7 +1147,7 @@ Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) - this[offset] = value + this[offset] = (value & 0xff) return offset + 1 } @@ -901,7 +1164,7 @@ Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = value + this[offset] = (value & 0xff) this[offset + 1] = (value >>> 8) } else { objectWriteUInt16(this, value, offset, true) @@ -915,7 +1178,7 @@ Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = (value >>> 8) - this[offset + 1] = value + this[offset + 1] = (value & 0xff) } else { objectWriteUInt16(this, value, offset, false) } @@ -937,7 +1200,7 @@ Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert this[offset + 3] = (value >>> 24) this[offset + 2] = (value >>> 16) this[offset + 1] = (value >>> 8) - this[offset] = value + this[offset] = (value & 0xff) } else { objectWriteUInt32(this, value, offset, true) } @@ -952,7 +1215,7 @@ Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert this[offset] = (value >>> 24) this[offset + 1] = (value >>> 16) this[offset + 2] = (value >>> 8) - this[offset + 3] = value + this[offset + 3] = (value & 0xff) } else { objectWriteUInt32(this, value, offset, false) } @@ -1005,7 +1268,7 @@ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) if (value < 0) value = 0xff + value + 1 - this[offset] = value + this[offset] = (value & 0xff) return offset + 1 } @@ -1014,7 +1277,7 @@ Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = value + this[offset] = (value & 0xff) this[offset + 1] = (value >>> 8) } else { objectWriteUInt16(this, value, offset, true) @@ -1028,7 +1291,7 @@ Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = (value >>> 8) - this[offset + 1] = value + this[offset + 1] = (value & 0xff) } else { objectWriteUInt16(this, value, offset, false) } @@ -1040,7 +1303,7 @@ Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = value + this[offset] = (value & 0xff) this[offset + 1] = (value >>> 8) this[offset + 2] = (value >>> 16) this[offset + 3] = (value >>> 24) @@ -1059,7 +1322,7 @@ Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) this[offset] = (value >>> 24) this[offset + 1] = (value >>> 16) this[offset + 2] = (value >>> 8) - this[offset + 3] = value + this[offset + 3] = (value & 0xff) } else { objectWriteUInt32(this, value, offset, false) } @@ -1130,9 +1393,16 @@ Buffer.prototype.copy = function copy (target, targetStart, start, end) { } var len = end - start + var i - if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { - for (var i = 0; i < len; i++) { + if (this === target && start < targetStart && targetStart < end) { + // descending copy from end + for (i = len - 1; i >= 0; i--) { + target[i + targetStart] = this[i + start] + } + } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { + // ascending copy from start + for (i = 0; i < len; i++) { target[i + targetStart] = this[i + start] } } else { @@ -1208,7 +1478,7 @@ Buffer._augment = function _augment (arr) { // save reference to original Uint8Array set method before overwriting arr._set = arr.set - // deprecated, will be removed in node 0.13+ + // deprecated arr.get = BP.get arr.set = BP.set @@ -1264,7 +1534,7 @@ Buffer._augment = function _augment (arr) { return arr } -var INVALID_BASE64_RE = /[^+\/0-9A-z\-]/g +var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g function base64clean (str) { // Node strips out invalid characters like \n and \t from the string, base64-js does not @@ -1294,28 +1564,15 @@ function utf8ToBytes (string, units) { var length = string.length var leadSurrogate = null var bytes = [] - var i = 0 - for (; i < length; i++) { + for (var i = 0; i < length; i++) { codePoint = string.charCodeAt(i) // is surrogate component if (codePoint > 0xD7FF && codePoint < 0xE000) { // last char was a lead - if (leadSurrogate) { - // 2 leads in a row - if (codePoint < 0xDC00) { - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - leadSurrogate = codePoint - continue - } else { - // valid surrogate pair - codePoint = leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00 | 0x10000 - leadSurrogate = null - } - } else { + if (!leadSurrogate) { // no lead yet - if (codePoint > 0xDBFF) { // unexpected trail if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) @@ -1324,18 +1581,30 @@ function utf8ToBytes (string, units) { // unpaired lead if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) continue - } else { - // valid lead - leadSurrogate = codePoint - continue } + + // valid lead + leadSurrogate = codePoint + + continue } + + // 2 leads in a row + if (codePoint < 0xDC00) { + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + leadSurrogate = codePoint + continue + } + + // valid surrogate pair + codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 } else if (leadSurrogate) { // valid bmp char, but last char was a lead if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - leadSurrogate = null } + leadSurrogate = null + // encode utf8 if (codePoint < 0x80) { if ((units -= 1) < 0) break @@ -1353,7 +1622,7 @@ function utf8ToBytes (string, units) { codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80 ) - } else if (codePoint < 0x200000) { + } else if (codePoint < 0x110000) { if ((units -= 4) < 0) break bytes.push( codePoint >> 0x12 | 0xF0, @@ -1406,144 +1675,18 @@ function blitBuffer (src, dst, offset, length) { return i } -function decodeUtf8Char (str) { - try { - return decodeURIComponent(str) - } catch (err) { - return String.fromCharCode(0xFFFD) // UTF 8 invalid char - } -} +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"base64-js":1,"ieee754":4,"isarray":3}],3:[function(require,module,exports){ +var toString = {}.toString; -},{"base64-js":2,"ieee754":3,"is-array":4}],2:[function(require,module,exports){ -var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; +module.exports = Array.isArray || function (arr) { + return toString.call(arr) == '[object Array]'; +}; -;(function (exports) { - 'use strict'; - - var Arr = (typeof Uint8Array !== 'undefined') - ? Uint8Array - : Array - - var PLUS = '+'.charCodeAt(0) - var SLASH = '/'.charCodeAt(0) - var NUMBER = '0'.charCodeAt(0) - var LOWER = 'a'.charCodeAt(0) - var UPPER = 'A'.charCodeAt(0) - var PLUS_URL_SAFE = '-'.charCodeAt(0) - var SLASH_URL_SAFE = '_'.charCodeAt(0) - - function decode (elt) { - var code = elt.charCodeAt(0) - if (code === PLUS || - code === PLUS_URL_SAFE) - return 62 // '+' - if (code === SLASH || - code === SLASH_URL_SAFE) - return 63 // '/' - if (code < NUMBER) - return -1 //no match - if (code < NUMBER + 10) - return code - NUMBER + 26 + 26 - if (code < UPPER + 26) - return code - UPPER - if (code < LOWER + 26) - return code - LOWER + 26 - } - - function b64ToByteArray (b64) { - var i, j, l, tmp, placeHolders, arr - - if (b64.length % 4 > 0) { - throw new Error('Invalid string. Length must be a multiple of 4') - } - - // the number of equal signs (place holders) - // if there are two placeholders, than the two characters before it - // represent one byte - // if there is only one, then the three characters before it represent 2 bytes - // this is just a cheap hack to not do indexOf twice - var len = b64.length - placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0 - - // base64 is 4/3 + up to two characters of the original data - arr = new Arr(b64.length * 3 / 4 - placeHolders) - - // if there are placeholders, only get up to the last complete 4 chars - l = placeHolders > 0 ? b64.length - 4 : b64.length - - var L = 0 - - function push (v) { - arr[L++] = v - } - - for (i = 0, j = 0; i < l; i += 4, j += 3) { - tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3)) - push((tmp & 0xFF0000) >> 16) - push((tmp & 0xFF00) >> 8) - push(tmp & 0xFF) - } - - if (placeHolders === 2) { - tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4) - push(tmp & 0xFF) - } else if (placeHolders === 1) { - tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2) - push((tmp >> 8) & 0xFF) - push(tmp & 0xFF) - } - - return arr - } - - function uint8ToBase64 (uint8) { - var i, - extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes - output = "", - temp, length - - function encode (num) { - return lookup.charAt(num) - } - - function tripletToBase64 (num) { - return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F) - } - - // go through the array every three bytes, we'll deal with trailing stuff later - for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { - temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) - output += tripletToBase64(temp) - } - - // pad the end with zeros, but make sure to not forget the extra bytes - switch (extraBytes) { - case 1: - temp = uint8[uint8.length - 1] - output += encode(temp >> 2) - output += encode((temp << 4) & 0x3F) - output += '==' - break - case 2: - temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]) - output += encode(temp >> 10) - output += encode((temp >> 4) & 0x3F) - output += encode((temp << 2) & 0x3F) - output += '=' - break - } - - return output - } - - exports.toByteArray = b64ToByteArray - exports.fromByteArray = uint8ToBase64 -}(typeof exports === 'undefined' ? (this.base64js = {}) : exports)) - -},{}],3:[function(require,module,exports){ +},{}],4:[function(require,module,exports){ exports.read = function (buffer, offset, isLE, mLen, nBytes) { var e, m - var eLen = nBytes * 8 - mLen - 1 + var eLen = (nBytes * 8) - mLen - 1 var eMax = (1 << eLen) - 1 var eBias = eMax >> 1 var nBits = -7 @@ -1556,12 +1699,12 @@ exports.read = function (buffer, offset, isLE, mLen, nBytes) { e = s & ((1 << (-nBits)) - 1) s >>= (-nBits) nBits += eLen - for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} + for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {} m = e & ((1 << (-nBits)) - 1) e >>= (-nBits) nBits += mLen - for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} + for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {} if (e === 0) { e = 1 - eBias @@ -1576,7 +1719,7 @@ exports.read = function (buffer, offset, isLE, mLen, nBytes) { exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { var e, m, c - var eLen = nBytes * 8 - mLen - 1 + var eLen = (nBytes * 8) - mLen - 1 var eMax = (1 << eLen) - 1 var eBias = eMax >> 1 var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) @@ -1609,7 +1752,7 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { m = 0 e = eMax } else if (e + eBias >= 1) { - m = (value * c - 1) * Math.pow(2, mLen) + m = ((value * c) - 1) * Math.pow(2, mLen) e = e + eBias } else { m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) @@ -1626,41 +1769,6 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { buffer[offset + i - d] |= s * 128 } -},{}],4:[function(require,module,exports){ - -/** - * isArray - */ - -var isArray = Array.isArray; - -/** - * toString - */ - -var str = Object.prototype.toString; - -/** - * Whether or not the given `val` - * is an array. - * - * example: - * - * isArray([]); - * // > true - * isArray(arguments); - * // > false - * isArray(''); - * // > false - * - * @param {mixed} val - * @return {bool} - */ - -module.exports = isArray || function (val) { - return !! val && '[object Array]' == str.call(val); -}; - },{}],5:[function(require,module,exports){ (function (Buffer){ function FilerBuffer (subject, encoding, nonZero) { @@ -1688,5 +1796,5 @@ Object.keys(Buffer).forEach(function (p) { module.exports = FilerBuffer; }).call(this,require("buffer").Buffer) -},{"buffer":1}]},{},[5])(5) -}); \ No newline at end of file +},{"buffer":2}]},{},[5])(5) +}); diff --git a/dist/buffer.min.js b/dist/buffer.min.js index 6ddaf28..5e36947 100644 --- a/dist/buffer.min.js +++ b/dist/buffer.min.js @@ -1,2 +1,2 @@ -/*! filer 0.0.44 2017-05-25 */ -!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.FilerBuffer=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g1?arguments[1]:"utf8"):g(this,a)):arguments.length>1?new d(a,arguments[1]):new d(a)}function e(a,b){if(a=m(a,0>b?0:0|n(b)),!d.TYPED_ARRAY_SUPPORT)for(var c=0;b>c;c++)a[c]=0;return a}function f(a,b,c){("string"!=typeof c||""===c)&&(c="utf8");var d=0|p(b,c);return a=m(a,d),a.write(b,c),a}function g(a,b){if(d.isBuffer(b))return h(a,b);if(U(b))return i(a,b);if(null==b)throw new TypeError("must start with number, buffer, array or string");return"undefined"!=typeof ArrayBuffer&&b.buffer instanceof ArrayBuffer?j(a,b):b.length?k(a,b):l(a,b)}function h(a,b){var c=0|n(b.length);return a=m(a,c),b.copy(a,0,0,c),a}function i(a,b){var c=0|n(b.length);a=m(a,c);for(var d=0;c>d;d+=1)a[d]=255&b[d];return a}function j(a,b){var c=0|n(b.length);a=m(a,c);for(var d=0;c>d;d+=1)a[d]=255&b[d];return a}function k(a,b){var c=0|n(b.length);a=m(a,c);for(var d=0;c>d;d+=1)a[d]=255&b[d];return a}function l(a,b){var c,d=0;"Buffer"===b.type&&U(b.data)&&(c=b.data,d=0|n(c.length)),a=m(a,d);for(var e=0;d>e;e+=1)a[e]=255&c[e];return a}function m(a,b){d.TYPED_ARRAY_SUPPORT?a=d._augment(new Uint8Array(b)):(a.length=b,a._isBuffer=!0);var c=0!==b&&b<=d.poolSize>>>1;return c&&(a.parent=W),a}function n(a){if(a>=V)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+V.toString(16)+" bytes");return 0|a}function o(a,b){if(!(this instanceof o))return new o(a,b);var c=new d(a,b);return delete c.parent,c}function p(a,b){if("string"!=typeof a&&(a=String(a)),0===a.length)return 0;switch(b||"utf8"){case"ascii":case"binary":case"raw":return a.length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*a.length;case"hex":return a.length>>>1;case"utf8":case"utf-8":return M(a).length;case"base64":return P(a).length;default:return a.length}}function q(a,b,c,d){c=Number(c)||0;var e=a.length-c;d?(d=Number(d),d>e&&(d=e)):d=e;var f=b.length;if(f%2!==0)throw new Error("Invalid hex string");d>f/2&&(d=f/2);for(var g=0;d>g;g++){var h=parseInt(b.substr(2*g,2),16);if(isNaN(h))throw new Error("Invalid hex string");a[c+g]=h}return g}function r(a,b,c,d){return Q(M(b,a.length-c),a,c,d)}function s(a,b,c,d){return Q(N(b),a,c,d)}function t(a,b,c,d){return s(a,b,c,d)}function u(a,b,c,d){return Q(P(b),a,c,d)}function v(a,b,c,d){return Q(O(b,a.length-c),a,c,d)}function w(a,b,c){return 0===b&&c===a.length?S.fromByteArray(a):S.fromByteArray(a.slice(b,c))}function x(a,b,c){var d="",e="";c=Math.min(a.length,c);for(var f=b;c>f;f++)a[f]<=127?(d+=R(e)+String.fromCharCode(a[f]),e=""):e+="%"+a[f].toString(16);return d+R(e)}function y(a,b,c){var d="";c=Math.min(a.length,c);for(var e=b;c>e;e++)d+=String.fromCharCode(127&a[e]);return d}function z(a,b,c){var d="";c=Math.min(a.length,c);for(var e=b;c>e;e++)d+=String.fromCharCode(a[e]);return d}function A(a,b,c){var d=a.length;(!b||0>b)&&(b=0),(!c||0>c||c>d)&&(c=d);for(var e="",f=b;c>f;f++)e+=L(a[f]);return e}function B(a,b,c){for(var d=a.slice(b,c),e="",f=0;fa)throw new RangeError("offset is not uint");if(a+b>c)throw new RangeError("Trying to access beyond buffer length")}function D(a,b,c,e,f,g){if(!d.isBuffer(a))throw new TypeError("buffer must be a Buffer instance");if(b>f||g>b)throw new RangeError("value is out of bounds");if(c+e>a.length)throw new RangeError("index out of range")}function E(a,b,c,d){0>b&&(b=65535+b+1);for(var e=0,f=Math.min(a.length-c,2);f>e;e++)a[c+e]=(b&255<<8*(d?e:1-e))>>>8*(d?e:1-e)}function F(a,b,c,d){0>b&&(b=4294967295+b+1);for(var e=0,f=Math.min(a.length-c,4);f>e;e++)a[c+e]=b>>>8*(d?e:3-e)&255}function G(a,b,c,d,e,f){if(b>e||f>b)throw new RangeError("value is out of bounds");if(c+d>a.length)throw new RangeError("index out of range");if(0>c)throw new RangeError("index out of range")}function H(a,b,c,d,e){return e||G(a,b,c,4,3.4028234663852886e38,-3.4028234663852886e38),T.write(a,b,c,d,23,4),c+4}function I(a,b,c,d,e){return e||G(a,b,c,8,1.7976931348623157e308,-1.7976931348623157e308),T.write(a,b,c,d,52,8),c+8}function J(a){if(a=K(a).replace(Y,""),a.length<2)return"";for(;a.length%4!==0;)a+="=";return a}function K(a){return a.trim?a.trim():a.replace(/^\s+|\s+$/g,"")}function L(a){return 16>a?"0"+a.toString(16):a.toString(16)}function M(a,b){b=b||1/0;for(var c,d=a.length,e=null,f=[],g=0;d>g;g++){if(c=a.charCodeAt(g),c>55295&&57344>c){if(!e){if(c>56319){(b-=3)>-1&&f.push(239,191,189);continue}if(g+1===d){(b-=3)>-1&&f.push(239,191,189);continue}e=c;continue}if(56320>c){(b-=3)>-1&&f.push(239,191,189),e=c;continue}c=e-55296<<10|c-56320|65536,e=null}else e&&((b-=3)>-1&&f.push(239,191,189),e=null);if(128>c){if((b-=1)<0)break;f.push(c)}else if(2048>c){if((b-=2)<0)break;f.push(c>>6|192,63&c|128)}else if(65536>c){if((b-=3)<0)break;f.push(c>>12|224,c>>6&63|128,63&c|128)}else{if(!(2097152>c))throw new Error("Invalid code point");if((b-=4)<0)break;f.push(c>>18|240,c>>12&63|128,c>>6&63|128,63&c|128)}}return f}function N(a){for(var b=[],c=0;c>8,e=c%256,f.push(e),f.push(d);return f}function P(a){return S.toByteArray(J(a))}function Q(a,b,c,d){for(var e=0;d>e&&!(e+c>=b.length||e>=a.length);e++)b[e+c]=a[e];return e}function R(a){try{return decodeURIComponent(a)}catch(b){return String.fromCharCode(65533)}}var S=a("base64-js"),T=a("ieee754"),U=a("is-array");c.Buffer=d,c.SlowBuffer=o,c.INSPECT_MAX_BYTES=50,d.poolSize=8192;var V=1073741823,W={};d.TYPED_ARRAY_SUPPORT=function(){try{var a=new ArrayBuffer(0),b=new Uint8Array(a);return b.foo=function(){return 42},42===b.foo()&&"function"==typeof b.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(c){return!1}}(),d.isBuffer=function(a){return!(null==a||!a._isBuffer)},d.compare=function(a,b){if(!d.isBuffer(a)||!d.isBuffer(b))throw new TypeError("Arguments must be Buffers");if(a===b)return 0;for(var c=a.length,e=b.length,f=0,g=Math.min(c,e);g>f&&a[f]===b[f];)++f;return f!==g&&(c=a[f],e=b[f]),e>c?-1:c>e?1:0},d.isEncoding=function(a){switch(String(a).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},d.concat=function(a,b){if(!U(a))throw new TypeError("list argument must be an Array of Buffers.");if(0===a.length)return new d(0);if(1===a.length)return a[0];var c;if(void 0===b)for(b=0,c=0;cb&&(b=0),c>this.length&&(c=this.length),b>=c)return"";for(;;)switch(a){case"hex":return A(this,b,c);case"utf8":case"utf-8":return x(this,b,c);case"ascii":return y(this,b,c);case"binary":return z(this,b,c);case"base64":return w(this,b,c);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,b,c);default:if(d)throw new TypeError("Unknown encoding: "+a);a=(a+"").toLowerCase(),d=!0}},d.prototype.equals=function(a){if(!d.isBuffer(a))throw new TypeError("Argument must be a Buffer");return this===a?!0:0===d.compare(this,a)},d.prototype.inspect=function(){var a="",b=c.INSPECT_MAX_BYTES;return this.length>0&&(a=this.toString("hex",0,b).match(/.{2}/g).join(" "),this.length>b&&(a+=" ... ")),""},d.prototype.compare=function(a){if(!d.isBuffer(a))throw new TypeError("Argument must be a Buffer");return this===a?0:d.compare(this,a)},d.prototype.indexOf=function(a,b){function c(a,b,c){for(var d=-1,e=0;c+e2147483647?b=2147483647:-2147483648>b&&(b=-2147483648),b>>=0,0===this.length)return-1;if(b>=this.length)return-1;if(0>b&&(b=Math.max(this.length+b,0)),"string"==typeof a)return 0===a.length?-1:String.prototype.indexOf.call(this,a,b);if(d.isBuffer(a))return c(this,a,b);if("number"==typeof a)return d.TYPED_ARRAY_SUPPORT&&"function"===Uint8Array.prototype.indexOf?Uint8Array.prototype.indexOf.call(this,a,b):c(this,[a],b);throw new TypeError("val must be string, number or Buffer")},d.prototype.get=function(a){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(a)},d.prototype.set=function(a,b){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(a,b)},d.prototype.write=function(a,b,c,d){if(void 0===b)d="utf8",c=this.length,b=0;else if(void 0===c&&"string"==typeof b)d=b,c=this.length,b=0;else if(isFinite(b))b=0|b,isFinite(c)?(c=0|c,void 0===d&&(d="utf8")):(d=c,c=void 0);else{var e=d;d=b,b=0|c,c=e}var f=this.length-b;if((void 0===c||c>f)&&(c=f),a.length>0&&(0>c||0>b)||b>this.length)throw new RangeError("attempt to write outside buffer bounds");d||(d="utf8");for(var g=!1;;)switch(d){case"hex":return q(this,a,b,c);case"utf8":case"utf-8":return r(this,a,b,c);case"ascii":return s(this,a,b,c);case"binary":return t(this,a,b,c);case"base64":return u(this,a,b,c);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return v(this,a,b,c);default:if(g)throw new TypeError("Unknown encoding: "+d);d=(""+d).toLowerCase(),g=!0}},d.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},d.prototype.slice=function(a,b){var c=this.length;a=~~a,b=void 0===b?c:~~b,0>a?(a+=c,0>a&&(a=0)):a>c&&(a=c),0>b?(b+=c,0>b&&(b=0)):b>c&&(b=c),a>b&&(b=a);var e;if(d.TYPED_ARRAY_SUPPORT)e=d._augment(this.subarray(a,b));else{var f=b-a;e=new d(f,void 0);for(var g=0;f>g;g++)e[g]=this[g+a]}return e.length&&(e.parent=this.parent||this),e},d.prototype.readUIntLE=function(a,b,c){a=0|a,b=0|b,c||C(a,b,this.length);for(var d=this[a],e=1,f=0;++f0&&(e*=256);)d+=this[a+--b]*e;return d},d.prototype.readUInt8=function(a,b){return b||C(a,1,this.length),this[a]},d.prototype.readUInt16LE=function(a,b){return b||C(a,2,this.length),this[a]|this[a+1]<<8},d.prototype.readUInt16BE=function(a,b){return b||C(a,2,this.length),this[a]<<8|this[a+1]},d.prototype.readUInt32LE=function(a,b){return b||C(a,4,this.length),(this[a]|this[a+1]<<8|this[a+2]<<16)+16777216*this[a+3]},d.prototype.readUInt32BE=function(a,b){return b||C(a,4,this.length),16777216*this[a]+(this[a+1]<<16|this[a+2]<<8|this[a+3])},d.prototype.readIntLE=function(a,b,c){a=0|a,b=0|b,c||C(a,b,this.length);for(var d=this[a],e=1,f=0;++f=e&&(d-=Math.pow(2,8*b)),d},d.prototype.readIntBE=function(a,b,c){a=0|a,b=0|b,c||C(a,b,this.length);for(var d=b,e=1,f=this[a+--d];d>0&&(e*=256);)f+=this[a+--d]*e;return e*=128,f>=e&&(f-=Math.pow(2,8*b)),f},d.prototype.readInt8=function(a,b){return b||C(a,1,this.length),128&this[a]?-1*(255-this[a]+1):this[a]},d.prototype.readInt16LE=function(a,b){b||C(a,2,this.length);var c=this[a]|this[a+1]<<8;return 32768&c?4294901760|c:c},d.prototype.readInt16BE=function(a,b){b||C(a,2,this.length);var c=this[a+1]|this[a]<<8;return 32768&c?4294901760|c:c},d.prototype.readInt32LE=function(a,b){return b||C(a,4,this.length),this[a]|this[a+1]<<8|this[a+2]<<16|this[a+3]<<24},d.prototype.readInt32BE=function(a,b){return b||C(a,4,this.length),this[a]<<24|this[a+1]<<16|this[a+2]<<8|this[a+3]},d.prototype.readFloatLE=function(a,b){return b||C(a,4,this.length),T.read(this,a,!0,23,4)},d.prototype.readFloatBE=function(a,b){return b||C(a,4,this.length),T.read(this,a,!1,23,4)},d.prototype.readDoubleLE=function(a,b){return b||C(a,8,this.length),T.read(this,a,!0,52,8)},d.prototype.readDoubleBE=function(a,b){return b||C(a,8,this.length),T.read(this,a,!1,52,8)},d.prototype.writeUIntLE=function(a,b,c,d){a=+a,b=0|b,c=0|c,d||D(this,a,b,c,Math.pow(2,8*c),0);var e=1,f=0;for(this[b]=255&a;++f=0&&(f*=256);)this[b+e]=a/f&255;return b+c},d.prototype.writeUInt8=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,1,255,0),d.TYPED_ARRAY_SUPPORT||(a=Math.floor(a)),this[b]=a,b+1},d.prototype.writeUInt16LE=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,2,65535,0),d.TYPED_ARRAY_SUPPORT?(this[b]=a,this[b+1]=a>>>8):E(this,a,b,!0),b+2},d.prototype.writeUInt16BE=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,2,65535,0),d.TYPED_ARRAY_SUPPORT?(this[b]=a>>>8,this[b+1]=a):E(this,a,b,!1),b+2},d.prototype.writeUInt32LE=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,4,4294967295,0),d.TYPED_ARRAY_SUPPORT?(this[b+3]=a>>>24,this[b+2]=a>>>16,this[b+1]=a>>>8,this[b]=a):F(this,a,b,!0),b+4},d.prototype.writeUInt32BE=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,4,4294967295,0),d.TYPED_ARRAY_SUPPORT?(this[b]=a>>>24,this[b+1]=a>>>16,this[b+2]=a>>>8,this[b+3]=a):F(this,a,b,!1),b+4},d.prototype.writeIntLE=function(a,b,c,d){if(a=+a,b=0|b,!d){var e=Math.pow(2,8*c-1);D(this,a,b,c,e-1,-e)}var f=0,g=1,h=0>a?1:0;for(this[b]=255&a;++f>0)-h&255;return b+c},d.prototype.writeIntBE=function(a,b,c,d){if(a=+a,b=0|b,!d){var e=Math.pow(2,8*c-1);D(this,a,b,c,e-1,-e)}var f=c-1,g=1,h=0>a?1:0;for(this[b+f]=255&a;--f>=0&&(g*=256);)this[b+f]=(a/g>>0)-h&255;return b+c},d.prototype.writeInt8=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,1,127,-128),d.TYPED_ARRAY_SUPPORT||(a=Math.floor(a)),0>a&&(a=255+a+1),this[b]=a,b+1},d.prototype.writeInt16LE=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,2,32767,-32768),d.TYPED_ARRAY_SUPPORT?(this[b]=a,this[b+1]=a>>>8):E(this,a,b,!0),b+2},d.prototype.writeInt16BE=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,2,32767,-32768),d.TYPED_ARRAY_SUPPORT?(this[b]=a>>>8,this[b+1]=a):E(this,a,b,!1),b+2},d.prototype.writeInt32LE=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,4,2147483647,-2147483648),d.TYPED_ARRAY_SUPPORT?(this[b]=a,this[b+1]=a>>>8,this[b+2]=a>>>16,this[b+3]=a>>>24):F(this,a,b,!0),b+4},d.prototype.writeInt32BE=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,4,2147483647,-2147483648),0>a&&(a=4294967295+a+1),d.TYPED_ARRAY_SUPPORT?(this[b]=a>>>24,this[b+1]=a>>>16,this[b+2]=a>>>8,this[b+3]=a):F(this,a,b,!1),b+4},d.prototype.writeFloatLE=function(a,b,c){return H(this,a,b,!0,c)},d.prototype.writeFloatBE=function(a,b,c){return H(this,a,b,!1,c)},d.prototype.writeDoubleLE=function(a,b,c){return I(this,a,b,!0,c)},d.prototype.writeDoubleBE=function(a,b,c){return I(this,a,b,!1,c)},d.prototype.copy=function(a,b,c,e){if(c||(c=0),e||0===e||(e=this.length),b>=a.length&&(b=a.length),b||(b=0),e>0&&c>e&&(e=c),e===c)return 0;if(0===a.length||0===this.length)return 0;if(0>b)throw new RangeError("targetStart out of bounds");if(0>c||c>=this.length)throw new RangeError("sourceStart out of bounds");if(0>e)throw new RangeError("sourceEnd out of bounds");e>this.length&&(e=this.length),a.length-bf||!d.TYPED_ARRAY_SUPPORT)for(var g=0;f>g;g++)a[g+b]=this[g+c];else a._set(this.subarray(c,c+f),b);return f},d.prototype.fill=function(a,b,c){if(a||(a=0),b||(b=0),c||(c=this.length),b>c)throw new RangeError("end < start");if(c!==b&&0!==this.length){if(0>b||b>=this.length)throw new RangeError("start out of bounds");if(0>c||c>this.length)throw new RangeError("end out of bounds");var d;if("number"==typeof a)for(d=b;c>d;d++)this[d]=a;else{var e=M(a.toString()),f=e.length;for(d=b;c>d;d++)this[d]=e[d%f]}return this}},d.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(d.TYPED_ARRAY_SUPPORT)return new d(this).buffer;for(var a=new Uint8Array(this.length),b=0,c=a.length;c>b;b+=1)a[b]=this[b];return a.buffer}throw new TypeError("Buffer.toArrayBuffer not supported in this browser")};var X=d.prototype;d._augment=function(a){return a.constructor=d,a._isBuffer=!0,a._set=a.set,a.get=X.get,a.set=X.set,a.write=X.write,a.toString=X.toString,a.toLocaleString=X.toString,a.toJSON=X.toJSON,a.equals=X.equals,a.compare=X.compare,a.indexOf=X.indexOf,a.copy=X.copy,a.slice=X.slice,a.readUIntLE=X.readUIntLE,a.readUIntBE=X.readUIntBE,a.readUInt8=X.readUInt8,a.readUInt16LE=X.readUInt16LE,a.readUInt16BE=X.readUInt16BE,a.readUInt32LE=X.readUInt32LE,a.readUInt32BE=X.readUInt32BE,a.readIntLE=X.readIntLE,a.readIntBE=X.readIntBE,a.readInt8=X.readInt8,a.readInt16LE=X.readInt16LE,a.readInt16BE=X.readInt16BE,a.readInt32LE=X.readInt32LE,a.readInt32BE=X.readInt32BE,a.readFloatLE=X.readFloatLE,a.readFloatBE=X.readFloatBE,a.readDoubleLE=X.readDoubleLE,a.readDoubleBE=X.readDoubleBE,a.writeUInt8=X.writeUInt8,a.writeUIntLE=X.writeUIntLE,a.writeUIntBE=X.writeUIntBE,a.writeUInt16LE=X.writeUInt16LE,a.writeUInt16BE=X.writeUInt16BE,a.writeUInt32LE=X.writeUInt32LE,a.writeUInt32BE=X.writeUInt32BE,a.writeIntLE=X.writeIntLE,a.writeIntBE=X.writeIntBE,a.writeInt8=X.writeInt8,a.writeInt16LE=X.writeInt16LE,a.writeInt16BE=X.writeInt16BE,a.writeInt32LE=X.writeInt32LE,a.writeInt32BE=X.writeInt32BE,a.writeFloatLE=X.writeFloatLE,a.writeFloatBE=X.writeFloatBE,a.writeDoubleLE=X.writeDoubleLE,a.writeDoubleBE=X.writeDoubleBE,a.fill=X.fill,a.inspect=X.inspect,a.toArrayBuffer=X.toArrayBuffer,a};var Y=/[^+\/0-9A-z\-]/g},{"base64-js":2,ieee754:3,"is-array":4}],2:[function(a,b,c){var d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(a){"use strict";function b(a){var b=a.charCodeAt(0);return b===g||b===l?62:b===h||b===m?63:i>b?-1:i+10>b?b-i+26+26:k+26>b?b-k:j+26>b?b-j+26:void 0}function c(a){function c(a){j[l++]=a}var d,e,g,h,i,j;if(a.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var k=a.length;i="="===a.charAt(k-2)?2:"="===a.charAt(k-1)?1:0,j=new f(3*a.length/4-i),g=i>0?a.length-4:a.length;var l=0;for(d=0,e=0;g>d;d+=4,e+=3)h=b(a.charAt(d))<<18|b(a.charAt(d+1))<<12|b(a.charAt(d+2))<<6|b(a.charAt(d+3)),c((16711680&h)>>16),c((65280&h)>>8),c(255&h);return 2===i?(h=b(a.charAt(d))<<2|b(a.charAt(d+1))>>4,c(255&h)):1===i&&(h=b(a.charAt(d))<<10|b(a.charAt(d+1))<<4|b(a.charAt(d+2))>>2,c(h>>8&255),c(255&h)),j}function e(a){function b(a){return d.charAt(a)}function c(a){return b(a>>18&63)+b(a>>12&63)+b(a>>6&63)+b(63&a)}var e,f,g,h=a.length%3,i="";for(e=0,g=a.length-h;g>e;e+=3)f=(a[e]<<16)+(a[e+1]<<8)+a[e+2],i+=c(f);switch(h){case 1:f=a[a.length-1],i+=b(f>>2),i+=b(f<<4&63),i+="==";break;case 2:f=(a[a.length-2]<<8)+a[a.length-1],i+=b(f>>10),i+=b(f>>4&63),i+=b(f<<2&63),i+="="}return i}var f="undefined"!=typeof Uint8Array?Uint8Array:Array,g="+".charCodeAt(0),h="/".charCodeAt(0),i="0".charCodeAt(0),j="a".charCodeAt(0),k="A".charCodeAt(0),l="-".charCodeAt(0),m="_".charCodeAt(0);a.toByteArray=c,a.fromByteArray=e}("undefined"==typeof c?this.base64js={}:c)},{}],3:[function(a,b,c){c.read=function(a,b,c,d,e){var f,g,h=8*e-d-1,i=(1<>1,k=-7,l=c?e-1:0,m=c?-1:1,n=a[b+l];for(l+=m,f=n&(1<<-k)-1,n>>=-k,k+=h;k>0;f=256*f+a[b+l],l+=m,k-=8);for(g=f&(1<<-k)-1,f>>=-k,k+=d;k>0;g=256*g+a[b+l],l+=m,k-=8);if(0===f)f=1-j;else{if(f===i)return g?NaN:(n?-1:1)*(1/0);g+=Math.pow(2,d),f-=j}return(n?-1:1)*g*Math.pow(2,f-d)},c.write=function(a,b,c,d,e,f){var g,h,i,j=8*f-e-1,k=(1<>1,m=23===e?Math.pow(2,-24)-Math.pow(2,-77):0,n=d?0:f-1,o=d?1:-1,p=0>b||0===b&&0>1/b?1:0;for(b=Math.abs(b),isNaN(b)||b===1/0?(h=isNaN(b)?1:0,g=k):(g=Math.floor(Math.log(b)/Math.LN2),b*(i=Math.pow(2,-g))<1&&(g--,i*=2),b+=g+l>=1?m/i:m*Math.pow(2,1-l),b*i>=2&&(g++,i/=2),g+l>=k?(h=0,g=k):g+l>=1?(h=(b*i-1)*Math.pow(2,e),g+=l):(h=b*Math.pow(2,l-1)*Math.pow(2,e),g=0));e>=8;a[c+n]=255&h,n+=o,h/=256,e-=8);for(g=g<0;a[c+n]=255&g,n+=o,g/=256,j-=8);a[c+n-o]|=128*p}},{}],4:[function(a,b,c){var d=Array.isArray,e=Object.prototype.toString;b.exports=d||function(a){return!!a&&"[object Array]"==e.call(a)}},{}],5:[function(a,b,c){(function(a){function c(b,c,d){return b instanceof ArrayBuffer&&(b=new Uint8Array(b)),new a(b,c,d)}c.prototype=Object.create(a.prototype),c.prototype.constructor=c,Object.keys(a).forEach(function(b){a.hasOwnProperty(b)&&(c[b]=a[b])}),b.exports=c}).call(this,a("buffer").Buffer)},{buffer:1}]},{},[5])(5)}); \ No newline at end of file +/*! filer 0.0.44 2018-05-29 */ +!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.FilerBuffer=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c||a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g0)throw new Error("Invalid string. Length must be a multiple of 4");var k=a.length;i="="===a.charAt(k-2)?2:"="===a.charAt(k-1)?1:0,j=new e(3*a.length/4-i),g=i>0?a.length-4:a.length;var l=0;for(d=0,f=0;d>16),c((65280&h)>>8),c(255&h);return 2===i?(h=b(a.charAt(d))<<2|b(a.charAt(d+1))>>4,c(255&h)):1===i&&(h=b(a.charAt(d))<<10|b(a.charAt(d+1))<<4|b(a.charAt(d+2))>>2,c(h>>8&255),c(255&h)),j}function d(a){function b(a){return"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(a)}function c(a){return b(a>>18&63)+b(a>>12&63)+b(a>>6&63)+b(63&a)}var d,e,f,g=a.length%3,h="";for(d=0,f=a.length-g;d>2),h+=b(e<<4&63),h+="==";break;case 2:e=(a[a.length-2]<<8)+a[a.length-1],h+=b(e>>10),h+=b(e>>4&63),h+=b(e<<2&63),h+="="}return h}var e="undefined"!=typeof Uint8Array?Uint8Array:Array,f="+".charCodeAt(0),g="/".charCodeAt(0),h="0".charCodeAt(0),i="a".charCodeAt(0),j="A".charCodeAt(0),k="-".charCodeAt(0),l="_".charCodeAt(0);a.toByteArray=c,a.fromByteArray=d}(void 0===c?this.base64js={}:c)},{}],2:[function(a,b,c){(function(b){"use strict";function d(){function a(){}try{var b=new Uint8Array(1);return b.foo=function(){return 42},b.constructor=a,42===b.foo()&&b.constructor===a&&"function"==typeof b.subarray&&0===b.subarray(1,1).byteLength}catch(c){return!1}}function e(){return f.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function f(a){return this instanceof f?(f.TYPED_ARRAY_SUPPORT||(this.length=0,this.parent=void 0),"number"==typeof a?g(this,a):"string"==typeof a?h(this,a,arguments.length>1?arguments[1]:"utf8"):i(this,a)):arguments.length>1?new f(a,arguments[1]):new f(a)}function g(a,b){if(a=p(a,b<0?0:0|q(b)),!f.TYPED_ARRAY_SUPPORT)for(var c=0;c>>1&&(a.parent=Z),a}function q(a){if(a>=e())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+e().toString(16)+" bytes");return 0|a}function r(a,b){if(!(this instanceof r))return new r(a,b);var c=new f(a,b);return delete c.parent,c}function s(a,b){"string"!=typeof a&&(a=""+a);var c=a.length;if(0===c)return 0;for(var d=!1;;)switch(b){case"ascii":case"binary":case"raw":case"raws":return c;case"utf8":case"utf-8":return R(a).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*c;case"hex":return c>>>1;case"base64":return U(a).length;default:if(d)return R(a).length;b=(""+b).toLowerCase(),d=!0}}function t(a,b,c){var d=!1;if(b|=0,c=void 0===c||c===1/0?this.length:0|c,a||(a="utf8"),b<0&&(b=0),c>this.length&&(c=this.length),c<=b)return"";for(;;)switch(a){case"hex":return F(this,b,c);case"utf8":case"utf-8":return B(this,b,c);case"ascii":return D(this,b,c);case"binary":return E(this,b,c);case"base64":return A(this,b,c);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return G(this,b,c);default:if(d)throw new TypeError("Unknown encoding: "+a);a=(a+"").toLowerCase(),d=!0}}function u(a,b,c,d){c=Number(c)||0;var e=a.length-c;d?(d=Number(d))>e&&(d=e):d=e;var f=b.length;if(f%2!=0)throw new Error("Invalid hex string");d>f/2&&(d=f/2);for(var g=0;g239?4:f>223?3:f>191?2:1;if(e+h<=c){var i,j,k,l;switch(h){case 1:f<128&&(g=f);break;case 2:i=a[e+1],128==(192&i)&&(l=(31&f)<<6|63&i)>127&&(g=l);break;case 3:i=a[e+1],j=a[e+2],128==(192&i)&&128==(192&j)&&(l=(15&f)<<12|(63&i)<<6|63&j)>2047&&(l<55296||l>57343)&&(g=l);break;case 4:i=a[e+1],j=a[e+2],k=a[e+3],128==(192&i)&&128==(192&j)&&128==(192&k)&&(l=(15&f)<<18|(63&i)<<12|(63&j)<<6|63&k)>65535&&l<1114112&&(g=l)}}null===g?(g=65533,h=1):g>65535&&(g-=65536,d.push(g>>>10&1023|55296),g=56320|1023&g),d.push(g),e+=h}return C(d)}function C(a){var b=a.length;if(b<=$)return String.fromCharCode.apply(String,a);for(var c="",d=0;dd)&&(c=d);for(var e="",f=b;fc)throw new RangeError("Trying to access beyond buffer length")}function I(a,b,c,d,e,g){if(!f.isBuffer(a))throw new TypeError("buffer must be a Buffer instance");if(b>e||ba.length)throw new RangeError("index out of range")}function J(a,b,c,d){b<0&&(b=65535+b+1);for(var e=0,f=Math.min(a.length-c,2);e>>8*(d?e:1-e)}function K(a,b,c,d){b<0&&(b=4294967295+b+1);for(var e=0,f=Math.min(a.length-c,4);e>>8*(d?e:3-e)&255}function L(a,b,c,d,e,f){if(b>e||ba.length)throw new RangeError("index out of range");if(c<0)throw new RangeError("index out of range")}function M(a,b,c,d,e){return e||L(a,b,c,4,3.4028234663852886e38,-3.4028234663852886e38),X.write(a,b,c,d,23,4),c+4}function N(a,b,c,d,e){return e||L(a,b,c,8,1.7976931348623157e308,-1.7976931348623157e308),X.write(a,b,c,d,52,8),c+8}function O(a){if(a=P(a).replace(aa,""),a.length<2)return"";for(;a.length%4!=0;)a+="=";return a}function P(a){return a.trim?a.trim():a.replace(/^\s+|\s+$/g,"")}function Q(a){return a<16?"0"+a.toString(16):a.toString(16)}function R(a,b){b=b||1/0;for(var c,d=a.length,e=null,f=[],g=0;g55295&&c<57344){if(!e){if(c>56319){(b-=3)>-1&&f.push(239,191,189);continue}if(g+1===d){(b-=3)>-1&&f.push(239,191,189);continue}e=c;continue}if(c<56320){(b-=3)>-1&&f.push(239,191,189),e=c;continue}c=65536+(e-55296<<10|c-56320)}else e&&(b-=3)>-1&&f.push(239,191,189);if(e=null,c<128){if((b-=1)<0)break;f.push(c)}else if(c<2048){if((b-=2)<0)break;f.push(c>>6|192,63&c|128)}else if(c<65536){if((b-=3)<0)break;f.push(c>>12|224,c>>6&63|128,63&c|128)}else{if(!(c<1114112))throw new Error("Invalid code point");if((b-=4)<0)break;f.push(c>>18|240,c>>12&63|128,c>>6&63|128,63&c|128)}}return f}function S(a){for(var b=[],c=0;c>8,e=c%256,f.push(e),f.push(d);return f}function U(a){return W.toByteArray(O(a))}function V(a,b,c,d){for(var e=0;e=b.length||e>=a.length);e++)b[e+c]=a[e];return e}var W=a("base64-js"),X=a("ieee754"),Y=a("isarray");c.Buffer=f,c.SlowBuffer=r,c.INSPECT_MAX_BYTES=50,f.poolSize=8192;var Z={};f.TYPED_ARRAY_SUPPORT=void 0!==b.TYPED_ARRAY_SUPPORT?b.TYPED_ARRAY_SUPPORT:d(),f.TYPED_ARRAY_SUPPORT?(f.prototype.__proto__=Uint8Array.prototype,f.__proto__=Uint8Array):(f.prototype.length=void 0,f.prototype.parent=void 0),f.isBuffer=function(a){return!(null==a||!a._isBuffer)},f.compare=function(a,b){if(!f.isBuffer(a)||!f.isBuffer(b))throw new TypeError("Arguments must be Buffers");if(a===b)return 0;for(var c=a.length,d=b.length,e=0,g=Math.min(c,d);e0&&(a=this.toString("hex",0,b).match(/.{2}/g).join(" "),this.length>b&&(a+=" ... ")),""},f.prototype.compare=function(a){if(!f.isBuffer(a))throw new TypeError("Argument must be a Buffer");return this===a?0:f.compare(this,a)},f.prototype.indexOf=function(a,b){function c(a,b,c){for(var d=-1,e=0;c+e2147483647?b=2147483647:b<-2147483648&&(b=-2147483648),b>>=0,0===this.length)return-1;if(b>=this.length)return-1;if(b<0&&(b=Math.max(this.length+b,0)),"string"==typeof a)return 0===a.length?-1:String.prototype.indexOf.call(this,a,b);if(f.isBuffer(a))return c(this,a,b);if("number"==typeof a)return f.TYPED_ARRAY_SUPPORT&&"function"===Uint8Array.prototype.indexOf?Uint8Array.prototype.indexOf.call(this,a,b):c(this,[a],b);throw new TypeError("val must be string, number or Buffer")},f.prototype.get=function(a){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(a)},f.prototype.set=function(a,b){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(a,b)},f.prototype.write=function(a,b,c,d){if(void 0===b)d="utf8",c=this.length,b=0;else if(void 0===c&&"string"==typeof b)d=b,c=this.length,b=0;else if(isFinite(b))b|=0,isFinite(c)?(c|=0,void 0===d&&(d="utf8")):(d=c,c=void 0);else{var e=d;d=b,b=0|c,c=e}var f=this.length-b;if((void 0===c||c>f)&&(c=f),a.length>0&&(c<0||b<0)||b>this.length)throw new RangeError("attempt to write outside buffer bounds");d||(d="utf8");for(var g=!1;;)switch(d){case"hex":return u(this,a,b,c);case"utf8":case"utf-8":return v(this,a,b,c);case"ascii":return w(this,a,b,c);case"binary":return x(this,a,b,c);case"base64":return y(this,a,b,c);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return z(this,a,b,c);default:if(g)throw new TypeError("Unknown encoding: "+d);d=(""+d).toLowerCase(),g=!0}},f.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var $=4096;f.prototype.slice=function(a,b){var c=this.length;a=~~a,b=void 0===b?c:~~b,a<0?(a+=c)<0&&(a=0):a>c&&(a=c),b<0?(b+=c)<0&&(b=0):b>c&&(b=c),b0&&(e*=256);)d+=this[a+--b]*e;return d},f.prototype.readUInt8=function(a,b){return b||H(a,1,this.length),this[a]},f.prototype.readUInt16LE=function(a,b){return b||H(a,2,this.length),this[a]|this[a+1]<<8},f.prototype.readUInt16BE=function(a,b){return b||H(a,2,this.length),this[a]<<8|this[a+1]},f.prototype.readUInt32LE=function(a,b){return b||H(a,4,this.length),(this[a]|this[a+1]<<8|this[a+2]<<16)+16777216*this[a+3]},f.prototype.readUInt32BE=function(a,b){return b||H(a,4,this.length),16777216*this[a]+(this[a+1]<<16|this[a+2]<<8|this[a+3])},f.prototype.readIntLE=function(a,b,c){a|=0,b|=0,c||H(a,b,this.length);for(var d=this[a],e=1,f=0;++f=e&&(d-=Math.pow(2,8*b)),d},f.prototype.readIntBE=function(a,b,c){a|=0,b|=0,c||H(a,b,this.length);for(var d=b,e=1,f=this[a+--d];d>0&&(e*=256);)f+=this[a+--d]*e;return e*=128,f>=e&&(f-=Math.pow(2,8*b)),f},f.prototype.readInt8=function(a,b){return b||H(a,1,this.length),128&this[a]?-1*(255-this[a]+1):this[a]},f.prototype.readInt16LE=function(a,b){b||H(a,2,this.length);var c=this[a]|this[a+1]<<8;return 32768&c?4294901760|c:c},f.prototype.readInt16BE=function(a,b){b||H(a,2,this.length);var c=this[a+1]|this[a]<<8;return 32768&c?4294901760|c:c},f.prototype.readInt32LE=function(a,b){return b||H(a,4,this.length),this[a]|this[a+1]<<8|this[a+2]<<16|this[a+3]<<24},f.prototype.readInt32BE=function(a,b){return b||H(a,4,this.length),this[a]<<24|this[a+1]<<16|this[a+2]<<8|this[a+3]},f.prototype.readFloatLE=function(a,b){return b||H(a,4,this.length),X.read(this,a,!0,23,4)},f.prototype.readFloatBE=function(a,b){return b||H(a,4,this.length),X.read(this,a,!1,23,4)},f.prototype.readDoubleLE=function(a,b){return b||H(a,8,this.length),X.read(this,a,!0,52,8)},f.prototype.readDoubleBE=function(a,b){return b||H(a,8,this.length),X.read(this,a,!1,52,8)},f.prototype.writeUIntLE=function(a,b,c,d){a=+a,b|=0,c|=0,d||I(this,a,b,c,Math.pow(2,8*c),0);var e=1,f=0;for(this[b]=255&a;++f=0&&(f*=256);)this[b+e]=a/f&255;return b+c},f.prototype.writeUInt8=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,1,255,0),f.TYPED_ARRAY_SUPPORT||(a=Math.floor(a)),this[b]=255&a,b+1},f.prototype.writeUInt16LE=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,2,65535,0),f.TYPED_ARRAY_SUPPORT?(this[b]=255&a,this[b+1]=a>>>8):J(this,a,b,!0),b+2},f.prototype.writeUInt16BE=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,2,65535,0),f.TYPED_ARRAY_SUPPORT?(this[b]=a>>>8,this[b+1]=255&a):J(this,a,b,!1),b+2},f.prototype.writeUInt32LE=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,4,4294967295,0),f.TYPED_ARRAY_SUPPORT?(this[b+3]=a>>>24,this[b+2]=a>>>16,this[b+1]=a>>>8,this[b]=255&a):K(this,a,b,!0),b+4},f.prototype.writeUInt32BE=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,4,4294967295,0),f.TYPED_ARRAY_SUPPORT?(this[b]=a>>>24,this[b+1]=a>>>16,this[b+2]=a>>>8,this[b+3]=255&a):K(this,a,b,!1),b+4},f.prototype.writeIntLE=function(a,b,c,d){if(a=+a,b|=0,!d){var e=Math.pow(2,8*c-1);I(this,a,b,c,e-1,-e)}var f=0,g=1,h=a<0?1:0;for(this[b]=255&a;++f>0)-h&255;return b+c},f.prototype.writeIntBE=function(a,b,c,d){if(a=+a,b|=0,!d){var e=Math.pow(2,8*c-1);I(this,a,b,c,e-1,-e)}var f=c-1,g=1,h=a<0?1:0;for(this[b+f]=255&a;--f>=0&&(g*=256);)this[b+f]=(a/g>>0)-h&255;return b+c},f.prototype.writeInt8=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,1,127,-128),f.TYPED_ARRAY_SUPPORT||(a=Math.floor(a)),a<0&&(a=255+a+1),this[b]=255&a,b+1},f.prototype.writeInt16LE=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,2,32767,-32768),f.TYPED_ARRAY_SUPPORT?(this[b]=255&a,this[b+1]=a>>>8):J(this,a,b,!0),b+2},f.prototype.writeInt16BE=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,2,32767,-32768),f.TYPED_ARRAY_SUPPORT?(this[b]=a>>>8,this[b+1]=255&a):J(this,a,b,!1),b+2},f.prototype.writeInt32LE=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,4,2147483647,-2147483648),f.TYPED_ARRAY_SUPPORT?(this[b]=255&a,this[b+1]=a>>>8,this[b+2]=a>>>16,this[b+3]=a>>>24):K(this,a,b,!0),b+4},f.prototype.writeInt32BE=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,4,2147483647,-2147483648),a<0&&(a=4294967295+a+1),f.TYPED_ARRAY_SUPPORT?(this[b]=a>>>24,this[b+1]=a>>>16,this[b+2]=a>>>8,this[b+3]=255&a):K(this,a,b,!1),b+4},f.prototype.writeFloatLE=function(a,b,c){return M(this,a,b,!0,c)},f.prototype.writeFloatBE=function(a,b,c){return M(this,a,b,!1,c)},f.prototype.writeDoubleLE=function(a,b,c){return N(this,a,b,!0,c)},f.prototype.writeDoubleBE=function(a,b,c){return N(this,a,b,!1,c)},f.prototype.copy=function(a,b,c,d){if(c||(c=0),d||0===d||(d=this.length),b>=a.length&&(b=a.length),b||(b=0),d>0&&d=this.length)throw new RangeError("sourceStart out of bounds");if(d<0)throw new RangeError("sourceEnd out of bounds");d>this.length&&(d=this.length),a.length-b=0;e--)a[e+b]=this[e+c];else if(g<1e3||!f.TYPED_ARRAY_SUPPORT)for(e=0;e=this.length)throw new RangeError("start out of bounds");if(c<0||c>this.length)throw new RangeError("end out of bounds");var d;if("number"==typeof a)for(d=b;d>1,k=-7,l=c?e-1:0,m=c?-1:1,n=a[b+l];for(l+=m,f=n&(1<<-k)-1,n>>=-k,k+=h;k>0;f=256*f+a[b+l],l+=m,k-=8);for(g=f&(1<<-k)-1,f>>=-k,k+=d;k>0;g=256*g+a[b+l],l+=m,k-=8);if(0===f)f=1-j;else{if(f===i)return g?NaN:1/0*(n?-1:1);g+=Math.pow(2,d),f-=j}return(n?-1:1)*g*Math.pow(2,f-d)},c.write=function(a,b,c,d,e,f){var g,h,i,j=8*f-e-1,k=(1<>1,m=23===e?Math.pow(2,-24)-Math.pow(2,-77):0,n=d?0:f-1,o=d?1:-1,p=b<0||0===b&&1/b<0?1:0;for(b=Math.abs(b),isNaN(b)||b===1/0?(h=isNaN(b)?1:0,g=k):(g=Math.floor(Math.log(b)/Math.LN2),b*(i=Math.pow(2,-g))<1&&(g--,i*=2),b+=g+l>=1?m/i:m*Math.pow(2,1-l),b*i>=2&&(g++,i/=2),g+l>=k?(h=0,g=k):g+l>=1?(h=(b*i-1)*Math.pow(2,e),g+=l):(h=b*Math.pow(2,l-1)*Math.pow(2,e),g=0));e>=8;a[c+n]=255&h,n+=o,h/=256,e-=8);for(g=g<0;a[c+n]=255&g,n+=o,g/=256,j-=8);a[c+n-o]|=128*p}},{}],5:[function(a,b,c){(function(a){function c(b,c,d){return b instanceof ArrayBuffer&&(b=new Uint8Array(b)),new a(b,c,d)}c.prototype=Object.create(a.prototype),c.prototype.constructor=c,Object.keys(a).forEach(function(b){a.hasOwnProperty(b)&&(c[b]=a[b])}),b.exports=c}).call(this,a("buffer").Buffer)},{buffer:2}]},{},[5])(5)}); \ No newline at end of file diff --git a/dist/filer-perf.js b/dist/filer-perf.js index 180846a..d59041c 100644 --- a/dist/filer-perf.js +++ b/dist/filer-perf.js @@ -587,9 +587,17 @@ module.exports = nodash; * Copyright (c) 2012 Niklas von Hertzen * Licensed under the MIT license. */ -(function(chars){ +(function(){ "use strict"; + var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + + // Use a lookup table to find the index. + var lookup = new Uint8Array(256); + for (var i = 0; i < chars.length; i++) { + lookup[chars.charCodeAt(i)] = i; + } + exports.encode = function(arraybuffer) { var bytes = new Uint8Array(arraybuffer), i, len = bytes.length, base64 = ""; @@ -626,10 +634,10 @@ module.exports = nodash; bytes = new Uint8Array(arraybuffer); for (i = 0; i < len; i+=4) { - encoded1 = chars.indexOf(base64[i]); - encoded2 = chars.indexOf(base64[i+1]); - encoded3 = chars.indexOf(base64[i+2]); - encoded4 = chars.indexOf(base64[i+3]); + encoded1 = lookup[base64.charCodeAt(i)]; + encoded2 = lookup[base64.charCodeAt(i+1)]; + encoded3 = lookup[base64.charCodeAt(i+2)]; + encoded4 = lookup[base64.charCodeAt(i+3)]; bytes[p++] = (encoded1 << 2) | (encoded2 >> 4); bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2); @@ -638,19 +646,149 @@ module.exports = nodash; return arraybuffer; }; -})("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); +})(); },{}],6:[function(require,module,exports){ +var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; + +;(function (exports) { + 'use strict'; + + var Arr = (typeof Uint8Array !== 'undefined') + ? Uint8Array + : Array + + var PLUS = '+'.charCodeAt(0) + var SLASH = '/'.charCodeAt(0) + var NUMBER = '0'.charCodeAt(0) + var LOWER = 'a'.charCodeAt(0) + var UPPER = 'A'.charCodeAt(0) + var PLUS_URL_SAFE = '-'.charCodeAt(0) + var SLASH_URL_SAFE = '_'.charCodeAt(0) + + function decode (elt) { + var code = elt.charCodeAt(0) + if (code === PLUS || + code === PLUS_URL_SAFE) + return 62 // '+' + if (code === SLASH || + code === SLASH_URL_SAFE) + return 63 // '/' + if (code < NUMBER) + return -1 //no match + if (code < NUMBER + 10) + return code - NUMBER + 26 + 26 + if (code < UPPER + 26) + return code - UPPER + if (code < LOWER + 26) + return code - LOWER + 26 + } + + function b64ToByteArray (b64) { + var i, j, l, tmp, placeHolders, arr + + if (b64.length % 4 > 0) { + throw new Error('Invalid string. Length must be a multiple of 4') + } + + // the number of equal signs (place holders) + // if there are two placeholders, than the two characters before it + // represent one byte + // if there is only one, then the three characters before it represent 2 bytes + // this is just a cheap hack to not do indexOf twice + var len = b64.length + placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0 + + // base64 is 4/3 + up to two characters of the original data + arr = new Arr(b64.length * 3 / 4 - placeHolders) + + // if there are placeholders, only get up to the last complete 4 chars + l = placeHolders > 0 ? b64.length - 4 : b64.length + + var L = 0 + + function push (v) { + arr[L++] = v + } + + for (i = 0, j = 0; i < l; i += 4, j += 3) { + tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3)) + push((tmp & 0xFF0000) >> 16) + push((tmp & 0xFF00) >> 8) + push(tmp & 0xFF) + } + + if (placeHolders === 2) { + tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4) + push(tmp & 0xFF) + } else if (placeHolders === 1) { + tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2) + push((tmp >> 8) & 0xFF) + push(tmp & 0xFF) + } + + return arr + } + + function uint8ToBase64 (uint8) { + var i, + extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes + output = "", + temp, length + + function encode (num) { + return lookup.charAt(num) + } + + function tripletToBase64 (num) { + return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F) + } + + // go through the array every three bytes, we'll deal with trailing stuff later + for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { + temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) + output += tripletToBase64(temp) + } + + // pad the end with zeros, but make sure to not forget the extra bytes + switch (extraBytes) { + case 1: + temp = uint8[uint8.length - 1] + output += encode(temp >> 2) + output += encode((temp << 4) & 0x3F) + output += '==' + break + case 2: + temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]) + output += encode(temp >> 10) + output += encode((temp >> 4) & 0x3F) + output += encode((temp << 2) & 0x3F) + output += '=' + break + } + + return output + } + + exports.toByteArray = b64ToByteArray + exports.fromByteArray = uint8ToBase64 +}(typeof exports === 'undefined' ? (this.base64js = {}) : exports)) + +},{}],7:[function(require,module,exports){ +(function (global){ /*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh * @license MIT */ +/* eslint-disable no-proto */ + +'use strict' var base64 = require('base64-js') var ieee754 = require('ieee754') -var isArray = require('is-array') +var isArray = require('isarray') exports.Buffer = Buffer exports.SlowBuffer = SlowBuffer @@ -667,35 +805,43 @@ var rootParent = {} * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, * Opera 11.6+, iOS 4.2+. * + * Due to various browser bugs, sometimes the Object implementation will be used even + * when the browser supports typed arrays. + * * Note: * - * - Implementation must support adding new properties to `Uint8Array` instances. - * Firefox 4-29 lacked support, fixed in Firefox 30+. - * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. + * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, + * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. * - * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. + * - Safari 5-7 lacks support for changing the `Object.prototype.constructor` property + * on objects. * - * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of - * incorrect length in some situations. + * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. * - * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they will - * get the Object implementation, which is slower but will work correctly. + * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of + * incorrect length in some situations. + + * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they + * get the Object implementation, which is slower but behaves correctly. */ -Buffer.TYPED_ARRAY_SUPPORT = (function () { - function Foo () {} +Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined + ? global.TYPED_ARRAY_SUPPORT + : typedArraySupport() + +function typedArraySupport () { + function Bar () {} try { - var buf = new ArrayBuffer(0) - var arr = new Uint8Array(buf) + var arr = new Uint8Array(1) arr.foo = function () { return 42 } - arr.constructor = Foo + arr.constructor = Bar return arr.foo() === 42 && // typed array instances can be augmented - arr.constructor === Foo && // constructor can be set + arr.constructor === Bar && // constructor can be set typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` - new Uint8Array(1).subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` + arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` } catch (e) { return false } -})() +} function kMaxLength () { return Buffer.TYPED_ARRAY_SUPPORT @@ -722,8 +868,10 @@ function Buffer (arg) { return new Buffer(arg) } - this.length = 0 - this.parent = undefined + if (!Buffer.TYPED_ARRAY_SUPPORT) { + this.length = 0 + this.parent = undefined + } // Common case. if (typeof arg === 'number') { @@ -769,8 +917,13 @@ function fromObject (that, object) { throw new TypeError('must start with number, buffer, array or string') } - if (typeof ArrayBuffer !== 'undefined' && object.buffer instanceof ArrayBuffer) { - return fromTypedArray(that, object) + if (typeof ArrayBuffer !== 'undefined') { + if (object.buffer instanceof ArrayBuffer) { + return fromTypedArray(that, object) + } + if (object instanceof ArrayBuffer) { + return fromArrayBuffer(that, object) + } } if (object.length) return fromArrayLike(that, object) @@ -807,6 +960,18 @@ function fromTypedArray (that, array) { return that } +function fromArrayBuffer (that, array) { + if (Buffer.TYPED_ARRAY_SUPPORT) { + // Return an augmented `Uint8Array` instance, for best performance + array.byteLength + that = Buffer._augment(new Uint8Array(array)) + } else { + // Fallback: Return an object instance of the Buffer class + that = fromTypedArray(that, new Uint8Array(array)) + } + return that +} + function fromArrayLike (that, array) { var length = checked(array.length) | 0 that = allocate(that, length) @@ -834,10 +999,20 @@ function fromJsonObject (that, object) { return that } +if (Buffer.TYPED_ARRAY_SUPPORT) { + Buffer.prototype.__proto__ = Uint8Array.prototype + Buffer.__proto__ = Uint8Array +} else { + // pre-set for values that may exist in the future + Buffer.prototype.length = undefined + Buffer.prototype.parent = undefined +} + function allocate (that, length) { if (Buffer.TYPED_ARRAY_SUPPORT) { // Return an augmented `Uint8Array` instance, for best performance that = Buffer._augment(new Uint8Array(length)) + that.__proto__ = Buffer.prototype } else { // Fallback: Return an object instance of the Buffer class that.length = length @@ -924,8 +1099,6 @@ Buffer.concat = function concat (list, length) { if (list.length === 0) { return new Buffer(0) - } else if (list.length === 1) { - return list[0] } var i @@ -983,10 +1156,6 @@ function byteLength (string, encoding) { } Buffer.byteLength = byteLength -// pre-set for values that may exist in the future -Buffer.prototype.length = undefined -Buffer.prototype.parent = undefined - function slowToString (encoding, start, end) { var loweredCase = false @@ -1100,13 +1269,13 @@ Buffer.prototype.indexOf = function indexOf (val, byteOffset) { throw new TypeError('val must be string, number or Buffer') } -// `get` will be removed in Node 0.13+ +// `get` is deprecated Buffer.prototype.get = function get (offset) { console.log('.get() is deprecated. Access using array indexes instead.') return this.readUInt8(offset) } -// `set` will be removed in Node 0.13+ +// `set` is deprecated Buffer.prototype.set = function set (v, offset) { console.log('.set() is deprecated. Access using array indexes instead.') return this.writeUInt8(v, offset) @@ -1247,20 +1416,99 @@ function base64Slice (buf, start, end) { } function utf8Slice (buf, start, end) { - var res = '' - var tmp = '' end = Math.min(buf.length, end) + var res = [] - for (var i = start; i < end; i++) { - if (buf[i] <= 0x7F) { - res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i]) - tmp = '' - } else { - tmp += '%' + buf[i].toString(16) + var i = start + while (i < end) { + var firstByte = buf[i] + var codePoint = null + var bytesPerSequence = (firstByte > 0xEF) ? 4 + : (firstByte > 0xDF) ? 3 + : (firstByte > 0xBF) ? 2 + : 1 + + if (i + bytesPerSequence <= end) { + var secondByte, thirdByte, fourthByte, tempCodePoint + + switch (bytesPerSequence) { + case 1: + if (firstByte < 0x80) { + codePoint = firstByte + } + break + case 2: + secondByte = buf[i + 1] + if ((secondByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) + if (tempCodePoint > 0x7F) { + codePoint = tempCodePoint + } + } + break + case 3: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) + if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { + codePoint = tempCodePoint + } + } + break + case 4: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + fourthByte = buf[i + 3] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) + if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { + codePoint = tempCodePoint + } + } + } } + + if (codePoint === null) { + // we did not generate a valid codePoint so insert a + // replacement char (U+FFFD) and advance only 1 byte + codePoint = 0xFFFD + bytesPerSequence = 1 + } else if (codePoint > 0xFFFF) { + // encode to utf16 (surrogate pair dance) + codePoint -= 0x10000 + res.push(codePoint >>> 10 & 0x3FF | 0xD800) + codePoint = 0xDC00 | codePoint & 0x3FF + } + + res.push(codePoint) + i += bytesPerSequence } - return res + decodeUtf8Char(tmp) + return decodeCodePointsArray(res) +} + +// Based on http://stackoverflow.com/a/22747272/680742, the browser with +// the lowest limit is Chrome, with 0x10000 args. +// We go 1 magnitude less, for safety +var MAX_ARGUMENTS_LENGTH = 0x1000 + +function decodeCodePointsArray (codePoints) { + var len = codePoints.length + if (len <= MAX_ARGUMENTS_LENGTH) { + return String.fromCharCode.apply(String, codePoints) // avoid extra slice() + } + + // Decode in chunks to avoid "call stack size exceeded". + var res = '' + var i = 0 + while (i < len) { + res += String.fromCharCode.apply( + String, + codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) + ) + } + return res } function asciiSlice (buf, start, end) { @@ -1549,7 +1797,7 @@ Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) - this[offset] = value + this[offset] = (value & 0xff) return offset + 1 } @@ -1566,7 +1814,7 @@ Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = value + this[offset] = (value & 0xff) this[offset + 1] = (value >>> 8) } else { objectWriteUInt16(this, value, offset, true) @@ -1580,7 +1828,7 @@ Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = (value >>> 8) - this[offset + 1] = value + this[offset + 1] = (value & 0xff) } else { objectWriteUInt16(this, value, offset, false) } @@ -1602,7 +1850,7 @@ Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert this[offset + 3] = (value >>> 24) this[offset + 2] = (value >>> 16) this[offset + 1] = (value >>> 8) - this[offset] = value + this[offset] = (value & 0xff) } else { objectWriteUInt32(this, value, offset, true) } @@ -1617,7 +1865,7 @@ Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert this[offset] = (value >>> 24) this[offset + 1] = (value >>> 16) this[offset + 2] = (value >>> 8) - this[offset + 3] = value + this[offset + 3] = (value & 0xff) } else { objectWriteUInt32(this, value, offset, false) } @@ -1670,7 +1918,7 @@ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) if (value < 0) value = 0xff + value + 1 - this[offset] = value + this[offset] = (value & 0xff) return offset + 1 } @@ -1679,7 +1927,7 @@ Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = value + this[offset] = (value & 0xff) this[offset + 1] = (value >>> 8) } else { objectWriteUInt16(this, value, offset, true) @@ -1693,7 +1941,7 @@ Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = (value >>> 8) - this[offset + 1] = value + this[offset + 1] = (value & 0xff) } else { objectWriteUInt16(this, value, offset, false) } @@ -1705,7 +1953,7 @@ Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = value + this[offset] = (value & 0xff) this[offset + 1] = (value >>> 8) this[offset + 2] = (value >>> 16) this[offset + 3] = (value >>> 24) @@ -1724,7 +1972,7 @@ Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) this[offset] = (value >>> 24) this[offset + 1] = (value >>> 16) this[offset + 2] = (value >>> 8) - this[offset + 3] = value + this[offset + 3] = (value & 0xff) } else { objectWriteUInt32(this, value, offset, false) } @@ -1795,9 +2043,16 @@ Buffer.prototype.copy = function copy (target, targetStart, start, end) { } var len = end - start + var i - if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { - for (var i = 0; i < len; i++) { + if (this === target && start < targetStart && targetStart < end) { + // descending copy from end + for (i = len - 1; i >= 0; i--) { + target[i + targetStart] = this[i + start] + } + } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { + // ascending copy from start + for (i = 0; i < len; i++) { target[i + targetStart] = this[i + start] } } else { @@ -1873,7 +2128,7 @@ Buffer._augment = function _augment (arr) { // save reference to original Uint8Array set method before overwriting arr._set = arr.set - // deprecated, will be removed in node 0.13+ + // deprecated arr.get = BP.get arr.set = BP.set @@ -1929,7 +2184,7 @@ Buffer._augment = function _augment (arr) { return arr } -var INVALID_BASE64_RE = /[^+\/0-9A-z\-]/g +var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g function base64clean (str) { // Node strips out invalid characters like \n and \t from the string, base64-js does not @@ -1959,28 +2214,15 @@ function utf8ToBytes (string, units) { var length = string.length var leadSurrogate = null var bytes = [] - var i = 0 - for (; i < length; i++) { + for (var i = 0; i < length; i++) { codePoint = string.charCodeAt(i) // is surrogate component if (codePoint > 0xD7FF && codePoint < 0xE000) { // last char was a lead - if (leadSurrogate) { - // 2 leads in a row - if (codePoint < 0xDC00) { - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - leadSurrogate = codePoint - continue - } else { - // valid surrogate pair - codePoint = leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00 | 0x10000 - leadSurrogate = null - } - } else { + if (!leadSurrogate) { // no lead yet - if (codePoint > 0xDBFF) { // unexpected trail if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) @@ -1989,18 +2231,30 @@ function utf8ToBytes (string, units) { // unpaired lead if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) continue - } else { - // valid lead - leadSurrogate = codePoint - continue } + + // valid lead + leadSurrogate = codePoint + + continue } + + // 2 leads in a row + if (codePoint < 0xDC00) { + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + leadSurrogate = codePoint + continue + } + + // valid surrogate pair + codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 } else if (leadSurrogate) { // valid bmp char, but last char was a lead if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - leadSurrogate = null } + leadSurrogate = null + // encode utf8 if (codePoint < 0x80) { if ((units -= 1) < 0) break @@ -2018,7 +2272,7 @@ function utf8ToBytes (string, units) { codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80 ) - } else if (codePoint < 0x200000) { + } else if (codePoint < 0x110000) { if ((units -= 4) < 0) break bytes.push( codePoint >> 0x12 | 0xF0, @@ -2071,144 +2325,18 @@ function blitBuffer (src, dst, offset, length) { return i } -function decodeUtf8Char (str) { - try { - return decodeURIComponent(str) - } catch (err) { - return String.fromCharCode(0xFFFD) // UTF 8 invalid char - } -} +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"base64-js":6,"ieee754":9,"isarray":8}],8:[function(require,module,exports){ +var toString = {}.toString; -},{"base64-js":7,"ieee754":8,"is-array":9}],7:[function(require,module,exports){ -var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; +module.exports = Array.isArray || function (arr) { + return toString.call(arr) == '[object Array]'; +}; -;(function (exports) { - 'use strict'; - - var Arr = (typeof Uint8Array !== 'undefined') - ? Uint8Array - : Array - - var PLUS = '+'.charCodeAt(0) - var SLASH = '/'.charCodeAt(0) - var NUMBER = '0'.charCodeAt(0) - var LOWER = 'a'.charCodeAt(0) - var UPPER = 'A'.charCodeAt(0) - var PLUS_URL_SAFE = '-'.charCodeAt(0) - var SLASH_URL_SAFE = '_'.charCodeAt(0) - - function decode (elt) { - var code = elt.charCodeAt(0) - if (code === PLUS || - code === PLUS_URL_SAFE) - return 62 // '+' - if (code === SLASH || - code === SLASH_URL_SAFE) - return 63 // '/' - if (code < NUMBER) - return -1 //no match - if (code < NUMBER + 10) - return code - NUMBER + 26 + 26 - if (code < UPPER + 26) - return code - UPPER - if (code < LOWER + 26) - return code - LOWER + 26 - } - - function b64ToByteArray (b64) { - var i, j, l, tmp, placeHolders, arr - - if (b64.length % 4 > 0) { - throw new Error('Invalid string. Length must be a multiple of 4') - } - - // the number of equal signs (place holders) - // if there are two placeholders, than the two characters before it - // represent one byte - // if there is only one, then the three characters before it represent 2 bytes - // this is just a cheap hack to not do indexOf twice - var len = b64.length - placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0 - - // base64 is 4/3 + up to two characters of the original data - arr = new Arr(b64.length * 3 / 4 - placeHolders) - - // if there are placeholders, only get up to the last complete 4 chars - l = placeHolders > 0 ? b64.length - 4 : b64.length - - var L = 0 - - function push (v) { - arr[L++] = v - } - - for (i = 0, j = 0; i < l; i += 4, j += 3) { - tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3)) - push((tmp & 0xFF0000) >> 16) - push((tmp & 0xFF00) >> 8) - push(tmp & 0xFF) - } - - if (placeHolders === 2) { - tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4) - push(tmp & 0xFF) - } else if (placeHolders === 1) { - tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2) - push((tmp >> 8) & 0xFF) - push(tmp & 0xFF) - } - - return arr - } - - function uint8ToBase64 (uint8) { - var i, - extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes - output = "", - temp, length - - function encode (num) { - return lookup.charAt(num) - } - - function tripletToBase64 (num) { - return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F) - } - - // go through the array every three bytes, we'll deal with trailing stuff later - for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { - temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) - output += tripletToBase64(temp) - } - - // pad the end with zeros, but make sure to not forget the extra bytes - switch (extraBytes) { - case 1: - temp = uint8[uint8.length - 1] - output += encode(temp >> 2) - output += encode((temp << 4) & 0x3F) - output += '==' - break - case 2: - temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]) - output += encode(temp >> 10) - output += encode((temp >> 4) & 0x3F) - output += encode((temp << 2) & 0x3F) - output += '=' - break - } - - return output - } - - exports.toByteArray = b64ToByteArray - exports.fromByteArray = uint8ToBase64 -}(typeof exports === 'undefined' ? (this.base64js = {}) : exports)) - -},{}],8:[function(require,module,exports){ +},{}],9:[function(require,module,exports){ exports.read = function (buffer, offset, isLE, mLen, nBytes) { var e, m - var eLen = nBytes * 8 - mLen - 1 + var eLen = (nBytes * 8) - mLen - 1 var eMax = (1 << eLen) - 1 var eBias = eMax >> 1 var nBits = -7 @@ -2221,12 +2349,12 @@ exports.read = function (buffer, offset, isLE, mLen, nBytes) { e = s & ((1 << (-nBits)) - 1) s >>= (-nBits) nBits += eLen - for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} + for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {} m = e & ((1 << (-nBits)) - 1) e >>= (-nBits) nBits += mLen - for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} + for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {} if (e === 0) { e = 1 - eBias @@ -2241,7 +2369,7 @@ exports.read = function (buffer, offset, isLE, mLen, nBytes) { exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { var e, m, c - var eLen = nBytes * 8 - mLen - 1 + var eLen = (nBytes * 8) - mLen - 1 var eMax = (1 << eLen) - 1 var eBias = eMax >> 1 var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) @@ -2274,7 +2402,7 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { m = 0 e = eMax } else if (e + eBias >= 1) { - m = (value * c - 1) * Math.pow(2, mLen) + m = ((value * c) - 1) * Math.pow(2, mLen) e = e + eBias } else { m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) @@ -2291,1690 +2419,262 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { buffer[offset + i - d] |= s * 128 } -},{}],9:[function(require,module,exports){ - -/** - * isArray - */ - -var isArray = Array.isArray; - -/** - * toString - */ - -var str = Object.prototype.toString; - -/** - * Whether or not the given `val` - * is an array. - * - * example: - * - * isArray([]); - * // > true - * isArray(arguments); - * // > false - * isArray(''); - * // > false - * - * @param {mixed} val - * @return {bool} - */ - -module.exports = isArray || function (val) { - return !! val && '[object Array]' == str.call(val); -}; - },{}],10:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +;(function () { // closure for web browsers -// resolves . and .. elements in a path array with directory names there -// must be no slashes, empty elements, or device names (c:\) in the array -// (so also no leading and trailing slashes - it does not distinguish -// relative and absolute paths) -function normalizeArray(parts, allowAboveRoot) { - // if the path tries to go above the root, `up` ends up > 0 - var up = 0; - for (var i = parts.length - 1; i >= 0; i--) { - var last = parts[i]; - if (last === '.') { - parts.splice(i, 1); - } else if (last === '..') { - parts.splice(i, 1); - up++; - } else if (up) { - parts.splice(i, 1); - up--; - } - } - - // if the path is allowed to go above the root, restore leading ..s - if (allowAboveRoot) { - for (; up--; up) { - parts.unshift('..'); - } - } - - return parts; +if (typeof module === 'object' && module.exports) { + module.exports = LRUCache +} else { + // just set the global for non-node platforms. + this.LRUCache = LRUCache } -// Split a filename into [root, dir, basename, ext], unix version -// 'root' is just a slash, or nothing. -var splitPathRe = - /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/; -var splitPath = function(filename) { - return splitPathRe.exec(filename).slice(1); -}; - -// path.resolve([from ...], to) -// posix version -exports.resolve = function() { - var resolvedPath = '', - resolvedAbsolute = false; - - for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { - var path = (i >= 0) ? arguments[i] : process.cwd(); - - // Skip empty and invalid entries - if (typeof path !== 'string') { - throw new TypeError('Arguments to path.resolve must be strings'); - } else if (!path) { - continue; - } - - resolvedPath = path + '/' + resolvedPath; - resolvedAbsolute = path.charAt(0) === '/'; - } - - // At this point the path should be resolved to a full absolute path, but - // handle relative paths to be safe (might happen when process.cwd() fails) - - // Normalize the path - resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) { - return !!p; - }), !resolvedAbsolute).join('/'); - - return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; -}; - -// path.normalize(path) -// posix version -exports.normalize = function(path) { - var isAbsolute = exports.isAbsolute(path), - trailingSlash = substr(path, -1) === '/'; - - // Normalize the path - path = normalizeArray(filter(path.split('/'), function(p) { - return !!p; - }), !isAbsolute).join('/'); - - if (!path && !isAbsolute) { - path = '.'; - } - if (path && trailingSlash) { - path += '/'; - } - - return (isAbsolute ? '/' : '') + path; -}; - -// posix version -exports.isAbsolute = function(path) { - return path.charAt(0) === '/'; -}; - -// posix version -exports.join = function() { - var paths = Array.prototype.slice.call(arguments, 0); - return exports.normalize(filter(paths, function(p, index) { - if (typeof p !== 'string') { - throw new TypeError('Arguments to path.join must be strings'); - } - return p; - }).join('/')); -}; - - -// path.relative(from, to) -// posix version -exports.relative = function(from, to) { - from = exports.resolve(from).substr(1); - to = exports.resolve(to).substr(1); - - function trim(arr) { - var start = 0; - for (; start < arr.length; start++) { - if (arr[start] !== '') break; - } - - var end = arr.length - 1; - for (; end >= 0; end--) { - if (arr[end] !== '') break; - } - - if (start > end) return []; - return arr.slice(start, end - start + 1); - } - - var fromParts = trim(from.split('/')); - var toParts = trim(to.split('/')); - - var length = Math.min(fromParts.length, toParts.length); - var samePartsLength = length; - for (var i = 0; i < length; i++) { - if (fromParts[i] !== toParts[i]) { - samePartsLength = i; - break; - } - } - - var outputParts = []; - for (var i = samePartsLength; i < fromParts.length; i++) { - outputParts.push('..'); - } - - outputParts = outputParts.concat(toParts.slice(samePartsLength)); - - return outputParts.join('/'); -}; - -exports.sep = '/'; -exports.delimiter = ':'; - -exports.dirname = function(path) { - var result = splitPath(path), - root = result[0], - dir = result[1]; - - if (!root && !dir) { - // No dirname whatsoever - return '.'; - } - - if (dir) { - // It has a dirname, strip trailing slash - dir = dir.substr(0, dir.length - 1); - } - - return root + dir; -}; - - -exports.basename = function(path, ext) { - var f = splitPath(path)[2]; - // TODO: make this comparison case-insensitive on windows? - if (ext && f.substr(-1 * ext.length) === ext) { - f = f.substr(0, f.length - ext.length); - } - return f; -}; - - -exports.extname = function(path) { - return splitPath(path)[3]; -}; - -function filter (xs, f) { - if (xs.filter) return xs.filter(f); - var res = []; - for (var i = 0; i < xs.length; i++) { - if (f(xs[i], i, xs)) res.push(xs[i]); - } - return res; +function hOP (obj, key) { + return Object.prototype.hasOwnProperty.call(obj, key) } -// String.prototype.substr - negative index don't work in IE8 -var substr = 'ab'.substr(-1) === 'b' - ? function (str, start, len) { return str.substr(start, len) } - : function (str, start, len) { - if (start < 0) start = str.length + start; - return str.substr(start, len); - } -; +function naiveLength () { return 1 } -},{}],11:[function(require,module,exports){ -(function (global){ -/*! https://mths.be/punycode v1.3.2 by @mathias */ -;(function(root) { +function LRUCache (options) { + if (!(this instanceof LRUCache)) + return new LRUCache(options) - /** Detect free variables */ - var freeExports = typeof exports == 'object' && exports && - !exports.nodeType && exports; - var freeModule = typeof module == 'object' && module && - !module.nodeType && module; - var freeGlobal = typeof global == 'object' && global; - if ( - freeGlobal.global === freeGlobal || - freeGlobal.window === freeGlobal || - freeGlobal.self === freeGlobal - ) { - root = freeGlobal; - } + if (typeof options === 'number') + options = { max: options } - /** - * The `punycode` object. - * @name punycode - * @type Object - */ - var punycode, + if (!options) + options = {} - /** Highest positive signed 32-bit float value */ - maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1 + this._max = options.max + // Kind of weird to have a default max of Infinity, but oh well. + if (!this._max || !(typeof this._max === "number") || this._max <= 0 ) + this._max = Infinity - /** Bootstring parameters */ - base = 36, - tMin = 1, - tMax = 26, - skew = 38, - damp = 700, - initialBias = 72, - initialN = 128, // 0x80 - delimiter = '-', // '\x2D' + this._lengthCalculator = options.length || naiveLength + if (typeof this._lengthCalculator !== "function") + this._lengthCalculator = naiveLength - /** Regular expressions */ - regexPunycode = /^xn--/, - regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars - regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators - - /** Error messages */ - errors = { - 'overflow': 'Overflow: input needs wider integers to process', - 'not-basic': 'Illegal input >= 0x80 (not a basic code point)', - 'invalid-input': 'Invalid input' - }, - - /** Convenience shortcuts */ - baseMinusTMin = base - tMin, - floor = Math.floor, - stringFromCharCode = String.fromCharCode, - - /** Temporary variable */ - key; - - /*--------------------------------------------------------------------------*/ - - /** - * A generic error utility function. - * @private - * @param {String} type The error type. - * @returns {Error} Throws a `RangeError` with the applicable error message. - */ - function error(type) { - throw RangeError(errors[type]); - } - - /** - * A generic `Array#map` utility function. - * @private - * @param {Array} array The array to iterate over. - * @param {Function} callback The function that gets called for every array - * item. - * @returns {Array} A new array of values returned by the callback function. - */ - function map(array, fn) { - var length = array.length; - var result = []; - while (length--) { - result[length] = fn(array[length]); - } - return result; - } - - /** - * A simple `Array#map`-like wrapper to work with domain name strings or email - * addresses. - * @private - * @param {String} domain The domain name or email address. - * @param {Function} callback The function that gets called for every - * character. - * @returns {Array} A new string of characters returned by the callback - * function. - */ - function mapDomain(string, fn) { - var parts = string.split('@'); - var result = ''; - if (parts.length > 1) { - // In email addresses, only the domain name should be punycoded. Leave - // the local part (i.e. everything up to `@`) intact. - result = parts[0] + '@'; - string = parts[1]; - } - // Avoid `split(regex)` for IE8 compatibility. See #17. - string = string.replace(regexSeparators, '\x2E'); - var labels = string.split('.'); - var encoded = map(labels, fn).join('.'); - return result + encoded; - } - - /** - * Creates an array containing the numeric code points of each Unicode - * character in the string. While JavaScript uses UCS-2 internally, - * this function will convert a pair of surrogate halves (each of which - * UCS-2 exposes as separate characters) into a single code point, - * matching UTF-16. - * @see `punycode.ucs2.encode` - * @see - * @memberOf punycode.ucs2 - * @name decode - * @param {String} string The Unicode input string (UCS-2). - * @returns {Array} The new array of code points. - */ - function ucs2decode(string) { - var output = [], - counter = 0, - length = string.length, - value, - extra; - while (counter < length) { - value = string.charCodeAt(counter++); - if (value >= 0xD800 && value <= 0xDBFF && counter < length) { - // high surrogate, and there is a next character - extra = string.charCodeAt(counter++); - if ((extra & 0xFC00) == 0xDC00) { // low surrogate - output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); - } else { - // unmatched surrogate; only append this code unit, in case the next - // code unit is the high surrogate of a surrogate pair - output.push(value); - counter--; - } - } else { - output.push(value); - } - } - return output; - } - - /** - * Creates a string based on an array of numeric code points. - * @see `punycode.ucs2.decode` - * @memberOf punycode.ucs2 - * @name encode - * @param {Array} codePoints The array of numeric code points. - * @returns {String} The new Unicode string (UCS-2). - */ - function ucs2encode(array) { - return map(array, function(value) { - var output = ''; - if (value > 0xFFFF) { - value -= 0x10000; - output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); - value = 0xDC00 | value & 0x3FF; - } - output += stringFromCharCode(value); - return output; - }).join(''); - } - - /** - * Converts a basic code point into a digit/integer. - * @see `digitToBasic()` - * @private - * @param {Number} codePoint The basic numeric code point value. - * @returns {Number} The numeric value of a basic code point (for use in - * representing integers) in the range `0` to `base - 1`, or `base` if - * the code point does not represent a value. - */ - function basicToDigit(codePoint) { - if (codePoint - 48 < 10) { - return codePoint - 22; - } - if (codePoint - 65 < 26) { - return codePoint - 65; - } - if (codePoint - 97 < 26) { - return codePoint - 97; - } - return base; - } - - /** - * Converts a digit/integer into a basic code point. - * @see `basicToDigit()` - * @private - * @param {Number} digit The numeric value of a basic code point. - * @returns {Number} The basic code point whose value (when used for - * representing integers) is `digit`, which needs to be in the range - * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is - * used; else, the lowercase form is used. The behavior is undefined - * if `flag` is non-zero and `digit` has no uppercase form. - */ - function digitToBasic(digit, flag) { - // 0..25 map to ASCII a..z or A..Z - // 26..35 map to ASCII 0..9 - return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5); - } - - /** - * Bias adaptation function as per section 3.4 of RFC 3492. - * http://tools.ietf.org/html/rfc3492#section-3.4 - * @private - */ - function adapt(delta, numPoints, firstTime) { - var k = 0; - delta = firstTime ? floor(delta / damp) : delta >> 1; - delta += floor(delta / numPoints); - for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) { - delta = floor(delta / baseMinusTMin); - } - return floor(k + (baseMinusTMin + 1) * delta / (delta + skew)); - } - - /** - * Converts a Punycode string of ASCII-only symbols to a string of Unicode - * symbols. - * @memberOf punycode - * @param {String} input The Punycode string of ASCII-only symbols. - * @returns {String} The resulting string of Unicode symbols. - */ - function decode(input) { - // Don't use UCS-2 - var output = [], - inputLength = input.length, - out, - i = 0, - n = initialN, - bias = initialBias, - basic, - j, - index, - oldi, - w, - k, - digit, - t, - /** Cached calculation results */ - baseMinusT; - - // Handle the basic code points: let `basic` be the number of input code - // points before the last delimiter, or `0` if there is none, then copy - // the first basic code points to the output. - - basic = input.lastIndexOf(delimiter); - if (basic < 0) { - basic = 0; - } - - for (j = 0; j < basic; ++j) { - // if it's not a basic code point - if (input.charCodeAt(j) >= 0x80) { - error('not-basic'); - } - output.push(input.charCodeAt(j)); - } - - // Main decoding loop: start just after the last delimiter if any basic code - // points were copied; start at the beginning otherwise. - - for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) { - - // `index` is the index of the next character to be consumed. - // Decode a generalized variable-length integer into `delta`, - // which gets added to `i`. The overflow checking is easier - // if we increase `i` as we go, then subtract off its starting - // value at the end to obtain `delta`. - for (oldi = i, w = 1, k = base; /* no condition */; k += base) { - - if (index >= inputLength) { - error('invalid-input'); - } - - digit = basicToDigit(input.charCodeAt(index++)); - - if (digit >= base || digit > floor((maxInt - i) / w)) { - error('overflow'); - } - - i += digit * w; - t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); - - if (digit < t) { - break; - } - - baseMinusT = base - t; - if (w > floor(maxInt / baseMinusT)) { - error('overflow'); - } - - w *= baseMinusT; - - } - - out = output.length + 1; - bias = adapt(i - oldi, out, oldi == 0); - - // `i` was supposed to wrap around from `out` to `0`, - // incrementing `n` each time, so we'll fix that now: - if (floor(i / out) > maxInt - n) { - error('overflow'); - } - - n += floor(i / out); - i %= out; - - // Insert `n` at position `i` of the output - output.splice(i++, 0, n); - - } - - return ucs2encode(output); - } - - /** - * Converts a string of Unicode symbols (e.g. a domain name label) to a - * Punycode string of ASCII-only symbols. - * @memberOf punycode - * @param {String} input The string of Unicode symbols. - * @returns {String} The resulting Punycode string of ASCII-only symbols. - */ - function encode(input) { - var n, - delta, - handledCPCount, - basicLength, - bias, - j, - m, - q, - k, - t, - currentValue, - output = [], - /** `inputLength` will hold the number of code points in `input`. */ - inputLength, - /** Cached calculation results */ - handledCPCountPlusOne, - baseMinusT, - qMinusT; - - // Convert the input in UCS-2 to Unicode - input = ucs2decode(input); - - // Cache the length - inputLength = input.length; - - // Initialize the state - n = initialN; - delta = 0; - bias = initialBias; - - // Handle the basic code points - for (j = 0; j < inputLength; ++j) { - currentValue = input[j]; - if (currentValue < 0x80) { - output.push(stringFromCharCode(currentValue)); - } - } - - handledCPCount = basicLength = output.length; - - // `handledCPCount` is the number of code points that have been handled; - // `basicLength` is the number of basic code points. - - // Finish the basic string - if it is not empty - with a delimiter - if (basicLength) { - output.push(delimiter); - } - - // Main encoding loop: - while (handledCPCount < inputLength) { - - // All non-basic code points < n have been handled already. Find the next - // larger one: - for (m = maxInt, j = 0; j < inputLength; ++j) { - currentValue = input[j]; - if (currentValue >= n && currentValue < m) { - m = currentValue; - } - } - - // Increase `delta` enough to advance the decoder's state to , - // but guard against overflow - handledCPCountPlusOne = handledCPCount + 1; - if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) { - error('overflow'); - } - - delta += (m - n) * handledCPCountPlusOne; - n = m; - - for (j = 0; j < inputLength; ++j) { - currentValue = input[j]; - - if (currentValue < n && ++delta > maxInt) { - error('overflow'); - } - - if (currentValue == n) { - // Represent delta as a generalized variable-length integer - for (q = delta, k = base; /* no condition */; k += base) { - t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); - if (q < t) { - break; - } - qMinusT = q - t; - baseMinusT = base - t; - output.push( - stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)) - ); - q = floor(qMinusT / baseMinusT); - } - - output.push(stringFromCharCode(digitToBasic(q, 0))); - bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength); - delta = 0; - ++handledCPCount; - } - } - - ++delta; - ++n; - - } - return output.join(''); - } - - /** - * Converts a Punycode string representing a domain name or an email address - * to Unicode. Only the Punycoded parts of the input will be converted, i.e. - * it doesn't matter if you call it on a string that has already been - * converted to Unicode. - * @memberOf punycode - * @param {String} input The Punycoded domain name or email address to - * convert to Unicode. - * @returns {String} The Unicode representation of the given Punycode - * string. - */ - function toUnicode(input) { - return mapDomain(input, function(string) { - return regexPunycode.test(string) - ? decode(string.slice(4).toLowerCase()) - : string; - }); - } - - /** - * Converts a Unicode string representing a domain name or an email address to - * Punycode. Only the non-ASCII parts of the domain name will be converted, - * i.e. it doesn't matter if you call it with a domain that's already in - * ASCII. - * @memberOf punycode - * @param {String} input The domain name or email address to convert, as a - * Unicode string. - * @returns {String} The Punycode representation of the given domain name or - * email address. - */ - function toASCII(input) { - return mapDomain(input, function(string) { - return regexNonASCII.test(string) - ? 'xn--' + encode(string) - : string; - }); - } - - /*--------------------------------------------------------------------------*/ - - /** Define the public API */ - punycode = { - /** - * A string representing the current Punycode.js version number. - * @memberOf punycode - * @type String - */ - 'version': '1.3.2', - /** - * An object of methods to convert from JavaScript's internal character - * representation (UCS-2) to Unicode code points, and back. - * @see - * @memberOf punycode - * @type Object - */ - 'ucs2': { - 'decode': ucs2decode, - 'encode': ucs2encode - }, - 'decode': decode, - 'encode': encode, - 'toASCII': toASCII, - 'toUnicode': toUnicode - }; - - /** Expose `punycode` */ - // Some AMD build optimizers, like r.js, check for specific condition patterns - // like the following: - if ( - typeof define == 'function' && - typeof define.amd == 'object' && - define.amd - ) { - define('punycode', function() { - return punycode; - }); - } else if (freeExports && freeModule) { - if (module.exports == freeExports) { // in Node.js or RingoJS v0.8.0+ - freeModule.exports = punycode; - } else { // in Narwhal or RingoJS v0.7.0- - for (key in punycode) { - punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]); - } - } - } else { // in Rhino or a web browser - root.punycode = punycode; - } - -}(this)); - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],12:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; - -// If obj.hasOwnProperty has been overridden, then calling -// obj.hasOwnProperty(prop) will break. -// See: https://github.com/joyent/node/issues/1707 -function hasOwnProperty(obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); + this._allowStale = options.stale || false + this._maxAge = options.maxAge || null + this._dispose = options.dispose + this.reset() } -module.exports = function(qs, sep, eq, options) { - sep = sep || '&'; - eq = eq || '='; - var obj = {}; - - if (typeof qs !== 'string' || qs.length === 0) { - return obj; - } - - var regexp = /\+/g; - qs = qs.split(sep); - - var maxKeys = 1000; - if (options && typeof options.maxKeys === 'number') { - maxKeys = options.maxKeys; - } - - var len = qs.length; - // maxKeys <= 0 means that we should not limit keys count - if (maxKeys > 0 && len > maxKeys) { - len = maxKeys; - } - - for (var i = 0; i < len; ++i) { - var x = qs[i].replace(regexp, '%20'), - idx = x.indexOf(eq), - kstr, vstr, k, v; - - if (idx >= 0) { - kstr = x.substr(0, idx); - vstr = x.substr(idx + 1); - } else { - kstr = x; - vstr = ''; +// resize the cache when the max changes. +Object.defineProperty(LRUCache.prototype, "max", + { set : function (mL) { + if (!mL || !(typeof mL === "number") || mL <= 0 ) mL = Infinity + this._max = mL + if (this._length > this._max) trim(this) } + , get : function () { return this._max } + , enumerable : true + }) - k = decodeURIComponent(kstr); - v = decodeURIComponent(vstr); - - if (!hasOwnProperty(obj, k)) { - obj[k] = v; - } else if (isArray(obj[k])) { - obj[k].push(v); - } else { - obj[k] = [obj[k], v]; - } - } - - return obj; -}; - -var isArray = Array.isArray || function (xs) { - return Object.prototype.toString.call(xs) === '[object Array]'; -}; - -},{}],13:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; - -var stringifyPrimitive = function(v) { - switch (typeof v) { - case 'string': - return v; - - case 'boolean': - return v ? 'true' : 'false'; - - case 'number': - return isFinite(v) ? v : ''; - - default: - return ''; - } -}; - -module.exports = function(obj, sep, eq, name) { - sep = sep || '&'; - eq = eq || '='; - if (obj === null) { - obj = undefined; - } - - if (typeof obj === 'object') { - return map(objectKeys(obj), function(k) { - var ks = encodeURIComponent(stringifyPrimitive(k)) + eq; - if (isArray(obj[k])) { - return map(obj[k], function(v) { - return ks + encodeURIComponent(stringifyPrimitive(v)); - }).join(sep); +// resize the cache when the lengthCalculator changes. +Object.defineProperty(LRUCache.prototype, "lengthCalculator", + { set : function (lC) { + if (typeof lC !== "function") { + this._lengthCalculator = naiveLength + this._length = this._itemCount + for (var key in this._cache) { + this._cache[key].length = 1 + } } else { - return ks + encodeURIComponent(stringifyPrimitive(obj[k])); - } - }).join(sep); - - } - - if (!name) return ''; - return encodeURIComponent(stringifyPrimitive(name)) + eq + - encodeURIComponent(stringifyPrimitive(obj)); -}; - -var isArray = Array.isArray || function (xs) { - return Object.prototype.toString.call(xs) === '[object Array]'; -}; - -function map (xs, f) { - if (xs.map) return xs.map(f); - var res = []; - for (var i = 0; i < xs.length; i++) { - res.push(f(xs[i], i)); - } - return res; -} - -var objectKeys = Object.keys || function (obj) { - var res = []; - for (var key in obj) { - if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key); - } - return res; -}; - -},{}],14:[function(require,module,exports){ -'use strict'; - -exports.decode = exports.parse = require('./decode'); -exports.encode = exports.stringify = require('./encode'); - -},{"./decode":12,"./encode":13}],15:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var punycode = require('punycode'); - -exports.parse = urlParse; -exports.resolve = urlResolve; -exports.resolveObject = urlResolveObject; -exports.format = urlFormat; - -exports.Url = Url; - -function Url() { - this.protocol = null; - this.slashes = null; - this.auth = null; - this.host = null; - this.port = null; - this.hostname = null; - this.hash = null; - this.search = null; - this.query = null; - this.pathname = null; - this.path = null; - this.href = null; -} - -// Reference: RFC 3986, RFC 1808, RFC 2396 - -// define these here so at least they only have to be -// compiled once on the first module load. -var protocolPattern = /^([a-z0-9.+-]+:)/i, - portPattern = /:[0-9]*$/, - - // RFC 2396: characters reserved for delimiting URLs. - // We actually just auto-escape these. - delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'], - - // RFC 2396: characters not allowed for various reasons. - unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims), - - // Allowed by RFCs, but cause of XSS attacks. Always escape these. - autoEscape = ['\''].concat(unwise), - // Characters that are never ever allowed in a hostname. - // Note that any invalid chars are also handled, but these - // are the ones that are *expected* to be seen, so we fast-path - // them. - nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape), - hostEndingChars = ['/', '?', '#'], - hostnameMaxLen = 255, - hostnamePartPattern = /^[a-z0-9A-Z_-]{0,63}$/, - hostnamePartStart = /^([a-z0-9A-Z_-]{0,63})(.*)$/, - // protocols that can allow "unsafe" and "unwise" chars. - unsafeProtocol = { - 'javascript': true, - 'javascript:': true - }, - // protocols that never have a hostname. - hostlessProtocol = { - 'javascript': true, - 'javascript:': true - }, - // protocols that always contain a // bit. - slashedProtocol = { - 'http': true, - 'https': true, - 'ftp': true, - 'gopher': true, - 'file': true, - 'http:': true, - 'https:': true, - 'ftp:': true, - 'gopher:': true, - 'file:': true - }, - querystring = require('querystring'); - -function urlParse(url, parseQueryString, slashesDenoteHost) { - if (url && isObject(url) && url instanceof Url) return url; - - var u = new Url; - u.parse(url, parseQueryString, slashesDenoteHost); - return u; -} - -Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) { - if (!isString(url)) { - throw new TypeError("Parameter 'url' must be a string, not " + typeof url); - } - - var rest = url; - - // trim before proceeding. - // This is to support parse stuff like " http://foo.com \n" - rest = rest.trim(); - - var proto = protocolPattern.exec(rest); - if (proto) { - proto = proto[0]; - var lowerProto = proto.toLowerCase(); - this.protocol = lowerProto; - rest = rest.substr(proto.length); - } - - // figure out if it's got a host - // user@server is *always* interpreted as a hostname, and url - // resolution will treat //foo/bar as host=foo,path=bar because that's - // how the browser resolves relative URLs. - if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) { - var slashes = rest.substr(0, 2) === '//'; - if (slashes && !(proto && hostlessProtocol[proto])) { - rest = rest.substr(2); - this.slashes = true; - } - } - - if (!hostlessProtocol[proto] && - (slashes || (proto && !slashedProtocol[proto]))) { - - // there's a hostname. - // the first instance of /, ?, ;, or # ends the host. - // - // If there is an @ in the hostname, then non-host chars *are* allowed - // to the left of the last @ sign, unless some host-ending character - // comes *before* the @-sign. - // URLs are obnoxious. - // - // ex: - // http://a@b@c/ => user:a@b host:c - // http://a@b?@c => user:a host:c path:/?@c - - // v0.12 TODO(isaacs): This is not quite how Chrome does things. - // Review our test case against browsers more comprehensively. - - // find the first instance of any hostEndingChars - var hostEnd = -1; - for (var i = 0; i < hostEndingChars.length; i++) { - var hec = rest.indexOf(hostEndingChars[i]); - if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) - hostEnd = hec; - } - - // at this point, either we have an explicit point where the - // auth portion cannot go past, or the last @ char is the decider. - var auth, atSign; - if (hostEnd === -1) { - // atSign can be anywhere. - atSign = rest.lastIndexOf('@'); - } else { - // atSign must be in auth portion. - // http://a@b/c@d => host:b auth:a path:/c@d - atSign = rest.lastIndexOf('@', hostEnd); - } - - // Now we have a portion which is definitely the auth. - // Pull that off. - if (atSign !== -1) { - auth = rest.slice(0, atSign); - rest = rest.slice(atSign + 1); - this.auth = decodeURIComponent(auth); - } - - // the host is the remaining to the left of the first non-host char - hostEnd = -1; - for (var i = 0; i < nonHostChars.length; i++) { - var hec = rest.indexOf(nonHostChars[i]); - if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) - hostEnd = hec; - } - // if we still have not hit it, then the entire thing is a host. - if (hostEnd === -1) - hostEnd = rest.length; - - this.host = rest.slice(0, hostEnd); - rest = rest.slice(hostEnd); - - // pull out port. - this.parseHost(); - - // we've indicated that there is a hostname, - // so even if it's empty, it has to be present. - this.hostname = this.hostname || ''; - - // if hostname begins with [ and ends with ] - // assume that it's an IPv6 address. - var ipv6Hostname = this.hostname[0] === '[' && - this.hostname[this.hostname.length - 1] === ']'; - - // validate a little. - if (!ipv6Hostname) { - var hostparts = this.hostname.split(/\./); - for (var i = 0, l = hostparts.length; i < l; i++) { - var part = hostparts[i]; - if (!part) continue; - if (!part.match(hostnamePartPattern)) { - var newpart = ''; - for (var j = 0, k = part.length; j < k; j++) { - if (part.charCodeAt(j) > 127) { - // we replace non-ASCII char with a temporary placeholder - // we need this to make sure size of hostname is not - // broken by replacing non-ASCII by nothing - newpart += 'x'; - } else { - newpart += part[j]; - } - } - // we test again with ASCII char only - if (!newpart.match(hostnamePartPattern)) { - var validParts = hostparts.slice(0, i); - var notHost = hostparts.slice(i + 1); - var bit = part.match(hostnamePartStart); - if (bit) { - validParts.push(bit[1]); - notHost.unshift(bit[2]); - } - if (notHost.length) { - rest = '/' + notHost.join('.') + rest; - } - this.hostname = validParts.join('.'); - break; - } + this._lengthCalculator = lC + this._length = 0 + for (var key in this._cache) { + this._cache[key].length = this._lengthCalculator(this._cache[key].value) + this._length += this._cache[key].length } } - } - if (this.hostname.length > hostnameMaxLen) { - this.hostname = ''; + if (this._length > this._max) trim(this) + } + , get : function () { return this._lengthCalculator } + , enumerable : true + }) + +Object.defineProperty(LRUCache.prototype, "length", + { get : function () { return this._length } + , enumerable : true + }) + + +Object.defineProperty(LRUCache.prototype, "itemCount", + { get : function () { return this._itemCount } + , enumerable : true + }) + +LRUCache.prototype.forEach = function (fn, thisp) { + thisp = thisp || this + var i = 0; + for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) { + i++ + var hit = this._lruList[k] + if (this._maxAge && (Date.now() - hit.now > this._maxAge)) { + del(this, hit) + if (!this._allowStale) hit = undefined + } + if (hit) { + fn.call(thisp, hit.value, hit.key, this) + } + } +} + +LRUCache.prototype.keys = function () { + var keys = new Array(this._itemCount) + var i = 0 + for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) { + var hit = this._lruList[k] + keys[i++] = hit.key + } + return keys +} + +LRUCache.prototype.values = function () { + var values = new Array(this._itemCount) + var i = 0 + for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) { + var hit = this._lruList[k] + values[i++] = hit.value + } + return values +} + +LRUCache.prototype.reset = function () { + if (this._dispose && this._cache) { + for (var k in this._cache) { + this._dispose(k, this._cache[k].value) + } + } + + this._cache = Object.create(null) // hash of items by key + this._lruList = Object.create(null) // list of items in order of use recency + this._mru = 0 // most recently used + this._lru = 0 // least recently used + this._length = 0 // number of items in the list + this._itemCount = 0 +} + +// Provided for debugging/dev purposes only. No promises whatsoever that +// this API stays stable. +LRUCache.prototype.dump = function () { + return this._cache +} + +LRUCache.prototype.dumpLru = function () { + return this._lruList +} + +LRUCache.prototype.set = function (key, value) { + if (hOP(this._cache, key)) { + // dispose of the old one before overwriting + if (this._dispose) this._dispose(key, this._cache[key].value) + if (this._maxAge) this._cache[key].now = Date.now() + this._cache[key].value = value + this.get(key) + return true + } + + var len = this._lengthCalculator(value) + var age = this._maxAge ? Date.now() : 0 + var hit = new Entry(key, value, this._mru++, len, age) + + // oversized objects fall out of cache automatically. + if (hit.length > this._max) { + if (this._dispose) this._dispose(key, value) + return false + } + + this._length += hit.length + this._lruList[hit.lu] = this._cache[key] = hit + this._itemCount ++ + + if (this._length > this._max) trim(this) + return true +} + +LRUCache.prototype.has = function (key) { + if (!hOP(this._cache, key)) return false + var hit = this._cache[key] + if (this._maxAge && (Date.now() - hit.now > this._maxAge)) { + return false + } + return true +} + +LRUCache.prototype.get = function (key) { + return get(this, key, true) +} + +LRUCache.prototype.peek = function (key) { + return get(this, key, false) +} + +LRUCache.prototype.pop = function () { + var hit = this._lruList[this._lru] + del(this, hit) + return hit || null +} + +LRUCache.prototype.del = function (key) { + del(this, this._cache[key]) +} + +function get (self, key, doUse) { + var hit = self._cache[key] + if (hit) { + if (self._maxAge && (Date.now() - hit.now > self._maxAge)) { + del(self, hit) + if (!self._allowStale) hit = undefined } else { - // hostnames are always lower case. - this.hostname = this.hostname.toLowerCase(); - } - - if (!ipv6Hostname) { - // IDNA Support: Returns a puny coded representation of "domain". - // It only converts the part of the domain name that - // has non ASCII characters. I.e. it dosent matter if - // you call it with a domain that already is in ASCII. - var domainArray = this.hostname.split('.'); - var newOut = []; - for (var i = 0; i < domainArray.length; ++i) { - var s = domainArray[i]; - newOut.push(s.match(/[^A-Za-z0-9_-]/) ? - 'xn--' + punycode.encode(s) : s); - } - this.hostname = newOut.join('.'); - } - - var p = this.port ? ':' + this.port : ''; - var h = this.hostname || ''; - this.host = h + p; - this.href += this.host; - - // strip [ and ] from the hostname - // the host field still retains them, though - if (ipv6Hostname) { - this.hostname = this.hostname.substr(1, this.hostname.length - 2); - if (rest[0] !== '/') { - rest = '/' + rest; - } + if (doUse) use(self, hit) } + if (hit) hit = hit.value } - - // now rest is set to the post-host stuff. - // chop off any delim chars. - if (!unsafeProtocol[lowerProto]) { - - // First, make 100% sure that any "autoEscape" chars get - // escaped, even if encodeURIComponent doesn't think they - // need to be. - for (var i = 0, l = autoEscape.length; i < l; i++) { - var ae = autoEscape[i]; - var esc = encodeURIComponent(ae); - if (esc === ae) { - esc = escape(ae); - } - rest = rest.split(ae).join(esc); - } - } - - - // chop off from the tail first. - var hash = rest.indexOf('#'); - if (hash !== -1) { - // got a fragment string. - this.hash = rest.substr(hash); - rest = rest.slice(0, hash); - } - var qm = rest.indexOf('?'); - if (qm !== -1) { - this.search = rest.substr(qm); - this.query = rest.substr(qm + 1); - if (parseQueryString) { - this.query = querystring.parse(this.query); - } - rest = rest.slice(0, qm); - } else if (parseQueryString) { - // no query string, but parseQueryString still requested - this.search = ''; - this.query = {}; - } - if (rest) this.pathname = rest; - if (slashedProtocol[lowerProto] && - this.hostname && !this.pathname) { - this.pathname = '/'; - } - - //to support http.request - if (this.pathname || this.search) { - var p = this.pathname || ''; - var s = this.search || ''; - this.path = p + s; - } - - // finally, reconstruct the href based on what has been validated. - this.href = this.format(); - return this; -}; - -// format a parsed object into a url string -function urlFormat(obj) { - // ensure it's an object, and not a string url. - // If it's an obj, this is a no-op. - // this way, you can call url_format() on strings - // to clean up potentially wonky urls. - if (isString(obj)) obj = urlParse(obj); - if (!(obj instanceof Url)) return Url.prototype.format.call(obj); - return obj.format(); + return hit } -Url.prototype.format = function() { - var auth = this.auth || ''; - if (auth) { - auth = encodeURIComponent(auth); - auth = auth.replace(/%3A/i, ':'); - auth += '@'; - } - - var protocol = this.protocol || '', - pathname = this.pathname || '', - hash = this.hash || '', - host = false, - query = ''; - - if (this.host) { - host = auth + this.host; - } else if (this.hostname) { - host = auth + (this.hostname.indexOf(':') === -1 ? - this.hostname : - '[' + this.hostname + ']'); - if (this.port) { - host += ':' + this.port; - } - } - - if (this.query && - isObject(this.query) && - Object.keys(this.query).length) { - query = querystring.stringify(this.query); - } - - var search = this.search || (query && ('?' + query)) || ''; - - if (protocol && protocol.substr(-1) !== ':') protocol += ':'; - - // only the slashedProtocols get the //. Not mailto:, xmpp:, etc. - // unless they had them to begin with. - if (this.slashes || - (!protocol || slashedProtocol[protocol]) && host !== false) { - host = '//' + (host || ''); - if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname; - } else if (!host) { - host = ''; - } - - if (hash && hash.charAt(0) !== '#') hash = '#' + hash; - if (search && search.charAt(0) !== '?') search = '?' + search; - - pathname = pathname.replace(/[?#]/g, function(match) { - return encodeURIComponent(match); - }); - search = search.replace('#', '%23'); - - return protocol + host + pathname + search + hash; -}; - -function urlResolve(source, relative) { - return urlParse(source, false, true).resolve(relative); +function use (self, hit) { + shiftLU(self, hit) + hit.lu = self._mru ++ + if (self._maxAge) hit.now = Date.now() + self._lruList[hit.lu] = hit } -Url.prototype.resolve = function(relative) { - return this.resolveObject(urlParse(relative, false, true)).format(); -}; - -function urlResolveObject(source, relative) { - if (!source) return relative; - return urlParse(source, false, true).resolveObject(relative); +function trim (self) { + while (self._lru < self._mru && self._length > self._max) + del(self, self._lruList[self._lru]) } -Url.prototype.resolveObject = function(relative) { - if (isString(relative)) { - var rel = new Url(); - rel.parse(relative, false, true); - relative = rel; - } - - var result = new Url(); - Object.keys(this).forEach(function(k) { - result[k] = this[k]; - }, this); - - // hash is always overridden, no matter what. - // even href="" will remove it. - result.hash = relative.hash; - - // if the relative url is empty, then there's nothing left to do here. - if (relative.href === '') { - result.href = result.format(); - return result; - } - - // hrefs like //foo/bar always cut to the protocol. - if (relative.slashes && !relative.protocol) { - // take everything except the protocol from relative - Object.keys(relative).forEach(function(k) { - if (k !== 'protocol') - result[k] = relative[k]; - }); - - //urlParse appends trailing / to urls like http://www.example.com - if (slashedProtocol[result.protocol] && - result.hostname && !result.pathname) { - result.path = result.pathname = '/'; - } - - result.href = result.format(); - return result; - } - - if (relative.protocol && relative.protocol !== result.protocol) { - // if it's a known url protocol, then changing - // the protocol does weird things - // first, if it's not file:, then we MUST have a host, - // and if there was a path - // to begin with, then we MUST have a path. - // if it is file:, then the host is dropped, - // because that's known to be hostless. - // anything else is assumed to be absolute. - if (!slashedProtocol[relative.protocol]) { - Object.keys(relative).forEach(function(k) { - result[k] = relative[k]; - }); - result.href = result.format(); - return result; - } - - result.protocol = relative.protocol; - if (!relative.host && !hostlessProtocol[relative.protocol]) { - var relPath = (relative.pathname || '').split('/'); - while (relPath.length && !(relative.host = relPath.shift())); - if (!relative.host) relative.host = ''; - if (!relative.hostname) relative.hostname = ''; - if (relPath[0] !== '') relPath.unshift(''); - if (relPath.length < 2) relPath.unshift(''); - result.pathname = relPath.join('/'); - } else { - result.pathname = relative.pathname; - } - result.search = relative.search; - result.query = relative.query; - result.host = relative.host || ''; - result.auth = relative.auth; - result.hostname = relative.hostname || relative.host; - result.port = relative.port; - // to support http.request - if (result.pathname || result.search) { - var p = result.pathname || ''; - var s = result.search || ''; - result.path = p + s; - } - result.slashes = result.slashes || relative.slashes; - result.href = result.format(); - return result; - } - - var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'), - isRelAbs = ( - relative.host || - relative.pathname && relative.pathname.charAt(0) === '/' - ), - mustEndAbs = (isRelAbs || isSourceAbs || - (result.host && relative.pathname)), - removeAllDots = mustEndAbs, - srcPath = result.pathname && result.pathname.split('/') || [], - relPath = relative.pathname && relative.pathname.split('/') || [], - psychotic = result.protocol && !slashedProtocol[result.protocol]; - - // if the url is a non-slashed url, then relative - // links like ../.. should be able - // to crawl up to the hostname, as well. This is strange. - // result.protocol has already been set by now. - // Later on, put the first path part into the host field. - if (psychotic) { - result.hostname = ''; - result.port = null; - if (result.host) { - if (srcPath[0] === '') srcPath[0] = result.host; - else srcPath.unshift(result.host); - } - result.host = ''; - if (relative.protocol) { - relative.hostname = null; - relative.port = null; - if (relative.host) { - if (relPath[0] === '') relPath[0] = relative.host; - else relPath.unshift(relative.host); - } - relative.host = null; - } - mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === ''); - } - - if (isRelAbs) { - // it's absolute. - result.host = (relative.host || relative.host === '') ? - relative.host : result.host; - result.hostname = (relative.hostname || relative.hostname === '') ? - relative.hostname : result.hostname; - result.search = relative.search; - result.query = relative.query; - srcPath = relPath; - // fall through to the dot-handling below. - } else if (relPath.length) { - // it's relative - // throw away the existing file, and take the new path instead. - if (!srcPath) srcPath = []; - srcPath.pop(); - srcPath = srcPath.concat(relPath); - result.search = relative.search; - result.query = relative.query; - } else if (!isNullOrUndefined(relative.search)) { - // just pull out the search. - // like href='?foo'. - // Put this after the other two cases because it simplifies the booleans - if (psychotic) { - result.hostname = result.host = srcPath.shift(); - //occationaly the auth can get stuck only in host - //this especialy happens in cases like - //url.resolveObject('mailto:local1@domain1', 'local2@domain2') - var authInHost = result.host && result.host.indexOf('@') > 0 ? - result.host.split('@') : false; - if (authInHost) { - result.auth = authInHost.shift(); - result.host = result.hostname = authInHost.shift(); - } - } - result.search = relative.search; - result.query = relative.query; - //to support http.request - if (!isNull(result.pathname) || !isNull(result.search)) { - result.path = (result.pathname ? result.pathname : '') + - (result.search ? result.search : ''); - } - result.href = result.format(); - return result; - } - - if (!srcPath.length) { - // no path at all. easy. - // we've already handled the other stuff above. - result.pathname = null; - //to support http.request - if (result.search) { - result.path = '/' + result.search; - } else { - result.path = null; - } - result.href = result.format(); - return result; - } - - // if a url ENDs in . or .., then it must get a trailing slash. - // however, if it ends in anything else non-slashy, - // then it must NOT get a trailing slash. - var last = srcPath.slice(-1)[0]; - var hasTrailingSlash = ( - (result.host || relative.host) && (last === '.' || last === '..') || - last === ''); - - // strip single dots, resolve double dots to parent dir - // if the path tries to go above the root, `up` ends up > 0 - var up = 0; - for (var i = srcPath.length; i >= 0; i--) { - last = srcPath[i]; - if (last == '.') { - srcPath.splice(i, 1); - } else if (last === '..') { - srcPath.splice(i, 1); - up++; - } else if (up) { - srcPath.splice(i, 1); - up--; - } - } - - // if the path is allowed to go above the root, restore leading ..s - if (!mustEndAbs && !removeAllDots) { - for (; up--; up) { - srcPath.unshift('..'); - } - } - - if (mustEndAbs && srcPath[0] !== '' && - (!srcPath[0] || srcPath[0].charAt(0) !== '/')) { - srcPath.unshift(''); - } - - if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) { - srcPath.push(''); - } - - var isAbsolute = srcPath[0] === '' || - (srcPath[0] && srcPath[0].charAt(0) === '/'); - - // put the host back - if (psychotic) { - result.hostname = result.host = isAbsolute ? '' : - srcPath.length ? srcPath.shift() : ''; - //occationaly the auth can get stuck only in host - //this especialy happens in cases like - //url.resolveObject('mailto:local1@domain1', 'local2@domain2') - var authInHost = result.host && result.host.indexOf('@') > 0 ? - result.host.split('@') : false; - if (authInHost) { - result.auth = authInHost.shift(); - result.host = result.hostname = authInHost.shift(); - } - } - - mustEndAbs = mustEndAbs || (result.host && srcPath.length); - - if (mustEndAbs && !isAbsolute) { - srcPath.unshift(''); - } - - if (!srcPath.length) { - result.pathname = null; - result.path = null; - } else { - result.pathname = srcPath.join('/'); - } - - //to support request.http - if (!isNull(result.pathname) || !isNull(result.search)) { - result.path = (result.pathname ? result.pathname : '') + - (result.search ? result.search : ''); - } - result.auth = relative.auth || result.auth; - result.slashes = result.slashes || relative.slashes; - result.href = result.format(); - return result; -}; - -Url.prototype.parseHost = function() { - var host = this.host; - var port = portPattern.exec(host); - if (port) { - port = port[0]; - if (port !== ':') { - this.port = port.substr(1); - } - host = host.substr(0, host.length - port.length); - } - if (host) this.hostname = host; -}; - -function isString(arg) { - return typeof arg === "string"; +function shiftLU (self, hit) { + delete self._lruList[ hit.lu ] + while (self._lru < self._mru && !self._lruList[self._lru]) self._lru ++ } -function isObject(arg) { - return typeof arg === 'object' && arg !== null; +function del (self, hit) { + if (hit) { + if (self._dispose) self._dispose(hit.key, hit.value) + self._length -= hit.length + self._itemCount -- + delete self._cache[ hit.key ] + shiftLU(self, hit) + } } -function isNull(arg) { - return arg === null; -} -function isNullOrUndefined(arg) { - return arg == null; +// classy, since V8 prefers predictable objects. +function Entry (key, value, lu, length, now) { + this.key = key + this.value = value + this.lu = lu + this.length = length + this.now = now } -},{"punycode":11,"querystring":14}],16:[function(require,module,exports){ +})() + +},{}],11:[function(require,module,exports){ ;(function (require, exports, module, platform) { if (module) module.exports = minimatch @@ -5049,283 +3749,949 @@ function regExpEscape (s) { typeof process === "object" ? process.platform : "win32" ) -},{"lru-cache":17,"path":10,"sigmund":18}],17:[function(require,module,exports){ -;(function () { // closure for web browsers +},{"lru-cache":10,"path":12,"sigmund":17}],12:[function(require,module,exports){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. -if (typeof module === 'object' && module.exports) { - module.exports = LRUCache -} else { - // just set the global for non-node platforms. - this.LRUCache = LRUCache -} - -function hOP (obj, key) { - return Object.prototype.hasOwnProperty.call(obj, key) -} - -function naiveLength () { return 1 } - -function LRUCache (options) { - if (!(this instanceof LRUCache)) - return new LRUCache(options) - - if (typeof options === 'number') - options = { max: options } - - if (!options) - options = {} - - this._max = options.max - // Kind of weird to have a default max of Infinity, but oh well. - if (!this._max || !(typeof this._max === "number") || this._max <= 0 ) - this._max = Infinity - - this._lengthCalculator = options.length || naiveLength - if (typeof this._lengthCalculator !== "function") - this._lengthCalculator = naiveLength - - this._allowStale = options.stale || false - this._maxAge = options.maxAge || null - this._dispose = options.dispose - this.reset() -} - -// resize the cache when the max changes. -Object.defineProperty(LRUCache.prototype, "max", - { set : function (mL) { - if (!mL || !(typeof mL === "number") || mL <= 0 ) mL = Infinity - this._max = mL - if (this._length > this._max) trim(this) - } - , get : function () { return this._max } - , enumerable : true - }) - -// resize the cache when the lengthCalculator changes. -Object.defineProperty(LRUCache.prototype, "lengthCalculator", - { set : function (lC) { - if (typeof lC !== "function") { - this._lengthCalculator = naiveLength - this._length = this._itemCount - for (var key in this._cache) { - this._cache[key].length = 1 - } - } else { - this._lengthCalculator = lC - this._length = 0 - for (var key in this._cache) { - this._cache[key].length = this._lengthCalculator(this._cache[key].value) - this._length += this._cache[key].length - } - } - - if (this._length > this._max) trim(this) - } - , get : function () { return this._lengthCalculator } - , enumerable : true - }) - -Object.defineProperty(LRUCache.prototype, "length", - { get : function () { return this._length } - , enumerable : true - }) - - -Object.defineProperty(LRUCache.prototype, "itemCount", - { get : function () { return this._itemCount } - , enumerable : true - }) - -LRUCache.prototype.forEach = function (fn, thisp) { - thisp = thisp || this - var i = 0 - var itemCount = this._itemCount - - for (var k = this._mru - 1; k >= 0 && i < itemCount; k--) if (this._lruList[k]) { - i++ - var hit = this._lruList[k] - if (isStale(this, hit)) { - del(this, hit) - if (!this._allowStale) hit = undefined - } - if (hit) { - fn.call(thisp, hit.value, hit.key, this) - } - } -} - -LRUCache.prototype.keys = function () { - var keys = new Array(this._itemCount) - var i = 0 - for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) { - var hit = this._lruList[k] - keys[i++] = hit.key - } - return keys -} - -LRUCache.prototype.values = function () { - var values = new Array(this._itemCount) - var i = 0 - for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) { - var hit = this._lruList[k] - values[i++] = hit.value - } - return values -} - -LRUCache.prototype.reset = function () { - if (this._dispose && this._cache) { - for (var k in this._cache) { - this._dispose(k, this._cache[k].value) +// resolves . and .. elements in a path array with directory names there +// must be no slashes, empty elements, or device names (c:\) in the array +// (so also no leading and trailing slashes - it does not distinguish +// relative and absolute paths) +function normalizeArray(parts, allowAboveRoot) { + // if the path tries to go above the root, `up` ends up > 0 + var up = 0; + for (var i = parts.length - 1; i >= 0; i--) { + var last = parts[i]; + if (last === '.') { + parts.splice(i, 1); + } else if (last === '..') { + parts.splice(i, 1); + up++; + } else if (up) { + parts.splice(i, 1); + up--; } } - this._cache = Object.create(null) // hash of items by key - this._lruList = Object.create(null) // list of items in order of use recency - this._mru = 0 // most recently used - this._lru = 0 // least recently used - this._length = 0 // number of items in the list - this._itemCount = 0 -} - -// Provided for debugging/dev purposes only. No promises whatsoever that -// this API stays stable. -LRUCache.prototype.dump = function () { - return this._cache -} - -LRUCache.prototype.dumpLru = function () { - return this._lruList -} - -LRUCache.prototype.set = function (key, value, maxAge) { - maxAge = maxAge || this._maxAge - var now = maxAge ? Date.now() : 0 - - if (hOP(this._cache, key)) { - // dispose of the old one before overwriting - if (this._dispose) - this._dispose(key, this._cache[key].value) - - this._cache[key].now = now - this._cache[key].maxAge = maxAge - this._cache[key].value = value - this.get(key) - return true + // if the path is allowed to go above the root, restore leading ..s + if (allowAboveRoot) { + for (; up--; up) { + parts.unshift('..'); + } } - var len = this._lengthCalculator(value) - var hit = new Entry(key, value, this._mru++, len, now, maxAge) + return parts; +} - // oversized objects fall out of cache automatically. - if (hit.length > this._max) { - if (this._dispose) this._dispose(key, value) - return false +// Split a filename into [root, dir, basename, ext], unix version +// 'root' is just a slash, or nothing. +var splitPathRe = + /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/; +var splitPath = function(filename) { + return splitPathRe.exec(filename).slice(1); +}; + +// path.resolve([from ...], to) +// posix version +exports.resolve = function() { + var resolvedPath = '', + resolvedAbsolute = false; + + for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { + var path = (i >= 0) ? arguments[i] : process.cwd(); + + // Skip empty and invalid entries + if (typeof path !== 'string') { + throw new TypeError('Arguments to path.resolve must be strings'); + } else if (!path) { + continue; + } + + resolvedPath = path + '/' + resolvedPath; + resolvedAbsolute = path.charAt(0) === '/'; } - this._length += hit.length - this._lruList[hit.lu] = this._cache[key] = hit - this._itemCount ++ + // At this point the path should be resolved to a full absolute path, but + // handle relative paths to be safe (might happen when process.cwd() fails) - if (this._length > this._max) - trim(this) + // Normalize the path + resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) { + return !!p; + }), !resolvedAbsolute).join('/'); - return true -} + return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; +}; -LRUCache.prototype.has = function (key) { - if (!hOP(this._cache, key)) return false - var hit = this._cache[key] - if (isStale(this, hit)) { - return false +// path.normalize(path) +// posix version +exports.normalize = function(path) { + var isAbsolute = exports.isAbsolute(path), + trailingSlash = substr(path, -1) === '/'; + + // Normalize the path + path = normalizeArray(filter(path.split('/'), function(p) { + return !!p; + }), !isAbsolute).join('/'); + + if (!path && !isAbsolute) { + path = '.'; } - return true + if (path && trailingSlash) { + path += '/'; + } + + return (isAbsolute ? '/' : '') + path; +}; + +// posix version +exports.isAbsolute = function(path) { + return path.charAt(0) === '/'; +}; + +// posix version +exports.join = function() { + var paths = Array.prototype.slice.call(arguments, 0); + return exports.normalize(filter(paths, function(p, index) { + if (typeof p !== 'string') { + throw new TypeError('Arguments to path.join must be strings'); + } + return p; + }).join('/')); +}; + + +// path.relative(from, to) +// posix version +exports.relative = function(from, to) { + from = exports.resolve(from).substr(1); + to = exports.resolve(to).substr(1); + + function trim(arr) { + var start = 0; + for (; start < arr.length; start++) { + if (arr[start] !== '') break; + } + + var end = arr.length - 1; + for (; end >= 0; end--) { + if (arr[end] !== '') break; + } + + if (start > end) return []; + return arr.slice(start, end - start + 1); + } + + var fromParts = trim(from.split('/')); + var toParts = trim(to.split('/')); + + var length = Math.min(fromParts.length, toParts.length); + var samePartsLength = length; + for (var i = 0; i < length; i++) { + if (fromParts[i] !== toParts[i]) { + samePartsLength = i; + break; + } + } + + var outputParts = []; + for (var i = samePartsLength; i < fromParts.length; i++) { + outputParts.push('..'); + } + + outputParts = outputParts.concat(toParts.slice(samePartsLength)); + + return outputParts.join('/'); +}; + +exports.sep = '/'; +exports.delimiter = ':'; + +exports.dirname = function(path) { + var result = splitPath(path), + root = result[0], + dir = result[1]; + + if (!root && !dir) { + // No dirname whatsoever + return '.'; + } + + if (dir) { + // It has a dirname, strip trailing slash + dir = dir.substr(0, dir.length - 1); + } + + return root + dir; +}; + + +exports.basename = function(path, ext) { + var f = splitPath(path)[2]; + // TODO: make this comparison case-insensitive on windows? + if (ext && f.substr(-1 * ext.length) === ext) { + f = f.substr(0, f.length - ext.length); + } + return f; +}; + + +exports.extname = function(path) { + return splitPath(path)[3]; +}; + +function filter (xs, f) { + if (xs.filter) return xs.filter(f); + var res = []; + for (var i = 0; i < xs.length; i++) { + if (f(xs[i], i, xs)) res.push(xs[i]); + } + return res; } -LRUCache.prototype.get = function (key) { - return get(this, key, true) +// String.prototype.substr - negative index don't work in IE8 +var substr = 'ab'.substr(-1) === 'b' + ? function (str, start, len) { return str.substr(start, len) } + : function (str, start, len) { + if (start < 0) start = str.length + start; + return str.substr(start, len); + } +; + +},{}],13:[function(require,module,exports){ +(function (global){ +/*! https://mths.be/punycode v1.4.1 by @mathias */ +;(function(root) { + + /** Detect free variables */ + var freeExports = typeof exports == 'object' && exports && + !exports.nodeType && exports; + var freeModule = typeof module == 'object' && module && + !module.nodeType && module; + var freeGlobal = typeof global == 'object' && global; + if ( + freeGlobal.global === freeGlobal || + freeGlobal.window === freeGlobal || + freeGlobal.self === freeGlobal + ) { + root = freeGlobal; + } + + /** + * The `punycode` object. + * @name punycode + * @type Object + */ + var punycode, + + /** Highest positive signed 32-bit float value */ + maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1 + + /** Bootstring parameters */ + base = 36, + tMin = 1, + tMax = 26, + skew = 38, + damp = 700, + initialBias = 72, + initialN = 128, // 0x80 + delimiter = '-', // '\x2D' + + /** Regular expressions */ + regexPunycode = /^xn--/, + regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars + regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators + + /** Error messages */ + errors = { + 'overflow': 'Overflow: input needs wider integers to process', + 'not-basic': 'Illegal input >= 0x80 (not a basic code point)', + 'invalid-input': 'Invalid input' + }, + + /** Convenience shortcuts */ + baseMinusTMin = base - tMin, + floor = Math.floor, + stringFromCharCode = String.fromCharCode, + + /** Temporary variable */ + key; + + /*--------------------------------------------------------------------------*/ + + /** + * A generic error utility function. + * @private + * @param {String} type The error type. + * @returns {Error} Throws a `RangeError` with the applicable error message. + */ + function error(type) { + throw new RangeError(errors[type]); + } + + /** + * A generic `Array#map` utility function. + * @private + * @param {Array} array The array to iterate over. + * @param {Function} callback The function that gets called for every array + * item. + * @returns {Array} A new array of values returned by the callback function. + */ + function map(array, fn) { + var length = array.length; + var result = []; + while (length--) { + result[length] = fn(array[length]); + } + return result; + } + + /** + * A simple `Array#map`-like wrapper to work with domain name strings or email + * addresses. + * @private + * @param {String} domain The domain name or email address. + * @param {Function} callback The function that gets called for every + * character. + * @returns {Array} A new string of characters returned by the callback + * function. + */ + function mapDomain(string, fn) { + var parts = string.split('@'); + var result = ''; + if (parts.length > 1) { + // In email addresses, only the domain name should be punycoded. Leave + // the local part (i.e. everything up to `@`) intact. + result = parts[0] + '@'; + string = parts[1]; + } + // Avoid `split(regex)` for IE8 compatibility. See #17. + string = string.replace(regexSeparators, '\x2E'); + var labels = string.split('.'); + var encoded = map(labels, fn).join('.'); + return result + encoded; + } + + /** + * Creates an array containing the numeric code points of each Unicode + * character in the string. While JavaScript uses UCS-2 internally, + * this function will convert a pair of surrogate halves (each of which + * UCS-2 exposes as separate characters) into a single code point, + * matching UTF-16. + * @see `punycode.ucs2.encode` + * @see + * @memberOf punycode.ucs2 + * @name decode + * @param {String} string The Unicode input string (UCS-2). + * @returns {Array} The new array of code points. + */ + function ucs2decode(string) { + var output = [], + counter = 0, + length = string.length, + value, + extra; + while (counter < length) { + value = string.charCodeAt(counter++); + if (value >= 0xD800 && value <= 0xDBFF && counter < length) { + // high surrogate, and there is a next character + extra = string.charCodeAt(counter++); + if ((extra & 0xFC00) == 0xDC00) { // low surrogate + output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); + } else { + // unmatched surrogate; only append this code unit, in case the next + // code unit is the high surrogate of a surrogate pair + output.push(value); + counter--; + } + } else { + output.push(value); + } + } + return output; + } + + /** + * Creates a string based on an array of numeric code points. + * @see `punycode.ucs2.decode` + * @memberOf punycode.ucs2 + * @name encode + * @param {Array} codePoints The array of numeric code points. + * @returns {String} The new Unicode string (UCS-2). + */ + function ucs2encode(array) { + return map(array, function(value) { + var output = ''; + if (value > 0xFFFF) { + value -= 0x10000; + output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); + value = 0xDC00 | value & 0x3FF; + } + output += stringFromCharCode(value); + return output; + }).join(''); + } + + /** + * Converts a basic code point into a digit/integer. + * @see `digitToBasic()` + * @private + * @param {Number} codePoint The basic numeric code point value. + * @returns {Number} The numeric value of a basic code point (for use in + * representing integers) in the range `0` to `base - 1`, or `base` if + * the code point does not represent a value. + */ + function basicToDigit(codePoint) { + if (codePoint - 48 < 10) { + return codePoint - 22; + } + if (codePoint - 65 < 26) { + return codePoint - 65; + } + if (codePoint - 97 < 26) { + return codePoint - 97; + } + return base; + } + + /** + * Converts a digit/integer into a basic code point. + * @see `basicToDigit()` + * @private + * @param {Number} digit The numeric value of a basic code point. + * @returns {Number} The basic code point whose value (when used for + * representing integers) is `digit`, which needs to be in the range + * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is + * used; else, the lowercase form is used. The behavior is undefined + * if `flag` is non-zero and `digit` has no uppercase form. + */ + function digitToBasic(digit, flag) { + // 0..25 map to ASCII a..z or A..Z + // 26..35 map to ASCII 0..9 + return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5); + } + + /** + * Bias adaptation function as per section 3.4 of RFC 3492. + * https://tools.ietf.org/html/rfc3492#section-3.4 + * @private + */ + function adapt(delta, numPoints, firstTime) { + var k = 0; + delta = firstTime ? floor(delta / damp) : delta >> 1; + delta += floor(delta / numPoints); + for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) { + delta = floor(delta / baseMinusTMin); + } + return floor(k + (baseMinusTMin + 1) * delta / (delta + skew)); + } + + /** + * Converts a Punycode string of ASCII-only symbols to a string of Unicode + * symbols. + * @memberOf punycode + * @param {String} input The Punycode string of ASCII-only symbols. + * @returns {String} The resulting string of Unicode symbols. + */ + function decode(input) { + // Don't use UCS-2 + var output = [], + inputLength = input.length, + out, + i = 0, + n = initialN, + bias = initialBias, + basic, + j, + index, + oldi, + w, + k, + digit, + t, + /** Cached calculation results */ + baseMinusT; + + // Handle the basic code points: let `basic` be the number of input code + // points before the last delimiter, or `0` if there is none, then copy + // the first basic code points to the output. + + basic = input.lastIndexOf(delimiter); + if (basic < 0) { + basic = 0; + } + + for (j = 0; j < basic; ++j) { + // if it's not a basic code point + if (input.charCodeAt(j) >= 0x80) { + error('not-basic'); + } + output.push(input.charCodeAt(j)); + } + + // Main decoding loop: start just after the last delimiter if any basic code + // points were copied; start at the beginning otherwise. + + for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) { + + // `index` is the index of the next character to be consumed. + // Decode a generalized variable-length integer into `delta`, + // which gets added to `i`. The overflow checking is easier + // if we increase `i` as we go, then subtract off its starting + // value at the end to obtain `delta`. + for (oldi = i, w = 1, k = base; /* no condition */; k += base) { + + if (index >= inputLength) { + error('invalid-input'); + } + + digit = basicToDigit(input.charCodeAt(index++)); + + if (digit >= base || digit > floor((maxInt - i) / w)) { + error('overflow'); + } + + i += digit * w; + t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); + + if (digit < t) { + break; + } + + baseMinusT = base - t; + if (w > floor(maxInt / baseMinusT)) { + error('overflow'); + } + + w *= baseMinusT; + + } + + out = output.length + 1; + bias = adapt(i - oldi, out, oldi == 0); + + // `i` was supposed to wrap around from `out` to `0`, + // incrementing `n` each time, so we'll fix that now: + if (floor(i / out) > maxInt - n) { + error('overflow'); + } + + n += floor(i / out); + i %= out; + + // Insert `n` at position `i` of the output + output.splice(i++, 0, n); + + } + + return ucs2encode(output); + } + + /** + * Converts a string of Unicode symbols (e.g. a domain name label) to a + * Punycode string of ASCII-only symbols. + * @memberOf punycode + * @param {String} input The string of Unicode symbols. + * @returns {String} The resulting Punycode string of ASCII-only symbols. + */ + function encode(input) { + var n, + delta, + handledCPCount, + basicLength, + bias, + j, + m, + q, + k, + t, + currentValue, + output = [], + /** `inputLength` will hold the number of code points in `input`. */ + inputLength, + /** Cached calculation results */ + handledCPCountPlusOne, + baseMinusT, + qMinusT; + + // Convert the input in UCS-2 to Unicode + input = ucs2decode(input); + + // Cache the length + inputLength = input.length; + + // Initialize the state + n = initialN; + delta = 0; + bias = initialBias; + + // Handle the basic code points + for (j = 0; j < inputLength; ++j) { + currentValue = input[j]; + if (currentValue < 0x80) { + output.push(stringFromCharCode(currentValue)); + } + } + + handledCPCount = basicLength = output.length; + + // `handledCPCount` is the number of code points that have been handled; + // `basicLength` is the number of basic code points. + + // Finish the basic string - if it is not empty - with a delimiter + if (basicLength) { + output.push(delimiter); + } + + // Main encoding loop: + while (handledCPCount < inputLength) { + + // All non-basic code points < n have been handled already. Find the next + // larger one: + for (m = maxInt, j = 0; j < inputLength; ++j) { + currentValue = input[j]; + if (currentValue >= n && currentValue < m) { + m = currentValue; + } + } + + // Increase `delta` enough to advance the decoder's state to , + // but guard against overflow + handledCPCountPlusOne = handledCPCount + 1; + if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) { + error('overflow'); + } + + delta += (m - n) * handledCPCountPlusOne; + n = m; + + for (j = 0; j < inputLength; ++j) { + currentValue = input[j]; + + if (currentValue < n && ++delta > maxInt) { + error('overflow'); + } + + if (currentValue == n) { + // Represent delta as a generalized variable-length integer + for (q = delta, k = base; /* no condition */; k += base) { + t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); + if (q < t) { + break; + } + qMinusT = q - t; + baseMinusT = base - t; + output.push( + stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)) + ); + q = floor(qMinusT / baseMinusT); + } + + output.push(stringFromCharCode(digitToBasic(q, 0))); + bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength); + delta = 0; + ++handledCPCount; + } + } + + ++delta; + ++n; + + } + return output.join(''); + } + + /** + * Converts a Punycode string representing a domain name or an email address + * to Unicode. Only the Punycoded parts of the input will be converted, i.e. + * it doesn't matter if you call it on a string that has already been + * converted to Unicode. + * @memberOf punycode + * @param {String} input The Punycoded domain name or email address to + * convert to Unicode. + * @returns {String} The Unicode representation of the given Punycode + * string. + */ + function toUnicode(input) { + return mapDomain(input, function(string) { + return regexPunycode.test(string) + ? decode(string.slice(4).toLowerCase()) + : string; + }); + } + + /** + * Converts a Unicode string representing a domain name or an email address to + * Punycode. Only the non-ASCII parts of the domain name will be converted, + * i.e. it doesn't matter if you call it with a domain that's already in + * ASCII. + * @memberOf punycode + * @param {String} input The domain name or email address to convert, as a + * Unicode string. + * @returns {String} The Punycode representation of the given domain name or + * email address. + */ + function toASCII(input) { + return mapDomain(input, function(string) { + return regexNonASCII.test(string) + ? 'xn--' + encode(string) + : string; + }); + } + + /*--------------------------------------------------------------------------*/ + + /** Define the public API */ + punycode = { + /** + * A string representing the current Punycode.js version number. + * @memberOf punycode + * @type String + */ + 'version': '1.4.1', + /** + * An object of methods to convert from JavaScript's internal character + * representation (UCS-2) to Unicode code points, and back. + * @see + * @memberOf punycode + * @type Object + */ + 'ucs2': { + 'decode': ucs2decode, + 'encode': ucs2encode + }, + 'decode': decode, + 'encode': encode, + 'toASCII': toASCII, + 'toUnicode': toUnicode + }; + + /** Expose `punycode` */ + // Some AMD build optimizers, like r.js, check for specific condition patterns + // like the following: + if ( + typeof define == 'function' && + typeof define.amd == 'object' && + define.amd + ) { + define('punycode', function() { + return punycode; + }); + } else if (freeExports && freeModule) { + if (module.exports == freeExports) { + // in Node.js, io.js, or RingoJS v0.8.0+ + freeModule.exports = punycode; + } else { + // in Narwhal or RingoJS v0.7.0- + for (key in punycode) { + punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]); + } + } + } else { + // in Rhino or a web browser + root.punycode = punycode; + } + +}(this)); + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],14:[function(require,module,exports){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +'use strict'; + +// If obj.hasOwnProperty has been overridden, then calling +// obj.hasOwnProperty(prop) will break. +// See: https://github.com/joyent/node/issues/1707 +function hasOwnProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); } -LRUCache.prototype.peek = function (key) { - return get(this, key, false) -} +module.exports = function(qs, sep, eq, options) { + sep = sep || '&'; + eq = eq || '='; + var obj = {}; -LRUCache.prototype.pop = function () { - var hit = this._lruList[this._lru] - del(this, hit) - return hit || null -} + if (typeof qs !== 'string' || qs.length === 0) { + return obj; + } -LRUCache.prototype.del = function (key) { - del(this, this._cache[key]) -} + var regexp = /\+/g; + qs = qs.split(sep); -function get (self, key, doUse) { - var hit = self._cache[key] - if (hit) { - if (isStale(self, hit)) { - del(self, hit) - if (!self._allowStale) hit = undefined + var maxKeys = 1000; + if (options && typeof options.maxKeys === 'number') { + maxKeys = options.maxKeys; + } + + var len = qs.length; + // maxKeys <= 0 means that we should not limit keys count + if (maxKeys > 0 && len > maxKeys) { + len = maxKeys; + } + + for (var i = 0; i < len; ++i) { + var x = qs[i].replace(regexp, '%20'), + idx = x.indexOf(eq), + kstr, vstr, k, v; + + if (idx >= 0) { + kstr = x.substr(0, idx); + vstr = x.substr(idx + 1); } else { - if (doUse) use(self, hit) + kstr = x; + vstr = ''; + } + + k = decodeURIComponent(kstr); + v = decodeURIComponent(vstr); + + if (!hasOwnProperty(obj, k)) { + obj[k] = v; + } else if (isArray(obj[k])) { + obj[k].push(v); + } else { + obj[k] = [obj[k], v]; } - if (hit) hit = hit.value } - return hit -} -function isStale(self, hit) { - if (!hit || (!hit.maxAge && !self._maxAge)) return false - var stale = false; - var diff = Date.now() - hit.now - if (hit.maxAge) { - stale = diff > hit.maxAge - } else { - stale = self._maxAge && (diff > self._maxAge) + return obj; +}; + +var isArray = Array.isArray || function (xs) { + return Object.prototype.toString.call(xs) === '[object Array]'; +}; + +},{}],15:[function(require,module,exports){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +'use strict'; + +var stringifyPrimitive = function(v) { + switch (typeof v) { + case 'string': + return v; + + case 'boolean': + return v ? 'true' : 'false'; + + case 'number': + return isFinite(v) ? v : ''; + + default: + return ''; } - return stale; -} +}; -function use (self, hit) { - shiftLU(self, hit) - hit.lu = self._mru ++ - self._lruList[hit.lu] = hit -} - -function trim (self) { - while (self._lru < self._mru && self._length > self._max) - del(self, self._lruList[self._lru]) -} - -function shiftLU (self, hit) { - delete self._lruList[ hit.lu ] - while (self._lru < self._mru && !self._lruList[self._lru]) self._lru ++ -} - -function del (self, hit) { - if (hit) { - if (self._dispose) self._dispose(hit.key, hit.value) - self._length -= hit.length - self._itemCount -- - delete self._cache[ hit.key ] - shiftLU(self, hit) +module.exports = function(obj, sep, eq, name) { + sep = sep || '&'; + eq = eq || '='; + if (obj === null) { + obj = undefined; } + + if (typeof obj === 'object') { + return map(objectKeys(obj), function(k) { + var ks = encodeURIComponent(stringifyPrimitive(k)) + eq; + if (isArray(obj[k])) { + return map(obj[k], function(v) { + return ks + encodeURIComponent(stringifyPrimitive(v)); + }).join(sep); + } else { + return ks + encodeURIComponent(stringifyPrimitive(obj[k])); + } + }).join(sep); + + } + + if (!name) return ''; + return encodeURIComponent(stringifyPrimitive(name)) + eq + + encodeURIComponent(stringifyPrimitive(obj)); +}; + +var isArray = Array.isArray || function (xs) { + return Object.prototype.toString.call(xs) === '[object Array]'; +}; + +function map (xs, f) { + if (xs.map) return xs.map(f); + var res = []; + for (var i = 0; i < xs.length; i++) { + res.push(f(xs[i], i)); + } + return res; } -// classy, since V8 prefers predictable objects. -function Entry (key, value, lu, length, now, maxAge) { - this.key = key - this.value = value - this.lu = lu - this.length = length - this.now = now - if (maxAge) this.maxAge = maxAge -} +var objectKeys = Object.keys || function (obj) { + var res = []; + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key); + } + return res; +}; -})() +},{}],16:[function(require,module,exports){ +'use strict'; -},{}],18:[function(require,module,exports){ +exports.decode = exports.parse = require('./decode'); +exports.encode = exports.stringify = require('./encode'); + +},{"./decode":14,"./encode":15}],17:[function(require,module,exports){ module.exports = sigmund function sigmund (subject, maxSessions) { maxSessions = maxSessions || 10; @@ -5366,7 +4732,716 @@ function sigmund (subject, maxSessions) { // vim: set softtabstop=4 shiftwidth=4: -},{}],19:[function(require,module,exports){ +},{}],18:[function(require,module,exports){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +var punycode = require('punycode'); + +exports.parse = urlParse; +exports.resolve = urlResolve; +exports.resolveObject = urlResolveObject; +exports.format = urlFormat; + +exports.Url = Url; + +function Url() { + this.protocol = null; + this.slashes = null; + this.auth = null; + this.host = null; + this.port = null; + this.hostname = null; + this.hash = null; + this.search = null; + this.query = null; + this.pathname = null; + this.path = null; + this.href = null; +} + +// Reference: RFC 3986, RFC 1808, RFC 2396 + +// define these here so at least they only have to be +// compiled once on the first module load. +var protocolPattern = /^([a-z0-9.+-]+:)/i, + portPattern = /:[0-9]*$/, + + // RFC 2396: characters reserved for delimiting URLs. + // We actually just auto-escape these. + delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'], + + // RFC 2396: characters not allowed for various reasons. + unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims), + + // Allowed by RFCs, but cause of XSS attacks. Always escape these. + autoEscape = ['\''].concat(unwise), + // Characters that are never ever allowed in a hostname. + // Note that any invalid chars are also handled, but these + // are the ones that are *expected* to be seen, so we fast-path + // them. + nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape), + hostEndingChars = ['/', '?', '#'], + hostnameMaxLen = 255, + hostnamePartPattern = /^[a-z0-9A-Z_-]{0,63}$/, + hostnamePartStart = /^([a-z0-9A-Z_-]{0,63})(.*)$/, + // protocols that can allow "unsafe" and "unwise" chars. + unsafeProtocol = { + 'javascript': true, + 'javascript:': true + }, + // protocols that never have a hostname. + hostlessProtocol = { + 'javascript': true, + 'javascript:': true + }, + // protocols that always contain a // bit. + slashedProtocol = { + 'http': true, + 'https': true, + 'ftp': true, + 'gopher': true, + 'file': true, + 'http:': true, + 'https:': true, + 'ftp:': true, + 'gopher:': true, + 'file:': true + }, + querystring = require('querystring'); + +function urlParse(url, parseQueryString, slashesDenoteHost) { + if (url && isObject(url) && url instanceof Url) return url; + + var u = new Url; + u.parse(url, parseQueryString, slashesDenoteHost); + return u; +} + +Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) { + if (!isString(url)) { + throw new TypeError("Parameter 'url' must be a string, not " + typeof url); + } + + var rest = url; + + // trim before proceeding. + // This is to support parse stuff like " http://foo.com \n" + rest = rest.trim(); + + var proto = protocolPattern.exec(rest); + if (proto) { + proto = proto[0]; + var lowerProto = proto.toLowerCase(); + this.protocol = lowerProto; + rest = rest.substr(proto.length); + } + + // figure out if it's got a host + // user@server is *always* interpreted as a hostname, and url + // resolution will treat //foo/bar as host=foo,path=bar because that's + // how the browser resolves relative URLs. + if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) { + var slashes = rest.substr(0, 2) === '//'; + if (slashes && !(proto && hostlessProtocol[proto])) { + rest = rest.substr(2); + this.slashes = true; + } + } + + if (!hostlessProtocol[proto] && + (slashes || (proto && !slashedProtocol[proto]))) { + + // there's a hostname. + // the first instance of /, ?, ;, or # ends the host. + // + // If there is an @ in the hostname, then non-host chars *are* allowed + // to the left of the last @ sign, unless some host-ending character + // comes *before* the @-sign. + // URLs are obnoxious. + // + // ex: + // http://a@b@c/ => user:a@b host:c + // http://a@b?@c => user:a host:c path:/?@c + + // v0.12 TODO(isaacs): This is not quite how Chrome does things. + // Review our test case against browsers more comprehensively. + + // find the first instance of any hostEndingChars + var hostEnd = -1; + for (var i = 0; i < hostEndingChars.length; i++) { + var hec = rest.indexOf(hostEndingChars[i]); + if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) + hostEnd = hec; + } + + // at this point, either we have an explicit point where the + // auth portion cannot go past, or the last @ char is the decider. + var auth, atSign; + if (hostEnd === -1) { + // atSign can be anywhere. + atSign = rest.lastIndexOf('@'); + } else { + // atSign must be in auth portion. + // http://a@b/c@d => host:b auth:a path:/c@d + atSign = rest.lastIndexOf('@', hostEnd); + } + + // Now we have a portion which is definitely the auth. + // Pull that off. + if (atSign !== -1) { + auth = rest.slice(0, atSign); + rest = rest.slice(atSign + 1); + this.auth = decodeURIComponent(auth); + } + + // the host is the remaining to the left of the first non-host char + hostEnd = -1; + for (var i = 0; i < nonHostChars.length; i++) { + var hec = rest.indexOf(nonHostChars[i]); + if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) + hostEnd = hec; + } + // if we still have not hit it, then the entire thing is a host. + if (hostEnd === -1) + hostEnd = rest.length; + + this.host = rest.slice(0, hostEnd); + rest = rest.slice(hostEnd); + + // pull out port. + this.parseHost(); + + // we've indicated that there is a hostname, + // so even if it's empty, it has to be present. + this.hostname = this.hostname || ''; + + // if hostname begins with [ and ends with ] + // assume that it's an IPv6 address. + var ipv6Hostname = this.hostname[0] === '[' && + this.hostname[this.hostname.length - 1] === ']'; + + // validate a little. + if (!ipv6Hostname) { + var hostparts = this.hostname.split(/\./); + for (var i = 0, l = hostparts.length; i < l; i++) { + var part = hostparts[i]; + if (!part) continue; + if (!part.match(hostnamePartPattern)) { + var newpart = ''; + for (var j = 0, k = part.length; j < k; j++) { + if (part.charCodeAt(j) > 127) { + // we replace non-ASCII char with a temporary placeholder + // we need this to make sure size of hostname is not + // broken by replacing non-ASCII by nothing + newpart += 'x'; + } else { + newpart += part[j]; + } + } + // we test again with ASCII char only + if (!newpart.match(hostnamePartPattern)) { + var validParts = hostparts.slice(0, i); + var notHost = hostparts.slice(i + 1); + var bit = part.match(hostnamePartStart); + if (bit) { + validParts.push(bit[1]); + notHost.unshift(bit[2]); + } + if (notHost.length) { + rest = '/' + notHost.join('.') + rest; + } + this.hostname = validParts.join('.'); + break; + } + } + } + } + + if (this.hostname.length > hostnameMaxLen) { + this.hostname = ''; + } else { + // hostnames are always lower case. + this.hostname = this.hostname.toLowerCase(); + } + + if (!ipv6Hostname) { + // IDNA Support: Returns a puny coded representation of "domain". + // It only converts the part of the domain name that + // has non ASCII characters. I.e. it dosent matter if + // you call it with a domain that already is in ASCII. + var domainArray = this.hostname.split('.'); + var newOut = []; + for (var i = 0; i < domainArray.length; ++i) { + var s = domainArray[i]; + newOut.push(s.match(/[^A-Za-z0-9_-]/) ? + 'xn--' + punycode.encode(s) : s); + } + this.hostname = newOut.join('.'); + } + + var p = this.port ? ':' + this.port : ''; + var h = this.hostname || ''; + this.host = h + p; + this.href += this.host; + + // strip [ and ] from the hostname + // the host field still retains them, though + if (ipv6Hostname) { + this.hostname = this.hostname.substr(1, this.hostname.length - 2); + if (rest[0] !== '/') { + rest = '/' + rest; + } + } + } + + // now rest is set to the post-host stuff. + // chop off any delim chars. + if (!unsafeProtocol[lowerProto]) { + + // First, make 100% sure that any "autoEscape" chars get + // escaped, even if encodeURIComponent doesn't think they + // need to be. + for (var i = 0, l = autoEscape.length; i < l; i++) { + var ae = autoEscape[i]; + var esc = encodeURIComponent(ae); + if (esc === ae) { + esc = escape(ae); + } + rest = rest.split(ae).join(esc); + } + } + + + // chop off from the tail first. + var hash = rest.indexOf('#'); + if (hash !== -1) { + // got a fragment string. + this.hash = rest.substr(hash); + rest = rest.slice(0, hash); + } + var qm = rest.indexOf('?'); + if (qm !== -1) { + this.search = rest.substr(qm); + this.query = rest.substr(qm + 1); + if (parseQueryString) { + this.query = querystring.parse(this.query); + } + rest = rest.slice(0, qm); + } else if (parseQueryString) { + // no query string, but parseQueryString still requested + this.search = ''; + this.query = {}; + } + if (rest) this.pathname = rest; + if (slashedProtocol[lowerProto] && + this.hostname && !this.pathname) { + this.pathname = '/'; + } + + //to support http.request + if (this.pathname || this.search) { + var p = this.pathname || ''; + var s = this.search || ''; + this.path = p + s; + } + + // finally, reconstruct the href based on what has been validated. + this.href = this.format(); + return this; +}; + +// format a parsed object into a url string +function urlFormat(obj) { + // ensure it's an object, and not a string url. + // If it's an obj, this is a no-op. + // this way, you can call url_format() on strings + // to clean up potentially wonky urls. + if (isString(obj)) obj = urlParse(obj); + if (!(obj instanceof Url)) return Url.prototype.format.call(obj); + return obj.format(); +} + +Url.prototype.format = function() { + var auth = this.auth || ''; + if (auth) { + auth = encodeURIComponent(auth); + auth = auth.replace(/%3A/i, ':'); + auth += '@'; + } + + var protocol = this.protocol || '', + pathname = this.pathname || '', + hash = this.hash || '', + host = false, + query = ''; + + if (this.host) { + host = auth + this.host; + } else if (this.hostname) { + host = auth + (this.hostname.indexOf(':') === -1 ? + this.hostname : + '[' + this.hostname + ']'); + if (this.port) { + host += ':' + this.port; + } + } + + if (this.query && + isObject(this.query) && + Object.keys(this.query).length) { + query = querystring.stringify(this.query); + } + + var search = this.search || (query && ('?' + query)) || ''; + + if (protocol && protocol.substr(-1) !== ':') protocol += ':'; + + // only the slashedProtocols get the //. Not mailto:, xmpp:, etc. + // unless they had them to begin with. + if (this.slashes || + (!protocol || slashedProtocol[protocol]) && host !== false) { + host = '//' + (host || ''); + if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname; + } else if (!host) { + host = ''; + } + + if (hash && hash.charAt(0) !== '#') hash = '#' + hash; + if (search && search.charAt(0) !== '?') search = '?' + search; + + pathname = pathname.replace(/[?#]/g, function(match) { + return encodeURIComponent(match); + }); + search = search.replace('#', '%23'); + + return protocol + host + pathname + search + hash; +}; + +function urlResolve(source, relative) { + return urlParse(source, false, true).resolve(relative); +} + +Url.prototype.resolve = function(relative) { + return this.resolveObject(urlParse(relative, false, true)).format(); +}; + +function urlResolveObject(source, relative) { + if (!source) return relative; + return urlParse(source, false, true).resolveObject(relative); +} + +Url.prototype.resolveObject = function(relative) { + if (isString(relative)) { + var rel = new Url(); + rel.parse(relative, false, true); + relative = rel; + } + + var result = new Url(); + Object.keys(this).forEach(function(k) { + result[k] = this[k]; + }, this); + + // hash is always overridden, no matter what. + // even href="" will remove it. + result.hash = relative.hash; + + // if the relative url is empty, then there's nothing left to do here. + if (relative.href === '') { + result.href = result.format(); + return result; + } + + // hrefs like //foo/bar always cut to the protocol. + if (relative.slashes && !relative.protocol) { + // take everything except the protocol from relative + Object.keys(relative).forEach(function(k) { + if (k !== 'protocol') + result[k] = relative[k]; + }); + + //urlParse appends trailing / to urls like http://www.example.com + if (slashedProtocol[result.protocol] && + result.hostname && !result.pathname) { + result.path = result.pathname = '/'; + } + + result.href = result.format(); + return result; + } + + if (relative.protocol && relative.protocol !== result.protocol) { + // if it's a known url protocol, then changing + // the protocol does weird things + // first, if it's not file:, then we MUST have a host, + // and if there was a path + // to begin with, then we MUST have a path. + // if it is file:, then the host is dropped, + // because that's known to be hostless. + // anything else is assumed to be absolute. + if (!slashedProtocol[relative.protocol]) { + Object.keys(relative).forEach(function(k) { + result[k] = relative[k]; + }); + result.href = result.format(); + return result; + } + + result.protocol = relative.protocol; + if (!relative.host && !hostlessProtocol[relative.protocol]) { + var relPath = (relative.pathname || '').split('/'); + while (relPath.length && !(relative.host = relPath.shift())); + if (!relative.host) relative.host = ''; + if (!relative.hostname) relative.hostname = ''; + if (relPath[0] !== '') relPath.unshift(''); + if (relPath.length < 2) relPath.unshift(''); + result.pathname = relPath.join('/'); + } else { + result.pathname = relative.pathname; + } + result.search = relative.search; + result.query = relative.query; + result.host = relative.host || ''; + result.auth = relative.auth; + result.hostname = relative.hostname || relative.host; + result.port = relative.port; + // to support http.request + if (result.pathname || result.search) { + var p = result.pathname || ''; + var s = result.search || ''; + result.path = p + s; + } + result.slashes = result.slashes || relative.slashes; + result.href = result.format(); + return result; + } + + var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'), + isRelAbs = ( + relative.host || + relative.pathname && relative.pathname.charAt(0) === '/' + ), + mustEndAbs = (isRelAbs || isSourceAbs || + (result.host && relative.pathname)), + removeAllDots = mustEndAbs, + srcPath = result.pathname && result.pathname.split('/') || [], + relPath = relative.pathname && relative.pathname.split('/') || [], + psychotic = result.protocol && !slashedProtocol[result.protocol]; + + // if the url is a non-slashed url, then relative + // links like ../.. should be able + // to crawl up to the hostname, as well. This is strange. + // result.protocol has already been set by now. + // Later on, put the first path part into the host field. + if (psychotic) { + result.hostname = ''; + result.port = null; + if (result.host) { + if (srcPath[0] === '') srcPath[0] = result.host; + else srcPath.unshift(result.host); + } + result.host = ''; + if (relative.protocol) { + relative.hostname = null; + relative.port = null; + if (relative.host) { + if (relPath[0] === '') relPath[0] = relative.host; + else relPath.unshift(relative.host); + } + relative.host = null; + } + mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === ''); + } + + if (isRelAbs) { + // it's absolute. + result.host = (relative.host || relative.host === '') ? + relative.host : result.host; + result.hostname = (relative.hostname || relative.hostname === '') ? + relative.hostname : result.hostname; + result.search = relative.search; + result.query = relative.query; + srcPath = relPath; + // fall through to the dot-handling below. + } else if (relPath.length) { + // it's relative + // throw away the existing file, and take the new path instead. + if (!srcPath) srcPath = []; + srcPath.pop(); + srcPath = srcPath.concat(relPath); + result.search = relative.search; + result.query = relative.query; + } else if (!isNullOrUndefined(relative.search)) { + // just pull out the search. + // like href='?foo'. + // Put this after the other two cases because it simplifies the booleans + if (psychotic) { + result.hostname = result.host = srcPath.shift(); + //occationaly the auth can get stuck only in host + //this especialy happens in cases like + //url.resolveObject('mailto:local1@domain1', 'local2@domain2') + var authInHost = result.host && result.host.indexOf('@') > 0 ? + result.host.split('@') : false; + if (authInHost) { + result.auth = authInHost.shift(); + result.host = result.hostname = authInHost.shift(); + } + } + result.search = relative.search; + result.query = relative.query; + //to support http.request + if (!isNull(result.pathname) || !isNull(result.search)) { + result.path = (result.pathname ? result.pathname : '') + + (result.search ? result.search : ''); + } + result.href = result.format(); + return result; + } + + if (!srcPath.length) { + // no path at all. easy. + // we've already handled the other stuff above. + result.pathname = null; + //to support http.request + if (result.search) { + result.path = '/' + result.search; + } else { + result.path = null; + } + result.href = result.format(); + return result; + } + + // if a url ENDs in . or .., then it must get a trailing slash. + // however, if it ends in anything else non-slashy, + // then it must NOT get a trailing slash. + var last = srcPath.slice(-1)[0]; + var hasTrailingSlash = ( + (result.host || relative.host) && (last === '.' || last === '..') || + last === ''); + + // strip single dots, resolve double dots to parent dir + // if the path tries to go above the root, `up` ends up > 0 + var up = 0; + for (var i = srcPath.length; i >= 0; i--) { + last = srcPath[i]; + if (last == '.') { + srcPath.splice(i, 1); + } else if (last === '..') { + srcPath.splice(i, 1); + up++; + } else if (up) { + srcPath.splice(i, 1); + up--; + } + } + + // if the path is allowed to go above the root, restore leading ..s + if (!mustEndAbs && !removeAllDots) { + for (; up--; up) { + srcPath.unshift('..'); + } + } + + if (mustEndAbs && srcPath[0] !== '' && + (!srcPath[0] || srcPath[0].charAt(0) !== '/')) { + srcPath.unshift(''); + } + + if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) { + srcPath.push(''); + } + + var isAbsolute = srcPath[0] === '' || + (srcPath[0] && srcPath[0].charAt(0) === '/'); + + // put the host back + if (psychotic) { + result.hostname = result.host = isAbsolute ? '' : + srcPath.length ? srcPath.shift() : ''; + //occationaly the auth can get stuck only in host + //this especialy happens in cases like + //url.resolveObject('mailto:local1@domain1', 'local2@domain2') + var authInHost = result.host && result.host.indexOf('@') > 0 ? + result.host.split('@') : false; + if (authInHost) { + result.auth = authInHost.shift(); + result.host = result.hostname = authInHost.shift(); + } + } + + mustEndAbs = mustEndAbs || (result.host && srcPath.length); + + if (mustEndAbs && !isAbsolute) { + srcPath.unshift(''); + } + + if (!srcPath.length) { + result.pathname = null; + result.path = null; + } else { + result.pathname = srcPath.join('/'); + } + + //to support request.http + if (!isNull(result.pathname) || !isNull(result.search)) { + result.path = (result.pathname ? result.pathname : '') + + (result.search ? result.search : ''); + } + result.auth = relative.auth || result.auth; + result.slashes = result.slashes || relative.slashes; + result.href = result.format(); + return result; +}; + +Url.prototype.parseHost = function() { + var host = this.host; + var port = portPattern.exec(host); + if (port) { + port = port[0]; + if (port !== ':') { + this.port = port.substr(1); + } + host = host.substr(0, host.length - port.length); + } + if (host) this.hostname = host; +}; + +function isString(arg) { + return typeof arg === "string"; +} + +function isObject(arg) { + return typeof arg === 'object' && arg !== null; +} + +function isNull(arg) { + return arg === null; +} +function isNullOrUndefined(arg) { + return arg == null; +} + +},{"punycode":13,"querystring":16}],19:[function(require,module,exports){ (function (Buffer){ var Filer = require('..'); var util = require('../tests/lib/test-utils.js'); @@ -5490,7 +5565,7 @@ progress.max = iterations; run(); }).call(this,require("buffer").Buffer) -},{"..":28,"../tests/lib/test-utils.js":43,"buffer":6}],20:[function(require,module,exports){ +},{"..":28,"../tests/lib/test-utils.js":43,"buffer":7}],20:[function(require,module,exports){ (function (Buffer){ function FilerBuffer (subject, encoding, nonZero) { @@ -5517,7 +5592,7 @@ Object.keys(Buffer).forEach(function (p) { module.exports = FilerBuffer; }).call(this,require("buffer").Buffer) -},{"buffer":6}],21:[function(require,module,exports){ +},{"buffer":7}],21:[function(require,module,exports){ var O_READ = 'READ'; var O_WRITE = 'WRITE'; var O_CREATE = 'CREATE'; @@ -5539,10 +5614,17 @@ module.exports = { WSQL_SIZE: 5 * 1024 * 1024, WSQL_DESC: "FileSystem Storage", - MODE_FILE: 'FILE', - MODE_DIRECTORY: 'DIRECTORY', - MODE_SYMBOLIC_LINK: 'SYMLINK', - MODE_META: 'META', + NODE_TYPE_FILE: 'FILE', + NODE_TYPE_DIRECTORY: 'DIRECTORY', + NODE_TYPE_SYMBOLIC_LINK: 'SYMLINK', + NODE_TYPE_META: 'META', + + S_IFREG: 0x8000, + S_IFDIR: 0x4000, + S_IFLNK: 0xA000, + + DEFAULT_DIR_PERMISSIONS: 0x1ED, // 755 + DEFAULT_FILE_PERMISSIONS: 0x1A4, // 644 SYMLOOP_MAX: 10, @@ -5600,11 +5682,11 @@ module.exports = { }; },{}],22:[function(require,module,exports){ -var MODE_FILE = require('./constants.js').MODE_FILE; +var NODE_TYPE_FILE = require('./constants.js').NODE_TYPE_FILE; module.exports = function DirectoryEntry(id, type) { this.id = id; - this.type = type || MODE_FILE; + this.type = type || NODE_TYPE_FILE; }; },{"./constants.js":21}],23:[function(require,module,exports){ @@ -5624,7 +5706,7 @@ module.exports = { }; }).call(this,require("buffer").Buffer) -},{"buffer":6}],24:[function(require,module,exports){ +},{"buffer":7}],24:[function(require,module,exports){ var errors = {}; [ /** @@ -5741,10 +5823,10 @@ var isAbsolutePath = Path.isAbsolute; var isNullPath = Path.isNull; var Constants = require('../constants.js'); -var MODE_FILE = Constants.MODE_FILE; -var MODE_DIRECTORY = Constants.MODE_DIRECTORY; -var MODE_SYMBOLIC_LINK = Constants.MODE_SYMBOLIC_LINK; -var MODE_META = Constants.MODE_META; +var NODE_TYPE_FILE = Constants.NODE_TYPE_FILE; +var NODE_TYPE_DIRECTORY = Constants.NODE_TYPE_DIRECTORY; +var NODE_TYPE_SYMBOLIC_LINK = Constants.NODE_TYPE_SYMBOLIC_LINK; +var NODE_TYPE_META = Constants.NODE_TYPE_META; var ROOT_DIRECTORY_NAME = Constants.ROOT_DIRECTORY_NAME; var SUPER_NODE_ID = Constants.SUPER_NODE_ID; @@ -5777,17 +5859,17 @@ var Buffer = require('../buffer.js'); * and filesystem flags are examined in order to override update logic. */ function update_node_times(context, path, node, times, callback) { + var update = false; + // Honour mount flags for how we update times var flags = context.flags; if(_(flags).contains(FS_NOCTIME)) { delete times.ctime; } - if(_(flags).contains(FS_NOMTIME)) { + if(_(flags).contains(FS_NOMTIME)) { delete times.mtime; } - // Only do the update if required (i.e., times are still present) - var update = false; if(times.ctime) { node.ctime = times.ctime; // We don't do atime tracking for perf reasons, but do mirror ctime @@ -5806,8 +5888,6 @@ function update_node_times(context, path, node, times, callback) { } function complete(error) { - // Queue this change so we can send watch events. - // Unlike node.js, we send the full path vs. basename/dirname only. context.changes.push({ event: 'change', path: path }); callback(error); } @@ -5824,9 +5904,9 @@ function update_node_times(context, path, node, times, callback) { */ // in: file or directory path // out: new node representing file/directory -function make_node(context, path, mode, callback) { - if(mode !== MODE_DIRECTORY && mode !== MODE_FILE) { - return callback(new Errors.EINVAL('mode must be a directory or file', path)); +function make_node(context, path, type, callback) { + if(type !== NODE_TYPE_DIRECTORY && type !== NODE_TYPE_FILE) { + return callback(new Errors.EINVAL('type must be a directory or file', path)); } path = normalize(path); @@ -5841,7 +5921,7 @@ function make_node(context, path, mode, callback) { function create_node_in_parent(error, parentDirectoryNode) { if(error) { callback(error); - } else if(parentDirectoryNode.mode !== MODE_DIRECTORY) { + } else if(parentDirectoryNode.type !== NODE_TYPE_DIRECTORY) { callback(new Errors.ENOTDIR('a component of the path prefix is not a directory', path)); } else { parentNode = parentDirectoryNode; @@ -5866,7 +5946,11 @@ function make_node(context, path, mode, callback) { callback(error); } else { parentNodeData = result; - Node.create({guid: context.guid, mode: mode}, function(error, result) { + Node.create({ + path: path, + guid: context.guid, + type: type + }, function(error, result) { if(error) { callback(error); return; @@ -5893,7 +5977,7 @@ function make_node(context, path, mode, callback) { if(error) { callback(error); } else { - parentNodeData[name] = new DirectoryEntry(node.id, mode); + parentNodeData[name] = new DirectoryEntry(node.id, type); context.putObject(parentNode.data, parentNodeData, update_time); } } @@ -5919,7 +6003,7 @@ function find_node(context, path, callback) { function read_root_directory_node(error, superNode) { if(error) { callback(error); - } else if(!superNode || superNode.mode !== MODE_META || !superNode.rnode) { + } else if(!superNode || superNode.type !== NODE_TYPE_META || !superNode.rnode) { callback(new Errors.EFILESYSTEMERROR()); } else { context.getObject(superNode.rnode, check_root_directory_node); @@ -5941,7 +6025,7 @@ function find_node(context, path, callback) { function read_parent_directory_data(error, parentDirectoryNode) { if(error) { callback(error); - } else if(parentDirectoryNode.mode !== MODE_DIRECTORY || !parentDirectoryNode.data) { + } else if(parentDirectoryNode.type !== NODE_TYPE_DIRECTORY || !parentDirectoryNode.data) { callback(new Errors.ENOTDIR('a component of the path prefix is not a directory', path)); } else { context.getObject(parentDirectoryNode.data, get_node_from_parent_directory_data); @@ -5967,7 +6051,7 @@ function find_node(context, path, callback) { if(error) { callback(error); } else { - if(node.mode == MODE_SYMBOLIC_LINK) { + if(node.type == NODE_TYPE_SYMBOLIC_LINK) { followedCount++; if(followedCount > SYMLOOP_MAX){ callback(new Errors.ELOOP(null, path)); @@ -6044,7 +6128,7 @@ function ensure_root_directory(context, callback) { } else if(error && !(error instanceof Errors.ENOENT)) { callback(error); } else { - SuperNode.create({guid: context.guid}, function(error, result) { + SuperNode.create({ guid: context.guid }, function(error, result) { if(error) { callback(error); return; @@ -6059,7 +6143,12 @@ function ensure_root_directory(context, callback) { if(error) { callback(error); } else { - Node.create({guid: context.guid, id: superNode.rnode, mode: MODE_DIRECTORY}, function(error, result) { + Node.create({ + guid: context.guid, + id: superNode.rnode, + type: NODE_TYPE_DIRECTORY, + path: ROOT_DIRECTORY_NAME + }, function(error, result) { if(error) { callback(error); return; @@ -6120,7 +6209,11 @@ function make_directory(context, path, callback) { callback(error); } else { parentDirectoryData = result; - Node.create({guid: context.guid, mode: MODE_DIRECTORY}, function(error, result) { + Node.create({ + guid: context.guid, + type: NODE_TYPE_DIRECTORY, + path: path + }, function(error, result) { if(error) { callback(error); return; @@ -6154,7 +6247,7 @@ function make_directory(context, path, callback) { if(error) { callback(error); } else { - parentDirectoryData[name] = new DirectoryEntry(directoryNode.id, MODE_DIRECTORY); + parentDirectoryData[name] = new DirectoryEntry(directoryNode.id, NODE_TYPE_DIRECTORY); context.putObject(parentDirectoryNode.data, parentDirectoryData, update_time); } } @@ -6201,7 +6294,7 @@ function remove_directory(context, path, callback) { function check_if_node_is_directory(error, result) { if(error) { callback(error); - } else if(result.mode != MODE_DIRECTORY) { + } else if(result.type != NODE_TYPE_DIRECTORY) { callback(new Errors.ENOTDIR(null, path)); } else { directoryNode = result; @@ -6281,7 +6374,7 @@ function open_file(context, path, flags, callback) { function read_directory_data(error, result) { if(error) { callback(error); - } else if(result.mode !== MODE_DIRECTORY) { + } else if(result.type !== NODE_TYPE_DIRECTORY) { callback(new Errors.ENOENT(null, path)); } else { directoryNode = result; @@ -6299,7 +6392,7 @@ function open_file(context, path, flags, callback) { callback(new Errors.ENOENT('O_CREATE and O_EXCLUSIVE are set, and the named file exists', path)); } else { directoryEntry = directoryData[name]; - if(directoryEntry.type == MODE_DIRECTORY && _(flags).contains(O_WRITE)) { + if(directoryEntry.type == NODE_TYPE_DIRECTORY && _(flags).contains(O_WRITE)) { callback(new Errors.EISDIR('the named file is a directory and O_WRITE is set', path)); } else { context.getObject(directoryEntry.id, check_if_symbolic_link); @@ -6320,7 +6413,7 @@ function open_file(context, path, flags, callback) { callback(error); } else { var node = result; - if(node.mode == MODE_SYMBOLIC_LINK) { + if(node.type == NODE_TYPE_SYMBOLIC_LINK) { followedCount++; if(followedCount > SYMLOOP_MAX){ callback(new Errors.ELOOP(null, path)); @@ -6357,7 +6450,11 @@ function open_file(context, path, flags, callback) { } function write_file_node() { - Node.create({guid: context.guid, mode: MODE_FILE}, function(error, result) { + Node.create({ + guid: context.guid, + type: NODE_TYPE_FILE, + path: path + }, function(error, result) { if(error) { callback(error); return; @@ -6391,7 +6488,7 @@ function open_file(context, path, flags, callback) { if(error) { callback(error); } else { - directoryData[name] = new DirectoryEntry(fileNode.id, MODE_FILE); + directoryData[name] = new DirectoryEntry(fileNode.id, NODE_TYPE_FILE); context.putObject(directoryNode.data, directoryData, update_time); } } @@ -6546,7 +6643,7 @@ function read_data(context, ofd, buffer, offset, length, position, callback) { function read_file_data(error, result) { if(error) { callback(error); - } else if(result.mode === 'DIRECTORY') { + } else if(result.type === NODE_TYPE_DIRECTORY) { callback(new Errors.EISDIR('the named file is a directory', ofd.path)); } else { fileNode = result; @@ -6612,18 +6709,20 @@ function link_node(context, oldpath, newpath, callback) { newpath = normalize(newpath); var newname = basename(newpath); var newParentPath = dirname(newpath); + var ctime = Date.now(); var oldDirectoryNode; var oldDirectoryData; var newDirectoryNode; var newDirectoryData; + var fileNodeID; var fileNode; function update_time(error) { if(error) { callback(error); } else { - update_node_times(context, newpath, fileNode, { ctime: Date.now() }, callback); + update_node_times(context, newpath, fileNode, { ctime: ctime }, callback); } } @@ -6637,11 +6736,11 @@ function link_node(context, oldpath, newpath, callback) { } } - function read_directory_entry(error, result) { + function read_file_node(error, result) { if(error) { callback(error); } else { - context.getObject(newDirectoryData[newname].id, update_file_node); + context.getObject(fileNodeID, update_file_node); } } @@ -6654,7 +6753,8 @@ function link_node(context, oldpath, newpath, callback) { callback(new Errors.EEXIST('newpath resolves to an existing file', newname)); } else { newDirectoryData[newname] = oldDirectoryData[oldname]; - context.putObject(newDirectoryNode.data, newDirectoryData, read_directory_entry); + fileNodeID = newDirectoryData[newname].id; + context.putObject(newDirectoryNode.data, newDirectoryData, read_file_node); } } } @@ -6675,7 +6775,7 @@ function link_node(context, oldpath, newpath, callback) { oldDirectoryData = result; if(!_(oldDirectoryData).has(oldname)) { callback(new Errors.ENOENT('a component of either path prefix does not exist', oldname)); - } else if(oldDirectoryData[oldname].type === 'DIRECTORY') { + } else if(oldDirectoryData[oldname].type === NODE_TYPE_DIRECTORY) { callback(new Errors.EPERM('oldpath refers to a directory')); } else { find_node(context, newParentPath, read_new_directory_data); @@ -6743,7 +6843,7 @@ function unlink_node(context, path, callback) { function check_if_node_is_directory(error, result) { if(error) { callback(error); - } else if(result.mode === 'DIRECTORY') { + } else if(result.type === NODE_TYPE_DIRECTORY) { callback(new Errors.EPERM('unlink not permitted on directories', name)); } else { update_file_node(null, result); @@ -6795,7 +6895,7 @@ function read_directory(context, path, callback) { function read_directory_data(error, result) { if(error) { callback(error); - } else if(result.mode !== MODE_DIRECTORY) { + } else if(result.type !== NODE_TYPE_DIRECTORY) { callback(new Errors.ENOTDIR(null, path)); } else { directoryNode = result; @@ -6844,7 +6944,11 @@ function make_symbolic_link(context, srcpath, dstpath, callback) { } function write_file_node() { - Node.create({guid: context.guid, mode: MODE_SYMBOLIC_LINK}, function(error, result) { + Node.create({ + guid: context.guid, + type: NODE_TYPE_SYMBOLIC_LINK, + path: dstpath + }, function(error, result) { if(error) { callback(error); return; @@ -6870,7 +6974,7 @@ function make_symbolic_link(context, srcpath, dstpath, callback) { if(error) { callback(error); } else { - directoryData[name] = new DirectoryEntry(fileNode.id, MODE_SYMBOLIC_LINK); + directoryData[name] = new DirectoryEntry(fileNode.id, NODE_TYPE_SYMBOLIC_LINK); context.putObject(directoryNode.data, directoryData, update_time); } } @@ -6912,7 +7016,7 @@ function read_link(context, path, callback) { if(error) { callback(error); } else { - if(result.mode != MODE_SYMBOLIC_LINK) { + if(result.type != NODE_TYPE_SYMBOLIC_LINK) { callback(new Errors.EINVAL('path not a symbolic link', path)); } else { callback(null, result.data); @@ -6929,7 +7033,7 @@ function truncate_file(context, path, length, callback) { function read_file_data (error, node) { if (error) { callback(error); - } else if(node.mode == MODE_DIRECTORY ) { + } else if(node.type == NODE_TYPE_DIRECTORY ) { callback(new Errors.EISDIR(null, path)); } else{ fileNode = node; @@ -6985,7 +7089,7 @@ function ftruncate_file(context, ofd, length, callback) { function read_file_data (error, node) { if (error) { callback(error); - } else if(node.mode == MODE_DIRECTORY ) { + } else if(node.type == NODE_TYPE_DIRECTORY ) { callback(new Errors.EISDIR()); } else{ fileNode = node; @@ -7336,9 +7440,9 @@ function close(fs, context, fd, callback) { } } -function mknod(fs, context, path, mode, callback) { +function mknod(fs, context, path, type, callback) { if(!pathCheck(path, callback)) return; - make_node(context, path, mode, callback); + make_node(context, path, type, callback); } function mkdir(fs, context, path, mode, callback) { @@ -7360,7 +7464,7 @@ function stat(fs, context, path, callback) { if(error) { callback(error); } else { - var stats = new Stats(result, fs.name); + var stats = new Stats(path, result, fs.name); callback(null, stats); } } @@ -7373,7 +7477,7 @@ function fstat(fs, context, fd, callback) { if(error) { callback(error); } else { - var stats = new Stats(result, fs.name); + var stats = new Stats(fd.path, result, fs.name); callback(null, stats); } } @@ -7446,7 +7550,7 @@ function readFile(fs, context, path, options, callback) { return callback(err); } - var stats = new Stats(fstatResult, fs.name); + var stats = new Stats(ofd.path, fstatResult, fs.name); if(stats.isDirectory()) { cleanup(); @@ -7718,12 +7822,15 @@ function rename(fs, context, oldpath, newpath, callback) { var newName = Path.basename(newpath); var oldParentDirectory, oldParentData; var newParentDirectory, newParentData; + var ctime = Date.now(); + var fileNode; - function update_times(error, newNode) { + function update_times(error, result) { if(error) { callback(error); } else { - update_node_times(context, newpath, newNode, { ctime: Date.now() }, callback); + fileNode = result; + update_node_times(context, newpath, fileNode, { ctime: ctime }, callback); } } @@ -7807,7 +7914,7 @@ function rename(fs, context, oldpath, newpath, callback) { function check_node_type(error, node) { if(error) { callback(error); - } else if(node.mode === 'DIRECTORY') { + } else if(node.type === NODE_TYPE_DIRECTORY) { find_node(context, oldParentPath, read_parent_directory_data); } else { link_node(context, oldpath, newpath, unlink_old_file); @@ -7837,7 +7944,7 @@ function lstat(fs, context, path, callback) { if(error) { callback(error); } else { - var stats = new Stats(result, fs.name); + var stats = new Stats(path, result, fs.name); callback(null, stats); } } @@ -8327,13 +8434,42 @@ module.exports = { }; },{"./buffer.js":20,"./errors.js":24,"./filesystem/interface.js":26,"./path.js":31,"./shell/shell.js":38}],29:[function(require,module,exports){ -var MODE_FILE = require('./constants.js').MODE_FILE; +var path = require('./path.js'); +var hash32 = require('./encoding.js').hash32; + +var NODE_TYPE_FILE = require('./constants.js').NODE_TYPE_FILE; +var NODE_TYPE_DIRECTORY = require('./constants.js').NODE_TYPE_DIRECTORY; +var NODE_TYPE_SYMBOLIC_LINK = require('./constants.js').NODE_TYPE_SYMBOLIC_LINK; +var NODE_TYPE_META = require('./constants.js').NODE_TYPE_META; + +var ROOT_DIRECTORY_NAME = require('./constants.js').ROOT_DIRECTORY_NAME; + +var S_IFREG = require('./constants.js').S_IFREG; +var S_IFDIR = require('./constants.js').S_IFDIR; +var S_IFLNK = require('./constants.js').S_IFLNK; + +var DEFAULT_FILE_PERMISSIONS = require('./constants.js').DEFAULT_FILE_PERMISSIONS; +var DEFAULT_DIR_PERMISSIONS = require('./constants.js').DEFAULT_DIR_PERMISSIONS; + +function getMode(type) { + switch(type) { + case NODE_TYPE_DIRECTORY: + return DEFAULT_DIR_PERMISSIONS | S_IFDIR; + case NODE_TYPE_SYMBOLIC_LINK: + return DEFAULT_FILE_PERMISSIONS | S_IFLNK; + /* jshint -W086 */ + case NODE_TYPE_FILE: + // falls through + default: + return DEFAULT_FILE_PERMISSIONS | S_IFREG; + } +} function Node(options) { var now = Date.now(); this.id = options.id; - this.mode = options.mode || MODE_FILE; // node type (file, directory, etc) + this.type = options.type || NODE_TYPE_FILE; // node type (file, directory, etc) this.size = options.size || 0; // size (bytes for files, entries for directories) this.atime = options.atime || now; // access time (will mirror ctime after creation) this.ctime = options.ctime || now; // creation/change time @@ -8341,10 +8477,13 @@ function Node(options) { this.flags = options.flags || []; // file flags this.xattrs = options.xattrs || {}; // extended attributes this.nlinks = options.nlinks || 0; // links count - this.version = options.version || 0; // node version - this.blksize = undefined; // block size - this.nblocks = 1; // blocks count this.data = options.data; // id for data object + this.version = options.version || 1; + + // permissions and flags + this.mode = options.mode || (getMode(this.type)); + this.uid = options.uid || 0x0; // owner name + this.gid = options.gid || 0x0; // group name } // Make sure the options object has an id on property, @@ -8381,7 +8520,7 @@ Node.create = function(options, callback) { module.exports = Node; -},{"./constants.js":21}],30:[function(require,module,exports){ +},{"./constants.js":21,"./encoding.js":23,"./path.js":31}],30:[function(require,module,exports){ var Errors = require('./errors.js'); function OpenFileDescription(path, id, flags, position) { @@ -8707,43 +8846,57 @@ var indexedDB = global.indexedDB || global.msIndexedDB; function IndexedDBContext(db, mode) { - var transaction = db.transaction(FILE_STORE_NAME, mode); - this.objectStore = transaction.objectStore(FILE_STORE_NAME); + this.db = db; + this.mode = mode; } +IndexedDBContext.prototype._getObjectStore = function() { + if(this.objectStore) { + return this.objectStore; + } + + var transaction = this.db.transaction(FILE_STORE_NAME, this.mode); + this.objectStore = transaction.objectStore(FILE_STORE_NAME); + return this.objectStore; +}; + IndexedDBContext.prototype.clear = function(callback) { try { - var request = this.objectStore.clear(); - request.onsuccess = function(event) { + var objectStore = this._getObjectStore(); + var request = objectStore.clear(); + request.onsuccess = function() { callback(); }; - request.onerror = function(error) { - callback(error); + request.onerror = function(event) { + event.preventDefault(); + callback(event.error); }; - } catch(e) { - callback(e); + } catch(err) { + callback(err); } }; -function _get(objectStore, key, callback) { +IndexedDBContext.prototype._get = function(key, callback) { try { + var objectStore = this._getObjectStore(); var request = objectStore.get(key); request.onsuccess = function onsuccess(event) { var result = event.target.result; callback(null, result); }; - request.onerror = function onerror(error) { - callback(error); + request.onerror = function(event) { + event.preventDefault(); + callback(event.error); }; - } catch(e) { - callback(e); + } catch(err) { + callback(err); } -} +}; IndexedDBContext.prototype.getObject = function(key, callback) { - _get(this.objectStore, key, callback); + this._get(key, callback); }; IndexedDBContext.prototype.getBuffer = function(key, callback) { - _get(this.objectStore, key, function(err, arrayBuffer) { + this._get(key, function(err, arrayBuffer) { if(err) { return callback(err); } @@ -8751,22 +8904,24 @@ IndexedDBContext.prototype.getBuffer = function(key, callback) { }); }; -function _put(objectStore, key, value, callback) { +IndexedDBContext.prototype._put = function(key, value, callback) { try { + var objectStore = this._getObjectStore(); var request = objectStore.put(value, key); request.onsuccess = function onsuccess(event) { var result = event.target.result; callback(null, result); }; - request.onerror = function onerror(error) { - callback(error); + request.onerror = function(event) { + event.preventDefault(); + callback(event.error); }; - } catch(e) { - callback(e); + } catch(err) { + callback(err); } -} +}; IndexedDBContext.prototype.putObject = function(key, value, callback) { - _put(this.objectStore, key, value, callback); + this._put(key, value, callback); }; IndexedDBContext.prototype.putBuffer = function(key, uint8BackedBuffer, callback) { var buf; @@ -8775,21 +8930,23 @@ IndexedDBContext.prototype.putBuffer = function(key, uint8BackedBuffer, callback } else { buf = uint8BackedBuffer.buffer; } - _put(this.objectStore, key, buf, callback); + this._put(key, buf, callback); }; IndexedDBContext.prototype.delete = function(key, callback) { try { - var request = this.objectStore.delete(key); + var objectStore = this._getObjectStore(); + var request = objectStore.delete(key); request.onsuccess = function onsuccess(event) { var result = event.target.result; callback(null, result); }; - request.onerror = function(error) { - callback(error); + request.onerror = function(event) { + event.preventDefault(); + callback(event.error); }; - } catch(e) { - callback(e); + } catch(err) { + callback(err); } }; @@ -8810,32 +8967,35 @@ IndexedDB.prototype.open = function(callback) { return callback(); } - // NOTE: we're not using versioned databases. - var openRequest = indexedDB.open(that.name); + try { + // NOTE: we're not using versioned databases. + var openRequest = indexedDB.open(that.name); - // If the db doesn't exist, we'll create it - openRequest.onupgradeneeded = function onupgradeneeded(event) { - var db = event.target.result; + // If the db doesn't exist, we'll create it + openRequest.onupgradeneeded = function onupgradeneeded(event) { + var db = event.target.result; - if(db.objectStoreNames.contains(FILE_STORE_NAME)) { - db.deleteObjectStore(FILE_STORE_NAME); - } - db.createObjectStore(FILE_STORE_NAME); - }; + if(db.objectStoreNames.contains(FILE_STORE_NAME)) { + db.deleteObjectStore(FILE_STORE_NAME); + } + db.createObjectStore(FILE_STORE_NAME); + }; - openRequest.onsuccess = function onsuccess(event) { - that.db = event.target.result; - callback(); - }; - openRequest.onerror = function onerror(error) { - callback(new Errors.EINVAL('IndexedDB cannot be accessed. If private browsing is enabled, disable it.')); - }; + openRequest.onsuccess = function onsuccess(event) { + that.db = event.target.result; + callback(); + }; + openRequest.onerror = function onerror(event) { + event.preventDefault(); + callback(event.error); + }; + } catch(err) { + callback(err); + } }; + IndexedDB.prototype.getReadOnlyContext = function() { - // Due to timing issues in Chrome with readwrite vs. readonly indexeddb transactions - // always use readwrite so we can make sure pending commits finish before callbacks. - // See https://github.com/js-platform/filer/issues/128 - return new IndexedDBContext(this.db, IDB_RW); + return new IndexedDBContext(this.db, IDB_RO); }; IndexedDB.prototype.getReadWriteContext = function() { return new IndexedDBContext(this.db, IDB_RW); @@ -8844,7 +9004,7 @@ IndexedDB.prototype.getReadWriteContext = function() { module.exports = IndexedDB; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer) -},{"../buffer.js":20,"../constants.js":21,"../errors.js":24,"buffer":6}],34:[function(require,module,exports){ +},{"../buffer.js":20,"../constants.js":21,"../errors.js":24,"buffer":7}],34:[function(require,module,exports){ var FILE_SYSTEM_NAME = require('../constants.js').FILE_SYSTEM_NAME; // NOTE: prefer setImmediate to nextTick for proper recursion yielding. // see https://github.com/js-platform/filer/pull/24 @@ -9392,16 +9552,10 @@ Shell.prototype.ls = function(dir, options, callback) { callback(error); return; } - var entry = { - path: Path.basename(name), - links: stats.nlinks, - size: stats.size, - modified: stats.mtime, - type: stats.type - }; + var entry = stats; if(options.recursive && stats.type === 'DIRECTORY') { - list(Path.join(pathname, entry.path), function(error, items) { + list(Path.join(pathname, entry.name), function(error, items) { if(error) { callback(error); return; @@ -9704,30 +9858,37 @@ Shell.prototype.mkdirp = function(path, callback) { module.exports = Shell; -},{"../../lib/async.js":1,"../encoding.js":23,"../errors.js":24,"../path.js":31,"./environment.js":37,"minimatch":16}],39:[function(require,module,exports){ +},{"../../lib/async.js":1,"../encoding.js":23,"../errors.js":24,"../path.js":31,"./environment.js":37,"minimatch":11}],39:[function(require,module,exports){ var Constants = require('./constants.js'); +var Path = require('./path.js'); -function Stats(fileNode, devName) { - this.node = fileNode.id; +function Stats(path, fileNode, devName) { this.dev = devName; + this.node = fileNode.id; + this.type = fileNode.type; + this.name = fileNode.name; this.size = fileNode.size; this.nlinks = fileNode.nlinks; this.atime = fileNode.atime; this.mtime = fileNode.mtime; this.ctime = fileNode.ctime; - this.type = fileNode.mode; + this.version = fileNode.version; + this.mode = fileNode.mode; + this.uid = fileNode.uid; + this.gid = fileNode.gid; + this.name = Path.basename(path); } Stats.prototype.isFile = function() { - return this.type === Constants.MODE_FILE; + return this.type === Constants.NODE_TYPE_FILE; }; Stats.prototype.isDirectory = function() { - return this.type === Constants.MODE_DIRECTORY; + return this.type === Constants.NODE_TYPE_DIRECTORY; }; Stats.prototype.isSymbolicLink = function() { - return this.type === Constants.MODE_SYMBOLIC_LINK; + return this.type === Constants.NODE_TYPE_SYMBOLIC_LINK; }; // These will always be false in Filer. @@ -9741,14 +9902,14 @@ function() { module.exports = Stats; -},{"./constants.js":21}],40:[function(require,module,exports){ +},{"./constants.js":21,"./path.js":31}],40:[function(require,module,exports){ var Constants = require('./constants.js'); function SuperNode(options) { var now = Date.now(); this.id = Constants.SUPER_NODE_ID; - this.mode = Constants.MODE_META; + this.type = Constants.NODE_TYPE_META; this.atime = options.atime || now; this.ctime = options.ctime || now; this.mtime = options.mtime || now; @@ -9796,20 +9957,26 @@ function IndexedDBTestProvider(name) { return callback(); } - // We have to force any other connections to close - // before we can delete a db. - if(that.provider.db) { - that.provider.db.close(); - } - - var request = indexedDB.deleteDatabase(name); function finished() { that.provider = null; _done = true; callback(); } - request.onsuccess = finished; - request.onerror = finished; + + try { + // We have to force any other connections to close + // before we can delete a db. + if(that.provider.db) { + that.provider.db.close(); + } + + var request = indexedDB.deleteDatabase(name); + request.onsuccess = finished; + request.onerror = finished; + } catch(e) { + console.log("Failed to delete test database", e); + finished(); + } } function init() { @@ -9900,6 +10067,7 @@ function getUrlParams() { } function getProviderType() { + var defaultProvider = 'default'; var queryString = getUrlParams(); // If the environment is node or the query string is empty, @@ -9908,7 +10076,7 @@ function getProviderType() { return defaultProvider; } - return queryString['filer-provider'] || 'default'; + return queryString['filer-provider'] || defaultProvider; } function setup(callback) { @@ -9931,7 +10099,6 @@ function setup(callback) { break; case 'default': default: - console.log('default'); var BestProvider = findBestProvider(); _provider = new BestProvider(name); break; @@ -10019,7 +10186,7 @@ module.exports = { }; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"../..":28,"./indexeddb.js":41,"./memory.js":42,"./websql.js":44,"url":15}],44:[function(require,module,exports){ +},{"../..":28,"./indexeddb.js":41,"./memory.js":42,"./websql.js":44,"url":18}],44:[function(require,module,exports){ (function (global){ var Filer = require('../..'); @@ -10073,4 +10240,4 @@ module.exports = WebSQLTestProvider; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"../..":28}]},{},[19])(19) -}); \ No newline at end of file +}); diff --git a/dist/filer-test.js b/dist/filer-test.js index cc7d37e..fbf152d 100644 --- a/dist/filer-test.js +++ b/dist/filer-test.js @@ -580,6 +580,118 @@ function nodash(value) { module.exports = nodash; },{}],5:[function(require,module,exports){ +/*! + * assertion-error + * Copyright(c) 2013 Jake Luer + * MIT Licensed + */ + +/*! + * Return a function that will copy properties from + * one object to another excluding any originally + * listed. Returned function will create a new `{}`. + * + * @param {String} excluded properties ... + * @return {Function} + */ + +function exclude () { + var excludes = [].slice.call(arguments); + + function excludeProps (res, obj) { + Object.keys(obj).forEach(function (key) { + if (!~excludes.indexOf(key)) res[key] = obj[key]; + }); + } + + return function extendExclude () { + var args = [].slice.call(arguments) + , i = 0 + , res = {}; + + for (; i < args.length; i++) { + excludeProps(res, args[i]); + } + + return res; + }; +}; + +/*! + * Primary Exports + */ + +module.exports = AssertionError; + +/** + * ### AssertionError + * + * An extension of the JavaScript `Error` constructor for + * assertion and validation scenarios. + * + * @param {String} message + * @param {Object} properties to include (optional) + * @param {callee} start stack function (optional) + */ + +function AssertionError (message, _props, ssf) { + var extend = exclude('name', 'message', 'stack', 'constructor', 'toJSON') + , props = extend(_props || {}); + + // default values + this.message = message || 'Unspecified AssertionError'; + this.showDiff = false; + + // copy from properties + for (var key in props) { + this[key] = props[key]; + } + + // capture stack trace + ssf = ssf || arguments.callee; + if (ssf && Error.captureStackTrace) { + Error.captureStackTrace(this, ssf); + } +} + +/*! + * Inherit from Error.prototype + */ + +AssertionError.prototype = Object.create(Error.prototype); + +/*! + * Statically set name + */ + +AssertionError.prototype.name = 'AssertionError'; + +/*! + * Ensure correct constructor + */ + +AssertionError.prototype.constructor = AssertionError; + +/** + * Allow errors to be converted to JSON for static transfer. + * + * @param {Boolean} include stack (default: `true`) + * @return {Object} object that can be `JSON.stringify` + */ + +AssertionError.prototype.toJSON = function (stack) { + var extend = exclude('constructor', 'toJSON', 'stack') + , props = extend({ name: this.name }, this); + + // include stack if exists and not turned off + if (false !== stack && this.stack) { + props.stack = this.stack; + } + + return props; +}; + +},{}],6:[function(require,module,exports){ /* * base64-arraybuffer * https://github.com/niklasvh/base64-arraybuffer @@ -587,9 +699,17 @@ module.exports = nodash; * Copyright (c) 2012 Niklas von Hertzen * Licensed under the MIT license. */ -(function(chars){ +(function(){ "use strict"; + var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + + // Use a lookup table to find the index. + var lookup = new Uint8Array(256); + for (var i = 0; i < chars.length; i++) { + lookup[chars.charCodeAt(i)] = i; + } + exports.encode = function(arraybuffer) { var bytes = new Uint8Array(arraybuffer), i, len = bytes.length, base64 = ""; @@ -626,10 +746,10 @@ module.exports = nodash; bytes = new Uint8Array(arraybuffer); for (i = 0; i < len; i+=4) { - encoded1 = chars.indexOf(base64[i]); - encoded2 = chars.indexOf(base64[i+1]); - encoded3 = chars.indexOf(base64[i+2]); - encoded4 = chars.indexOf(base64[i+3]); + encoded1 = lookup[base64.charCodeAt(i)]; + encoded2 = lookup[base64.charCodeAt(i+1)]; + encoded3 = lookup[base64.charCodeAt(i+2)]; + encoded4 = lookup[base64.charCodeAt(i+3)]; bytes[p++] = (encoded1 << 2) | (encoded2 >> 4); bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2); @@ -638,12 +758,1697 @@ module.exports = nodash; return arraybuffer; }; -})("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); +})(); -},{}],6:[function(require,module,exports){ +},{}],7:[function(require,module,exports){ +var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; + +;(function (exports) { + 'use strict'; + + var Arr = (typeof Uint8Array !== 'undefined') + ? Uint8Array + : Array + + var PLUS = '+'.charCodeAt(0) + var SLASH = '/'.charCodeAt(0) + var NUMBER = '0'.charCodeAt(0) + var LOWER = 'a'.charCodeAt(0) + var UPPER = 'A'.charCodeAt(0) + var PLUS_URL_SAFE = '-'.charCodeAt(0) + var SLASH_URL_SAFE = '_'.charCodeAt(0) + + function decode (elt) { + var code = elt.charCodeAt(0) + if (code === PLUS || + code === PLUS_URL_SAFE) + return 62 // '+' + if (code === SLASH || + code === SLASH_URL_SAFE) + return 63 // '/' + if (code < NUMBER) + return -1 //no match + if (code < NUMBER + 10) + return code - NUMBER + 26 + 26 + if (code < UPPER + 26) + return code - UPPER + if (code < LOWER + 26) + return code - LOWER + 26 + } + + function b64ToByteArray (b64) { + var i, j, l, tmp, placeHolders, arr + + if (b64.length % 4 > 0) { + throw new Error('Invalid string. Length must be a multiple of 4') + } + + // the number of equal signs (place holders) + // if there are two placeholders, than the two characters before it + // represent one byte + // if there is only one, then the three characters before it represent 2 bytes + // this is just a cheap hack to not do indexOf twice + var len = b64.length + placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0 + + // base64 is 4/3 + up to two characters of the original data + arr = new Arr(b64.length * 3 / 4 - placeHolders) + + // if there are placeholders, only get up to the last complete 4 chars + l = placeHolders > 0 ? b64.length - 4 : b64.length + + var L = 0 + + function push (v) { + arr[L++] = v + } + + for (i = 0, j = 0; i < l; i += 4, j += 3) { + tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3)) + push((tmp & 0xFF0000) >> 16) + push((tmp & 0xFF00) >> 8) + push(tmp & 0xFF) + } + + if (placeHolders === 2) { + tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4) + push(tmp & 0xFF) + } else if (placeHolders === 1) { + tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2) + push((tmp >> 8) & 0xFF) + push(tmp & 0xFF) + } + + return arr + } + + function uint8ToBase64 (uint8) { + var i, + extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes + output = "", + temp, length + + function encode (num) { + return lookup.charAt(num) + } + + function tripletToBase64 (num) { + return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F) + } + + // go through the array every three bytes, we'll deal with trailing stuff later + for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { + temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) + output += tripletToBase64(temp) + } + + // pad the end with zeros, but make sure to not forget the extra bytes + switch (extraBytes) { + case 1: + temp = uint8[uint8.length - 1] + output += encode(temp >> 2) + output += encode((temp << 4) & 0x3F) + output += '==' + break + case 2: + temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]) + output += encode(temp >> 10) + output += encode((temp >> 4) & 0x3F) + output += encode((temp << 2) & 0x3F) + output += '=' + break + } + + return output + } + + exports.toByteArray = b64ToByteArray + exports.fromByteArray = uint8ToBase64 +}(typeof exports === 'undefined' ? (this.base64js = {}) : exports)) + +},{}],8:[function(require,module,exports){ +(function (global){ +/*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijeh + * @license MIT + */ +/* eslint-disable no-proto */ + +'use strict' + +var base64 = require('base64-js') +var ieee754 = require('ieee754') +var isArray = require('isarray') + +exports.Buffer = Buffer +exports.SlowBuffer = SlowBuffer +exports.INSPECT_MAX_BYTES = 50 +Buffer.poolSize = 8192 // not used by this implementation + +var rootParent = {} + +/** + * If `Buffer.TYPED_ARRAY_SUPPORT`: + * === true Use Uint8Array implementation (fastest) + * === false Use Object implementation (most compatible, even IE6) + * + * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, + * Opera 11.6+, iOS 4.2+. + * + * Due to various browser bugs, sometimes the Object implementation will be used even + * when the browser supports typed arrays. + * + * Note: + * + * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, + * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. + * + * - Safari 5-7 lacks support for changing the `Object.prototype.constructor` property + * on objects. + * + * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. + * + * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of + * incorrect length in some situations. + + * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they + * get the Object implementation, which is slower but behaves correctly. + */ +Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined + ? global.TYPED_ARRAY_SUPPORT + : typedArraySupport() + +function typedArraySupport () { + function Bar () {} + try { + var arr = new Uint8Array(1) + arr.foo = function () { return 42 } + arr.constructor = Bar + return arr.foo() === 42 && // typed array instances can be augmented + arr.constructor === Bar && // constructor can be set + typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` + arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` + } catch (e) { + return false + } +} + +function kMaxLength () { + return Buffer.TYPED_ARRAY_SUPPORT + ? 0x7fffffff + : 0x3fffffff +} + +/** + * Class: Buffer + * ============= + * + * The Buffer constructor returns instances of `Uint8Array` that are augmented + * with function properties for all the node `Buffer` API functions. We use + * `Uint8Array` so that square bracket notation works as expected -- it returns + * a single octet. + * + * By augmenting the instances, we can avoid modifying the `Uint8Array` + * prototype. + */ +function Buffer (arg) { + if (!(this instanceof Buffer)) { + // Avoid going through an ArgumentsAdaptorTrampoline in the common case. + if (arguments.length > 1) return new Buffer(arg, arguments[1]) + return new Buffer(arg) + } + + if (!Buffer.TYPED_ARRAY_SUPPORT) { + this.length = 0 + this.parent = undefined + } + + // Common case. + if (typeof arg === 'number') { + return fromNumber(this, arg) + } + + // Slightly less common case. + if (typeof arg === 'string') { + return fromString(this, arg, arguments.length > 1 ? arguments[1] : 'utf8') + } + + // Unusual. + return fromObject(this, arg) +} + +function fromNumber (that, length) { + that = allocate(that, length < 0 ? 0 : checked(length) | 0) + if (!Buffer.TYPED_ARRAY_SUPPORT) { + for (var i = 0; i < length; i++) { + that[i] = 0 + } + } + return that +} + +function fromString (that, string, encoding) { + if (typeof encoding !== 'string' || encoding === '') encoding = 'utf8' + + // Assumption: byteLength() return value is always < kMaxLength. + var length = byteLength(string, encoding) | 0 + that = allocate(that, length) + + that.write(string, encoding) + return that +} + +function fromObject (that, object) { + if (Buffer.isBuffer(object)) return fromBuffer(that, object) + + if (isArray(object)) return fromArray(that, object) + + if (object == null) { + throw new TypeError('must start with number, buffer, array or string') + } + + if (typeof ArrayBuffer !== 'undefined') { + if (object.buffer instanceof ArrayBuffer) { + return fromTypedArray(that, object) + } + if (object instanceof ArrayBuffer) { + return fromArrayBuffer(that, object) + } + } + + if (object.length) return fromArrayLike(that, object) + + return fromJsonObject(that, object) +} + +function fromBuffer (that, buffer) { + var length = checked(buffer.length) | 0 + that = allocate(that, length) + buffer.copy(that, 0, 0, length) + return that +} + +function fromArray (that, array) { + var length = checked(array.length) | 0 + that = allocate(that, length) + for (var i = 0; i < length; i += 1) { + that[i] = array[i] & 255 + } + return that +} + +// Duplicate of fromArray() to keep fromArray() monomorphic. +function fromTypedArray (that, array) { + var length = checked(array.length) | 0 + that = allocate(that, length) + // Truncating the elements is probably not what people expect from typed + // arrays with BYTES_PER_ELEMENT > 1 but it's compatible with the behavior + // of the old Buffer constructor. + for (var i = 0; i < length; i += 1) { + that[i] = array[i] & 255 + } + return that +} + +function fromArrayBuffer (that, array) { + if (Buffer.TYPED_ARRAY_SUPPORT) { + // Return an augmented `Uint8Array` instance, for best performance + array.byteLength + that = Buffer._augment(new Uint8Array(array)) + } else { + // Fallback: Return an object instance of the Buffer class + that = fromTypedArray(that, new Uint8Array(array)) + } + return that +} + +function fromArrayLike (that, array) { + var length = checked(array.length) | 0 + that = allocate(that, length) + for (var i = 0; i < length; i += 1) { + that[i] = array[i] & 255 + } + return that +} + +// Deserialize { type: 'Buffer', data: [1,2,3,...] } into a Buffer object. +// Returns a zero-length buffer for inputs that don't conform to the spec. +function fromJsonObject (that, object) { + var array + var length = 0 + + if (object.type === 'Buffer' && isArray(object.data)) { + array = object.data + length = checked(array.length) | 0 + } + that = allocate(that, length) + + for (var i = 0; i < length; i += 1) { + that[i] = array[i] & 255 + } + return that +} + +if (Buffer.TYPED_ARRAY_SUPPORT) { + Buffer.prototype.__proto__ = Uint8Array.prototype + Buffer.__proto__ = Uint8Array +} else { + // pre-set for values that may exist in the future + Buffer.prototype.length = undefined + Buffer.prototype.parent = undefined +} + +function allocate (that, length) { + if (Buffer.TYPED_ARRAY_SUPPORT) { + // Return an augmented `Uint8Array` instance, for best performance + that = Buffer._augment(new Uint8Array(length)) + that.__proto__ = Buffer.prototype + } else { + // Fallback: Return an object instance of the Buffer class + that.length = length + that._isBuffer = true + } + + var fromPool = length !== 0 && length <= Buffer.poolSize >>> 1 + if (fromPool) that.parent = rootParent + + return that +} + +function checked (length) { + // Note: cannot use `length < kMaxLength` here because that fails when + // length is NaN (which is otherwise coerced to zero.) + if (length >= kMaxLength()) { + throw new RangeError('Attempt to allocate Buffer larger than maximum ' + + 'size: 0x' + kMaxLength().toString(16) + ' bytes') + } + return length | 0 +} + +function SlowBuffer (subject, encoding) { + if (!(this instanceof SlowBuffer)) return new SlowBuffer(subject, encoding) + + var buf = new Buffer(subject, encoding) + delete buf.parent + return buf +} + +Buffer.isBuffer = function isBuffer (b) { + return !!(b != null && b._isBuffer) +} + +Buffer.compare = function compare (a, b) { + if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { + throw new TypeError('Arguments must be Buffers') + } + + if (a === b) return 0 + + var x = a.length + var y = b.length + + var i = 0 + var len = Math.min(x, y) + while (i < len) { + if (a[i] !== b[i]) break + + ++i + } + + if (i !== len) { + x = a[i] + y = b[i] + } + + if (x < y) return -1 + if (y < x) return 1 + return 0 +} + +Buffer.isEncoding = function isEncoding (encoding) { + switch (String(encoding).toLowerCase()) { + case 'hex': + case 'utf8': + case 'utf-8': + case 'ascii': + case 'binary': + case 'base64': + case 'raw': + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return true + default: + return false + } +} + +Buffer.concat = function concat (list, length) { + if (!isArray(list)) throw new TypeError('list argument must be an Array of Buffers.') + + if (list.length === 0) { + return new Buffer(0) + } + + var i + if (length === undefined) { + length = 0 + for (i = 0; i < list.length; i++) { + length += list[i].length + } + } + + var buf = new Buffer(length) + var pos = 0 + for (i = 0; i < list.length; i++) { + var item = list[i] + item.copy(buf, pos) + pos += item.length + } + return buf +} + +function byteLength (string, encoding) { + if (typeof string !== 'string') string = '' + string + + var len = string.length + if (len === 0) return 0 + + // Use a for loop to avoid recursion + var loweredCase = false + for (;;) { + switch (encoding) { + case 'ascii': + case 'binary': + // Deprecated + case 'raw': + case 'raws': + return len + case 'utf8': + case 'utf-8': + return utf8ToBytes(string).length + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return len * 2 + case 'hex': + return len >>> 1 + case 'base64': + return base64ToBytes(string).length + default: + if (loweredCase) return utf8ToBytes(string).length // assume utf8 + encoding = ('' + encoding).toLowerCase() + loweredCase = true + } + } +} +Buffer.byteLength = byteLength + +function slowToString (encoding, start, end) { + var loweredCase = false + + start = start | 0 + end = end === undefined || end === Infinity ? this.length : end | 0 + + if (!encoding) encoding = 'utf8' + if (start < 0) start = 0 + if (end > this.length) end = this.length + if (end <= start) return '' + + while (true) { + switch (encoding) { + case 'hex': + return hexSlice(this, start, end) + + case 'utf8': + case 'utf-8': + return utf8Slice(this, start, end) + + case 'ascii': + return asciiSlice(this, start, end) + + case 'binary': + return binarySlice(this, start, end) + + case 'base64': + return base64Slice(this, start, end) + + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return utf16leSlice(this, start, end) + + default: + if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) + encoding = (encoding + '').toLowerCase() + loweredCase = true + } + } +} + +Buffer.prototype.toString = function toString () { + var length = this.length | 0 + if (length === 0) return '' + if (arguments.length === 0) return utf8Slice(this, 0, length) + return slowToString.apply(this, arguments) +} + +Buffer.prototype.equals = function equals (b) { + if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') + if (this === b) return true + return Buffer.compare(this, b) === 0 +} + +Buffer.prototype.inspect = function inspect () { + var str = '' + var max = exports.INSPECT_MAX_BYTES + if (this.length > 0) { + str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') + if (this.length > max) str += ' ... ' + } + return '' +} + +Buffer.prototype.compare = function compare (b) { + if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') + if (this === b) return 0 + return Buffer.compare(this, b) +} + +Buffer.prototype.indexOf = function indexOf (val, byteOffset) { + if (byteOffset > 0x7fffffff) byteOffset = 0x7fffffff + else if (byteOffset < -0x80000000) byteOffset = -0x80000000 + byteOffset >>= 0 + + if (this.length === 0) return -1 + if (byteOffset >= this.length) return -1 + + // Negative offsets start from the end of the buffer + if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0) + + if (typeof val === 'string') { + if (val.length === 0) return -1 // special case: looking for empty string always fails + return String.prototype.indexOf.call(this, val, byteOffset) + } + if (Buffer.isBuffer(val)) { + return arrayIndexOf(this, val, byteOffset) + } + if (typeof val === 'number') { + if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') { + return Uint8Array.prototype.indexOf.call(this, val, byteOffset) + } + return arrayIndexOf(this, [ val ], byteOffset) + } + + function arrayIndexOf (arr, val, byteOffset) { + var foundIndex = -1 + for (var i = 0; byteOffset + i < arr.length; i++) { + if (arr[byteOffset + i] === val[foundIndex === -1 ? 0 : i - foundIndex]) { + if (foundIndex === -1) foundIndex = i + if (i - foundIndex + 1 === val.length) return byteOffset + foundIndex + } else { + foundIndex = -1 + } + } + return -1 + } + + throw new TypeError('val must be string, number or Buffer') +} + +// `get` is deprecated +Buffer.prototype.get = function get (offset) { + console.log('.get() is deprecated. Access using array indexes instead.') + return this.readUInt8(offset) +} + +// `set` is deprecated +Buffer.prototype.set = function set (v, offset) { + console.log('.set() is deprecated. Access using array indexes instead.') + return this.writeUInt8(v, offset) +} + +function hexWrite (buf, string, offset, length) { + offset = Number(offset) || 0 + var remaining = buf.length - offset + if (!length) { + length = remaining + } else { + length = Number(length) + if (length > remaining) { + length = remaining + } + } + + // must be an even number of digits + var strLen = string.length + if (strLen % 2 !== 0) throw new Error('Invalid hex string') + + if (length > strLen / 2) { + length = strLen / 2 + } + for (var i = 0; i < length; i++) { + var parsed = parseInt(string.substr(i * 2, 2), 16) + if (isNaN(parsed)) throw new Error('Invalid hex string') + buf[offset + i] = parsed + } + return i +} + +function utf8Write (buf, string, offset, length) { + return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) +} + +function asciiWrite (buf, string, offset, length) { + return blitBuffer(asciiToBytes(string), buf, offset, length) +} + +function binaryWrite (buf, string, offset, length) { + return asciiWrite(buf, string, offset, length) +} + +function base64Write (buf, string, offset, length) { + return blitBuffer(base64ToBytes(string), buf, offset, length) +} + +function ucs2Write (buf, string, offset, length) { + return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) +} + +Buffer.prototype.write = function write (string, offset, length, encoding) { + // Buffer#write(string) + if (offset === undefined) { + encoding = 'utf8' + length = this.length + offset = 0 + // Buffer#write(string, encoding) + } else if (length === undefined && typeof offset === 'string') { + encoding = offset + length = this.length + offset = 0 + // Buffer#write(string, offset[, length][, encoding]) + } else if (isFinite(offset)) { + offset = offset | 0 + if (isFinite(length)) { + length = length | 0 + if (encoding === undefined) encoding = 'utf8' + } else { + encoding = length + length = undefined + } + // legacy write(string, encoding, offset, length) - remove in v0.13 + } else { + var swap = encoding + encoding = offset + offset = length | 0 + length = swap + } + + var remaining = this.length - offset + if (length === undefined || length > remaining) length = remaining + + if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { + throw new RangeError('attempt to write outside buffer bounds') + } + + if (!encoding) encoding = 'utf8' + + var loweredCase = false + for (;;) { + switch (encoding) { + case 'hex': + return hexWrite(this, string, offset, length) + + case 'utf8': + case 'utf-8': + return utf8Write(this, string, offset, length) + + case 'ascii': + return asciiWrite(this, string, offset, length) + + case 'binary': + return binaryWrite(this, string, offset, length) + + case 'base64': + // Warning: maxLength not taken into account in base64Write + return base64Write(this, string, offset, length) + + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return ucs2Write(this, string, offset, length) + + default: + if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) + encoding = ('' + encoding).toLowerCase() + loweredCase = true + } + } +} + +Buffer.prototype.toJSON = function toJSON () { + return { + type: 'Buffer', + data: Array.prototype.slice.call(this._arr || this, 0) + } +} + +function base64Slice (buf, start, end) { + if (start === 0 && end === buf.length) { + return base64.fromByteArray(buf) + } else { + return base64.fromByteArray(buf.slice(start, end)) + } +} + +function utf8Slice (buf, start, end) { + end = Math.min(buf.length, end) + var res = [] + + var i = start + while (i < end) { + var firstByte = buf[i] + var codePoint = null + var bytesPerSequence = (firstByte > 0xEF) ? 4 + : (firstByte > 0xDF) ? 3 + : (firstByte > 0xBF) ? 2 + : 1 + + if (i + bytesPerSequence <= end) { + var secondByte, thirdByte, fourthByte, tempCodePoint + + switch (bytesPerSequence) { + case 1: + if (firstByte < 0x80) { + codePoint = firstByte + } + break + case 2: + secondByte = buf[i + 1] + if ((secondByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) + if (tempCodePoint > 0x7F) { + codePoint = tempCodePoint + } + } + break + case 3: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) + if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { + codePoint = tempCodePoint + } + } + break + case 4: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + fourthByte = buf[i + 3] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) + if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { + codePoint = tempCodePoint + } + } + } + } + + if (codePoint === null) { + // we did not generate a valid codePoint so insert a + // replacement char (U+FFFD) and advance only 1 byte + codePoint = 0xFFFD + bytesPerSequence = 1 + } else if (codePoint > 0xFFFF) { + // encode to utf16 (surrogate pair dance) + codePoint -= 0x10000 + res.push(codePoint >>> 10 & 0x3FF | 0xD800) + codePoint = 0xDC00 | codePoint & 0x3FF + } + + res.push(codePoint) + i += bytesPerSequence + } + + return decodeCodePointsArray(res) +} + +// Based on http://stackoverflow.com/a/22747272/680742, the browser with +// the lowest limit is Chrome, with 0x10000 args. +// We go 1 magnitude less, for safety +var MAX_ARGUMENTS_LENGTH = 0x1000 + +function decodeCodePointsArray (codePoints) { + var len = codePoints.length + if (len <= MAX_ARGUMENTS_LENGTH) { + return String.fromCharCode.apply(String, codePoints) // avoid extra slice() + } + + // Decode in chunks to avoid "call stack size exceeded". + var res = '' + var i = 0 + while (i < len) { + res += String.fromCharCode.apply( + String, + codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) + ) + } + return res +} + +function asciiSlice (buf, start, end) { + var ret = '' + end = Math.min(buf.length, end) + + for (var i = start; i < end; i++) { + ret += String.fromCharCode(buf[i] & 0x7F) + } + return ret +} + +function binarySlice (buf, start, end) { + var ret = '' + end = Math.min(buf.length, end) + + for (var i = start; i < end; i++) { + ret += String.fromCharCode(buf[i]) + } + return ret +} + +function hexSlice (buf, start, end) { + var len = buf.length + + if (!start || start < 0) start = 0 + if (!end || end < 0 || end > len) end = len + + var out = '' + for (var i = start; i < end; i++) { + out += toHex(buf[i]) + } + return out +} + +function utf16leSlice (buf, start, end) { + var bytes = buf.slice(start, end) + var res = '' + for (var i = 0; i < bytes.length; i += 2) { + res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256) + } + return res +} + +Buffer.prototype.slice = function slice (start, end) { + var len = this.length + start = ~~start + end = end === undefined ? len : ~~end + + if (start < 0) { + start += len + if (start < 0) start = 0 + } else if (start > len) { + start = len + } + + if (end < 0) { + end += len + if (end < 0) end = 0 + } else if (end > len) { + end = len + } + + if (end < start) end = start + + var newBuf + if (Buffer.TYPED_ARRAY_SUPPORT) { + newBuf = Buffer._augment(this.subarray(start, end)) + } else { + var sliceLen = end - start + newBuf = new Buffer(sliceLen, undefined) + for (var i = 0; i < sliceLen; i++) { + newBuf[i] = this[i + start] + } + } + + if (newBuf.length) newBuf.parent = this.parent || this + + return newBuf +} + +/* + * Need to make sure that buffer isn't trying to write out of bounds. + */ +function checkOffset (offset, ext, length) { + if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') + if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') +} + +Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) checkOffset(offset, byteLength, this.length) + + var val = this[offset] + var mul = 1 + var i = 0 + while (++i < byteLength && (mul *= 0x100)) { + val += this[offset + i] * mul + } + + return val +} + +Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) { + checkOffset(offset, byteLength, this.length) + } + + var val = this[offset + --byteLength] + var mul = 1 + while (byteLength > 0 && (mul *= 0x100)) { + val += this[offset + --byteLength] * mul + } + + return val +} + +Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { + if (!noAssert) checkOffset(offset, 1, this.length) + return this[offset] +} + +Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + return this[offset] | (this[offset + 1] << 8) +} + +Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + return (this[offset] << 8) | this[offset + 1] +} + +Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + + return ((this[offset]) | + (this[offset + 1] << 8) | + (this[offset + 2] << 16)) + + (this[offset + 3] * 0x1000000) +} + +Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + + return (this[offset] * 0x1000000) + + ((this[offset + 1] << 16) | + (this[offset + 2] << 8) | + this[offset + 3]) +} + +Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) checkOffset(offset, byteLength, this.length) + + var val = this[offset] + var mul = 1 + var i = 0 + while (++i < byteLength && (mul *= 0x100)) { + val += this[offset + i] * mul + } + mul *= 0x80 + + if (val >= mul) val -= Math.pow(2, 8 * byteLength) + + return val +} + +Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) checkOffset(offset, byteLength, this.length) + + var i = byteLength + var mul = 1 + var val = this[offset + --i] + while (i > 0 && (mul *= 0x100)) { + val += this[offset + --i] * mul + } + mul *= 0x80 + + if (val >= mul) val -= Math.pow(2, 8 * byteLength) + + return val +} + +Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { + if (!noAssert) checkOffset(offset, 1, this.length) + if (!(this[offset] & 0x80)) return (this[offset]) + return ((0xff - this[offset] + 1) * -1) +} + +Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + var val = this[offset] | (this[offset + 1] << 8) + return (val & 0x8000) ? val | 0xFFFF0000 : val +} + +Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + var val = this[offset + 1] | (this[offset] << 8) + return (val & 0x8000) ? val | 0xFFFF0000 : val +} + +Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + + return (this[offset]) | + (this[offset + 1] << 8) | + (this[offset + 2] << 16) | + (this[offset + 3] << 24) +} + +Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + + return (this[offset] << 24) | + (this[offset + 1] << 16) | + (this[offset + 2] << 8) | + (this[offset + 3]) +} + +Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + return ieee754.read(this, offset, true, 23, 4) +} + +Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + return ieee754.read(this, offset, false, 23, 4) +} + +Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 8, this.length) + return ieee754.read(this, offset, true, 52, 8) +} + +Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 8, this.length) + return ieee754.read(this, offset, false, 52, 8) +} + +function checkInt (buf, value, offset, ext, max, min) { + if (!Buffer.isBuffer(buf)) throw new TypeError('buffer must be a Buffer instance') + if (value > max || value < min) throw new RangeError('value is out of bounds') + if (offset + ext > buf.length) throw new RangeError('index out of range') +} + +Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0) + + var mul = 1 + var i = 0 + this[offset] = value & 0xFF + while (++i < byteLength && (mul *= 0x100)) { + this[offset + i] = (value / mul) & 0xFF + } + + return offset + byteLength +} + +Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0) + + var i = byteLength - 1 + var mul = 1 + this[offset + i] = value & 0xFF + while (--i >= 0 && (mul *= 0x100)) { + this[offset + i] = (value / mul) & 0xFF + } + + return offset + byteLength +} + +Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) + if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) + this[offset] = (value & 0xff) + return offset + 1 +} + +function objectWriteUInt16 (buf, value, offset, littleEndian) { + if (value < 0) value = 0xffff + value + 1 + for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) { + buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> + (littleEndian ? i : 1 - i) * 8 + } +} + +Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + } else { + objectWriteUInt16(this, value, offset, true) + } + return offset + 2 +} + +Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) + } else { + objectWriteUInt16(this, value, offset, false) + } + return offset + 2 +} + +function objectWriteUInt32 (buf, value, offset, littleEndian) { + if (value < 0) value = 0xffffffff + value + 1 + for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) { + buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff + } +} + +Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset + 3] = (value >>> 24) + this[offset + 2] = (value >>> 16) + this[offset + 1] = (value >>> 8) + this[offset] = (value & 0xff) + } else { + objectWriteUInt32(this, value, offset, true) + } + return offset + 4 +} + +Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) + } else { + objectWriteUInt32(this, value, offset, false) + } + return offset + 4 +} + +Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) { + var limit = Math.pow(2, 8 * byteLength - 1) + + checkInt(this, value, offset, byteLength, limit - 1, -limit) + } + + var i = 0 + var mul = 1 + var sub = value < 0 ? 1 : 0 + this[offset] = value & 0xFF + while (++i < byteLength && (mul *= 0x100)) { + this[offset + i] = ((value / mul) >> 0) - sub & 0xFF + } + + return offset + byteLength +} + +Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) { + var limit = Math.pow(2, 8 * byteLength - 1) + + checkInt(this, value, offset, byteLength, limit - 1, -limit) + } + + var i = byteLength - 1 + var mul = 1 + var sub = value < 0 ? 1 : 0 + this[offset + i] = value & 0xFF + while (--i >= 0 && (mul *= 0x100)) { + this[offset + i] = ((value / mul) >> 0) - sub & 0xFF + } + + return offset + byteLength +} + +Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) + if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) + if (value < 0) value = 0xff + value + 1 + this[offset] = (value & 0xff) + return offset + 1 +} + +Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + } else { + objectWriteUInt16(this, value, offset, true) + } + return offset + 2 +} + +Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) + } else { + objectWriteUInt16(this, value, offset, false) + } + return offset + 2 +} + +Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + this[offset + 2] = (value >>> 16) + this[offset + 3] = (value >>> 24) + } else { + objectWriteUInt32(this, value, offset, true) + } + return offset + 4 +} + +Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) + if (value < 0) value = 0xffffffff + value + 1 + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) + } else { + objectWriteUInt32(this, value, offset, false) + } + return offset + 4 +} + +function checkIEEE754 (buf, value, offset, ext, max, min) { + if (value > max || value < min) throw new RangeError('value is out of bounds') + if (offset + ext > buf.length) throw new RangeError('index out of range') + if (offset < 0) throw new RangeError('index out of range') +} + +function writeFloat (buf, value, offset, littleEndian, noAssert) { + if (!noAssert) { + checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) + } + ieee754.write(buf, value, offset, littleEndian, 23, 4) + return offset + 4 +} + +Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { + return writeFloat(this, value, offset, true, noAssert) +} + +Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { + return writeFloat(this, value, offset, false, noAssert) +} + +function writeDouble (buf, value, offset, littleEndian, noAssert) { + if (!noAssert) { + checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) + } + ieee754.write(buf, value, offset, littleEndian, 52, 8) + return offset + 8 +} + +Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { + return writeDouble(this, value, offset, true, noAssert) +} + +Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { + return writeDouble(this, value, offset, false, noAssert) +} + +// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) +Buffer.prototype.copy = function copy (target, targetStart, start, end) { + if (!start) start = 0 + if (!end && end !== 0) end = this.length + if (targetStart >= target.length) targetStart = target.length + if (!targetStart) targetStart = 0 + if (end > 0 && end < start) end = start + + // Copy 0 bytes; we're done + if (end === start) return 0 + if (target.length === 0 || this.length === 0) return 0 + + // Fatal error conditions + if (targetStart < 0) { + throw new RangeError('targetStart out of bounds') + } + if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') + if (end < 0) throw new RangeError('sourceEnd out of bounds') + + // Are we oob? + if (end > this.length) end = this.length + if (target.length - targetStart < end - start) { + end = target.length - targetStart + start + } + + var len = end - start + var i + + if (this === target && start < targetStart && targetStart < end) { + // descending copy from end + for (i = len - 1; i >= 0; i--) { + target[i + targetStart] = this[i + start] + } + } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { + // ascending copy from start + for (i = 0; i < len; i++) { + target[i + targetStart] = this[i + start] + } + } else { + target._set(this.subarray(start, start + len), targetStart) + } + + return len +} + +// fill(value, start=0, end=buffer.length) +Buffer.prototype.fill = function fill (value, start, end) { + if (!value) value = 0 + if (!start) start = 0 + if (!end) end = this.length + + if (end < start) throw new RangeError('end < start') + + // Fill 0 bytes; we're done + if (end === start) return + if (this.length === 0) return + + if (start < 0 || start >= this.length) throw new RangeError('start out of bounds') + if (end < 0 || end > this.length) throw new RangeError('end out of bounds') + + var i + if (typeof value === 'number') { + for (i = start; i < end; i++) { + this[i] = value + } + } else { + var bytes = utf8ToBytes(value.toString()) + var len = bytes.length + for (i = start; i < end; i++) { + this[i] = bytes[i % len] + } + } + + return this +} + +/** + * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance. + * Added in Node 0.12. Only available in browsers that support ArrayBuffer. + */ +Buffer.prototype.toArrayBuffer = function toArrayBuffer () { + if (typeof Uint8Array !== 'undefined') { + if (Buffer.TYPED_ARRAY_SUPPORT) { + return (new Buffer(this)).buffer + } else { + var buf = new Uint8Array(this.length) + for (var i = 0, len = buf.length; i < len; i += 1) { + buf[i] = this[i] + } + return buf.buffer + } + } else { + throw new TypeError('Buffer.toArrayBuffer not supported in this browser') + } +} + +// HELPER FUNCTIONS +// ================ + +var BP = Buffer.prototype + +/** + * Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods + */ +Buffer._augment = function _augment (arr) { + arr.constructor = Buffer + arr._isBuffer = true + + // save reference to original Uint8Array set method before overwriting + arr._set = arr.set + + // deprecated + arr.get = BP.get + arr.set = BP.set + + arr.write = BP.write + arr.toString = BP.toString + arr.toLocaleString = BP.toString + arr.toJSON = BP.toJSON + arr.equals = BP.equals + arr.compare = BP.compare + arr.indexOf = BP.indexOf + arr.copy = BP.copy + arr.slice = BP.slice + arr.readUIntLE = BP.readUIntLE + arr.readUIntBE = BP.readUIntBE + arr.readUInt8 = BP.readUInt8 + arr.readUInt16LE = BP.readUInt16LE + arr.readUInt16BE = BP.readUInt16BE + arr.readUInt32LE = BP.readUInt32LE + arr.readUInt32BE = BP.readUInt32BE + arr.readIntLE = BP.readIntLE + arr.readIntBE = BP.readIntBE + arr.readInt8 = BP.readInt8 + arr.readInt16LE = BP.readInt16LE + arr.readInt16BE = BP.readInt16BE + arr.readInt32LE = BP.readInt32LE + arr.readInt32BE = BP.readInt32BE + arr.readFloatLE = BP.readFloatLE + arr.readFloatBE = BP.readFloatBE + arr.readDoubleLE = BP.readDoubleLE + arr.readDoubleBE = BP.readDoubleBE + arr.writeUInt8 = BP.writeUInt8 + arr.writeUIntLE = BP.writeUIntLE + arr.writeUIntBE = BP.writeUIntBE + arr.writeUInt16LE = BP.writeUInt16LE + arr.writeUInt16BE = BP.writeUInt16BE + arr.writeUInt32LE = BP.writeUInt32LE + arr.writeUInt32BE = BP.writeUInt32BE + arr.writeIntLE = BP.writeIntLE + arr.writeIntBE = BP.writeIntBE + arr.writeInt8 = BP.writeInt8 + arr.writeInt16LE = BP.writeInt16LE + arr.writeInt16BE = BP.writeInt16BE + arr.writeInt32LE = BP.writeInt32LE + arr.writeInt32BE = BP.writeInt32BE + arr.writeFloatLE = BP.writeFloatLE + arr.writeFloatBE = BP.writeFloatBE + arr.writeDoubleLE = BP.writeDoubleLE + arr.writeDoubleBE = BP.writeDoubleBE + arr.fill = BP.fill + arr.inspect = BP.inspect + arr.toArrayBuffer = BP.toArrayBuffer + + return arr +} + +var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g + +function base64clean (str) { + // Node strips out invalid characters like \n and \t from the string, base64-js does not + str = stringtrim(str).replace(INVALID_BASE64_RE, '') + // Node converts strings with length < 2 to '' + if (str.length < 2) return '' + // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not + while (str.length % 4 !== 0) { + str = str + '=' + } + return str +} + +function stringtrim (str) { + if (str.trim) return str.trim() + return str.replace(/^\s+|\s+$/g, '') +} + +function toHex (n) { + if (n < 16) return '0' + n.toString(16) + return n.toString(16) +} + +function utf8ToBytes (string, units) { + units = units || Infinity + var codePoint + var length = string.length + var leadSurrogate = null + var bytes = [] + + for (var i = 0; i < length; i++) { + codePoint = string.charCodeAt(i) + + // is surrogate component + if (codePoint > 0xD7FF && codePoint < 0xE000) { + // last char was a lead + if (!leadSurrogate) { + // no lead yet + if (codePoint > 0xDBFF) { + // unexpected trail + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + continue + } else if (i + 1 === length) { + // unpaired lead + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + continue + } + + // valid lead + leadSurrogate = codePoint + + continue + } + + // 2 leads in a row + if (codePoint < 0xDC00) { + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + leadSurrogate = codePoint + continue + } + + // valid surrogate pair + codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 + } else if (leadSurrogate) { + // valid bmp char, but last char was a lead + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + } + + leadSurrogate = null + + // encode utf8 + if (codePoint < 0x80) { + if ((units -= 1) < 0) break + bytes.push(codePoint) + } else if (codePoint < 0x800) { + if ((units -= 2) < 0) break + bytes.push( + codePoint >> 0x6 | 0xC0, + codePoint & 0x3F | 0x80 + ) + } else if (codePoint < 0x10000) { + if ((units -= 3) < 0) break + bytes.push( + codePoint >> 0xC | 0xE0, + codePoint >> 0x6 & 0x3F | 0x80, + codePoint & 0x3F | 0x80 + ) + } else if (codePoint < 0x110000) { + if ((units -= 4) < 0) break + bytes.push( + codePoint >> 0x12 | 0xF0, + codePoint >> 0xC & 0x3F | 0x80, + codePoint >> 0x6 & 0x3F | 0x80, + codePoint & 0x3F | 0x80 + ) + } else { + throw new Error('Invalid code point') + } + } + + return bytes +} + +function asciiToBytes (str) { + var byteArray = [] + for (var i = 0; i < str.length; i++) { + // Node's code seems to be doing this and not & 0x7F.. + byteArray.push(str.charCodeAt(i) & 0xFF) + } + return byteArray +} + +function utf16leToBytes (str, units) { + var c, hi, lo + var byteArray = [] + for (var i = 0; i < str.length; i++) { + if ((units -= 2) < 0) break + + c = str.charCodeAt(i) + hi = c >> 8 + lo = c % 256 + byteArray.push(lo) + byteArray.push(hi) + } + + return byteArray +} + +function base64ToBytes (str) { + return base64.toByteArray(base64clean(str)) +} + +function blitBuffer (src, dst, offset, length) { + for (var i = 0; i < length; i++) { + if ((i + offset >= dst.length) || (i >= src.length)) break + dst[i + offset] = src[i] + } + return i +} + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"base64-js":7,"ieee754":39,"isarray":9}],9:[function(require,module,exports){ +var toString = {}.toString; + +module.exports = Array.isArray || function (arr) { + return toString.call(arr) == '[object Array]'; +}; + +},{}],10:[function(require,module,exports){ module.exports = require('./lib/chai'); -},{"./lib/chai":7}],7:[function(require,module,exports){ +},{"./lib/chai":11}],11:[function(require,module,exports){ /*! * chai * Copyright(c) 2011-2014 Jake Luer @@ -732,7 +2537,7 @@ exports.use(should); var assert = require('./chai/interface/assert'); exports.use(assert); -},{"./chai/assertion":8,"./chai/config":9,"./chai/core/assertions":10,"./chai/interface/assert":11,"./chai/interface/expect":12,"./chai/interface/should":13,"./chai/utils":24,"assertion-error":33}],8:[function(require,module,exports){ +},{"./chai/assertion":12,"./chai/config":13,"./chai/core/assertions":14,"./chai/interface/assert":15,"./chai/interface/expect":16,"./chai/interface/should":17,"./chai/utils":28,"assertion-error":5}],12:[function(require,module,exports){ /*! * chai * http://chaijs.com @@ -864,7 +2669,7 @@ module.exports = function (_chai, util) { }); }; -},{"./config":9}],9:[function(require,module,exports){ +},{"./config":13}],13:[function(require,module,exports){ module.exports = { /** @@ -916,7 +2721,7 @@ module.exports = { }; -},{}],10:[function(require,module,exports){ +},{}],14:[function(require,module,exports){ /*! * chai * http://chaijs.com @@ -2243,7 +4048,7 @@ module.exports = function (chai, _) { }); }; -},{}],11:[function(require,module,exports){ +},{}],15:[function(require,module,exports){ /*! * chai * Copyright(c) 2011-2014 Jake Luer @@ -3301,7 +5106,7 @@ module.exports = function (chai, util) { ('Throw', 'throws'); }; -},{}],12:[function(require,module,exports){ +},{}],16:[function(require,module,exports){ /*! * chai * Copyright(c) 2011-2014 Jake Luer @@ -3315,7 +5120,7 @@ module.exports = function (chai, util) { }; -},{}],13:[function(require,module,exports){ +},{}],17:[function(require,module,exports){ /*! * chai * Copyright(c) 2011-2014 Jake Luer @@ -3395,7 +5200,7 @@ module.exports = function (chai, util) { chai.Should = loadShould; }; -},{}],14:[function(require,module,exports){ +},{}],18:[function(require,module,exports){ /*! * Chai - addChainingMethod utility * Copyright(c) 2012-2014 Jake Luer @@ -3508,7 +5313,7 @@ module.exports = function (ctx, name, method, chainingBehavior) { }); }; -},{"../config":9,"./flag":17,"./transferFlags":31}],15:[function(require,module,exports){ +},{"../config":13,"./flag":21,"./transferFlags":35}],19:[function(require,module,exports){ /*! * Chai - addMethod utility * Copyright(c) 2012-2014 Jake Luer @@ -3553,7 +5358,7 @@ module.exports = function (ctx, name, method) { }; }; -},{"../config":9,"./flag":17}],16:[function(require,module,exports){ +},{"../config":13,"./flag":21}],20:[function(require,module,exports){ /*! * Chai - addProperty utility * Copyright(c) 2012-2014 Jake Luer @@ -3595,7 +5400,7 @@ module.exports = function (ctx, name, getter) { }); }; -},{}],17:[function(require,module,exports){ +},{}],21:[function(require,module,exports){ /*! * Chai - flag utility * Copyright(c) 2012-2014 Jake Luer @@ -3629,7 +5434,7 @@ module.exports = function (obj, key, value) { } }; -},{}],18:[function(require,module,exports){ +},{}],22:[function(require,module,exports){ /*! * Chai - getActual utility * Copyright(c) 2012-2014 Jake Luer @@ -3649,7 +5454,7 @@ module.exports = function (obj, args) { return args.length > 4 ? args[4] : obj._obj; }; -},{}],19:[function(require,module,exports){ +},{}],23:[function(require,module,exports){ /*! * Chai - getEnumerableProperties utility * Copyright(c) 2012-2014 Jake Luer @@ -3676,7 +5481,7 @@ module.exports = function getEnumerableProperties(object) { return result; }; -},{}],20:[function(require,module,exports){ +},{}],24:[function(require,module,exports){ /*! * Chai - message composition utility * Copyright(c) 2012-2014 Jake Luer @@ -3728,7 +5533,7 @@ module.exports = function (obj, args) { return flagMsg ? flagMsg + ': ' + msg : msg; }; -},{"./flag":17,"./getActual":18,"./inspect":25,"./objDisplay":26}],21:[function(require,module,exports){ +},{"./flag":21,"./getActual":22,"./inspect":29,"./objDisplay":30}],25:[function(require,module,exports){ /*! * Chai - getName utility * Copyright(c) 2012-2014 Jake Luer @@ -3750,7 +5555,7 @@ module.exports = function (func) { return match && match[1] ? match[1] : ""; }; -},{}],22:[function(require,module,exports){ +},{}],26:[function(require,module,exports){ /*! * Chai - getPathValue utility * Copyright(c) 2012-2014 Jake Luer @@ -3854,7 +5659,7 @@ function _getPathValue (parsed, obj) { return res; }; -},{}],23:[function(require,module,exports){ +},{}],27:[function(require,module,exports){ /*! * Chai - getProperties utility * Copyright(c) 2012-2014 Jake Luer @@ -3891,7 +5696,7 @@ module.exports = function getProperties(object) { return result; }; -},{}],24:[function(require,module,exports){ +},{}],28:[function(require,module,exports){ /*! * chai * Copyright(c) 2011 Jake Luer @@ -4007,7 +5812,7 @@ exports.addChainableMethod = require('./addChainableMethod'); exports.overwriteChainableMethod = require('./overwriteChainableMethod'); -},{"./addChainableMethod":14,"./addMethod":15,"./addProperty":16,"./flag":17,"./getActual":18,"./getMessage":20,"./getName":21,"./getPathValue":22,"./inspect":25,"./objDisplay":26,"./overwriteChainableMethod":27,"./overwriteMethod":28,"./overwriteProperty":29,"./test":30,"./transferFlags":31,"./type":32,"deep-eql":34}],25:[function(require,module,exports){ +},{"./addChainableMethod":18,"./addMethod":19,"./addProperty":20,"./flag":21,"./getActual":22,"./getMessage":24,"./getName":25,"./getPathValue":26,"./inspect":29,"./objDisplay":30,"./overwriteChainableMethod":31,"./overwriteMethod":32,"./overwriteProperty":33,"./test":34,"./transferFlags":35,"./type":36,"deep-eql":37}],29:[function(require,module,exports){ // This is (almost) directly from Node.js utils // https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js @@ -4339,7 +6144,7 @@ function objectToString(o) { return Object.prototype.toString.call(o); } -},{"./getEnumerableProperties":19,"./getName":21,"./getProperties":23}],26:[function(require,module,exports){ +},{"./getEnumerableProperties":23,"./getName":25,"./getProperties":27}],30:[function(require,module,exports){ /*! * Chai - flag utility * Copyright(c) 2012-2014 Jake Luer @@ -4390,7 +6195,7 @@ module.exports = function (obj) { } }; -},{"../config":9,"./inspect":25}],27:[function(require,module,exports){ +},{"../config":13,"./inspect":29}],31:[function(require,module,exports){ /*! * Chai - overwriteChainableMethod utility * Copyright(c) 2012-2014 Jake Luer @@ -4445,7 +6250,7 @@ module.exports = function (ctx, name, method, chainingBehavior) { }; }; -},{}],28:[function(require,module,exports){ +},{}],32:[function(require,module,exports){ /*! * Chai - overwriteMethod utility * Copyright(c) 2012-2014 Jake Luer @@ -4498,7 +6303,7 @@ module.exports = function (ctx, name, method) { } }; -},{}],29:[function(require,module,exports){ +},{}],33:[function(require,module,exports){ /*! * Chai - overwriteProperty utility * Copyright(c) 2012-2014 Jake Luer @@ -4554,7 +6359,7 @@ module.exports = function (ctx, name, getter) { }); }; -},{}],30:[function(require,module,exports){ +},{}],34:[function(require,module,exports){ /*! * Chai - test utility * Copyright(c) 2012-2014 Jake Luer @@ -4582,7 +6387,7 @@ module.exports = function (obj, args) { return negate ? !expr : expr; }; -},{"./flag":17}],31:[function(require,module,exports){ +},{"./flag":21}],35:[function(require,module,exports){ /*! * Chai - transferFlags utility * Copyright(c) 2012-2014 Jake Luer @@ -4628,7 +6433,7 @@ module.exports = function (assertion, object, includeAll) { } }; -},{}],32:[function(require,module,exports){ +},{}],36:[function(require,module,exports){ /*! * Chai - type utility * Copyright(c) 2012-2014 Jake Luer @@ -4675,122 +6480,10 @@ module.exports = function (obj) { return typeof obj; }; -},{}],33:[function(require,module,exports){ -/*! - * assertion-error - * Copyright(c) 2013 Jake Luer - * MIT Licensed - */ - -/*! - * Return a function that will copy properties from - * one object to another excluding any originally - * listed. Returned function will create a new `{}`. - * - * @param {String} excluded properties ... - * @return {Function} - */ - -function exclude () { - var excludes = [].slice.call(arguments); - - function excludeProps (res, obj) { - Object.keys(obj).forEach(function (key) { - if (!~excludes.indexOf(key)) res[key] = obj[key]; - }); - } - - return function extendExclude () { - var args = [].slice.call(arguments) - , i = 0 - , res = {}; - - for (; i < args.length; i++) { - excludeProps(res, args[i]); - } - - return res; - }; -}; - -/*! - * Primary Exports - */ - -module.exports = AssertionError; - -/** - * ### AssertionError - * - * An extension of the JavaScript `Error` constructor for - * assertion and validation scenarios. - * - * @param {String} message - * @param {Object} properties to include (optional) - * @param {callee} start stack function (optional) - */ - -function AssertionError (message, _props, ssf) { - var extend = exclude('name', 'message', 'stack', 'constructor', 'toJSON') - , props = extend(_props || {}); - - // default values - this.message = message || 'Unspecified AssertionError'; - this.showDiff = false; - - // copy from properties - for (var key in props) { - this[key] = props[key]; - } - - // capture stack trace - ssf = ssf || arguments.callee; - if (ssf && Error.captureStackTrace) { - Error.captureStackTrace(this, ssf); - } -} - -/*! - * Inherit from Error.prototype - */ - -AssertionError.prototype = Object.create(Error.prototype); - -/*! - * Statically set name - */ - -AssertionError.prototype.name = 'AssertionError'; - -/*! - * Ensure correct constructor - */ - -AssertionError.prototype.constructor = AssertionError; - -/** - * Allow errors to be converted to JSON for static transfer. - * - * @param {Boolean} include stack (default: `true`) - * @return {Object} object that can be `JSON.stringify` - */ - -AssertionError.prototype.toJSON = function (stack) { - var extend = exclude('constructor', 'toJSON', 'stack') - , props = extend({ name: this.name }, this); - - // include stack if exists and not turned off - if (false !== stack && this.stack) { - props.stack = this.stack; - } - - return props; -}; - -},{}],34:[function(require,module,exports){ +},{}],37:[function(require,module,exports){ module.exports = require('./lib/eql'); -},{"./lib/eql":35}],35:[function(require,module,exports){ +},{"./lib/eql":38}],38:[function(require,module,exports){ /*! * deep-eql * Copyright(c) 2013 Jake Luer @@ -5049,1722 +6742,10 @@ function objectEqual(a, b, m) { return true; } -},{"buffer":38,"type-detect":36}],36:[function(require,module,exports){ -module.exports = require('./lib/type'); - -},{"./lib/type":37}],37:[function(require,module,exports){ -/*! - * type-detect - * Copyright(c) 2013 jake luer - * MIT Licensed - */ - -/*! - * Primary Exports - */ - -var exports = module.exports = getType; - -/*! - * Detectable javascript natives - */ - -var natives = { - '[object Array]': 'array' - , '[object RegExp]': 'regexp' - , '[object Function]': 'function' - , '[object Arguments]': 'arguments' - , '[object Date]': 'date' -}; - -/** - * ### typeOf (obj) - * - * Use several different techniques to determine - * the type of object being tested. - * - * - * @param {Mixed} object - * @return {String} object type - * @api public - */ - -function getType (obj) { - var str = Object.prototype.toString.call(obj); - if (natives[str]) return natives[str]; - if (obj === null) return 'null'; - if (obj === undefined) return 'undefined'; - if (obj === Object(obj)) return 'object'; - return typeof obj; -} - -exports.Library = Library; - -/** - * ### Library - * - * Create a repository for custom type detection. - * - * ```js - * var lib = new type.Library; - * ``` - * - */ - -function Library () { - this.tests = {}; -} - -/** - * #### .of (obj) - * - * Expose replacement `typeof` detection to the library. - * - * ```js - * if ('string' === lib.of('hello world')) { - * // ... - * } - * ``` - * - * @param {Mixed} object to test - * @return {String} type - */ - -Library.prototype.of = getType; - -/** - * #### .define (type, test) - * - * Add a test to for the `.test()` assertion. - * - * Can be defined as a regular expression: - * - * ```js - * lib.define('int', /^[0-9]+$/); - * ``` - * - * ... or as a function: - * - * ```js - * lib.define('bln', function (obj) { - * if ('boolean' === lib.of(obj)) return true; - * var blns = [ 'yes', 'no', 'true', 'false', 1, 0 ]; - * if ('string' === lib.of(obj)) obj = obj.toLowerCase(); - * return !! ~blns.indexOf(obj); - * }); - * ``` - * - * @param {String} type - * @param {RegExp|Function} test - * @api public - */ - -Library.prototype.define = function (type, test) { - if (arguments.length === 1) return this.tests[type]; - this.tests[type] = test; - return this; -}; - -/** - * #### .test (obj, test) - * - * Assert that an object is of type. Will first - * check natives, and if that does not pass it will - * use the user defined custom tests. - * - * ```js - * assert(lib.test('1', 'int')); - * assert(lib.test('yes', 'bln')); - * ``` - * - * @param {Mixed} object - * @param {String} type - * @return {Boolean} result - * @api public - */ - -Library.prototype.test = function (obj, type) { - if (type === getType(obj)) return true; - var test = this.tests[type]; - - if (test && 'regexp' === getType(test)) { - return test.test(obj); - } else if (test && 'function' === getType(test)) { - return test(obj); - } else { - throw new ReferenceError('Type test "' + type + '" not defined or invalid.'); - } -}; - -},{}],38:[function(require,module,exports){ -/*! - * The buffer module from node.js, for the browser. - * - * @author Feross Aboukhadijeh - * @license MIT - */ - -var base64 = require('base64-js') -var ieee754 = require('ieee754') -var isArray = require('is-array') - -exports.Buffer = Buffer -exports.SlowBuffer = SlowBuffer -exports.INSPECT_MAX_BYTES = 50 -Buffer.poolSize = 8192 // not used by this implementation - -var rootParent = {} - -/** - * If `Buffer.TYPED_ARRAY_SUPPORT`: - * === true Use Uint8Array implementation (fastest) - * === false Use Object implementation (most compatible, even IE6) - * - * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, - * Opera 11.6+, iOS 4.2+. - * - * Note: - * - * - Implementation must support adding new properties to `Uint8Array` instances. - * Firefox 4-29 lacked support, fixed in Firefox 30+. - * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. - * - * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. - * - * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of - * incorrect length in some situations. - * - * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they will - * get the Object implementation, which is slower but will work correctly. - */ -Buffer.TYPED_ARRAY_SUPPORT = (function () { - function Foo () {} - try { - var buf = new ArrayBuffer(0) - var arr = new Uint8Array(buf) - arr.foo = function () { return 42 } - arr.constructor = Foo - return arr.foo() === 42 && // typed array instances can be augmented - arr.constructor === Foo && // constructor can be set - typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` - new Uint8Array(1).subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` - } catch (e) { - return false - } -})() - -function kMaxLength () { - return Buffer.TYPED_ARRAY_SUPPORT - ? 0x7fffffff - : 0x3fffffff -} - -/** - * Class: Buffer - * ============= - * - * The Buffer constructor returns instances of `Uint8Array` that are augmented - * with function properties for all the node `Buffer` API functions. We use - * `Uint8Array` so that square bracket notation works as expected -- it returns - * a single octet. - * - * By augmenting the instances, we can avoid modifying the `Uint8Array` - * prototype. - */ -function Buffer (arg) { - if (!(this instanceof Buffer)) { - // Avoid going through an ArgumentsAdaptorTrampoline in the common case. - if (arguments.length > 1) return new Buffer(arg, arguments[1]) - return new Buffer(arg) - } - - this.length = 0 - this.parent = undefined - - // Common case. - if (typeof arg === 'number') { - return fromNumber(this, arg) - } - - // Slightly less common case. - if (typeof arg === 'string') { - return fromString(this, arg, arguments.length > 1 ? arguments[1] : 'utf8') - } - - // Unusual. - return fromObject(this, arg) -} - -function fromNumber (that, length) { - that = allocate(that, length < 0 ? 0 : checked(length) | 0) - if (!Buffer.TYPED_ARRAY_SUPPORT) { - for (var i = 0; i < length; i++) { - that[i] = 0 - } - } - return that -} - -function fromString (that, string, encoding) { - if (typeof encoding !== 'string' || encoding === '') encoding = 'utf8' - - // Assumption: byteLength() return value is always < kMaxLength. - var length = byteLength(string, encoding) | 0 - that = allocate(that, length) - - that.write(string, encoding) - return that -} - -function fromObject (that, object) { - if (Buffer.isBuffer(object)) return fromBuffer(that, object) - - if (isArray(object)) return fromArray(that, object) - - if (object == null) { - throw new TypeError('must start with number, buffer, array or string') - } - - if (typeof ArrayBuffer !== 'undefined' && object.buffer instanceof ArrayBuffer) { - return fromTypedArray(that, object) - } - - if (object.length) return fromArrayLike(that, object) - - return fromJsonObject(that, object) -} - -function fromBuffer (that, buffer) { - var length = checked(buffer.length) | 0 - that = allocate(that, length) - buffer.copy(that, 0, 0, length) - return that -} - -function fromArray (that, array) { - var length = checked(array.length) | 0 - that = allocate(that, length) - for (var i = 0; i < length; i += 1) { - that[i] = array[i] & 255 - } - return that -} - -// Duplicate of fromArray() to keep fromArray() monomorphic. -function fromTypedArray (that, array) { - var length = checked(array.length) | 0 - that = allocate(that, length) - // Truncating the elements is probably not what people expect from typed - // arrays with BYTES_PER_ELEMENT > 1 but it's compatible with the behavior - // of the old Buffer constructor. - for (var i = 0; i < length; i += 1) { - that[i] = array[i] & 255 - } - return that -} - -function fromArrayLike (that, array) { - var length = checked(array.length) | 0 - that = allocate(that, length) - for (var i = 0; i < length; i += 1) { - that[i] = array[i] & 255 - } - return that -} - -// Deserialize { type: 'Buffer', data: [1,2,3,...] } into a Buffer object. -// Returns a zero-length buffer for inputs that don't conform to the spec. -function fromJsonObject (that, object) { - var array - var length = 0 - - if (object.type === 'Buffer' && isArray(object.data)) { - array = object.data - length = checked(array.length) | 0 - } - that = allocate(that, length) - - for (var i = 0; i < length; i += 1) { - that[i] = array[i] & 255 - } - return that -} - -function allocate (that, length) { - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Return an augmented `Uint8Array` instance, for best performance - that = Buffer._augment(new Uint8Array(length)) - } else { - // Fallback: Return an object instance of the Buffer class - that.length = length - that._isBuffer = true - } - - var fromPool = length !== 0 && length <= Buffer.poolSize >>> 1 - if (fromPool) that.parent = rootParent - - return that -} - -function checked (length) { - // Note: cannot use `length < kMaxLength` here because that fails when - // length is NaN (which is otherwise coerced to zero.) - if (length >= kMaxLength()) { - throw new RangeError('Attempt to allocate Buffer larger than maximum ' + - 'size: 0x' + kMaxLength().toString(16) + ' bytes') - } - return length | 0 -} - -function SlowBuffer (subject, encoding) { - if (!(this instanceof SlowBuffer)) return new SlowBuffer(subject, encoding) - - var buf = new Buffer(subject, encoding) - delete buf.parent - return buf -} - -Buffer.isBuffer = function isBuffer (b) { - return !!(b != null && b._isBuffer) -} - -Buffer.compare = function compare (a, b) { - if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { - throw new TypeError('Arguments must be Buffers') - } - - if (a === b) return 0 - - var x = a.length - var y = b.length - - var i = 0 - var len = Math.min(x, y) - while (i < len) { - if (a[i] !== b[i]) break - - ++i - } - - if (i !== len) { - x = a[i] - y = b[i] - } - - if (x < y) return -1 - if (y < x) return 1 - return 0 -} - -Buffer.isEncoding = function isEncoding (encoding) { - switch (String(encoding).toLowerCase()) { - case 'hex': - case 'utf8': - case 'utf-8': - case 'ascii': - case 'binary': - case 'base64': - case 'raw': - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return true - default: - return false - } -} - -Buffer.concat = function concat (list, length) { - if (!isArray(list)) throw new TypeError('list argument must be an Array of Buffers.') - - if (list.length === 0) { - return new Buffer(0) - } else if (list.length === 1) { - return list[0] - } - - var i - if (length === undefined) { - length = 0 - for (i = 0; i < list.length; i++) { - length += list[i].length - } - } - - var buf = new Buffer(length) - var pos = 0 - for (i = 0; i < list.length; i++) { - var item = list[i] - item.copy(buf, pos) - pos += item.length - } - return buf -} - -function byteLength (string, encoding) { - if (typeof string !== 'string') string = '' + string - - var len = string.length - if (len === 0) return 0 - - // Use a for loop to avoid recursion - var loweredCase = false - for (;;) { - switch (encoding) { - case 'ascii': - case 'binary': - // Deprecated - case 'raw': - case 'raws': - return len - case 'utf8': - case 'utf-8': - return utf8ToBytes(string).length - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return len * 2 - case 'hex': - return len >>> 1 - case 'base64': - return base64ToBytes(string).length - default: - if (loweredCase) return utf8ToBytes(string).length // assume utf8 - encoding = ('' + encoding).toLowerCase() - loweredCase = true - } - } -} -Buffer.byteLength = byteLength - -// pre-set for values that may exist in the future -Buffer.prototype.length = undefined -Buffer.prototype.parent = undefined - -function slowToString (encoding, start, end) { - var loweredCase = false - - start = start | 0 - end = end === undefined || end === Infinity ? this.length : end | 0 - - if (!encoding) encoding = 'utf8' - if (start < 0) start = 0 - if (end > this.length) end = this.length - if (end <= start) return '' - - while (true) { - switch (encoding) { - case 'hex': - return hexSlice(this, start, end) - - case 'utf8': - case 'utf-8': - return utf8Slice(this, start, end) - - case 'ascii': - return asciiSlice(this, start, end) - - case 'binary': - return binarySlice(this, start, end) - - case 'base64': - return base64Slice(this, start, end) - - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return utf16leSlice(this, start, end) - - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) - encoding = (encoding + '').toLowerCase() - loweredCase = true - } - } -} - -Buffer.prototype.toString = function toString () { - var length = this.length | 0 - if (length === 0) return '' - if (arguments.length === 0) return utf8Slice(this, 0, length) - return slowToString.apply(this, arguments) -} - -Buffer.prototype.equals = function equals (b) { - if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') - if (this === b) return true - return Buffer.compare(this, b) === 0 -} - -Buffer.prototype.inspect = function inspect () { - var str = '' - var max = exports.INSPECT_MAX_BYTES - if (this.length > 0) { - str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') - if (this.length > max) str += ' ... ' - } - return '' -} - -Buffer.prototype.compare = function compare (b) { - if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') - if (this === b) return 0 - return Buffer.compare(this, b) -} - -Buffer.prototype.indexOf = function indexOf (val, byteOffset) { - if (byteOffset > 0x7fffffff) byteOffset = 0x7fffffff - else if (byteOffset < -0x80000000) byteOffset = -0x80000000 - byteOffset >>= 0 - - if (this.length === 0) return -1 - if (byteOffset >= this.length) return -1 - - // Negative offsets start from the end of the buffer - if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0) - - if (typeof val === 'string') { - if (val.length === 0) return -1 // special case: looking for empty string always fails - return String.prototype.indexOf.call(this, val, byteOffset) - } - if (Buffer.isBuffer(val)) { - return arrayIndexOf(this, val, byteOffset) - } - if (typeof val === 'number') { - if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') { - return Uint8Array.prototype.indexOf.call(this, val, byteOffset) - } - return arrayIndexOf(this, [ val ], byteOffset) - } - - function arrayIndexOf (arr, val, byteOffset) { - var foundIndex = -1 - for (var i = 0; byteOffset + i < arr.length; i++) { - if (arr[byteOffset + i] === val[foundIndex === -1 ? 0 : i - foundIndex]) { - if (foundIndex === -1) foundIndex = i - if (i - foundIndex + 1 === val.length) return byteOffset + foundIndex - } else { - foundIndex = -1 - } - } - return -1 - } - - throw new TypeError('val must be string, number or Buffer') -} - -// `get` will be removed in Node 0.13+ -Buffer.prototype.get = function get (offset) { - console.log('.get() is deprecated. Access using array indexes instead.') - return this.readUInt8(offset) -} - -// `set` will be removed in Node 0.13+ -Buffer.prototype.set = function set (v, offset) { - console.log('.set() is deprecated. Access using array indexes instead.') - return this.writeUInt8(v, offset) -} - -function hexWrite (buf, string, offset, length) { - offset = Number(offset) || 0 - var remaining = buf.length - offset - if (!length) { - length = remaining - } else { - length = Number(length) - if (length > remaining) { - length = remaining - } - } - - // must be an even number of digits - var strLen = string.length - if (strLen % 2 !== 0) throw new Error('Invalid hex string') - - if (length > strLen / 2) { - length = strLen / 2 - } - for (var i = 0; i < length; i++) { - var parsed = parseInt(string.substr(i * 2, 2), 16) - if (isNaN(parsed)) throw new Error('Invalid hex string') - buf[offset + i] = parsed - } - return i -} - -function utf8Write (buf, string, offset, length) { - return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) -} - -function asciiWrite (buf, string, offset, length) { - return blitBuffer(asciiToBytes(string), buf, offset, length) -} - -function binaryWrite (buf, string, offset, length) { - return asciiWrite(buf, string, offset, length) -} - -function base64Write (buf, string, offset, length) { - return blitBuffer(base64ToBytes(string), buf, offset, length) -} - -function ucs2Write (buf, string, offset, length) { - return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) -} - -Buffer.prototype.write = function write (string, offset, length, encoding) { - // Buffer#write(string) - if (offset === undefined) { - encoding = 'utf8' - length = this.length - offset = 0 - // Buffer#write(string, encoding) - } else if (length === undefined && typeof offset === 'string') { - encoding = offset - length = this.length - offset = 0 - // Buffer#write(string, offset[, length][, encoding]) - } else if (isFinite(offset)) { - offset = offset | 0 - if (isFinite(length)) { - length = length | 0 - if (encoding === undefined) encoding = 'utf8' - } else { - encoding = length - length = undefined - } - // legacy write(string, encoding, offset, length) - remove in v0.13 - } else { - var swap = encoding - encoding = offset - offset = length | 0 - length = swap - } - - var remaining = this.length - offset - if (length === undefined || length > remaining) length = remaining - - if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { - throw new RangeError('attempt to write outside buffer bounds') - } - - if (!encoding) encoding = 'utf8' - - var loweredCase = false - for (;;) { - switch (encoding) { - case 'hex': - return hexWrite(this, string, offset, length) - - case 'utf8': - case 'utf-8': - return utf8Write(this, string, offset, length) - - case 'ascii': - return asciiWrite(this, string, offset, length) - - case 'binary': - return binaryWrite(this, string, offset, length) - - case 'base64': - // Warning: maxLength not taken into account in base64Write - return base64Write(this, string, offset, length) - - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return ucs2Write(this, string, offset, length) - - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) - encoding = ('' + encoding).toLowerCase() - loweredCase = true - } - } -} - -Buffer.prototype.toJSON = function toJSON () { - return { - type: 'Buffer', - data: Array.prototype.slice.call(this._arr || this, 0) - } -} - -function base64Slice (buf, start, end) { - if (start === 0 && end === buf.length) { - return base64.fromByteArray(buf) - } else { - return base64.fromByteArray(buf.slice(start, end)) - } -} - -function utf8Slice (buf, start, end) { - var res = '' - var tmp = '' - end = Math.min(buf.length, end) - - for (var i = start; i < end; i++) { - if (buf[i] <= 0x7F) { - res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i]) - tmp = '' - } else { - tmp += '%' + buf[i].toString(16) - } - } - - return res + decodeUtf8Char(tmp) -} - -function asciiSlice (buf, start, end) { - var ret = '' - end = Math.min(buf.length, end) - - for (var i = start; i < end; i++) { - ret += String.fromCharCode(buf[i] & 0x7F) - } - return ret -} - -function binarySlice (buf, start, end) { - var ret = '' - end = Math.min(buf.length, end) - - for (var i = start; i < end; i++) { - ret += String.fromCharCode(buf[i]) - } - return ret -} - -function hexSlice (buf, start, end) { - var len = buf.length - - if (!start || start < 0) start = 0 - if (!end || end < 0 || end > len) end = len - - var out = '' - for (var i = start; i < end; i++) { - out += toHex(buf[i]) - } - return out -} - -function utf16leSlice (buf, start, end) { - var bytes = buf.slice(start, end) - var res = '' - for (var i = 0; i < bytes.length; i += 2) { - res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256) - } - return res -} - -Buffer.prototype.slice = function slice (start, end) { - var len = this.length - start = ~~start - end = end === undefined ? len : ~~end - - if (start < 0) { - start += len - if (start < 0) start = 0 - } else if (start > len) { - start = len - } - - if (end < 0) { - end += len - if (end < 0) end = 0 - } else if (end > len) { - end = len - } - - if (end < start) end = start - - var newBuf - if (Buffer.TYPED_ARRAY_SUPPORT) { - newBuf = Buffer._augment(this.subarray(start, end)) - } else { - var sliceLen = end - start - newBuf = new Buffer(sliceLen, undefined) - for (var i = 0; i < sliceLen; i++) { - newBuf[i] = this[i + start] - } - } - - if (newBuf.length) newBuf.parent = this.parent || this - - return newBuf -} - -/* - * Need to make sure that buffer isn't trying to write out of bounds. - */ -function checkOffset (offset, ext, length) { - if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') - if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') -} - -Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) checkOffset(offset, byteLength, this.length) - - var val = this[offset] - var mul = 1 - var i = 0 - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul - } - - return val -} - -Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) { - checkOffset(offset, byteLength, this.length) - } - - var val = this[offset + --byteLength] - var mul = 1 - while (byteLength > 0 && (mul *= 0x100)) { - val += this[offset + --byteLength] * mul - } - - return val -} - -Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { - if (!noAssert) checkOffset(offset, 1, this.length) - return this[offset] -} - -Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length) - return this[offset] | (this[offset + 1] << 8) -} - -Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length) - return (this[offset] << 8) | this[offset + 1] -} - -Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) - - return ((this[offset]) | - (this[offset + 1] << 8) | - (this[offset + 2] << 16)) + - (this[offset + 3] * 0x1000000) -} - -Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) - - return (this[offset] * 0x1000000) + - ((this[offset + 1] << 16) | - (this[offset + 2] << 8) | - this[offset + 3]) -} - -Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) checkOffset(offset, byteLength, this.length) - - var val = this[offset] - var mul = 1 - var i = 0 - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul - } - mul *= 0x80 - - if (val >= mul) val -= Math.pow(2, 8 * byteLength) - - return val -} - -Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) checkOffset(offset, byteLength, this.length) - - var i = byteLength - var mul = 1 - var val = this[offset + --i] - while (i > 0 && (mul *= 0x100)) { - val += this[offset + --i] * mul - } - mul *= 0x80 - - if (val >= mul) val -= Math.pow(2, 8 * byteLength) - - return val -} - -Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { - if (!noAssert) checkOffset(offset, 1, this.length) - if (!(this[offset] & 0x80)) return (this[offset]) - return ((0xff - this[offset] + 1) * -1) -} - -Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length) - var val = this[offset] | (this[offset + 1] << 8) - return (val & 0x8000) ? val | 0xFFFF0000 : val -} - -Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length) - var val = this[offset + 1] | (this[offset] << 8) - return (val & 0x8000) ? val | 0xFFFF0000 : val -} - -Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) - - return (this[offset]) | - (this[offset + 1] << 8) | - (this[offset + 2] << 16) | - (this[offset + 3] << 24) -} - -Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) - - return (this[offset] << 24) | - (this[offset + 1] << 16) | - (this[offset + 2] << 8) | - (this[offset + 3]) -} - -Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) - return ieee754.read(this, offset, true, 23, 4) -} - -Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) - return ieee754.read(this, offset, false, 23, 4) -} - -Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 8, this.length) - return ieee754.read(this, offset, true, 52, 8) -} - -Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 8, this.length) - return ieee754.read(this, offset, false, 52, 8) -} - -function checkInt (buf, value, offset, ext, max, min) { - if (!Buffer.isBuffer(buf)) throw new TypeError('buffer must be a Buffer instance') - if (value > max || value < min) throw new RangeError('value is out of bounds') - if (offset + ext > buf.length) throw new RangeError('index out of range') -} - -Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { - value = +value - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0) - - var mul = 1 - var i = 0 - this[offset] = value & 0xFF - while (++i < byteLength && (mul *= 0x100)) { - this[offset + i] = (value / mul) & 0xFF - } - - return offset + byteLength -} - -Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { - value = +value - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0) - - var i = byteLength - 1 - var mul = 1 - this[offset + i] = value & 0xFF - while (--i >= 0 && (mul *= 0x100)) { - this[offset + i] = (value / mul) & 0xFF - } - - return offset + byteLength -} - -Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) - this[offset] = value - return offset + 1 -} - -function objectWriteUInt16 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffff + value + 1 - for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) { - buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> - (littleEndian ? i : 1 - i) * 8 - } -} - -Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = value - this[offset + 1] = (value >>> 8) - } else { - objectWriteUInt16(this, value, offset, true) - } - return offset + 2 -} - -Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8) - this[offset + 1] = value - } else { - objectWriteUInt16(this, value, offset, false) - } - return offset + 2 -} - -function objectWriteUInt32 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffffffff + value + 1 - for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) { - buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff - } -} - -Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset + 3] = (value >>> 24) - this[offset + 2] = (value >>> 16) - this[offset + 1] = (value >>> 8) - this[offset] = value - } else { - objectWriteUInt32(this, value, offset, true) - } - return offset + 4 -} - -Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = value - } else { - objectWriteUInt32(this, value, offset, false) - } - return offset + 4 -} - -Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1) - - checkInt(this, value, offset, byteLength, limit - 1, -limit) - } - - var i = 0 - var mul = 1 - var sub = value < 0 ? 1 : 0 - this[offset] = value & 0xFF - while (++i < byteLength && (mul *= 0x100)) { - this[offset + i] = ((value / mul) >> 0) - sub & 0xFF - } - - return offset + byteLength -} - -Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1) - - checkInt(this, value, offset, byteLength, limit - 1, -limit) - } - - var i = byteLength - 1 - var mul = 1 - var sub = value < 0 ? 1 : 0 - this[offset + i] = value & 0xFF - while (--i >= 0 && (mul *= 0x100)) { - this[offset + i] = ((value / mul) >> 0) - sub & 0xFF - } - - return offset + byteLength -} - -Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) - if (value < 0) value = 0xff + value + 1 - this[offset] = value - return offset + 1 -} - -Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = value - this[offset + 1] = (value >>> 8) - } else { - objectWriteUInt16(this, value, offset, true) - } - return offset + 2 -} - -Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8) - this[offset + 1] = value - } else { - objectWriteUInt16(this, value, offset, false) - } - return offset + 2 -} - -Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = value - this[offset + 1] = (value >>> 8) - this[offset + 2] = (value >>> 16) - this[offset + 3] = (value >>> 24) - } else { - objectWriteUInt32(this, value, offset, true) - } - return offset + 4 -} - -Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) - if (value < 0) value = 0xffffffff + value + 1 - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = value - } else { - objectWriteUInt32(this, value, offset, false) - } - return offset + 4 -} - -function checkIEEE754 (buf, value, offset, ext, max, min) { - if (value > max || value < min) throw new RangeError('value is out of bounds') - if (offset + ext > buf.length) throw new RangeError('index out of range') - if (offset < 0) throw new RangeError('index out of range') -} - -function writeFloat (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) - } - ieee754.write(buf, value, offset, littleEndian, 23, 4) - return offset + 4 -} - -Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { - return writeFloat(this, value, offset, true, noAssert) -} - -Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { - return writeFloat(this, value, offset, false, noAssert) -} - -function writeDouble (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) - } - ieee754.write(buf, value, offset, littleEndian, 52, 8) - return offset + 8 -} - -Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { - return writeDouble(this, value, offset, true, noAssert) -} - -Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { - return writeDouble(this, value, offset, false, noAssert) -} - -// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) -Buffer.prototype.copy = function copy (target, targetStart, start, end) { - if (!start) start = 0 - if (!end && end !== 0) end = this.length - if (targetStart >= target.length) targetStart = target.length - if (!targetStart) targetStart = 0 - if (end > 0 && end < start) end = start - - // Copy 0 bytes; we're done - if (end === start) return 0 - if (target.length === 0 || this.length === 0) return 0 - - // Fatal error conditions - if (targetStart < 0) { - throw new RangeError('targetStart out of bounds') - } - if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') - if (end < 0) throw new RangeError('sourceEnd out of bounds') - - // Are we oob? - if (end > this.length) end = this.length - if (target.length - targetStart < end - start) { - end = target.length - targetStart + start - } - - var len = end - start - - if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { - for (var i = 0; i < len; i++) { - target[i + targetStart] = this[i + start] - } - } else { - target._set(this.subarray(start, start + len), targetStart) - } - - return len -} - -// fill(value, start=0, end=buffer.length) -Buffer.prototype.fill = function fill (value, start, end) { - if (!value) value = 0 - if (!start) start = 0 - if (!end) end = this.length - - if (end < start) throw new RangeError('end < start') - - // Fill 0 bytes; we're done - if (end === start) return - if (this.length === 0) return - - if (start < 0 || start >= this.length) throw new RangeError('start out of bounds') - if (end < 0 || end > this.length) throw new RangeError('end out of bounds') - - var i - if (typeof value === 'number') { - for (i = start; i < end; i++) { - this[i] = value - } - } else { - var bytes = utf8ToBytes(value.toString()) - var len = bytes.length - for (i = start; i < end; i++) { - this[i] = bytes[i % len] - } - } - - return this -} - -/** - * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance. - * Added in Node 0.12. Only available in browsers that support ArrayBuffer. - */ -Buffer.prototype.toArrayBuffer = function toArrayBuffer () { - if (typeof Uint8Array !== 'undefined') { - if (Buffer.TYPED_ARRAY_SUPPORT) { - return (new Buffer(this)).buffer - } else { - var buf = new Uint8Array(this.length) - for (var i = 0, len = buf.length; i < len; i += 1) { - buf[i] = this[i] - } - return buf.buffer - } - } else { - throw new TypeError('Buffer.toArrayBuffer not supported in this browser') - } -} - -// HELPER FUNCTIONS -// ================ - -var BP = Buffer.prototype - -/** - * Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods - */ -Buffer._augment = function _augment (arr) { - arr.constructor = Buffer - arr._isBuffer = true - - // save reference to original Uint8Array set method before overwriting - arr._set = arr.set - - // deprecated, will be removed in node 0.13+ - arr.get = BP.get - arr.set = BP.set - - arr.write = BP.write - arr.toString = BP.toString - arr.toLocaleString = BP.toString - arr.toJSON = BP.toJSON - arr.equals = BP.equals - arr.compare = BP.compare - arr.indexOf = BP.indexOf - arr.copy = BP.copy - arr.slice = BP.slice - arr.readUIntLE = BP.readUIntLE - arr.readUIntBE = BP.readUIntBE - arr.readUInt8 = BP.readUInt8 - arr.readUInt16LE = BP.readUInt16LE - arr.readUInt16BE = BP.readUInt16BE - arr.readUInt32LE = BP.readUInt32LE - arr.readUInt32BE = BP.readUInt32BE - arr.readIntLE = BP.readIntLE - arr.readIntBE = BP.readIntBE - arr.readInt8 = BP.readInt8 - arr.readInt16LE = BP.readInt16LE - arr.readInt16BE = BP.readInt16BE - arr.readInt32LE = BP.readInt32LE - arr.readInt32BE = BP.readInt32BE - arr.readFloatLE = BP.readFloatLE - arr.readFloatBE = BP.readFloatBE - arr.readDoubleLE = BP.readDoubleLE - arr.readDoubleBE = BP.readDoubleBE - arr.writeUInt8 = BP.writeUInt8 - arr.writeUIntLE = BP.writeUIntLE - arr.writeUIntBE = BP.writeUIntBE - arr.writeUInt16LE = BP.writeUInt16LE - arr.writeUInt16BE = BP.writeUInt16BE - arr.writeUInt32LE = BP.writeUInt32LE - arr.writeUInt32BE = BP.writeUInt32BE - arr.writeIntLE = BP.writeIntLE - arr.writeIntBE = BP.writeIntBE - arr.writeInt8 = BP.writeInt8 - arr.writeInt16LE = BP.writeInt16LE - arr.writeInt16BE = BP.writeInt16BE - arr.writeInt32LE = BP.writeInt32LE - arr.writeInt32BE = BP.writeInt32BE - arr.writeFloatLE = BP.writeFloatLE - arr.writeFloatBE = BP.writeFloatBE - arr.writeDoubleLE = BP.writeDoubleLE - arr.writeDoubleBE = BP.writeDoubleBE - arr.fill = BP.fill - arr.inspect = BP.inspect - arr.toArrayBuffer = BP.toArrayBuffer - - return arr -} - -var INVALID_BASE64_RE = /[^+\/0-9A-z\-]/g - -function base64clean (str) { - // Node strips out invalid characters like \n and \t from the string, base64-js does not - str = stringtrim(str).replace(INVALID_BASE64_RE, '') - // Node converts strings with length < 2 to '' - if (str.length < 2) return '' - // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not - while (str.length % 4 !== 0) { - str = str + '=' - } - return str -} - -function stringtrim (str) { - if (str.trim) return str.trim() - return str.replace(/^\s+|\s+$/g, '') -} - -function toHex (n) { - if (n < 16) return '0' + n.toString(16) - return n.toString(16) -} - -function utf8ToBytes (string, units) { - units = units || Infinity - var codePoint - var length = string.length - var leadSurrogate = null - var bytes = [] - var i = 0 - - for (; i < length; i++) { - codePoint = string.charCodeAt(i) - - // is surrogate component - if (codePoint > 0xD7FF && codePoint < 0xE000) { - // last char was a lead - if (leadSurrogate) { - // 2 leads in a row - if (codePoint < 0xDC00) { - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - leadSurrogate = codePoint - continue - } else { - // valid surrogate pair - codePoint = leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00 | 0x10000 - leadSurrogate = null - } - } else { - // no lead yet - - if (codePoint > 0xDBFF) { - // unexpected trail - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - continue - } else if (i + 1 === length) { - // unpaired lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - continue - } else { - // valid lead - leadSurrogate = codePoint - continue - } - } - } else if (leadSurrogate) { - // valid bmp char, but last char was a lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - leadSurrogate = null - } - - // encode utf8 - if (codePoint < 0x80) { - if ((units -= 1) < 0) break - bytes.push(codePoint) - } else if (codePoint < 0x800) { - if ((units -= 2) < 0) break - bytes.push( - codePoint >> 0x6 | 0xC0, - codePoint & 0x3F | 0x80 - ) - } else if (codePoint < 0x10000) { - if ((units -= 3) < 0) break - bytes.push( - codePoint >> 0xC | 0xE0, - codePoint >> 0x6 & 0x3F | 0x80, - codePoint & 0x3F | 0x80 - ) - } else if (codePoint < 0x200000) { - if ((units -= 4) < 0) break - bytes.push( - codePoint >> 0x12 | 0xF0, - codePoint >> 0xC & 0x3F | 0x80, - codePoint >> 0x6 & 0x3F | 0x80, - codePoint & 0x3F | 0x80 - ) - } else { - throw new Error('Invalid code point') - } - } - - return bytes -} - -function asciiToBytes (str) { - var byteArray = [] - for (var i = 0; i < str.length; i++) { - // Node's code seems to be doing this and not & 0x7F.. - byteArray.push(str.charCodeAt(i) & 0xFF) - } - return byteArray -} - -function utf16leToBytes (str, units) { - var c, hi, lo - var byteArray = [] - for (var i = 0; i < str.length; i++) { - if ((units -= 2) < 0) break - - c = str.charCodeAt(i) - hi = c >> 8 - lo = c % 256 - byteArray.push(lo) - byteArray.push(hi) - } - - return byteArray -} - -function base64ToBytes (str) { - return base64.toByteArray(base64clean(str)) -} - -function blitBuffer (src, dst, offset, length) { - for (var i = 0; i < length; i++) { - if ((i + offset >= dst.length) || (i >= src.length)) break - dst[i + offset] = src[i] - } - return i -} - -function decodeUtf8Char (str) { - try { - return decodeURIComponent(str) - } catch (err) { - return String.fromCharCode(0xFFFD) // UTF 8 invalid char - } -} - -},{"base64-js":39,"ieee754":40,"is-array":41}],39:[function(require,module,exports){ -var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; - -;(function (exports) { - 'use strict'; - - var Arr = (typeof Uint8Array !== 'undefined') - ? Uint8Array - : Array - - var PLUS = '+'.charCodeAt(0) - var SLASH = '/'.charCodeAt(0) - var NUMBER = '0'.charCodeAt(0) - var LOWER = 'a'.charCodeAt(0) - var UPPER = 'A'.charCodeAt(0) - var PLUS_URL_SAFE = '-'.charCodeAt(0) - var SLASH_URL_SAFE = '_'.charCodeAt(0) - - function decode (elt) { - var code = elt.charCodeAt(0) - if (code === PLUS || - code === PLUS_URL_SAFE) - return 62 // '+' - if (code === SLASH || - code === SLASH_URL_SAFE) - return 63 // '/' - if (code < NUMBER) - return -1 //no match - if (code < NUMBER + 10) - return code - NUMBER + 26 + 26 - if (code < UPPER + 26) - return code - UPPER - if (code < LOWER + 26) - return code - LOWER + 26 - } - - function b64ToByteArray (b64) { - var i, j, l, tmp, placeHolders, arr - - if (b64.length % 4 > 0) { - throw new Error('Invalid string. Length must be a multiple of 4') - } - - // the number of equal signs (place holders) - // if there are two placeholders, than the two characters before it - // represent one byte - // if there is only one, then the three characters before it represent 2 bytes - // this is just a cheap hack to not do indexOf twice - var len = b64.length - placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0 - - // base64 is 4/3 + up to two characters of the original data - arr = new Arr(b64.length * 3 / 4 - placeHolders) - - // if there are placeholders, only get up to the last complete 4 chars - l = placeHolders > 0 ? b64.length - 4 : b64.length - - var L = 0 - - function push (v) { - arr[L++] = v - } - - for (i = 0, j = 0; i < l; i += 4, j += 3) { - tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3)) - push((tmp & 0xFF0000) >> 16) - push((tmp & 0xFF00) >> 8) - push(tmp & 0xFF) - } - - if (placeHolders === 2) { - tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4) - push(tmp & 0xFF) - } else if (placeHolders === 1) { - tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2) - push((tmp >> 8) & 0xFF) - push(tmp & 0xFF) - } - - return arr - } - - function uint8ToBase64 (uint8) { - var i, - extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes - output = "", - temp, length - - function encode (num) { - return lookup.charAt(num) - } - - function tripletToBase64 (num) { - return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F) - } - - // go through the array every three bytes, we'll deal with trailing stuff later - for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { - temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) - output += tripletToBase64(temp) - } - - // pad the end with zeros, but make sure to not forget the extra bytes - switch (extraBytes) { - case 1: - temp = uint8[uint8.length - 1] - output += encode(temp >> 2) - output += encode((temp << 4) & 0x3F) - output += '==' - break - case 2: - temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]) - output += encode(temp >> 10) - output += encode((temp >> 4) & 0x3F) - output += encode((temp << 2) & 0x3F) - output += '=' - break - } - - return output - } - - exports.toByteArray = b64ToByteArray - exports.fromByteArray = uint8ToBase64 -}(typeof exports === 'undefined' ? (this.base64js = {}) : exports)) - -},{}],40:[function(require,module,exports){ +},{"buffer":8,"type-detect":48}],39:[function(require,module,exports){ exports.read = function (buffer, offset, isLE, mLen, nBytes) { var e, m - var eLen = nBytes * 8 - mLen - 1 + var eLen = (nBytes * 8) - mLen - 1 var eMax = (1 << eLen) - 1 var eBias = eMax >> 1 var nBits = -7 @@ -6777,12 +6758,12 @@ exports.read = function (buffer, offset, isLE, mLen, nBytes) { e = s & ((1 << (-nBits)) - 1) s >>= (-nBits) nBits += eLen - for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} + for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {} m = e & ((1 << (-nBits)) - 1) e >>= (-nBits) nBits += mLen - for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} + for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {} if (e === 0) { e = 1 - eBias @@ -6797,7 +6778,7 @@ exports.read = function (buffer, offset, isLE, mLen, nBytes) { exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { var e, m, c - var eLen = nBytes * 8 - mLen - 1 + var eLen = (nBytes * 8) - mLen - 1 var eMax = (1 << eLen) - 1 var eBias = eMax >> 1 var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) @@ -6830,7 +6811,7 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { m = 0 e = eMax } else if (e + eBias >= 1) { - m = (value * c - 1) * Math.pow(2, mLen) + m = ((value * c) - 1) * Math.pow(2, mLen) e = e + eBias } else { m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) @@ -6847,1690 +6828,262 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { buffer[offset + i - d] |= s * 128 } -},{}],41:[function(require,module,exports){ +},{}],40:[function(require,module,exports){ +;(function () { // closure for web browsers -/** - * isArray - */ - -var isArray = Array.isArray; - -/** - * toString - */ - -var str = Object.prototype.toString; - -/** - * Whether or not the given `val` - * is an array. - * - * example: - * - * isArray([]); - * // > true - * isArray(arguments); - * // > false - * isArray(''); - * // > false - * - * @param {mixed} val - * @return {bool} - */ - -module.exports = isArray || function (val) { - return !! val && '[object Array]' == str.call(val); -}; - -},{}],42:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// resolves . and .. elements in a path array with directory names there -// must be no slashes, empty elements, or device names (c:\) in the array -// (so also no leading and trailing slashes - it does not distinguish -// relative and absolute paths) -function normalizeArray(parts, allowAboveRoot) { - // if the path tries to go above the root, `up` ends up > 0 - var up = 0; - for (var i = parts.length - 1; i >= 0; i--) { - var last = parts[i]; - if (last === '.') { - parts.splice(i, 1); - } else if (last === '..') { - parts.splice(i, 1); - up++; - } else if (up) { - parts.splice(i, 1); - up--; - } - } - - // if the path is allowed to go above the root, restore leading ..s - if (allowAboveRoot) { - for (; up--; up) { - parts.unshift('..'); - } - } - - return parts; +if (typeof module === 'object' && module.exports) { + module.exports = LRUCache +} else { + // just set the global for non-node platforms. + this.LRUCache = LRUCache } -// Split a filename into [root, dir, basename, ext], unix version -// 'root' is just a slash, or nothing. -var splitPathRe = - /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/; -var splitPath = function(filename) { - return splitPathRe.exec(filename).slice(1); -}; - -// path.resolve([from ...], to) -// posix version -exports.resolve = function() { - var resolvedPath = '', - resolvedAbsolute = false; - - for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { - var path = (i >= 0) ? arguments[i] : process.cwd(); - - // Skip empty and invalid entries - if (typeof path !== 'string') { - throw new TypeError('Arguments to path.resolve must be strings'); - } else if (!path) { - continue; - } - - resolvedPath = path + '/' + resolvedPath; - resolvedAbsolute = path.charAt(0) === '/'; - } - - // At this point the path should be resolved to a full absolute path, but - // handle relative paths to be safe (might happen when process.cwd() fails) - - // Normalize the path - resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) { - return !!p; - }), !resolvedAbsolute).join('/'); - - return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; -}; - -// path.normalize(path) -// posix version -exports.normalize = function(path) { - var isAbsolute = exports.isAbsolute(path), - trailingSlash = substr(path, -1) === '/'; - - // Normalize the path - path = normalizeArray(filter(path.split('/'), function(p) { - return !!p; - }), !isAbsolute).join('/'); - - if (!path && !isAbsolute) { - path = '.'; - } - if (path && trailingSlash) { - path += '/'; - } - - return (isAbsolute ? '/' : '') + path; -}; - -// posix version -exports.isAbsolute = function(path) { - return path.charAt(0) === '/'; -}; - -// posix version -exports.join = function() { - var paths = Array.prototype.slice.call(arguments, 0); - return exports.normalize(filter(paths, function(p, index) { - if (typeof p !== 'string') { - throw new TypeError('Arguments to path.join must be strings'); - } - return p; - }).join('/')); -}; - - -// path.relative(from, to) -// posix version -exports.relative = function(from, to) { - from = exports.resolve(from).substr(1); - to = exports.resolve(to).substr(1); - - function trim(arr) { - var start = 0; - for (; start < arr.length; start++) { - if (arr[start] !== '') break; - } - - var end = arr.length - 1; - for (; end >= 0; end--) { - if (arr[end] !== '') break; - } - - if (start > end) return []; - return arr.slice(start, end - start + 1); - } - - var fromParts = trim(from.split('/')); - var toParts = trim(to.split('/')); - - var length = Math.min(fromParts.length, toParts.length); - var samePartsLength = length; - for (var i = 0; i < length; i++) { - if (fromParts[i] !== toParts[i]) { - samePartsLength = i; - break; - } - } - - var outputParts = []; - for (var i = samePartsLength; i < fromParts.length; i++) { - outputParts.push('..'); - } - - outputParts = outputParts.concat(toParts.slice(samePartsLength)); - - return outputParts.join('/'); -}; - -exports.sep = '/'; -exports.delimiter = ':'; - -exports.dirname = function(path) { - var result = splitPath(path), - root = result[0], - dir = result[1]; - - if (!root && !dir) { - // No dirname whatsoever - return '.'; - } - - if (dir) { - // It has a dirname, strip trailing slash - dir = dir.substr(0, dir.length - 1); - } - - return root + dir; -}; - - -exports.basename = function(path, ext) { - var f = splitPath(path)[2]; - // TODO: make this comparison case-insensitive on windows? - if (ext && f.substr(-1 * ext.length) === ext) { - f = f.substr(0, f.length - ext.length); - } - return f; -}; - - -exports.extname = function(path) { - return splitPath(path)[3]; -}; - -function filter (xs, f) { - if (xs.filter) return xs.filter(f); - var res = []; - for (var i = 0; i < xs.length; i++) { - if (f(xs[i], i, xs)) res.push(xs[i]); - } - return res; +function hOP (obj, key) { + return Object.prototype.hasOwnProperty.call(obj, key) } -// String.prototype.substr - negative index don't work in IE8 -var substr = 'ab'.substr(-1) === 'b' - ? function (str, start, len) { return str.substr(start, len) } - : function (str, start, len) { - if (start < 0) start = str.length + start; - return str.substr(start, len); - } -; +function naiveLength () { return 1 } -},{}],43:[function(require,module,exports){ -(function (global){ -/*! https://mths.be/punycode v1.3.2 by @mathias */ -;(function(root) { +function LRUCache (options) { + if (!(this instanceof LRUCache)) + return new LRUCache(options) - /** Detect free variables */ - var freeExports = typeof exports == 'object' && exports && - !exports.nodeType && exports; - var freeModule = typeof module == 'object' && module && - !module.nodeType && module; - var freeGlobal = typeof global == 'object' && global; - if ( - freeGlobal.global === freeGlobal || - freeGlobal.window === freeGlobal || - freeGlobal.self === freeGlobal - ) { - root = freeGlobal; - } + if (typeof options === 'number') + options = { max: options } - /** - * The `punycode` object. - * @name punycode - * @type Object - */ - var punycode, + if (!options) + options = {} - /** Highest positive signed 32-bit float value */ - maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1 + this._max = options.max + // Kind of weird to have a default max of Infinity, but oh well. + if (!this._max || !(typeof this._max === "number") || this._max <= 0 ) + this._max = Infinity - /** Bootstring parameters */ - base = 36, - tMin = 1, - tMax = 26, - skew = 38, - damp = 700, - initialBias = 72, - initialN = 128, // 0x80 - delimiter = '-', // '\x2D' + this._lengthCalculator = options.length || naiveLength + if (typeof this._lengthCalculator !== "function") + this._lengthCalculator = naiveLength - /** Regular expressions */ - regexPunycode = /^xn--/, - regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars - regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators - - /** Error messages */ - errors = { - 'overflow': 'Overflow: input needs wider integers to process', - 'not-basic': 'Illegal input >= 0x80 (not a basic code point)', - 'invalid-input': 'Invalid input' - }, - - /** Convenience shortcuts */ - baseMinusTMin = base - tMin, - floor = Math.floor, - stringFromCharCode = String.fromCharCode, - - /** Temporary variable */ - key; - - /*--------------------------------------------------------------------------*/ - - /** - * A generic error utility function. - * @private - * @param {String} type The error type. - * @returns {Error} Throws a `RangeError` with the applicable error message. - */ - function error(type) { - throw RangeError(errors[type]); - } - - /** - * A generic `Array#map` utility function. - * @private - * @param {Array} array The array to iterate over. - * @param {Function} callback The function that gets called for every array - * item. - * @returns {Array} A new array of values returned by the callback function. - */ - function map(array, fn) { - var length = array.length; - var result = []; - while (length--) { - result[length] = fn(array[length]); - } - return result; - } - - /** - * A simple `Array#map`-like wrapper to work with domain name strings or email - * addresses. - * @private - * @param {String} domain The domain name or email address. - * @param {Function} callback The function that gets called for every - * character. - * @returns {Array} A new string of characters returned by the callback - * function. - */ - function mapDomain(string, fn) { - var parts = string.split('@'); - var result = ''; - if (parts.length > 1) { - // In email addresses, only the domain name should be punycoded. Leave - // the local part (i.e. everything up to `@`) intact. - result = parts[0] + '@'; - string = parts[1]; - } - // Avoid `split(regex)` for IE8 compatibility. See #17. - string = string.replace(regexSeparators, '\x2E'); - var labels = string.split('.'); - var encoded = map(labels, fn).join('.'); - return result + encoded; - } - - /** - * Creates an array containing the numeric code points of each Unicode - * character in the string. While JavaScript uses UCS-2 internally, - * this function will convert a pair of surrogate halves (each of which - * UCS-2 exposes as separate characters) into a single code point, - * matching UTF-16. - * @see `punycode.ucs2.encode` - * @see - * @memberOf punycode.ucs2 - * @name decode - * @param {String} string The Unicode input string (UCS-2). - * @returns {Array} The new array of code points. - */ - function ucs2decode(string) { - var output = [], - counter = 0, - length = string.length, - value, - extra; - while (counter < length) { - value = string.charCodeAt(counter++); - if (value >= 0xD800 && value <= 0xDBFF && counter < length) { - // high surrogate, and there is a next character - extra = string.charCodeAt(counter++); - if ((extra & 0xFC00) == 0xDC00) { // low surrogate - output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); - } else { - // unmatched surrogate; only append this code unit, in case the next - // code unit is the high surrogate of a surrogate pair - output.push(value); - counter--; - } - } else { - output.push(value); - } - } - return output; - } - - /** - * Creates a string based on an array of numeric code points. - * @see `punycode.ucs2.decode` - * @memberOf punycode.ucs2 - * @name encode - * @param {Array} codePoints The array of numeric code points. - * @returns {String} The new Unicode string (UCS-2). - */ - function ucs2encode(array) { - return map(array, function(value) { - var output = ''; - if (value > 0xFFFF) { - value -= 0x10000; - output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); - value = 0xDC00 | value & 0x3FF; - } - output += stringFromCharCode(value); - return output; - }).join(''); - } - - /** - * Converts a basic code point into a digit/integer. - * @see `digitToBasic()` - * @private - * @param {Number} codePoint The basic numeric code point value. - * @returns {Number} The numeric value of a basic code point (for use in - * representing integers) in the range `0` to `base - 1`, or `base` if - * the code point does not represent a value. - */ - function basicToDigit(codePoint) { - if (codePoint - 48 < 10) { - return codePoint - 22; - } - if (codePoint - 65 < 26) { - return codePoint - 65; - } - if (codePoint - 97 < 26) { - return codePoint - 97; - } - return base; - } - - /** - * Converts a digit/integer into a basic code point. - * @see `basicToDigit()` - * @private - * @param {Number} digit The numeric value of a basic code point. - * @returns {Number} The basic code point whose value (when used for - * representing integers) is `digit`, which needs to be in the range - * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is - * used; else, the lowercase form is used. The behavior is undefined - * if `flag` is non-zero and `digit` has no uppercase form. - */ - function digitToBasic(digit, flag) { - // 0..25 map to ASCII a..z or A..Z - // 26..35 map to ASCII 0..9 - return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5); - } - - /** - * Bias adaptation function as per section 3.4 of RFC 3492. - * http://tools.ietf.org/html/rfc3492#section-3.4 - * @private - */ - function adapt(delta, numPoints, firstTime) { - var k = 0; - delta = firstTime ? floor(delta / damp) : delta >> 1; - delta += floor(delta / numPoints); - for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) { - delta = floor(delta / baseMinusTMin); - } - return floor(k + (baseMinusTMin + 1) * delta / (delta + skew)); - } - - /** - * Converts a Punycode string of ASCII-only symbols to a string of Unicode - * symbols. - * @memberOf punycode - * @param {String} input The Punycode string of ASCII-only symbols. - * @returns {String} The resulting string of Unicode symbols. - */ - function decode(input) { - // Don't use UCS-2 - var output = [], - inputLength = input.length, - out, - i = 0, - n = initialN, - bias = initialBias, - basic, - j, - index, - oldi, - w, - k, - digit, - t, - /** Cached calculation results */ - baseMinusT; - - // Handle the basic code points: let `basic` be the number of input code - // points before the last delimiter, or `0` if there is none, then copy - // the first basic code points to the output. - - basic = input.lastIndexOf(delimiter); - if (basic < 0) { - basic = 0; - } - - for (j = 0; j < basic; ++j) { - // if it's not a basic code point - if (input.charCodeAt(j) >= 0x80) { - error('not-basic'); - } - output.push(input.charCodeAt(j)); - } - - // Main decoding loop: start just after the last delimiter if any basic code - // points were copied; start at the beginning otherwise. - - for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) { - - // `index` is the index of the next character to be consumed. - // Decode a generalized variable-length integer into `delta`, - // which gets added to `i`. The overflow checking is easier - // if we increase `i` as we go, then subtract off its starting - // value at the end to obtain `delta`. - for (oldi = i, w = 1, k = base; /* no condition */; k += base) { - - if (index >= inputLength) { - error('invalid-input'); - } - - digit = basicToDigit(input.charCodeAt(index++)); - - if (digit >= base || digit > floor((maxInt - i) / w)) { - error('overflow'); - } - - i += digit * w; - t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); - - if (digit < t) { - break; - } - - baseMinusT = base - t; - if (w > floor(maxInt / baseMinusT)) { - error('overflow'); - } - - w *= baseMinusT; - - } - - out = output.length + 1; - bias = adapt(i - oldi, out, oldi == 0); - - // `i` was supposed to wrap around from `out` to `0`, - // incrementing `n` each time, so we'll fix that now: - if (floor(i / out) > maxInt - n) { - error('overflow'); - } - - n += floor(i / out); - i %= out; - - // Insert `n` at position `i` of the output - output.splice(i++, 0, n); - - } - - return ucs2encode(output); - } - - /** - * Converts a string of Unicode symbols (e.g. a domain name label) to a - * Punycode string of ASCII-only symbols. - * @memberOf punycode - * @param {String} input The string of Unicode symbols. - * @returns {String} The resulting Punycode string of ASCII-only symbols. - */ - function encode(input) { - var n, - delta, - handledCPCount, - basicLength, - bias, - j, - m, - q, - k, - t, - currentValue, - output = [], - /** `inputLength` will hold the number of code points in `input`. */ - inputLength, - /** Cached calculation results */ - handledCPCountPlusOne, - baseMinusT, - qMinusT; - - // Convert the input in UCS-2 to Unicode - input = ucs2decode(input); - - // Cache the length - inputLength = input.length; - - // Initialize the state - n = initialN; - delta = 0; - bias = initialBias; - - // Handle the basic code points - for (j = 0; j < inputLength; ++j) { - currentValue = input[j]; - if (currentValue < 0x80) { - output.push(stringFromCharCode(currentValue)); - } - } - - handledCPCount = basicLength = output.length; - - // `handledCPCount` is the number of code points that have been handled; - // `basicLength` is the number of basic code points. - - // Finish the basic string - if it is not empty - with a delimiter - if (basicLength) { - output.push(delimiter); - } - - // Main encoding loop: - while (handledCPCount < inputLength) { - - // All non-basic code points < n have been handled already. Find the next - // larger one: - for (m = maxInt, j = 0; j < inputLength; ++j) { - currentValue = input[j]; - if (currentValue >= n && currentValue < m) { - m = currentValue; - } - } - - // Increase `delta` enough to advance the decoder's state to , - // but guard against overflow - handledCPCountPlusOne = handledCPCount + 1; - if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) { - error('overflow'); - } - - delta += (m - n) * handledCPCountPlusOne; - n = m; - - for (j = 0; j < inputLength; ++j) { - currentValue = input[j]; - - if (currentValue < n && ++delta > maxInt) { - error('overflow'); - } - - if (currentValue == n) { - // Represent delta as a generalized variable-length integer - for (q = delta, k = base; /* no condition */; k += base) { - t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); - if (q < t) { - break; - } - qMinusT = q - t; - baseMinusT = base - t; - output.push( - stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)) - ); - q = floor(qMinusT / baseMinusT); - } - - output.push(stringFromCharCode(digitToBasic(q, 0))); - bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength); - delta = 0; - ++handledCPCount; - } - } - - ++delta; - ++n; - - } - return output.join(''); - } - - /** - * Converts a Punycode string representing a domain name or an email address - * to Unicode. Only the Punycoded parts of the input will be converted, i.e. - * it doesn't matter if you call it on a string that has already been - * converted to Unicode. - * @memberOf punycode - * @param {String} input The Punycoded domain name or email address to - * convert to Unicode. - * @returns {String} The Unicode representation of the given Punycode - * string. - */ - function toUnicode(input) { - return mapDomain(input, function(string) { - return regexPunycode.test(string) - ? decode(string.slice(4).toLowerCase()) - : string; - }); - } - - /** - * Converts a Unicode string representing a domain name or an email address to - * Punycode. Only the non-ASCII parts of the domain name will be converted, - * i.e. it doesn't matter if you call it with a domain that's already in - * ASCII. - * @memberOf punycode - * @param {String} input The domain name or email address to convert, as a - * Unicode string. - * @returns {String} The Punycode representation of the given domain name or - * email address. - */ - function toASCII(input) { - return mapDomain(input, function(string) { - return regexNonASCII.test(string) - ? 'xn--' + encode(string) - : string; - }); - } - - /*--------------------------------------------------------------------------*/ - - /** Define the public API */ - punycode = { - /** - * A string representing the current Punycode.js version number. - * @memberOf punycode - * @type String - */ - 'version': '1.3.2', - /** - * An object of methods to convert from JavaScript's internal character - * representation (UCS-2) to Unicode code points, and back. - * @see - * @memberOf punycode - * @type Object - */ - 'ucs2': { - 'decode': ucs2decode, - 'encode': ucs2encode - }, - 'decode': decode, - 'encode': encode, - 'toASCII': toASCII, - 'toUnicode': toUnicode - }; - - /** Expose `punycode` */ - // Some AMD build optimizers, like r.js, check for specific condition patterns - // like the following: - if ( - typeof define == 'function' && - typeof define.amd == 'object' && - define.amd - ) { - define('punycode', function() { - return punycode; - }); - } else if (freeExports && freeModule) { - if (module.exports == freeExports) { // in Node.js or RingoJS v0.8.0+ - freeModule.exports = punycode; - } else { // in Narwhal or RingoJS v0.7.0- - for (key in punycode) { - punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]); - } - } - } else { // in Rhino or a web browser - root.punycode = punycode; - } - -}(this)); - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],44:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; - -// If obj.hasOwnProperty has been overridden, then calling -// obj.hasOwnProperty(prop) will break. -// See: https://github.com/joyent/node/issues/1707 -function hasOwnProperty(obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); + this._allowStale = options.stale || false + this._maxAge = options.maxAge || null + this._dispose = options.dispose + this.reset() } -module.exports = function(qs, sep, eq, options) { - sep = sep || '&'; - eq = eq || '='; - var obj = {}; - - if (typeof qs !== 'string' || qs.length === 0) { - return obj; - } - - var regexp = /\+/g; - qs = qs.split(sep); - - var maxKeys = 1000; - if (options && typeof options.maxKeys === 'number') { - maxKeys = options.maxKeys; - } - - var len = qs.length; - // maxKeys <= 0 means that we should not limit keys count - if (maxKeys > 0 && len > maxKeys) { - len = maxKeys; - } - - for (var i = 0; i < len; ++i) { - var x = qs[i].replace(regexp, '%20'), - idx = x.indexOf(eq), - kstr, vstr, k, v; - - if (idx >= 0) { - kstr = x.substr(0, idx); - vstr = x.substr(idx + 1); - } else { - kstr = x; - vstr = ''; +// resize the cache when the max changes. +Object.defineProperty(LRUCache.prototype, "max", + { set : function (mL) { + if (!mL || !(typeof mL === "number") || mL <= 0 ) mL = Infinity + this._max = mL + if (this._length > this._max) trim(this) } + , get : function () { return this._max } + , enumerable : true + }) - k = decodeURIComponent(kstr); - v = decodeURIComponent(vstr); - - if (!hasOwnProperty(obj, k)) { - obj[k] = v; - } else if (isArray(obj[k])) { - obj[k].push(v); - } else { - obj[k] = [obj[k], v]; - } - } - - return obj; -}; - -var isArray = Array.isArray || function (xs) { - return Object.prototype.toString.call(xs) === '[object Array]'; -}; - -},{}],45:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; - -var stringifyPrimitive = function(v) { - switch (typeof v) { - case 'string': - return v; - - case 'boolean': - return v ? 'true' : 'false'; - - case 'number': - return isFinite(v) ? v : ''; - - default: - return ''; - } -}; - -module.exports = function(obj, sep, eq, name) { - sep = sep || '&'; - eq = eq || '='; - if (obj === null) { - obj = undefined; - } - - if (typeof obj === 'object') { - return map(objectKeys(obj), function(k) { - var ks = encodeURIComponent(stringifyPrimitive(k)) + eq; - if (isArray(obj[k])) { - return map(obj[k], function(v) { - return ks + encodeURIComponent(stringifyPrimitive(v)); - }).join(sep); +// resize the cache when the lengthCalculator changes. +Object.defineProperty(LRUCache.prototype, "lengthCalculator", + { set : function (lC) { + if (typeof lC !== "function") { + this._lengthCalculator = naiveLength + this._length = this._itemCount + for (var key in this._cache) { + this._cache[key].length = 1 + } } else { - return ks + encodeURIComponent(stringifyPrimitive(obj[k])); - } - }).join(sep); - - } - - if (!name) return ''; - return encodeURIComponent(stringifyPrimitive(name)) + eq + - encodeURIComponent(stringifyPrimitive(obj)); -}; - -var isArray = Array.isArray || function (xs) { - return Object.prototype.toString.call(xs) === '[object Array]'; -}; - -function map (xs, f) { - if (xs.map) return xs.map(f); - var res = []; - for (var i = 0; i < xs.length; i++) { - res.push(f(xs[i], i)); - } - return res; -} - -var objectKeys = Object.keys || function (obj) { - var res = []; - for (var key in obj) { - if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key); - } - return res; -}; - -},{}],46:[function(require,module,exports){ -'use strict'; - -exports.decode = exports.parse = require('./decode'); -exports.encode = exports.stringify = require('./encode'); - -},{"./decode":44,"./encode":45}],47:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var punycode = require('punycode'); - -exports.parse = urlParse; -exports.resolve = urlResolve; -exports.resolveObject = urlResolveObject; -exports.format = urlFormat; - -exports.Url = Url; - -function Url() { - this.protocol = null; - this.slashes = null; - this.auth = null; - this.host = null; - this.port = null; - this.hostname = null; - this.hash = null; - this.search = null; - this.query = null; - this.pathname = null; - this.path = null; - this.href = null; -} - -// Reference: RFC 3986, RFC 1808, RFC 2396 - -// define these here so at least they only have to be -// compiled once on the first module load. -var protocolPattern = /^([a-z0-9.+-]+:)/i, - portPattern = /:[0-9]*$/, - - // RFC 2396: characters reserved for delimiting URLs. - // We actually just auto-escape these. - delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'], - - // RFC 2396: characters not allowed for various reasons. - unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims), - - // Allowed by RFCs, but cause of XSS attacks. Always escape these. - autoEscape = ['\''].concat(unwise), - // Characters that are never ever allowed in a hostname. - // Note that any invalid chars are also handled, but these - // are the ones that are *expected* to be seen, so we fast-path - // them. - nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape), - hostEndingChars = ['/', '?', '#'], - hostnameMaxLen = 255, - hostnamePartPattern = /^[a-z0-9A-Z_-]{0,63}$/, - hostnamePartStart = /^([a-z0-9A-Z_-]{0,63})(.*)$/, - // protocols that can allow "unsafe" and "unwise" chars. - unsafeProtocol = { - 'javascript': true, - 'javascript:': true - }, - // protocols that never have a hostname. - hostlessProtocol = { - 'javascript': true, - 'javascript:': true - }, - // protocols that always contain a // bit. - slashedProtocol = { - 'http': true, - 'https': true, - 'ftp': true, - 'gopher': true, - 'file': true, - 'http:': true, - 'https:': true, - 'ftp:': true, - 'gopher:': true, - 'file:': true - }, - querystring = require('querystring'); - -function urlParse(url, parseQueryString, slashesDenoteHost) { - if (url && isObject(url) && url instanceof Url) return url; - - var u = new Url; - u.parse(url, parseQueryString, slashesDenoteHost); - return u; -} - -Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) { - if (!isString(url)) { - throw new TypeError("Parameter 'url' must be a string, not " + typeof url); - } - - var rest = url; - - // trim before proceeding. - // This is to support parse stuff like " http://foo.com \n" - rest = rest.trim(); - - var proto = protocolPattern.exec(rest); - if (proto) { - proto = proto[0]; - var lowerProto = proto.toLowerCase(); - this.protocol = lowerProto; - rest = rest.substr(proto.length); - } - - // figure out if it's got a host - // user@server is *always* interpreted as a hostname, and url - // resolution will treat //foo/bar as host=foo,path=bar because that's - // how the browser resolves relative URLs. - if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) { - var slashes = rest.substr(0, 2) === '//'; - if (slashes && !(proto && hostlessProtocol[proto])) { - rest = rest.substr(2); - this.slashes = true; - } - } - - if (!hostlessProtocol[proto] && - (slashes || (proto && !slashedProtocol[proto]))) { - - // there's a hostname. - // the first instance of /, ?, ;, or # ends the host. - // - // If there is an @ in the hostname, then non-host chars *are* allowed - // to the left of the last @ sign, unless some host-ending character - // comes *before* the @-sign. - // URLs are obnoxious. - // - // ex: - // http://a@b@c/ => user:a@b host:c - // http://a@b?@c => user:a host:c path:/?@c - - // v0.12 TODO(isaacs): This is not quite how Chrome does things. - // Review our test case against browsers more comprehensively. - - // find the first instance of any hostEndingChars - var hostEnd = -1; - for (var i = 0; i < hostEndingChars.length; i++) { - var hec = rest.indexOf(hostEndingChars[i]); - if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) - hostEnd = hec; - } - - // at this point, either we have an explicit point where the - // auth portion cannot go past, or the last @ char is the decider. - var auth, atSign; - if (hostEnd === -1) { - // atSign can be anywhere. - atSign = rest.lastIndexOf('@'); - } else { - // atSign must be in auth portion. - // http://a@b/c@d => host:b auth:a path:/c@d - atSign = rest.lastIndexOf('@', hostEnd); - } - - // Now we have a portion which is definitely the auth. - // Pull that off. - if (atSign !== -1) { - auth = rest.slice(0, atSign); - rest = rest.slice(atSign + 1); - this.auth = decodeURIComponent(auth); - } - - // the host is the remaining to the left of the first non-host char - hostEnd = -1; - for (var i = 0; i < nonHostChars.length; i++) { - var hec = rest.indexOf(nonHostChars[i]); - if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) - hostEnd = hec; - } - // if we still have not hit it, then the entire thing is a host. - if (hostEnd === -1) - hostEnd = rest.length; - - this.host = rest.slice(0, hostEnd); - rest = rest.slice(hostEnd); - - // pull out port. - this.parseHost(); - - // we've indicated that there is a hostname, - // so even if it's empty, it has to be present. - this.hostname = this.hostname || ''; - - // if hostname begins with [ and ends with ] - // assume that it's an IPv6 address. - var ipv6Hostname = this.hostname[0] === '[' && - this.hostname[this.hostname.length - 1] === ']'; - - // validate a little. - if (!ipv6Hostname) { - var hostparts = this.hostname.split(/\./); - for (var i = 0, l = hostparts.length; i < l; i++) { - var part = hostparts[i]; - if (!part) continue; - if (!part.match(hostnamePartPattern)) { - var newpart = ''; - for (var j = 0, k = part.length; j < k; j++) { - if (part.charCodeAt(j) > 127) { - // we replace non-ASCII char with a temporary placeholder - // we need this to make sure size of hostname is not - // broken by replacing non-ASCII by nothing - newpart += 'x'; - } else { - newpart += part[j]; - } - } - // we test again with ASCII char only - if (!newpart.match(hostnamePartPattern)) { - var validParts = hostparts.slice(0, i); - var notHost = hostparts.slice(i + 1); - var bit = part.match(hostnamePartStart); - if (bit) { - validParts.push(bit[1]); - notHost.unshift(bit[2]); - } - if (notHost.length) { - rest = '/' + notHost.join('.') + rest; - } - this.hostname = validParts.join('.'); - break; - } + this._lengthCalculator = lC + this._length = 0 + for (var key in this._cache) { + this._cache[key].length = this._lengthCalculator(this._cache[key].value) + this._length += this._cache[key].length } } - } - if (this.hostname.length > hostnameMaxLen) { - this.hostname = ''; + if (this._length > this._max) trim(this) + } + , get : function () { return this._lengthCalculator } + , enumerable : true + }) + +Object.defineProperty(LRUCache.prototype, "length", + { get : function () { return this._length } + , enumerable : true + }) + + +Object.defineProperty(LRUCache.prototype, "itemCount", + { get : function () { return this._itemCount } + , enumerable : true + }) + +LRUCache.prototype.forEach = function (fn, thisp) { + thisp = thisp || this + var i = 0; + for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) { + i++ + var hit = this._lruList[k] + if (this._maxAge && (Date.now() - hit.now > this._maxAge)) { + del(this, hit) + if (!this._allowStale) hit = undefined + } + if (hit) { + fn.call(thisp, hit.value, hit.key, this) + } + } +} + +LRUCache.prototype.keys = function () { + var keys = new Array(this._itemCount) + var i = 0 + for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) { + var hit = this._lruList[k] + keys[i++] = hit.key + } + return keys +} + +LRUCache.prototype.values = function () { + var values = new Array(this._itemCount) + var i = 0 + for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) { + var hit = this._lruList[k] + values[i++] = hit.value + } + return values +} + +LRUCache.prototype.reset = function () { + if (this._dispose && this._cache) { + for (var k in this._cache) { + this._dispose(k, this._cache[k].value) + } + } + + this._cache = Object.create(null) // hash of items by key + this._lruList = Object.create(null) // list of items in order of use recency + this._mru = 0 // most recently used + this._lru = 0 // least recently used + this._length = 0 // number of items in the list + this._itemCount = 0 +} + +// Provided for debugging/dev purposes only. No promises whatsoever that +// this API stays stable. +LRUCache.prototype.dump = function () { + return this._cache +} + +LRUCache.prototype.dumpLru = function () { + return this._lruList +} + +LRUCache.prototype.set = function (key, value) { + if (hOP(this._cache, key)) { + // dispose of the old one before overwriting + if (this._dispose) this._dispose(key, this._cache[key].value) + if (this._maxAge) this._cache[key].now = Date.now() + this._cache[key].value = value + this.get(key) + return true + } + + var len = this._lengthCalculator(value) + var age = this._maxAge ? Date.now() : 0 + var hit = new Entry(key, value, this._mru++, len, age) + + // oversized objects fall out of cache automatically. + if (hit.length > this._max) { + if (this._dispose) this._dispose(key, value) + return false + } + + this._length += hit.length + this._lruList[hit.lu] = this._cache[key] = hit + this._itemCount ++ + + if (this._length > this._max) trim(this) + return true +} + +LRUCache.prototype.has = function (key) { + if (!hOP(this._cache, key)) return false + var hit = this._cache[key] + if (this._maxAge && (Date.now() - hit.now > this._maxAge)) { + return false + } + return true +} + +LRUCache.prototype.get = function (key) { + return get(this, key, true) +} + +LRUCache.prototype.peek = function (key) { + return get(this, key, false) +} + +LRUCache.prototype.pop = function () { + var hit = this._lruList[this._lru] + del(this, hit) + return hit || null +} + +LRUCache.prototype.del = function (key) { + del(this, this._cache[key]) +} + +function get (self, key, doUse) { + var hit = self._cache[key] + if (hit) { + if (self._maxAge && (Date.now() - hit.now > self._maxAge)) { + del(self, hit) + if (!self._allowStale) hit = undefined } else { - // hostnames are always lower case. - this.hostname = this.hostname.toLowerCase(); - } - - if (!ipv6Hostname) { - // IDNA Support: Returns a puny coded representation of "domain". - // It only converts the part of the domain name that - // has non ASCII characters. I.e. it dosent matter if - // you call it with a domain that already is in ASCII. - var domainArray = this.hostname.split('.'); - var newOut = []; - for (var i = 0; i < domainArray.length; ++i) { - var s = domainArray[i]; - newOut.push(s.match(/[^A-Za-z0-9_-]/) ? - 'xn--' + punycode.encode(s) : s); - } - this.hostname = newOut.join('.'); - } - - var p = this.port ? ':' + this.port : ''; - var h = this.hostname || ''; - this.host = h + p; - this.href += this.host; - - // strip [ and ] from the hostname - // the host field still retains them, though - if (ipv6Hostname) { - this.hostname = this.hostname.substr(1, this.hostname.length - 2); - if (rest[0] !== '/') { - rest = '/' + rest; - } + if (doUse) use(self, hit) } + if (hit) hit = hit.value } - - // now rest is set to the post-host stuff. - // chop off any delim chars. - if (!unsafeProtocol[lowerProto]) { - - // First, make 100% sure that any "autoEscape" chars get - // escaped, even if encodeURIComponent doesn't think they - // need to be. - for (var i = 0, l = autoEscape.length; i < l; i++) { - var ae = autoEscape[i]; - var esc = encodeURIComponent(ae); - if (esc === ae) { - esc = escape(ae); - } - rest = rest.split(ae).join(esc); - } - } - - - // chop off from the tail first. - var hash = rest.indexOf('#'); - if (hash !== -1) { - // got a fragment string. - this.hash = rest.substr(hash); - rest = rest.slice(0, hash); - } - var qm = rest.indexOf('?'); - if (qm !== -1) { - this.search = rest.substr(qm); - this.query = rest.substr(qm + 1); - if (parseQueryString) { - this.query = querystring.parse(this.query); - } - rest = rest.slice(0, qm); - } else if (parseQueryString) { - // no query string, but parseQueryString still requested - this.search = ''; - this.query = {}; - } - if (rest) this.pathname = rest; - if (slashedProtocol[lowerProto] && - this.hostname && !this.pathname) { - this.pathname = '/'; - } - - //to support http.request - if (this.pathname || this.search) { - var p = this.pathname || ''; - var s = this.search || ''; - this.path = p + s; - } - - // finally, reconstruct the href based on what has been validated. - this.href = this.format(); - return this; -}; - -// format a parsed object into a url string -function urlFormat(obj) { - // ensure it's an object, and not a string url. - // If it's an obj, this is a no-op. - // this way, you can call url_format() on strings - // to clean up potentially wonky urls. - if (isString(obj)) obj = urlParse(obj); - if (!(obj instanceof Url)) return Url.prototype.format.call(obj); - return obj.format(); + return hit } -Url.prototype.format = function() { - var auth = this.auth || ''; - if (auth) { - auth = encodeURIComponent(auth); - auth = auth.replace(/%3A/i, ':'); - auth += '@'; - } - - var protocol = this.protocol || '', - pathname = this.pathname || '', - hash = this.hash || '', - host = false, - query = ''; - - if (this.host) { - host = auth + this.host; - } else if (this.hostname) { - host = auth + (this.hostname.indexOf(':') === -1 ? - this.hostname : - '[' + this.hostname + ']'); - if (this.port) { - host += ':' + this.port; - } - } - - if (this.query && - isObject(this.query) && - Object.keys(this.query).length) { - query = querystring.stringify(this.query); - } - - var search = this.search || (query && ('?' + query)) || ''; - - if (protocol && protocol.substr(-1) !== ':') protocol += ':'; - - // only the slashedProtocols get the //. Not mailto:, xmpp:, etc. - // unless they had them to begin with. - if (this.slashes || - (!protocol || slashedProtocol[protocol]) && host !== false) { - host = '//' + (host || ''); - if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname; - } else if (!host) { - host = ''; - } - - if (hash && hash.charAt(0) !== '#') hash = '#' + hash; - if (search && search.charAt(0) !== '?') search = '?' + search; - - pathname = pathname.replace(/[?#]/g, function(match) { - return encodeURIComponent(match); - }); - search = search.replace('#', '%23'); - - return protocol + host + pathname + search + hash; -}; - -function urlResolve(source, relative) { - return urlParse(source, false, true).resolve(relative); +function use (self, hit) { + shiftLU(self, hit) + hit.lu = self._mru ++ + if (self._maxAge) hit.now = Date.now() + self._lruList[hit.lu] = hit } -Url.prototype.resolve = function(relative) { - return this.resolveObject(urlParse(relative, false, true)).format(); -}; - -function urlResolveObject(source, relative) { - if (!source) return relative; - return urlParse(source, false, true).resolveObject(relative); +function trim (self) { + while (self._lru < self._mru && self._length > self._max) + del(self, self._lruList[self._lru]) } -Url.prototype.resolveObject = function(relative) { - if (isString(relative)) { - var rel = new Url(); - rel.parse(relative, false, true); - relative = rel; - } - - var result = new Url(); - Object.keys(this).forEach(function(k) { - result[k] = this[k]; - }, this); - - // hash is always overridden, no matter what. - // even href="" will remove it. - result.hash = relative.hash; - - // if the relative url is empty, then there's nothing left to do here. - if (relative.href === '') { - result.href = result.format(); - return result; - } - - // hrefs like //foo/bar always cut to the protocol. - if (relative.slashes && !relative.protocol) { - // take everything except the protocol from relative - Object.keys(relative).forEach(function(k) { - if (k !== 'protocol') - result[k] = relative[k]; - }); - - //urlParse appends trailing / to urls like http://www.example.com - if (slashedProtocol[result.protocol] && - result.hostname && !result.pathname) { - result.path = result.pathname = '/'; - } - - result.href = result.format(); - return result; - } - - if (relative.protocol && relative.protocol !== result.protocol) { - // if it's a known url protocol, then changing - // the protocol does weird things - // first, if it's not file:, then we MUST have a host, - // and if there was a path - // to begin with, then we MUST have a path. - // if it is file:, then the host is dropped, - // because that's known to be hostless. - // anything else is assumed to be absolute. - if (!slashedProtocol[relative.protocol]) { - Object.keys(relative).forEach(function(k) { - result[k] = relative[k]; - }); - result.href = result.format(); - return result; - } - - result.protocol = relative.protocol; - if (!relative.host && !hostlessProtocol[relative.protocol]) { - var relPath = (relative.pathname || '').split('/'); - while (relPath.length && !(relative.host = relPath.shift())); - if (!relative.host) relative.host = ''; - if (!relative.hostname) relative.hostname = ''; - if (relPath[0] !== '') relPath.unshift(''); - if (relPath.length < 2) relPath.unshift(''); - result.pathname = relPath.join('/'); - } else { - result.pathname = relative.pathname; - } - result.search = relative.search; - result.query = relative.query; - result.host = relative.host || ''; - result.auth = relative.auth; - result.hostname = relative.hostname || relative.host; - result.port = relative.port; - // to support http.request - if (result.pathname || result.search) { - var p = result.pathname || ''; - var s = result.search || ''; - result.path = p + s; - } - result.slashes = result.slashes || relative.slashes; - result.href = result.format(); - return result; - } - - var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'), - isRelAbs = ( - relative.host || - relative.pathname && relative.pathname.charAt(0) === '/' - ), - mustEndAbs = (isRelAbs || isSourceAbs || - (result.host && relative.pathname)), - removeAllDots = mustEndAbs, - srcPath = result.pathname && result.pathname.split('/') || [], - relPath = relative.pathname && relative.pathname.split('/') || [], - psychotic = result.protocol && !slashedProtocol[result.protocol]; - - // if the url is a non-slashed url, then relative - // links like ../.. should be able - // to crawl up to the hostname, as well. This is strange. - // result.protocol has already been set by now. - // Later on, put the first path part into the host field. - if (psychotic) { - result.hostname = ''; - result.port = null; - if (result.host) { - if (srcPath[0] === '') srcPath[0] = result.host; - else srcPath.unshift(result.host); - } - result.host = ''; - if (relative.protocol) { - relative.hostname = null; - relative.port = null; - if (relative.host) { - if (relPath[0] === '') relPath[0] = relative.host; - else relPath.unshift(relative.host); - } - relative.host = null; - } - mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === ''); - } - - if (isRelAbs) { - // it's absolute. - result.host = (relative.host || relative.host === '') ? - relative.host : result.host; - result.hostname = (relative.hostname || relative.hostname === '') ? - relative.hostname : result.hostname; - result.search = relative.search; - result.query = relative.query; - srcPath = relPath; - // fall through to the dot-handling below. - } else if (relPath.length) { - // it's relative - // throw away the existing file, and take the new path instead. - if (!srcPath) srcPath = []; - srcPath.pop(); - srcPath = srcPath.concat(relPath); - result.search = relative.search; - result.query = relative.query; - } else if (!isNullOrUndefined(relative.search)) { - // just pull out the search. - // like href='?foo'. - // Put this after the other two cases because it simplifies the booleans - if (psychotic) { - result.hostname = result.host = srcPath.shift(); - //occationaly the auth can get stuck only in host - //this especialy happens in cases like - //url.resolveObject('mailto:local1@domain1', 'local2@domain2') - var authInHost = result.host && result.host.indexOf('@') > 0 ? - result.host.split('@') : false; - if (authInHost) { - result.auth = authInHost.shift(); - result.host = result.hostname = authInHost.shift(); - } - } - result.search = relative.search; - result.query = relative.query; - //to support http.request - if (!isNull(result.pathname) || !isNull(result.search)) { - result.path = (result.pathname ? result.pathname : '') + - (result.search ? result.search : ''); - } - result.href = result.format(); - return result; - } - - if (!srcPath.length) { - // no path at all. easy. - // we've already handled the other stuff above. - result.pathname = null; - //to support http.request - if (result.search) { - result.path = '/' + result.search; - } else { - result.path = null; - } - result.href = result.format(); - return result; - } - - // if a url ENDs in . or .., then it must get a trailing slash. - // however, if it ends in anything else non-slashy, - // then it must NOT get a trailing slash. - var last = srcPath.slice(-1)[0]; - var hasTrailingSlash = ( - (result.host || relative.host) && (last === '.' || last === '..') || - last === ''); - - // strip single dots, resolve double dots to parent dir - // if the path tries to go above the root, `up` ends up > 0 - var up = 0; - for (var i = srcPath.length; i >= 0; i--) { - last = srcPath[i]; - if (last == '.') { - srcPath.splice(i, 1); - } else if (last === '..') { - srcPath.splice(i, 1); - up++; - } else if (up) { - srcPath.splice(i, 1); - up--; - } - } - - // if the path is allowed to go above the root, restore leading ..s - if (!mustEndAbs && !removeAllDots) { - for (; up--; up) { - srcPath.unshift('..'); - } - } - - if (mustEndAbs && srcPath[0] !== '' && - (!srcPath[0] || srcPath[0].charAt(0) !== '/')) { - srcPath.unshift(''); - } - - if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) { - srcPath.push(''); - } - - var isAbsolute = srcPath[0] === '' || - (srcPath[0] && srcPath[0].charAt(0) === '/'); - - // put the host back - if (psychotic) { - result.hostname = result.host = isAbsolute ? '' : - srcPath.length ? srcPath.shift() : ''; - //occationaly the auth can get stuck only in host - //this especialy happens in cases like - //url.resolveObject('mailto:local1@domain1', 'local2@domain2') - var authInHost = result.host && result.host.indexOf('@') > 0 ? - result.host.split('@') : false; - if (authInHost) { - result.auth = authInHost.shift(); - result.host = result.hostname = authInHost.shift(); - } - } - - mustEndAbs = mustEndAbs || (result.host && srcPath.length); - - if (mustEndAbs && !isAbsolute) { - srcPath.unshift(''); - } - - if (!srcPath.length) { - result.pathname = null; - result.path = null; - } else { - result.pathname = srcPath.join('/'); - } - - //to support request.http - if (!isNull(result.pathname) || !isNull(result.search)) { - result.path = (result.pathname ? result.pathname : '') + - (result.search ? result.search : ''); - } - result.auth = relative.auth || result.auth; - result.slashes = result.slashes || relative.slashes; - result.href = result.format(); - return result; -}; - -Url.prototype.parseHost = function() { - var host = this.host; - var port = portPattern.exec(host); - if (port) { - port = port[0]; - if (port !== ':') { - this.port = port.substr(1); - } - host = host.substr(0, host.length - port.length); - } - if (host) this.hostname = host; -}; - -function isString(arg) { - return typeof arg === "string"; +function shiftLU (self, hit) { + delete self._lruList[ hit.lu ] + while (self._lru < self._mru && !self._lruList[self._lru]) self._lru ++ } -function isObject(arg) { - return typeof arg === 'object' && arg !== null; +function del (self, hit) { + if (hit) { + if (self._dispose) self._dispose(hit.key, hit.value) + self._length -= hit.length + self._itemCount -- + delete self._cache[ hit.key ] + shiftLU(self, hit) + } } -function isNull(arg) { - return arg === null; -} -function isNullOrUndefined(arg) { - return arg == null; +// classy, since V8 prefers predictable objects. +function Entry (key, value, lu, length, now) { + this.key = key + this.value = value + this.lu = lu + this.length = length + this.now = now } -},{"punycode":43,"querystring":46}],48:[function(require,module,exports){ +})() + +},{}],41:[function(require,module,exports){ ;(function (require, exports, module, platform) { if (module) module.exports = minimatch @@ -9605,283 +8158,949 @@ function regExpEscape (s) { typeof process === "object" ? process.platform : "win32" ) -},{"lru-cache":49,"path":42,"sigmund":50}],49:[function(require,module,exports){ -;(function () { // closure for web browsers +},{"lru-cache":40,"path":42,"sigmund":47}],42:[function(require,module,exports){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. -if (typeof module === 'object' && module.exports) { - module.exports = LRUCache -} else { - // just set the global for non-node platforms. - this.LRUCache = LRUCache -} - -function hOP (obj, key) { - return Object.prototype.hasOwnProperty.call(obj, key) -} - -function naiveLength () { return 1 } - -function LRUCache (options) { - if (!(this instanceof LRUCache)) - return new LRUCache(options) - - if (typeof options === 'number') - options = { max: options } - - if (!options) - options = {} - - this._max = options.max - // Kind of weird to have a default max of Infinity, but oh well. - if (!this._max || !(typeof this._max === "number") || this._max <= 0 ) - this._max = Infinity - - this._lengthCalculator = options.length || naiveLength - if (typeof this._lengthCalculator !== "function") - this._lengthCalculator = naiveLength - - this._allowStale = options.stale || false - this._maxAge = options.maxAge || null - this._dispose = options.dispose - this.reset() -} - -// resize the cache when the max changes. -Object.defineProperty(LRUCache.prototype, "max", - { set : function (mL) { - if (!mL || !(typeof mL === "number") || mL <= 0 ) mL = Infinity - this._max = mL - if (this._length > this._max) trim(this) - } - , get : function () { return this._max } - , enumerable : true - }) - -// resize the cache when the lengthCalculator changes. -Object.defineProperty(LRUCache.prototype, "lengthCalculator", - { set : function (lC) { - if (typeof lC !== "function") { - this._lengthCalculator = naiveLength - this._length = this._itemCount - for (var key in this._cache) { - this._cache[key].length = 1 - } - } else { - this._lengthCalculator = lC - this._length = 0 - for (var key in this._cache) { - this._cache[key].length = this._lengthCalculator(this._cache[key].value) - this._length += this._cache[key].length - } - } - - if (this._length > this._max) trim(this) - } - , get : function () { return this._lengthCalculator } - , enumerable : true - }) - -Object.defineProperty(LRUCache.prototype, "length", - { get : function () { return this._length } - , enumerable : true - }) - - -Object.defineProperty(LRUCache.prototype, "itemCount", - { get : function () { return this._itemCount } - , enumerable : true - }) - -LRUCache.prototype.forEach = function (fn, thisp) { - thisp = thisp || this - var i = 0 - var itemCount = this._itemCount - - for (var k = this._mru - 1; k >= 0 && i < itemCount; k--) if (this._lruList[k]) { - i++ - var hit = this._lruList[k] - if (isStale(this, hit)) { - del(this, hit) - if (!this._allowStale) hit = undefined - } - if (hit) { - fn.call(thisp, hit.value, hit.key, this) - } - } -} - -LRUCache.prototype.keys = function () { - var keys = new Array(this._itemCount) - var i = 0 - for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) { - var hit = this._lruList[k] - keys[i++] = hit.key - } - return keys -} - -LRUCache.prototype.values = function () { - var values = new Array(this._itemCount) - var i = 0 - for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) { - var hit = this._lruList[k] - values[i++] = hit.value - } - return values -} - -LRUCache.prototype.reset = function () { - if (this._dispose && this._cache) { - for (var k in this._cache) { - this._dispose(k, this._cache[k].value) +// resolves . and .. elements in a path array with directory names there +// must be no slashes, empty elements, or device names (c:\) in the array +// (so also no leading and trailing slashes - it does not distinguish +// relative and absolute paths) +function normalizeArray(parts, allowAboveRoot) { + // if the path tries to go above the root, `up` ends up > 0 + var up = 0; + for (var i = parts.length - 1; i >= 0; i--) { + var last = parts[i]; + if (last === '.') { + parts.splice(i, 1); + } else if (last === '..') { + parts.splice(i, 1); + up++; + } else if (up) { + parts.splice(i, 1); + up--; } } - this._cache = Object.create(null) // hash of items by key - this._lruList = Object.create(null) // list of items in order of use recency - this._mru = 0 // most recently used - this._lru = 0 // least recently used - this._length = 0 // number of items in the list - this._itemCount = 0 -} - -// Provided for debugging/dev purposes only. No promises whatsoever that -// this API stays stable. -LRUCache.prototype.dump = function () { - return this._cache -} - -LRUCache.prototype.dumpLru = function () { - return this._lruList -} - -LRUCache.prototype.set = function (key, value, maxAge) { - maxAge = maxAge || this._maxAge - var now = maxAge ? Date.now() : 0 - - if (hOP(this._cache, key)) { - // dispose of the old one before overwriting - if (this._dispose) - this._dispose(key, this._cache[key].value) - - this._cache[key].now = now - this._cache[key].maxAge = maxAge - this._cache[key].value = value - this.get(key) - return true + // if the path is allowed to go above the root, restore leading ..s + if (allowAboveRoot) { + for (; up--; up) { + parts.unshift('..'); + } } - var len = this._lengthCalculator(value) - var hit = new Entry(key, value, this._mru++, len, now, maxAge) + return parts; +} - // oversized objects fall out of cache automatically. - if (hit.length > this._max) { - if (this._dispose) this._dispose(key, value) - return false +// Split a filename into [root, dir, basename, ext], unix version +// 'root' is just a slash, or nothing. +var splitPathRe = + /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/; +var splitPath = function(filename) { + return splitPathRe.exec(filename).slice(1); +}; + +// path.resolve([from ...], to) +// posix version +exports.resolve = function() { + var resolvedPath = '', + resolvedAbsolute = false; + + for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { + var path = (i >= 0) ? arguments[i] : process.cwd(); + + // Skip empty and invalid entries + if (typeof path !== 'string') { + throw new TypeError('Arguments to path.resolve must be strings'); + } else if (!path) { + continue; + } + + resolvedPath = path + '/' + resolvedPath; + resolvedAbsolute = path.charAt(0) === '/'; } - this._length += hit.length - this._lruList[hit.lu] = this._cache[key] = hit - this._itemCount ++ + // At this point the path should be resolved to a full absolute path, but + // handle relative paths to be safe (might happen when process.cwd() fails) - if (this._length > this._max) - trim(this) + // Normalize the path + resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) { + return !!p; + }), !resolvedAbsolute).join('/'); - return true -} + return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; +}; -LRUCache.prototype.has = function (key) { - if (!hOP(this._cache, key)) return false - var hit = this._cache[key] - if (isStale(this, hit)) { - return false +// path.normalize(path) +// posix version +exports.normalize = function(path) { + var isAbsolute = exports.isAbsolute(path), + trailingSlash = substr(path, -1) === '/'; + + // Normalize the path + path = normalizeArray(filter(path.split('/'), function(p) { + return !!p; + }), !isAbsolute).join('/'); + + if (!path && !isAbsolute) { + path = '.'; } - return true + if (path && trailingSlash) { + path += '/'; + } + + return (isAbsolute ? '/' : '') + path; +}; + +// posix version +exports.isAbsolute = function(path) { + return path.charAt(0) === '/'; +}; + +// posix version +exports.join = function() { + var paths = Array.prototype.slice.call(arguments, 0); + return exports.normalize(filter(paths, function(p, index) { + if (typeof p !== 'string') { + throw new TypeError('Arguments to path.join must be strings'); + } + return p; + }).join('/')); +}; + + +// path.relative(from, to) +// posix version +exports.relative = function(from, to) { + from = exports.resolve(from).substr(1); + to = exports.resolve(to).substr(1); + + function trim(arr) { + var start = 0; + for (; start < arr.length; start++) { + if (arr[start] !== '') break; + } + + var end = arr.length - 1; + for (; end >= 0; end--) { + if (arr[end] !== '') break; + } + + if (start > end) return []; + return arr.slice(start, end - start + 1); + } + + var fromParts = trim(from.split('/')); + var toParts = trim(to.split('/')); + + var length = Math.min(fromParts.length, toParts.length); + var samePartsLength = length; + for (var i = 0; i < length; i++) { + if (fromParts[i] !== toParts[i]) { + samePartsLength = i; + break; + } + } + + var outputParts = []; + for (var i = samePartsLength; i < fromParts.length; i++) { + outputParts.push('..'); + } + + outputParts = outputParts.concat(toParts.slice(samePartsLength)); + + return outputParts.join('/'); +}; + +exports.sep = '/'; +exports.delimiter = ':'; + +exports.dirname = function(path) { + var result = splitPath(path), + root = result[0], + dir = result[1]; + + if (!root && !dir) { + // No dirname whatsoever + return '.'; + } + + if (dir) { + // It has a dirname, strip trailing slash + dir = dir.substr(0, dir.length - 1); + } + + return root + dir; +}; + + +exports.basename = function(path, ext) { + var f = splitPath(path)[2]; + // TODO: make this comparison case-insensitive on windows? + if (ext && f.substr(-1 * ext.length) === ext) { + f = f.substr(0, f.length - ext.length); + } + return f; +}; + + +exports.extname = function(path) { + return splitPath(path)[3]; +}; + +function filter (xs, f) { + if (xs.filter) return xs.filter(f); + var res = []; + for (var i = 0; i < xs.length; i++) { + if (f(xs[i], i, xs)) res.push(xs[i]); + } + return res; } -LRUCache.prototype.get = function (key) { - return get(this, key, true) +// String.prototype.substr - negative index don't work in IE8 +var substr = 'ab'.substr(-1) === 'b' + ? function (str, start, len) { return str.substr(start, len) } + : function (str, start, len) { + if (start < 0) start = str.length + start; + return str.substr(start, len); + } +; + +},{}],43:[function(require,module,exports){ +(function (global){ +/*! https://mths.be/punycode v1.4.1 by @mathias */ +;(function(root) { + + /** Detect free variables */ + var freeExports = typeof exports == 'object' && exports && + !exports.nodeType && exports; + var freeModule = typeof module == 'object' && module && + !module.nodeType && module; + var freeGlobal = typeof global == 'object' && global; + if ( + freeGlobal.global === freeGlobal || + freeGlobal.window === freeGlobal || + freeGlobal.self === freeGlobal + ) { + root = freeGlobal; + } + + /** + * The `punycode` object. + * @name punycode + * @type Object + */ + var punycode, + + /** Highest positive signed 32-bit float value */ + maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1 + + /** Bootstring parameters */ + base = 36, + tMin = 1, + tMax = 26, + skew = 38, + damp = 700, + initialBias = 72, + initialN = 128, // 0x80 + delimiter = '-', // '\x2D' + + /** Regular expressions */ + regexPunycode = /^xn--/, + regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars + regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators + + /** Error messages */ + errors = { + 'overflow': 'Overflow: input needs wider integers to process', + 'not-basic': 'Illegal input >= 0x80 (not a basic code point)', + 'invalid-input': 'Invalid input' + }, + + /** Convenience shortcuts */ + baseMinusTMin = base - tMin, + floor = Math.floor, + stringFromCharCode = String.fromCharCode, + + /** Temporary variable */ + key; + + /*--------------------------------------------------------------------------*/ + + /** + * A generic error utility function. + * @private + * @param {String} type The error type. + * @returns {Error} Throws a `RangeError` with the applicable error message. + */ + function error(type) { + throw new RangeError(errors[type]); + } + + /** + * A generic `Array#map` utility function. + * @private + * @param {Array} array The array to iterate over. + * @param {Function} callback The function that gets called for every array + * item. + * @returns {Array} A new array of values returned by the callback function. + */ + function map(array, fn) { + var length = array.length; + var result = []; + while (length--) { + result[length] = fn(array[length]); + } + return result; + } + + /** + * A simple `Array#map`-like wrapper to work with domain name strings or email + * addresses. + * @private + * @param {String} domain The domain name or email address. + * @param {Function} callback The function that gets called for every + * character. + * @returns {Array} A new string of characters returned by the callback + * function. + */ + function mapDomain(string, fn) { + var parts = string.split('@'); + var result = ''; + if (parts.length > 1) { + // In email addresses, only the domain name should be punycoded. Leave + // the local part (i.e. everything up to `@`) intact. + result = parts[0] + '@'; + string = parts[1]; + } + // Avoid `split(regex)` for IE8 compatibility. See #17. + string = string.replace(regexSeparators, '\x2E'); + var labels = string.split('.'); + var encoded = map(labels, fn).join('.'); + return result + encoded; + } + + /** + * Creates an array containing the numeric code points of each Unicode + * character in the string. While JavaScript uses UCS-2 internally, + * this function will convert a pair of surrogate halves (each of which + * UCS-2 exposes as separate characters) into a single code point, + * matching UTF-16. + * @see `punycode.ucs2.encode` + * @see + * @memberOf punycode.ucs2 + * @name decode + * @param {String} string The Unicode input string (UCS-2). + * @returns {Array} The new array of code points. + */ + function ucs2decode(string) { + var output = [], + counter = 0, + length = string.length, + value, + extra; + while (counter < length) { + value = string.charCodeAt(counter++); + if (value >= 0xD800 && value <= 0xDBFF && counter < length) { + // high surrogate, and there is a next character + extra = string.charCodeAt(counter++); + if ((extra & 0xFC00) == 0xDC00) { // low surrogate + output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); + } else { + // unmatched surrogate; only append this code unit, in case the next + // code unit is the high surrogate of a surrogate pair + output.push(value); + counter--; + } + } else { + output.push(value); + } + } + return output; + } + + /** + * Creates a string based on an array of numeric code points. + * @see `punycode.ucs2.decode` + * @memberOf punycode.ucs2 + * @name encode + * @param {Array} codePoints The array of numeric code points. + * @returns {String} The new Unicode string (UCS-2). + */ + function ucs2encode(array) { + return map(array, function(value) { + var output = ''; + if (value > 0xFFFF) { + value -= 0x10000; + output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); + value = 0xDC00 | value & 0x3FF; + } + output += stringFromCharCode(value); + return output; + }).join(''); + } + + /** + * Converts a basic code point into a digit/integer. + * @see `digitToBasic()` + * @private + * @param {Number} codePoint The basic numeric code point value. + * @returns {Number} The numeric value of a basic code point (for use in + * representing integers) in the range `0` to `base - 1`, or `base` if + * the code point does not represent a value. + */ + function basicToDigit(codePoint) { + if (codePoint - 48 < 10) { + return codePoint - 22; + } + if (codePoint - 65 < 26) { + return codePoint - 65; + } + if (codePoint - 97 < 26) { + return codePoint - 97; + } + return base; + } + + /** + * Converts a digit/integer into a basic code point. + * @see `basicToDigit()` + * @private + * @param {Number} digit The numeric value of a basic code point. + * @returns {Number} The basic code point whose value (when used for + * representing integers) is `digit`, which needs to be in the range + * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is + * used; else, the lowercase form is used. The behavior is undefined + * if `flag` is non-zero and `digit` has no uppercase form. + */ + function digitToBasic(digit, flag) { + // 0..25 map to ASCII a..z or A..Z + // 26..35 map to ASCII 0..9 + return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5); + } + + /** + * Bias adaptation function as per section 3.4 of RFC 3492. + * https://tools.ietf.org/html/rfc3492#section-3.4 + * @private + */ + function adapt(delta, numPoints, firstTime) { + var k = 0; + delta = firstTime ? floor(delta / damp) : delta >> 1; + delta += floor(delta / numPoints); + for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) { + delta = floor(delta / baseMinusTMin); + } + return floor(k + (baseMinusTMin + 1) * delta / (delta + skew)); + } + + /** + * Converts a Punycode string of ASCII-only symbols to a string of Unicode + * symbols. + * @memberOf punycode + * @param {String} input The Punycode string of ASCII-only symbols. + * @returns {String} The resulting string of Unicode symbols. + */ + function decode(input) { + // Don't use UCS-2 + var output = [], + inputLength = input.length, + out, + i = 0, + n = initialN, + bias = initialBias, + basic, + j, + index, + oldi, + w, + k, + digit, + t, + /** Cached calculation results */ + baseMinusT; + + // Handle the basic code points: let `basic` be the number of input code + // points before the last delimiter, or `0` if there is none, then copy + // the first basic code points to the output. + + basic = input.lastIndexOf(delimiter); + if (basic < 0) { + basic = 0; + } + + for (j = 0; j < basic; ++j) { + // if it's not a basic code point + if (input.charCodeAt(j) >= 0x80) { + error('not-basic'); + } + output.push(input.charCodeAt(j)); + } + + // Main decoding loop: start just after the last delimiter if any basic code + // points were copied; start at the beginning otherwise. + + for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) { + + // `index` is the index of the next character to be consumed. + // Decode a generalized variable-length integer into `delta`, + // which gets added to `i`. The overflow checking is easier + // if we increase `i` as we go, then subtract off its starting + // value at the end to obtain `delta`. + for (oldi = i, w = 1, k = base; /* no condition */; k += base) { + + if (index >= inputLength) { + error('invalid-input'); + } + + digit = basicToDigit(input.charCodeAt(index++)); + + if (digit >= base || digit > floor((maxInt - i) / w)) { + error('overflow'); + } + + i += digit * w; + t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); + + if (digit < t) { + break; + } + + baseMinusT = base - t; + if (w > floor(maxInt / baseMinusT)) { + error('overflow'); + } + + w *= baseMinusT; + + } + + out = output.length + 1; + bias = adapt(i - oldi, out, oldi == 0); + + // `i` was supposed to wrap around from `out` to `0`, + // incrementing `n` each time, so we'll fix that now: + if (floor(i / out) > maxInt - n) { + error('overflow'); + } + + n += floor(i / out); + i %= out; + + // Insert `n` at position `i` of the output + output.splice(i++, 0, n); + + } + + return ucs2encode(output); + } + + /** + * Converts a string of Unicode symbols (e.g. a domain name label) to a + * Punycode string of ASCII-only symbols. + * @memberOf punycode + * @param {String} input The string of Unicode symbols. + * @returns {String} The resulting Punycode string of ASCII-only symbols. + */ + function encode(input) { + var n, + delta, + handledCPCount, + basicLength, + bias, + j, + m, + q, + k, + t, + currentValue, + output = [], + /** `inputLength` will hold the number of code points in `input`. */ + inputLength, + /** Cached calculation results */ + handledCPCountPlusOne, + baseMinusT, + qMinusT; + + // Convert the input in UCS-2 to Unicode + input = ucs2decode(input); + + // Cache the length + inputLength = input.length; + + // Initialize the state + n = initialN; + delta = 0; + bias = initialBias; + + // Handle the basic code points + for (j = 0; j < inputLength; ++j) { + currentValue = input[j]; + if (currentValue < 0x80) { + output.push(stringFromCharCode(currentValue)); + } + } + + handledCPCount = basicLength = output.length; + + // `handledCPCount` is the number of code points that have been handled; + // `basicLength` is the number of basic code points. + + // Finish the basic string - if it is not empty - with a delimiter + if (basicLength) { + output.push(delimiter); + } + + // Main encoding loop: + while (handledCPCount < inputLength) { + + // All non-basic code points < n have been handled already. Find the next + // larger one: + for (m = maxInt, j = 0; j < inputLength; ++j) { + currentValue = input[j]; + if (currentValue >= n && currentValue < m) { + m = currentValue; + } + } + + // Increase `delta` enough to advance the decoder's state to , + // but guard against overflow + handledCPCountPlusOne = handledCPCount + 1; + if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) { + error('overflow'); + } + + delta += (m - n) * handledCPCountPlusOne; + n = m; + + for (j = 0; j < inputLength; ++j) { + currentValue = input[j]; + + if (currentValue < n && ++delta > maxInt) { + error('overflow'); + } + + if (currentValue == n) { + // Represent delta as a generalized variable-length integer + for (q = delta, k = base; /* no condition */; k += base) { + t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); + if (q < t) { + break; + } + qMinusT = q - t; + baseMinusT = base - t; + output.push( + stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)) + ); + q = floor(qMinusT / baseMinusT); + } + + output.push(stringFromCharCode(digitToBasic(q, 0))); + bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength); + delta = 0; + ++handledCPCount; + } + } + + ++delta; + ++n; + + } + return output.join(''); + } + + /** + * Converts a Punycode string representing a domain name or an email address + * to Unicode. Only the Punycoded parts of the input will be converted, i.e. + * it doesn't matter if you call it on a string that has already been + * converted to Unicode. + * @memberOf punycode + * @param {String} input The Punycoded domain name or email address to + * convert to Unicode. + * @returns {String} The Unicode representation of the given Punycode + * string. + */ + function toUnicode(input) { + return mapDomain(input, function(string) { + return regexPunycode.test(string) + ? decode(string.slice(4).toLowerCase()) + : string; + }); + } + + /** + * Converts a Unicode string representing a domain name or an email address to + * Punycode. Only the non-ASCII parts of the domain name will be converted, + * i.e. it doesn't matter if you call it with a domain that's already in + * ASCII. + * @memberOf punycode + * @param {String} input The domain name or email address to convert, as a + * Unicode string. + * @returns {String} The Punycode representation of the given domain name or + * email address. + */ + function toASCII(input) { + return mapDomain(input, function(string) { + return regexNonASCII.test(string) + ? 'xn--' + encode(string) + : string; + }); + } + + /*--------------------------------------------------------------------------*/ + + /** Define the public API */ + punycode = { + /** + * A string representing the current Punycode.js version number. + * @memberOf punycode + * @type String + */ + 'version': '1.4.1', + /** + * An object of methods to convert from JavaScript's internal character + * representation (UCS-2) to Unicode code points, and back. + * @see + * @memberOf punycode + * @type Object + */ + 'ucs2': { + 'decode': ucs2decode, + 'encode': ucs2encode + }, + 'decode': decode, + 'encode': encode, + 'toASCII': toASCII, + 'toUnicode': toUnicode + }; + + /** Expose `punycode` */ + // Some AMD build optimizers, like r.js, check for specific condition patterns + // like the following: + if ( + typeof define == 'function' && + typeof define.amd == 'object' && + define.amd + ) { + define('punycode', function() { + return punycode; + }); + } else if (freeExports && freeModule) { + if (module.exports == freeExports) { + // in Node.js, io.js, or RingoJS v0.8.0+ + freeModule.exports = punycode; + } else { + // in Narwhal or RingoJS v0.7.0- + for (key in punycode) { + punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]); + } + } + } else { + // in Rhino or a web browser + root.punycode = punycode; + } + +}(this)); + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],44:[function(require,module,exports){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +'use strict'; + +// If obj.hasOwnProperty has been overridden, then calling +// obj.hasOwnProperty(prop) will break. +// See: https://github.com/joyent/node/issues/1707 +function hasOwnProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); } -LRUCache.prototype.peek = function (key) { - return get(this, key, false) -} +module.exports = function(qs, sep, eq, options) { + sep = sep || '&'; + eq = eq || '='; + var obj = {}; -LRUCache.prototype.pop = function () { - var hit = this._lruList[this._lru] - del(this, hit) - return hit || null -} + if (typeof qs !== 'string' || qs.length === 0) { + return obj; + } -LRUCache.prototype.del = function (key) { - del(this, this._cache[key]) -} + var regexp = /\+/g; + qs = qs.split(sep); -function get (self, key, doUse) { - var hit = self._cache[key] - if (hit) { - if (isStale(self, hit)) { - del(self, hit) - if (!self._allowStale) hit = undefined + var maxKeys = 1000; + if (options && typeof options.maxKeys === 'number') { + maxKeys = options.maxKeys; + } + + var len = qs.length; + // maxKeys <= 0 means that we should not limit keys count + if (maxKeys > 0 && len > maxKeys) { + len = maxKeys; + } + + for (var i = 0; i < len; ++i) { + var x = qs[i].replace(regexp, '%20'), + idx = x.indexOf(eq), + kstr, vstr, k, v; + + if (idx >= 0) { + kstr = x.substr(0, idx); + vstr = x.substr(idx + 1); } else { - if (doUse) use(self, hit) + kstr = x; + vstr = ''; + } + + k = decodeURIComponent(kstr); + v = decodeURIComponent(vstr); + + if (!hasOwnProperty(obj, k)) { + obj[k] = v; + } else if (isArray(obj[k])) { + obj[k].push(v); + } else { + obj[k] = [obj[k], v]; } - if (hit) hit = hit.value } - return hit -} -function isStale(self, hit) { - if (!hit || (!hit.maxAge && !self._maxAge)) return false - var stale = false; - var diff = Date.now() - hit.now - if (hit.maxAge) { - stale = diff > hit.maxAge - } else { - stale = self._maxAge && (diff > self._maxAge) + return obj; +}; + +var isArray = Array.isArray || function (xs) { + return Object.prototype.toString.call(xs) === '[object Array]'; +}; + +},{}],45:[function(require,module,exports){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +'use strict'; + +var stringifyPrimitive = function(v) { + switch (typeof v) { + case 'string': + return v; + + case 'boolean': + return v ? 'true' : 'false'; + + case 'number': + return isFinite(v) ? v : ''; + + default: + return ''; } - return stale; -} +}; -function use (self, hit) { - shiftLU(self, hit) - hit.lu = self._mru ++ - self._lruList[hit.lu] = hit -} - -function trim (self) { - while (self._lru < self._mru && self._length > self._max) - del(self, self._lruList[self._lru]) -} - -function shiftLU (self, hit) { - delete self._lruList[ hit.lu ] - while (self._lru < self._mru && !self._lruList[self._lru]) self._lru ++ -} - -function del (self, hit) { - if (hit) { - if (self._dispose) self._dispose(hit.key, hit.value) - self._length -= hit.length - self._itemCount -- - delete self._cache[ hit.key ] - shiftLU(self, hit) +module.exports = function(obj, sep, eq, name) { + sep = sep || '&'; + eq = eq || '='; + if (obj === null) { + obj = undefined; } + + if (typeof obj === 'object') { + return map(objectKeys(obj), function(k) { + var ks = encodeURIComponent(stringifyPrimitive(k)) + eq; + if (isArray(obj[k])) { + return map(obj[k], function(v) { + return ks + encodeURIComponent(stringifyPrimitive(v)); + }).join(sep); + } else { + return ks + encodeURIComponent(stringifyPrimitive(obj[k])); + } + }).join(sep); + + } + + if (!name) return ''; + return encodeURIComponent(stringifyPrimitive(name)) + eq + + encodeURIComponent(stringifyPrimitive(obj)); +}; + +var isArray = Array.isArray || function (xs) { + return Object.prototype.toString.call(xs) === '[object Array]'; +}; + +function map (xs, f) { + if (xs.map) return xs.map(f); + var res = []; + for (var i = 0; i < xs.length; i++) { + res.push(f(xs[i], i)); + } + return res; } -// classy, since V8 prefers predictable objects. -function Entry (key, value, lu, length, now, maxAge) { - this.key = key - this.value = value - this.lu = lu - this.length = length - this.now = now - if (maxAge) this.maxAge = maxAge -} +var objectKeys = Object.keys || function (obj) { + var res = []; + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key); + } + return res; +}; -})() +},{}],46:[function(require,module,exports){ +'use strict'; -},{}],50:[function(require,module,exports){ +exports.decode = exports.parse = require('./decode'); +exports.encode = exports.stringify = require('./encode'); + +},{"./decode":44,"./encode":45}],47:[function(require,module,exports){ module.exports = sigmund function sigmund (subject, maxSessions) { maxSessions = maxSessions || 10; @@ -9922,7 +9141,863 @@ function sigmund (subject, maxSessions) { // vim: set softtabstop=4 shiftwidth=4: -},{}],51:[function(require,module,exports){ +},{}],48:[function(require,module,exports){ +module.exports = require('./lib/type'); + +},{"./lib/type":49}],49:[function(require,module,exports){ +/*! + * type-detect + * Copyright(c) 2013 jake luer + * MIT Licensed + */ + +/*! + * Primary Exports + */ + +var exports = module.exports = getType; + +/*! + * Detectable javascript natives + */ + +var natives = { + '[object Array]': 'array' + , '[object RegExp]': 'regexp' + , '[object Function]': 'function' + , '[object Arguments]': 'arguments' + , '[object Date]': 'date' +}; + +/** + * ### typeOf (obj) + * + * Use several different techniques to determine + * the type of object being tested. + * + * + * @param {Mixed} object + * @return {String} object type + * @api public + */ + +function getType (obj) { + var str = Object.prototype.toString.call(obj); + if (natives[str]) return natives[str]; + if (obj === null) return 'null'; + if (obj === undefined) return 'undefined'; + if (obj === Object(obj)) return 'object'; + return typeof obj; +} + +exports.Library = Library; + +/** + * ### Library + * + * Create a repository for custom type detection. + * + * ```js + * var lib = new type.Library; + * ``` + * + */ + +function Library () { + this.tests = {}; +} + +/** + * #### .of (obj) + * + * Expose replacement `typeof` detection to the library. + * + * ```js + * if ('string' === lib.of('hello world')) { + * // ... + * } + * ``` + * + * @param {Mixed} object to test + * @return {String} type + */ + +Library.prototype.of = getType; + +/** + * #### .define (type, test) + * + * Add a test to for the `.test()` assertion. + * + * Can be defined as a regular expression: + * + * ```js + * lib.define('int', /^[0-9]+$/); + * ``` + * + * ... or as a function: + * + * ```js + * lib.define('bln', function (obj) { + * if ('boolean' === lib.of(obj)) return true; + * var blns = [ 'yes', 'no', 'true', 'false', 1, 0 ]; + * if ('string' === lib.of(obj)) obj = obj.toLowerCase(); + * return !! ~blns.indexOf(obj); + * }); + * ``` + * + * @param {String} type + * @param {RegExp|Function} test + * @api public + */ + +Library.prototype.define = function (type, test) { + if (arguments.length === 1) return this.tests[type]; + this.tests[type] = test; + return this; +}; + +/** + * #### .test (obj, test) + * + * Assert that an object is of type. Will first + * check natives, and if that does not pass it will + * use the user defined custom tests. + * + * ```js + * assert(lib.test('1', 'int')); + * assert(lib.test('yes', 'bln')); + * ``` + * + * @param {Mixed} object + * @param {String} type + * @return {Boolean} result + * @api public + */ + +Library.prototype.test = function (obj, type) { + if (type === getType(obj)) return true; + var test = this.tests[type]; + + if (test && 'regexp' === getType(test)) { + return test.test(obj); + } else if (test && 'function' === getType(test)) { + return test(obj); + } else { + throw new ReferenceError('Type test "' + type + '" not defined or invalid.'); + } +}; + +},{}],50:[function(require,module,exports){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +var punycode = require('punycode'); + +exports.parse = urlParse; +exports.resolve = urlResolve; +exports.resolveObject = urlResolveObject; +exports.format = urlFormat; + +exports.Url = Url; + +function Url() { + this.protocol = null; + this.slashes = null; + this.auth = null; + this.host = null; + this.port = null; + this.hostname = null; + this.hash = null; + this.search = null; + this.query = null; + this.pathname = null; + this.path = null; + this.href = null; +} + +// Reference: RFC 3986, RFC 1808, RFC 2396 + +// define these here so at least they only have to be +// compiled once on the first module load. +var protocolPattern = /^([a-z0-9.+-]+:)/i, + portPattern = /:[0-9]*$/, + + // RFC 2396: characters reserved for delimiting URLs. + // We actually just auto-escape these. + delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'], + + // RFC 2396: characters not allowed for various reasons. + unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims), + + // Allowed by RFCs, but cause of XSS attacks. Always escape these. + autoEscape = ['\''].concat(unwise), + // Characters that are never ever allowed in a hostname. + // Note that any invalid chars are also handled, but these + // are the ones that are *expected* to be seen, so we fast-path + // them. + nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape), + hostEndingChars = ['/', '?', '#'], + hostnameMaxLen = 255, + hostnamePartPattern = /^[a-z0-9A-Z_-]{0,63}$/, + hostnamePartStart = /^([a-z0-9A-Z_-]{0,63})(.*)$/, + // protocols that can allow "unsafe" and "unwise" chars. + unsafeProtocol = { + 'javascript': true, + 'javascript:': true + }, + // protocols that never have a hostname. + hostlessProtocol = { + 'javascript': true, + 'javascript:': true + }, + // protocols that always contain a // bit. + slashedProtocol = { + 'http': true, + 'https': true, + 'ftp': true, + 'gopher': true, + 'file': true, + 'http:': true, + 'https:': true, + 'ftp:': true, + 'gopher:': true, + 'file:': true + }, + querystring = require('querystring'); + +function urlParse(url, parseQueryString, slashesDenoteHost) { + if (url && isObject(url) && url instanceof Url) return url; + + var u = new Url; + u.parse(url, parseQueryString, slashesDenoteHost); + return u; +} + +Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) { + if (!isString(url)) { + throw new TypeError("Parameter 'url' must be a string, not " + typeof url); + } + + var rest = url; + + // trim before proceeding. + // This is to support parse stuff like " http://foo.com \n" + rest = rest.trim(); + + var proto = protocolPattern.exec(rest); + if (proto) { + proto = proto[0]; + var lowerProto = proto.toLowerCase(); + this.protocol = lowerProto; + rest = rest.substr(proto.length); + } + + // figure out if it's got a host + // user@server is *always* interpreted as a hostname, and url + // resolution will treat //foo/bar as host=foo,path=bar because that's + // how the browser resolves relative URLs. + if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) { + var slashes = rest.substr(0, 2) === '//'; + if (slashes && !(proto && hostlessProtocol[proto])) { + rest = rest.substr(2); + this.slashes = true; + } + } + + if (!hostlessProtocol[proto] && + (slashes || (proto && !slashedProtocol[proto]))) { + + // there's a hostname. + // the first instance of /, ?, ;, or # ends the host. + // + // If there is an @ in the hostname, then non-host chars *are* allowed + // to the left of the last @ sign, unless some host-ending character + // comes *before* the @-sign. + // URLs are obnoxious. + // + // ex: + // http://a@b@c/ => user:a@b host:c + // http://a@b?@c => user:a host:c path:/?@c + + // v0.12 TODO(isaacs): This is not quite how Chrome does things. + // Review our test case against browsers more comprehensively. + + // find the first instance of any hostEndingChars + var hostEnd = -1; + for (var i = 0; i < hostEndingChars.length; i++) { + var hec = rest.indexOf(hostEndingChars[i]); + if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) + hostEnd = hec; + } + + // at this point, either we have an explicit point where the + // auth portion cannot go past, or the last @ char is the decider. + var auth, atSign; + if (hostEnd === -1) { + // atSign can be anywhere. + atSign = rest.lastIndexOf('@'); + } else { + // atSign must be in auth portion. + // http://a@b/c@d => host:b auth:a path:/c@d + atSign = rest.lastIndexOf('@', hostEnd); + } + + // Now we have a portion which is definitely the auth. + // Pull that off. + if (atSign !== -1) { + auth = rest.slice(0, atSign); + rest = rest.slice(atSign + 1); + this.auth = decodeURIComponent(auth); + } + + // the host is the remaining to the left of the first non-host char + hostEnd = -1; + for (var i = 0; i < nonHostChars.length; i++) { + var hec = rest.indexOf(nonHostChars[i]); + if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) + hostEnd = hec; + } + // if we still have not hit it, then the entire thing is a host. + if (hostEnd === -1) + hostEnd = rest.length; + + this.host = rest.slice(0, hostEnd); + rest = rest.slice(hostEnd); + + // pull out port. + this.parseHost(); + + // we've indicated that there is a hostname, + // so even if it's empty, it has to be present. + this.hostname = this.hostname || ''; + + // if hostname begins with [ and ends with ] + // assume that it's an IPv6 address. + var ipv6Hostname = this.hostname[0] === '[' && + this.hostname[this.hostname.length - 1] === ']'; + + // validate a little. + if (!ipv6Hostname) { + var hostparts = this.hostname.split(/\./); + for (var i = 0, l = hostparts.length; i < l; i++) { + var part = hostparts[i]; + if (!part) continue; + if (!part.match(hostnamePartPattern)) { + var newpart = ''; + for (var j = 0, k = part.length; j < k; j++) { + if (part.charCodeAt(j) > 127) { + // we replace non-ASCII char with a temporary placeholder + // we need this to make sure size of hostname is not + // broken by replacing non-ASCII by nothing + newpart += 'x'; + } else { + newpart += part[j]; + } + } + // we test again with ASCII char only + if (!newpart.match(hostnamePartPattern)) { + var validParts = hostparts.slice(0, i); + var notHost = hostparts.slice(i + 1); + var bit = part.match(hostnamePartStart); + if (bit) { + validParts.push(bit[1]); + notHost.unshift(bit[2]); + } + if (notHost.length) { + rest = '/' + notHost.join('.') + rest; + } + this.hostname = validParts.join('.'); + break; + } + } + } + } + + if (this.hostname.length > hostnameMaxLen) { + this.hostname = ''; + } else { + // hostnames are always lower case. + this.hostname = this.hostname.toLowerCase(); + } + + if (!ipv6Hostname) { + // IDNA Support: Returns a puny coded representation of "domain". + // It only converts the part of the domain name that + // has non ASCII characters. I.e. it dosent matter if + // you call it with a domain that already is in ASCII. + var domainArray = this.hostname.split('.'); + var newOut = []; + for (var i = 0; i < domainArray.length; ++i) { + var s = domainArray[i]; + newOut.push(s.match(/[^A-Za-z0-9_-]/) ? + 'xn--' + punycode.encode(s) : s); + } + this.hostname = newOut.join('.'); + } + + var p = this.port ? ':' + this.port : ''; + var h = this.hostname || ''; + this.host = h + p; + this.href += this.host; + + // strip [ and ] from the hostname + // the host field still retains them, though + if (ipv6Hostname) { + this.hostname = this.hostname.substr(1, this.hostname.length - 2); + if (rest[0] !== '/') { + rest = '/' + rest; + } + } + } + + // now rest is set to the post-host stuff. + // chop off any delim chars. + if (!unsafeProtocol[lowerProto]) { + + // First, make 100% sure that any "autoEscape" chars get + // escaped, even if encodeURIComponent doesn't think they + // need to be. + for (var i = 0, l = autoEscape.length; i < l; i++) { + var ae = autoEscape[i]; + var esc = encodeURIComponent(ae); + if (esc === ae) { + esc = escape(ae); + } + rest = rest.split(ae).join(esc); + } + } + + + // chop off from the tail first. + var hash = rest.indexOf('#'); + if (hash !== -1) { + // got a fragment string. + this.hash = rest.substr(hash); + rest = rest.slice(0, hash); + } + var qm = rest.indexOf('?'); + if (qm !== -1) { + this.search = rest.substr(qm); + this.query = rest.substr(qm + 1); + if (parseQueryString) { + this.query = querystring.parse(this.query); + } + rest = rest.slice(0, qm); + } else if (parseQueryString) { + // no query string, but parseQueryString still requested + this.search = ''; + this.query = {}; + } + if (rest) this.pathname = rest; + if (slashedProtocol[lowerProto] && + this.hostname && !this.pathname) { + this.pathname = '/'; + } + + //to support http.request + if (this.pathname || this.search) { + var p = this.pathname || ''; + var s = this.search || ''; + this.path = p + s; + } + + // finally, reconstruct the href based on what has been validated. + this.href = this.format(); + return this; +}; + +// format a parsed object into a url string +function urlFormat(obj) { + // ensure it's an object, and not a string url. + // If it's an obj, this is a no-op. + // this way, you can call url_format() on strings + // to clean up potentially wonky urls. + if (isString(obj)) obj = urlParse(obj); + if (!(obj instanceof Url)) return Url.prototype.format.call(obj); + return obj.format(); +} + +Url.prototype.format = function() { + var auth = this.auth || ''; + if (auth) { + auth = encodeURIComponent(auth); + auth = auth.replace(/%3A/i, ':'); + auth += '@'; + } + + var protocol = this.protocol || '', + pathname = this.pathname || '', + hash = this.hash || '', + host = false, + query = ''; + + if (this.host) { + host = auth + this.host; + } else if (this.hostname) { + host = auth + (this.hostname.indexOf(':') === -1 ? + this.hostname : + '[' + this.hostname + ']'); + if (this.port) { + host += ':' + this.port; + } + } + + if (this.query && + isObject(this.query) && + Object.keys(this.query).length) { + query = querystring.stringify(this.query); + } + + var search = this.search || (query && ('?' + query)) || ''; + + if (protocol && protocol.substr(-1) !== ':') protocol += ':'; + + // only the slashedProtocols get the //. Not mailto:, xmpp:, etc. + // unless they had them to begin with. + if (this.slashes || + (!protocol || slashedProtocol[protocol]) && host !== false) { + host = '//' + (host || ''); + if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname; + } else if (!host) { + host = ''; + } + + if (hash && hash.charAt(0) !== '#') hash = '#' + hash; + if (search && search.charAt(0) !== '?') search = '?' + search; + + pathname = pathname.replace(/[?#]/g, function(match) { + return encodeURIComponent(match); + }); + search = search.replace('#', '%23'); + + return protocol + host + pathname + search + hash; +}; + +function urlResolve(source, relative) { + return urlParse(source, false, true).resolve(relative); +} + +Url.prototype.resolve = function(relative) { + return this.resolveObject(urlParse(relative, false, true)).format(); +}; + +function urlResolveObject(source, relative) { + if (!source) return relative; + return urlParse(source, false, true).resolveObject(relative); +} + +Url.prototype.resolveObject = function(relative) { + if (isString(relative)) { + var rel = new Url(); + rel.parse(relative, false, true); + relative = rel; + } + + var result = new Url(); + Object.keys(this).forEach(function(k) { + result[k] = this[k]; + }, this); + + // hash is always overridden, no matter what. + // even href="" will remove it. + result.hash = relative.hash; + + // if the relative url is empty, then there's nothing left to do here. + if (relative.href === '') { + result.href = result.format(); + return result; + } + + // hrefs like //foo/bar always cut to the protocol. + if (relative.slashes && !relative.protocol) { + // take everything except the protocol from relative + Object.keys(relative).forEach(function(k) { + if (k !== 'protocol') + result[k] = relative[k]; + }); + + //urlParse appends trailing / to urls like http://www.example.com + if (slashedProtocol[result.protocol] && + result.hostname && !result.pathname) { + result.path = result.pathname = '/'; + } + + result.href = result.format(); + return result; + } + + if (relative.protocol && relative.protocol !== result.protocol) { + // if it's a known url protocol, then changing + // the protocol does weird things + // first, if it's not file:, then we MUST have a host, + // and if there was a path + // to begin with, then we MUST have a path. + // if it is file:, then the host is dropped, + // because that's known to be hostless. + // anything else is assumed to be absolute. + if (!slashedProtocol[relative.protocol]) { + Object.keys(relative).forEach(function(k) { + result[k] = relative[k]; + }); + result.href = result.format(); + return result; + } + + result.protocol = relative.protocol; + if (!relative.host && !hostlessProtocol[relative.protocol]) { + var relPath = (relative.pathname || '').split('/'); + while (relPath.length && !(relative.host = relPath.shift())); + if (!relative.host) relative.host = ''; + if (!relative.hostname) relative.hostname = ''; + if (relPath[0] !== '') relPath.unshift(''); + if (relPath.length < 2) relPath.unshift(''); + result.pathname = relPath.join('/'); + } else { + result.pathname = relative.pathname; + } + result.search = relative.search; + result.query = relative.query; + result.host = relative.host || ''; + result.auth = relative.auth; + result.hostname = relative.hostname || relative.host; + result.port = relative.port; + // to support http.request + if (result.pathname || result.search) { + var p = result.pathname || ''; + var s = result.search || ''; + result.path = p + s; + } + result.slashes = result.slashes || relative.slashes; + result.href = result.format(); + return result; + } + + var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'), + isRelAbs = ( + relative.host || + relative.pathname && relative.pathname.charAt(0) === '/' + ), + mustEndAbs = (isRelAbs || isSourceAbs || + (result.host && relative.pathname)), + removeAllDots = mustEndAbs, + srcPath = result.pathname && result.pathname.split('/') || [], + relPath = relative.pathname && relative.pathname.split('/') || [], + psychotic = result.protocol && !slashedProtocol[result.protocol]; + + // if the url is a non-slashed url, then relative + // links like ../.. should be able + // to crawl up to the hostname, as well. This is strange. + // result.protocol has already been set by now. + // Later on, put the first path part into the host field. + if (psychotic) { + result.hostname = ''; + result.port = null; + if (result.host) { + if (srcPath[0] === '') srcPath[0] = result.host; + else srcPath.unshift(result.host); + } + result.host = ''; + if (relative.protocol) { + relative.hostname = null; + relative.port = null; + if (relative.host) { + if (relPath[0] === '') relPath[0] = relative.host; + else relPath.unshift(relative.host); + } + relative.host = null; + } + mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === ''); + } + + if (isRelAbs) { + // it's absolute. + result.host = (relative.host || relative.host === '') ? + relative.host : result.host; + result.hostname = (relative.hostname || relative.hostname === '') ? + relative.hostname : result.hostname; + result.search = relative.search; + result.query = relative.query; + srcPath = relPath; + // fall through to the dot-handling below. + } else if (relPath.length) { + // it's relative + // throw away the existing file, and take the new path instead. + if (!srcPath) srcPath = []; + srcPath.pop(); + srcPath = srcPath.concat(relPath); + result.search = relative.search; + result.query = relative.query; + } else if (!isNullOrUndefined(relative.search)) { + // just pull out the search. + // like href='?foo'. + // Put this after the other two cases because it simplifies the booleans + if (psychotic) { + result.hostname = result.host = srcPath.shift(); + //occationaly the auth can get stuck only in host + //this especialy happens in cases like + //url.resolveObject('mailto:local1@domain1', 'local2@domain2') + var authInHost = result.host && result.host.indexOf('@') > 0 ? + result.host.split('@') : false; + if (authInHost) { + result.auth = authInHost.shift(); + result.host = result.hostname = authInHost.shift(); + } + } + result.search = relative.search; + result.query = relative.query; + //to support http.request + if (!isNull(result.pathname) || !isNull(result.search)) { + result.path = (result.pathname ? result.pathname : '') + + (result.search ? result.search : ''); + } + result.href = result.format(); + return result; + } + + if (!srcPath.length) { + // no path at all. easy. + // we've already handled the other stuff above. + result.pathname = null; + //to support http.request + if (result.search) { + result.path = '/' + result.search; + } else { + result.path = null; + } + result.href = result.format(); + return result; + } + + // if a url ENDs in . or .., then it must get a trailing slash. + // however, if it ends in anything else non-slashy, + // then it must NOT get a trailing slash. + var last = srcPath.slice(-1)[0]; + var hasTrailingSlash = ( + (result.host || relative.host) && (last === '.' || last === '..') || + last === ''); + + // strip single dots, resolve double dots to parent dir + // if the path tries to go above the root, `up` ends up > 0 + var up = 0; + for (var i = srcPath.length; i >= 0; i--) { + last = srcPath[i]; + if (last == '.') { + srcPath.splice(i, 1); + } else if (last === '..') { + srcPath.splice(i, 1); + up++; + } else if (up) { + srcPath.splice(i, 1); + up--; + } + } + + // if the path is allowed to go above the root, restore leading ..s + if (!mustEndAbs && !removeAllDots) { + for (; up--; up) { + srcPath.unshift('..'); + } + } + + if (mustEndAbs && srcPath[0] !== '' && + (!srcPath[0] || srcPath[0].charAt(0) !== '/')) { + srcPath.unshift(''); + } + + if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) { + srcPath.push(''); + } + + var isAbsolute = srcPath[0] === '' || + (srcPath[0] && srcPath[0].charAt(0) === '/'); + + // put the host back + if (psychotic) { + result.hostname = result.host = isAbsolute ? '' : + srcPath.length ? srcPath.shift() : ''; + //occationaly the auth can get stuck only in host + //this especialy happens in cases like + //url.resolveObject('mailto:local1@domain1', 'local2@domain2') + var authInHost = result.host && result.host.indexOf('@') > 0 ? + result.host.split('@') : false; + if (authInHost) { + result.auth = authInHost.shift(); + result.host = result.hostname = authInHost.shift(); + } + } + + mustEndAbs = mustEndAbs || (result.host && srcPath.length); + + if (mustEndAbs && !isAbsolute) { + srcPath.unshift(''); + } + + if (!srcPath.length) { + result.pathname = null; + result.path = null; + } else { + result.pathname = srcPath.join('/'); + } + + //to support request.http + if (!isNull(result.pathname) || !isNull(result.search)) { + result.path = (result.pathname ? result.pathname : '') + + (result.search ? result.search : ''); + } + result.auth = relative.auth || result.auth; + result.slashes = result.slashes || relative.slashes; + result.href = result.format(); + return result; +}; + +Url.prototype.parseHost = function() { + var host = this.host; + var port = portPattern.exec(host); + if (port) { + port = port[0]; + if (port !== ':') { + this.port = port.substr(1); + } + host = host.substr(0, host.length - port.length); + } + if (host) this.hostname = host; +}; + +function isString(arg) { + return typeof arg === "string"; +} + +function isObject(arg) { + return typeof arg === 'object' && arg !== null; +} + +function isNull(arg) { + return arg === null; +} +function isNullOrUndefined(arg) { + return arg == null; +} + +},{"punycode":43,"querystring":46}],51:[function(require,module,exports){ (function (Buffer){ function FilerBuffer (subject, encoding, nonZero) { @@ -9949,7 +10024,7 @@ Object.keys(Buffer).forEach(function (p) { module.exports = FilerBuffer; }).call(this,require("buffer").Buffer) -},{"buffer":38}],52:[function(require,module,exports){ +},{"buffer":8}],52:[function(require,module,exports){ var O_READ = 'READ'; var O_WRITE = 'WRITE'; var O_CREATE = 'CREATE'; @@ -9971,10 +10046,17 @@ module.exports = { WSQL_SIZE: 5 * 1024 * 1024, WSQL_DESC: "FileSystem Storage", - MODE_FILE: 'FILE', - MODE_DIRECTORY: 'DIRECTORY', - MODE_SYMBOLIC_LINK: 'SYMLINK', - MODE_META: 'META', + NODE_TYPE_FILE: 'FILE', + NODE_TYPE_DIRECTORY: 'DIRECTORY', + NODE_TYPE_SYMBOLIC_LINK: 'SYMLINK', + NODE_TYPE_META: 'META', + + S_IFREG: 0x8000, + S_IFDIR: 0x4000, + S_IFLNK: 0xA000, + + DEFAULT_DIR_PERMISSIONS: 0x1ED, // 755 + DEFAULT_FILE_PERMISSIONS: 0x1A4, // 644 SYMLOOP_MAX: 10, @@ -10032,11 +10114,11 @@ module.exports = { }; },{}],53:[function(require,module,exports){ -var MODE_FILE = require('./constants.js').MODE_FILE; +var NODE_TYPE_FILE = require('./constants.js').NODE_TYPE_FILE; module.exports = function DirectoryEntry(id, type) { this.id = id; - this.type = type || MODE_FILE; + this.type = type || NODE_TYPE_FILE; }; },{"./constants.js":52}],54:[function(require,module,exports){ @@ -10056,7 +10138,7 @@ module.exports = { }; }).call(this,require("buffer").Buffer) -},{"buffer":38}],55:[function(require,module,exports){ +},{"buffer":8}],55:[function(require,module,exports){ var errors = {}; [ /** @@ -10173,10 +10255,10 @@ var isAbsolutePath = Path.isAbsolute; var isNullPath = Path.isNull; var Constants = require('../constants.js'); -var MODE_FILE = Constants.MODE_FILE; -var MODE_DIRECTORY = Constants.MODE_DIRECTORY; -var MODE_SYMBOLIC_LINK = Constants.MODE_SYMBOLIC_LINK; -var MODE_META = Constants.MODE_META; +var NODE_TYPE_FILE = Constants.NODE_TYPE_FILE; +var NODE_TYPE_DIRECTORY = Constants.NODE_TYPE_DIRECTORY; +var NODE_TYPE_SYMBOLIC_LINK = Constants.NODE_TYPE_SYMBOLIC_LINK; +var NODE_TYPE_META = Constants.NODE_TYPE_META; var ROOT_DIRECTORY_NAME = Constants.ROOT_DIRECTORY_NAME; var SUPER_NODE_ID = Constants.SUPER_NODE_ID; @@ -10209,17 +10291,17 @@ var Buffer = require('../buffer.js'); * and filesystem flags are examined in order to override update logic. */ function update_node_times(context, path, node, times, callback) { + var update = false; + // Honour mount flags for how we update times var flags = context.flags; if(_(flags).contains(FS_NOCTIME)) { delete times.ctime; } - if(_(flags).contains(FS_NOMTIME)) { + if(_(flags).contains(FS_NOMTIME)) { delete times.mtime; } - // Only do the update if required (i.e., times are still present) - var update = false; if(times.ctime) { node.ctime = times.ctime; // We don't do atime tracking for perf reasons, but do mirror ctime @@ -10238,8 +10320,6 @@ function update_node_times(context, path, node, times, callback) { } function complete(error) { - // Queue this change so we can send watch events. - // Unlike node.js, we send the full path vs. basename/dirname only. context.changes.push({ event: 'change', path: path }); callback(error); } @@ -10256,9 +10336,9 @@ function update_node_times(context, path, node, times, callback) { */ // in: file or directory path // out: new node representing file/directory -function make_node(context, path, mode, callback) { - if(mode !== MODE_DIRECTORY && mode !== MODE_FILE) { - return callback(new Errors.EINVAL('mode must be a directory or file', path)); +function make_node(context, path, type, callback) { + if(type !== NODE_TYPE_DIRECTORY && type !== NODE_TYPE_FILE) { + return callback(new Errors.EINVAL('type must be a directory or file', path)); } path = normalize(path); @@ -10273,7 +10353,7 @@ function make_node(context, path, mode, callback) { function create_node_in_parent(error, parentDirectoryNode) { if(error) { callback(error); - } else if(parentDirectoryNode.mode !== MODE_DIRECTORY) { + } else if(parentDirectoryNode.type !== NODE_TYPE_DIRECTORY) { callback(new Errors.ENOTDIR('a component of the path prefix is not a directory', path)); } else { parentNode = parentDirectoryNode; @@ -10298,7 +10378,11 @@ function make_node(context, path, mode, callback) { callback(error); } else { parentNodeData = result; - Node.create({guid: context.guid, mode: mode}, function(error, result) { + Node.create({ + path: path, + guid: context.guid, + type: type + }, function(error, result) { if(error) { callback(error); return; @@ -10325,7 +10409,7 @@ function make_node(context, path, mode, callback) { if(error) { callback(error); } else { - parentNodeData[name] = new DirectoryEntry(node.id, mode); + parentNodeData[name] = new DirectoryEntry(node.id, type); context.putObject(parentNode.data, parentNodeData, update_time); } } @@ -10351,7 +10435,7 @@ function find_node(context, path, callback) { function read_root_directory_node(error, superNode) { if(error) { callback(error); - } else if(!superNode || superNode.mode !== MODE_META || !superNode.rnode) { + } else if(!superNode || superNode.type !== NODE_TYPE_META || !superNode.rnode) { callback(new Errors.EFILESYSTEMERROR()); } else { context.getObject(superNode.rnode, check_root_directory_node); @@ -10373,7 +10457,7 @@ function find_node(context, path, callback) { function read_parent_directory_data(error, parentDirectoryNode) { if(error) { callback(error); - } else if(parentDirectoryNode.mode !== MODE_DIRECTORY || !parentDirectoryNode.data) { + } else if(parentDirectoryNode.type !== NODE_TYPE_DIRECTORY || !parentDirectoryNode.data) { callback(new Errors.ENOTDIR('a component of the path prefix is not a directory', path)); } else { context.getObject(parentDirectoryNode.data, get_node_from_parent_directory_data); @@ -10399,7 +10483,7 @@ function find_node(context, path, callback) { if(error) { callback(error); } else { - if(node.mode == MODE_SYMBOLIC_LINK) { + if(node.type == NODE_TYPE_SYMBOLIC_LINK) { followedCount++; if(followedCount > SYMLOOP_MAX){ callback(new Errors.ELOOP(null, path)); @@ -10476,7 +10560,7 @@ function ensure_root_directory(context, callback) { } else if(error && !(error instanceof Errors.ENOENT)) { callback(error); } else { - SuperNode.create({guid: context.guid}, function(error, result) { + SuperNode.create({ guid: context.guid }, function(error, result) { if(error) { callback(error); return; @@ -10491,7 +10575,12 @@ function ensure_root_directory(context, callback) { if(error) { callback(error); } else { - Node.create({guid: context.guid, id: superNode.rnode, mode: MODE_DIRECTORY}, function(error, result) { + Node.create({ + guid: context.guid, + id: superNode.rnode, + type: NODE_TYPE_DIRECTORY, + path: ROOT_DIRECTORY_NAME + }, function(error, result) { if(error) { callback(error); return; @@ -10552,7 +10641,11 @@ function make_directory(context, path, callback) { callback(error); } else { parentDirectoryData = result; - Node.create({guid: context.guid, mode: MODE_DIRECTORY}, function(error, result) { + Node.create({ + guid: context.guid, + type: NODE_TYPE_DIRECTORY, + path: path + }, function(error, result) { if(error) { callback(error); return; @@ -10586,7 +10679,7 @@ function make_directory(context, path, callback) { if(error) { callback(error); } else { - parentDirectoryData[name] = new DirectoryEntry(directoryNode.id, MODE_DIRECTORY); + parentDirectoryData[name] = new DirectoryEntry(directoryNode.id, NODE_TYPE_DIRECTORY); context.putObject(parentDirectoryNode.data, parentDirectoryData, update_time); } } @@ -10633,7 +10726,7 @@ function remove_directory(context, path, callback) { function check_if_node_is_directory(error, result) { if(error) { callback(error); - } else if(result.mode != MODE_DIRECTORY) { + } else if(result.type != NODE_TYPE_DIRECTORY) { callback(new Errors.ENOTDIR(null, path)); } else { directoryNode = result; @@ -10713,7 +10806,7 @@ function open_file(context, path, flags, callback) { function read_directory_data(error, result) { if(error) { callback(error); - } else if(result.mode !== MODE_DIRECTORY) { + } else if(result.type !== NODE_TYPE_DIRECTORY) { callback(new Errors.ENOENT(null, path)); } else { directoryNode = result; @@ -10731,7 +10824,7 @@ function open_file(context, path, flags, callback) { callback(new Errors.ENOENT('O_CREATE and O_EXCLUSIVE are set, and the named file exists', path)); } else { directoryEntry = directoryData[name]; - if(directoryEntry.type == MODE_DIRECTORY && _(flags).contains(O_WRITE)) { + if(directoryEntry.type == NODE_TYPE_DIRECTORY && _(flags).contains(O_WRITE)) { callback(new Errors.EISDIR('the named file is a directory and O_WRITE is set', path)); } else { context.getObject(directoryEntry.id, check_if_symbolic_link); @@ -10752,7 +10845,7 @@ function open_file(context, path, flags, callback) { callback(error); } else { var node = result; - if(node.mode == MODE_SYMBOLIC_LINK) { + if(node.type == NODE_TYPE_SYMBOLIC_LINK) { followedCount++; if(followedCount > SYMLOOP_MAX){ callback(new Errors.ELOOP(null, path)); @@ -10789,7 +10882,11 @@ function open_file(context, path, flags, callback) { } function write_file_node() { - Node.create({guid: context.guid, mode: MODE_FILE}, function(error, result) { + Node.create({ + guid: context.guid, + type: NODE_TYPE_FILE, + path: path + }, function(error, result) { if(error) { callback(error); return; @@ -10823,7 +10920,7 @@ function open_file(context, path, flags, callback) { if(error) { callback(error); } else { - directoryData[name] = new DirectoryEntry(fileNode.id, MODE_FILE); + directoryData[name] = new DirectoryEntry(fileNode.id, NODE_TYPE_FILE); context.putObject(directoryNode.data, directoryData, update_time); } } @@ -10978,7 +11075,7 @@ function read_data(context, ofd, buffer, offset, length, position, callback) { function read_file_data(error, result) { if(error) { callback(error); - } else if(result.mode === 'DIRECTORY') { + } else if(result.type === NODE_TYPE_DIRECTORY) { callback(new Errors.EISDIR('the named file is a directory', ofd.path)); } else { fileNode = result; @@ -11044,18 +11141,20 @@ function link_node(context, oldpath, newpath, callback) { newpath = normalize(newpath); var newname = basename(newpath); var newParentPath = dirname(newpath); + var ctime = Date.now(); var oldDirectoryNode; var oldDirectoryData; var newDirectoryNode; var newDirectoryData; + var fileNodeID; var fileNode; function update_time(error) { if(error) { callback(error); } else { - update_node_times(context, newpath, fileNode, { ctime: Date.now() }, callback); + update_node_times(context, newpath, fileNode, { ctime: ctime }, callback); } } @@ -11069,11 +11168,11 @@ function link_node(context, oldpath, newpath, callback) { } } - function read_directory_entry(error, result) { + function read_file_node(error, result) { if(error) { callback(error); } else { - context.getObject(newDirectoryData[newname].id, update_file_node); + context.getObject(fileNodeID, update_file_node); } } @@ -11086,7 +11185,8 @@ function link_node(context, oldpath, newpath, callback) { callback(new Errors.EEXIST('newpath resolves to an existing file', newname)); } else { newDirectoryData[newname] = oldDirectoryData[oldname]; - context.putObject(newDirectoryNode.data, newDirectoryData, read_directory_entry); + fileNodeID = newDirectoryData[newname].id; + context.putObject(newDirectoryNode.data, newDirectoryData, read_file_node); } } } @@ -11107,7 +11207,7 @@ function link_node(context, oldpath, newpath, callback) { oldDirectoryData = result; if(!_(oldDirectoryData).has(oldname)) { callback(new Errors.ENOENT('a component of either path prefix does not exist', oldname)); - } else if(oldDirectoryData[oldname].type === 'DIRECTORY') { + } else if(oldDirectoryData[oldname].type === NODE_TYPE_DIRECTORY) { callback(new Errors.EPERM('oldpath refers to a directory')); } else { find_node(context, newParentPath, read_new_directory_data); @@ -11175,7 +11275,7 @@ function unlink_node(context, path, callback) { function check_if_node_is_directory(error, result) { if(error) { callback(error); - } else if(result.mode === 'DIRECTORY') { + } else if(result.type === NODE_TYPE_DIRECTORY) { callback(new Errors.EPERM('unlink not permitted on directories', name)); } else { update_file_node(null, result); @@ -11227,7 +11327,7 @@ function read_directory(context, path, callback) { function read_directory_data(error, result) { if(error) { callback(error); - } else if(result.mode !== MODE_DIRECTORY) { + } else if(result.type !== NODE_TYPE_DIRECTORY) { callback(new Errors.ENOTDIR(null, path)); } else { directoryNode = result; @@ -11276,7 +11376,11 @@ function make_symbolic_link(context, srcpath, dstpath, callback) { } function write_file_node() { - Node.create({guid: context.guid, mode: MODE_SYMBOLIC_LINK}, function(error, result) { + Node.create({ + guid: context.guid, + type: NODE_TYPE_SYMBOLIC_LINK, + path: dstpath + }, function(error, result) { if(error) { callback(error); return; @@ -11302,7 +11406,7 @@ function make_symbolic_link(context, srcpath, dstpath, callback) { if(error) { callback(error); } else { - directoryData[name] = new DirectoryEntry(fileNode.id, MODE_SYMBOLIC_LINK); + directoryData[name] = new DirectoryEntry(fileNode.id, NODE_TYPE_SYMBOLIC_LINK); context.putObject(directoryNode.data, directoryData, update_time); } } @@ -11344,7 +11448,7 @@ function read_link(context, path, callback) { if(error) { callback(error); } else { - if(result.mode != MODE_SYMBOLIC_LINK) { + if(result.type != NODE_TYPE_SYMBOLIC_LINK) { callback(new Errors.EINVAL('path not a symbolic link', path)); } else { callback(null, result.data); @@ -11361,7 +11465,7 @@ function truncate_file(context, path, length, callback) { function read_file_data (error, node) { if (error) { callback(error); - } else if(node.mode == MODE_DIRECTORY ) { + } else if(node.type == NODE_TYPE_DIRECTORY ) { callback(new Errors.EISDIR(null, path)); } else{ fileNode = node; @@ -11417,7 +11521,7 @@ function ftruncate_file(context, ofd, length, callback) { function read_file_data (error, node) { if (error) { callback(error); - } else if(node.mode == MODE_DIRECTORY ) { + } else if(node.type == NODE_TYPE_DIRECTORY ) { callback(new Errors.EISDIR()); } else{ fileNode = node; @@ -11768,9 +11872,9 @@ function close(fs, context, fd, callback) { } } -function mknod(fs, context, path, mode, callback) { +function mknod(fs, context, path, type, callback) { if(!pathCheck(path, callback)) return; - make_node(context, path, mode, callback); + make_node(context, path, type, callback); } function mkdir(fs, context, path, mode, callback) { @@ -11792,7 +11896,7 @@ function stat(fs, context, path, callback) { if(error) { callback(error); } else { - var stats = new Stats(result, fs.name); + var stats = new Stats(path, result, fs.name); callback(null, stats); } } @@ -11805,7 +11909,7 @@ function fstat(fs, context, fd, callback) { if(error) { callback(error); } else { - var stats = new Stats(result, fs.name); + var stats = new Stats(fd.path, result, fs.name); callback(null, stats); } } @@ -11878,7 +11982,7 @@ function readFile(fs, context, path, options, callback) { return callback(err); } - var stats = new Stats(fstatResult, fs.name); + var stats = new Stats(ofd.path, fstatResult, fs.name); if(stats.isDirectory()) { cleanup(); @@ -12150,12 +12254,15 @@ function rename(fs, context, oldpath, newpath, callback) { var newName = Path.basename(newpath); var oldParentDirectory, oldParentData; var newParentDirectory, newParentData; + var ctime = Date.now(); + var fileNode; - function update_times(error, newNode) { + function update_times(error, result) { if(error) { callback(error); } else { - update_node_times(context, newpath, newNode, { ctime: Date.now() }, callback); + fileNode = result; + update_node_times(context, newpath, fileNode, { ctime: ctime }, callback); } } @@ -12239,7 +12346,7 @@ function rename(fs, context, oldpath, newpath, callback) { function check_node_type(error, node) { if(error) { callback(error); - } else if(node.mode === 'DIRECTORY') { + } else if(node.type === NODE_TYPE_DIRECTORY) { find_node(context, oldParentPath, read_parent_directory_data); } else { link_node(context, oldpath, newpath, unlink_old_file); @@ -12269,7 +12376,7 @@ function lstat(fs, context, path, callback) { if(error) { callback(error); } else { - var stats = new Stats(result, fs.name); + var stats = new Stats(path, result, fs.name); callback(null, stats); } } @@ -12759,13 +12866,42 @@ module.exports = { }; },{"./buffer.js":51,"./errors.js":55,"./filesystem/interface.js":57,"./path.js":62,"./shell/shell.js":69}],60:[function(require,module,exports){ -var MODE_FILE = require('./constants.js').MODE_FILE; +var path = require('./path.js'); +var hash32 = require('./encoding.js').hash32; + +var NODE_TYPE_FILE = require('./constants.js').NODE_TYPE_FILE; +var NODE_TYPE_DIRECTORY = require('./constants.js').NODE_TYPE_DIRECTORY; +var NODE_TYPE_SYMBOLIC_LINK = require('./constants.js').NODE_TYPE_SYMBOLIC_LINK; +var NODE_TYPE_META = require('./constants.js').NODE_TYPE_META; + +var ROOT_DIRECTORY_NAME = require('./constants.js').ROOT_DIRECTORY_NAME; + +var S_IFREG = require('./constants.js').S_IFREG; +var S_IFDIR = require('./constants.js').S_IFDIR; +var S_IFLNK = require('./constants.js').S_IFLNK; + +var DEFAULT_FILE_PERMISSIONS = require('./constants.js').DEFAULT_FILE_PERMISSIONS; +var DEFAULT_DIR_PERMISSIONS = require('./constants.js').DEFAULT_DIR_PERMISSIONS; + +function getMode(type) { + switch(type) { + case NODE_TYPE_DIRECTORY: + return DEFAULT_DIR_PERMISSIONS | S_IFDIR; + case NODE_TYPE_SYMBOLIC_LINK: + return DEFAULT_FILE_PERMISSIONS | S_IFLNK; + /* jshint -W086 */ + case NODE_TYPE_FILE: + // falls through + default: + return DEFAULT_FILE_PERMISSIONS | S_IFREG; + } +} function Node(options) { var now = Date.now(); this.id = options.id; - this.mode = options.mode || MODE_FILE; // node type (file, directory, etc) + this.type = options.type || NODE_TYPE_FILE; // node type (file, directory, etc) this.size = options.size || 0; // size (bytes for files, entries for directories) this.atime = options.atime || now; // access time (will mirror ctime after creation) this.ctime = options.ctime || now; // creation/change time @@ -12773,10 +12909,13 @@ function Node(options) { this.flags = options.flags || []; // file flags this.xattrs = options.xattrs || {}; // extended attributes this.nlinks = options.nlinks || 0; // links count - this.version = options.version || 0; // node version - this.blksize = undefined; // block size - this.nblocks = 1; // blocks count this.data = options.data; // id for data object + this.version = options.version || 1; + + // permissions and flags + this.mode = options.mode || (getMode(this.type)); + this.uid = options.uid || 0x0; // owner name + this.gid = options.gid || 0x0; // group name } // Make sure the options object has an id on property, @@ -12813,7 +12952,7 @@ Node.create = function(options, callback) { module.exports = Node; -},{"./constants.js":52}],61:[function(require,module,exports){ +},{"./constants.js":52,"./encoding.js":54,"./path.js":62}],61:[function(require,module,exports){ var Errors = require('./errors.js'); function OpenFileDescription(path, id, flags, position) { @@ -13139,43 +13278,57 @@ var indexedDB = global.indexedDB || global.msIndexedDB; function IndexedDBContext(db, mode) { - var transaction = db.transaction(FILE_STORE_NAME, mode); - this.objectStore = transaction.objectStore(FILE_STORE_NAME); + this.db = db; + this.mode = mode; } +IndexedDBContext.prototype._getObjectStore = function() { + if(this.objectStore) { + return this.objectStore; + } + + var transaction = this.db.transaction(FILE_STORE_NAME, this.mode); + this.objectStore = transaction.objectStore(FILE_STORE_NAME); + return this.objectStore; +}; + IndexedDBContext.prototype.clear = function(callback) { try { - var request = this.objectStore.clear(); - request.onsuccess = function(event) { + var objectStore = this._getObjectStore(); + var request = objectStore.clear(); + request.onsuccess = function() { callback(); }; - request.onerror = function(error) { - callback(error); + request.onerror = function(event) { + event.preventDefault(); + callback(event.error); }; - } catch(e) { - callback(e); + } catch(err) { + callback(err); } }; -function _get(objectStore, key, callback) { +IndexedDBContext.prototype._get = function(key, callback) { try { + var objectStore = this._getObjectStore(); var request = objectStore.get(key); request.onsuccess = function onsuccess(event) { var result = event.target.result; callback(null, result); }; - request.onerror = function onerror(error) { - callback(error); + request.onerror = function(event) { + event.preventDefault(); + callback(event.error); }; - } catch(e) { - callback(e); + } catch(err) { + callback(err); } -} +}; IndexedDBContext.prototype.getObject = function(key, callback) { - _get(this.objectStore, key, callback); + this._get(key, callback); }; IndexedDBContext.prototype.getBuffer = function(key, callback) { - _get(this.objectStore, key, function(err, arrayBuffer) { + this._get(key, function(err, arrayBuffer) { if(err) { return callback(err); } @@ -13183,22 +13336,24 @@ IndexedDBContext.prototype.getBuffer = function(key, callback) { }); }; -function _put(objectStore, key, value, callback) { +IndexedDBContext.prototype._put = function(key, value, callback) { try { + var objectStore = this._getObjectStore(); var request = objectStore.put(value, key); request.onsuccess = function onsuccess(event) { var result = event.target.result; callback(null, result); }; - request.onerror = function onerror(error) { - callback(error); + request.onerror = function(event) { + event.preventDefault(); + callback(event.error); }; - } catch(e) { - callback(e); + } catch(err) { + callback(err); } -} +}; IndexedDBContext.prototype.putObject = function(key, value, callback) { - _put(this.objectStore, key, value, callback); + this._put(key, value, callback); }; IndexedDBContext.prototype.putBuffer = function(key, uint8BackedBuffer, callback) { var buf; @@ -13207,21 +13362,23 @@ IndexedDBContext.prototype.putBuffer = function(key, uint8BackedBuffer, callback } else { buf = uint8BackedBuffer.buffer; } - _put(this.objectStore, key, buf, callback); + this._put(key, buf, callback); }; IndexedDBContext.prototype.delete = function(key, callback) { try { - var request = this.objectStore.delete(key); + var objectStore = this._getObjectStore(); + var request = objectStore.delete(key); request.onsuccess = function onsuccess(event) { var result = event.target.result; callback(null, result); }; - request.onerror = function(error) { - callback(error); + request.onerror = function(event) { + event.preventDefault(); + callback(event.error); }; - } catch(e) { - callback(e); + } catch(err) { + callback(err); } }; @@ -13242,32 +13399,35 @@ IndexedDB.prototype.open = function(callback) { return callback(); } - // NOTE: we're not using versioned databases. - var openRequest = indexedDB.open(that.name); + try { + // NOTE: we're not using versioned databases. + var openRequest = indexedDB.open(that.name); - // If the db doesn't exist, we'll create it - openRequest.onupgradeneeded = function onupgradeneeded(event) { - var db = event.target.result; + // If the db doesn't exist, we'll create it + openRequest.onupgradeneeded = function onupgradeneeded(event) { + var db = event.target.result; - if(db.objectStoreNames.contains(FILE_STORE_NAME)) { - db.deleteObjectStore(FILE_STORE_NAME); - } - db.createObjectStore(FILE_STORE_NAME); - }; + if(db.objectStoreNames.contains(FILE_STORE_NAME)) { + db.deleteObjectStore(FILE_STORE_NAME); + } + db.createObjectStore(FILE_STORE_NAME); + }; - openRequest.onsuccess = function onsuccess(event) { - that.db = event.target.result; - callback(); - }; - openRequest.onerror = function onerror(error) { - callback(new Errors.EINVAL('IndexedDB cannot be accessed. If private browsing is enabled, disable it.')); - }; + openRequest.onsuccess = function onsuccess(event) { + that.db = event.target.result; + callback(); + }; + openRequest.onerror = function onerror(event) { + event.preventDefault(); + callback(event.error); + }; + } catch(err) { + callback(err); + } }; + IndexedDB.prototype.getReadOnlyContext = function() { - // Due to timing issues in Chrome with readwrite vs. readonly indexeddb transactions - // always use readwrite so we can make sure pending commits finish before callbacks. - // See https://github.com/js-platform/filer/issues/128 - return new IndexedDBContext(this.db, IDB_RW); + return new IndexedDBContext(this.db, IDB_RO); }; IndexedDB.prototype.getReadWriteContext = function() { return new IndexedDBContext(this.db, IDB_RW); @@ -13276,7 +13436,7 @@ IndexedDB.prototype.getReadWriteContext = function() { module.exports = IndexedDB; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer) -},{"../buffer.js":51,"../constants.js":52,"../errors.js":55,"buffer":38}],65:[function(require,module,exports){ +},{"../buffer.js":51,"../constants.js":52,"../errors.js":55,"buffer":8}],65:[function(require,module,exports){ var FILE_SYSTEM_NAME = require('../constants.js').FILE_SYSTEM_NAME; // NOTE: prefer setImmediate to nextTick for proper recursion yielding. // see https://github.com/js-platform/filer/pull/24 @@ -13543,7 +13703,7 @@ WebSQL.prototype.getReadWriteContext = function() { module.exports = WebSQL; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"../buffer.js":51,"../constants.js":52,"../errors.js":55,"base64-arraybuffer":5}],67:[function(require,module,exports){ +},{"../buffer.js":51,"../constants.js":52,"../errors.js":55,"base64-arraybuffer":6}],67:[function(require,module,exports){ function guid() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); @@ -13824,16 +13984,10 @@ Shell.prototype.ls = function(dir, options, callback) { callback(error); return; } - var entry = { - path: Path.basename(name), - links: stats.nlinks, - size: stats.size, - modified: stats.mtime, - type: stats.type - }; + var entry = stats; if(options.recursive && stats.type === 'DIRECTORY') { - list(Path.join(pathname, entry.path), function(error, items) { + list(Path.join(pathname, entry.name), function(error, items) { if(error) { callback(error); return; @@ -14136,30 +14290,37 @@ Shell.prototype.mkdirp = function(path, callback) { module.exports = Shell; -},{"../../lib/async.js":1,"../encoding.js":54,"../errors.js":55,"../path.js":62,"./environment.js":68,"minimatch":48}],70:[function(require,module,exports){ +},{"../../lib/async.js":1,"../encoding.js":54,"../errors.js":55,"../path.js":62,"./environment.js":68,"minimatch":41}],70:[function(require,module,exports){ var Constants = require('./constants.js'); +var Path = require('./path.js'); -function Stats(fileNode, devName) { - this.node = fileNode.id; +function Stats(path, fileNode, devName) { this.dev = devName; + this.node = fileNode.id; + this.type = fileNode.type; + this.name = fileNode.name; this.size = fileNode.size; this.nlinks = fileNode.nlinks; this.atime = fileNode.atime; this.mtime = fileNode.mtime; this.ctime = fileNode.ctime; - this.type = fileNode.mode; + this.version = fileNode.version; + this.mode = fileNode.mode; + this.uid = fileNode.uid; + this.gid = fileNode.gid; + this.name = Path.basename(path); } Stats.prototype.isFile = function() { - return this.type === Constants.MODE_FILE; + return this.type === Constants.NODE_TYPE_FILE; }; Stats.prototype.isDirectory = function() { - return this.type === Constants.MODE_DIRECTORY; + return this.type === Constants.NODE_TYPE_DIRECTORY; }; Stats.prototype.isSymbolicLink = function() { - return this.type === Constants.MODE_SYMBOLIC_LINK; + return this.type === Constants.NODE_TYPE_SYMBOLIC_LINK; }; // These will always be false in Filer. @@ -14173,14 +14334,14 @@ function() { module.exports = Stats; -},{"./constants.js":52}],71:[function(require,module,exports){ +},{"./constants.js":52,"./path.js":62}],71:[function(require,module,exports){ var Constants = require('./constants.js'); function SuperNode(options) { var now = Date.now(); this.id = Constants.SUPER_NODE_ID; - this.mode = Constants.MODE_META; + this.type = Constants.NODE_TYPE_META; this.atime = options.atime || now; this.ctime = options.ctime || now; this.mtime = options.mtime || now; @@ -14239,7 +14400,7 @@ describe('trailing slashes in path names, issue 105', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],73:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],73:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -14273,7 +14434,7 @@ describe('fs.writeFile truncation - issue 106', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],74:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],74:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -14296,7 +14457,7 @@ describe('fs.writeFile and non-existing directory, issue 239', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],75:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],75:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -14334,7 +14495,7 @@ describe('sh.cd doesn\'t seem to be working from a relative path if I am one or }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],76:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],76:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -14378,7 +14539,7 @@ describe('Filer.Buffer static methods are in tact, issue 249', function() { }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],77:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],77:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -14427,7 +14588,7 @@ describe('EISDIR when trying to open a dir path - issue 254', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],78:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],78:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -14483,7 +14644,9 @@ describe('Queued operations should error when fs is in error state, issue 258', it('should get EFILESYSTEMERROR errors on callbacks to queued operations on provider error', function(done) { var errCount = 0; - var fs = new Filer.FileSystem({provider: provider}); + var fs = new Filer.FileSystem({provider: provider}, function(err) { + // Do nothing + }); function maybeDone(err) { expect(err).to.exist; @@ -14518,7 +14681,7 @@ describe('Queued operations should error when fs is in error state, issue 258', }); }); -},{"../..":59,"../../lib/async.js":1,"../lib/test-utils.js":87,"chai":6}],79:[function(require,module,exports){ +},{"../..":59,"../../lib/async.js":1,"../lib/test-utils.js":87,"chai":10}],79:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -14542,7 +14705,7 @@ describe('fs.readdir on non-dir paths, issue 267', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],80:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],80:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -14572,7 +14735,7 @@ describe('undefined and relative paths, issue270', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],81:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],81:[function(require,module,exports){ var Path = require('../..').Path; var expect = require('chai').expect; @@ -14591,7 +14754,7 @@ describe('Path.resolve does not work, issue357', function() { }); }); -},{"../..":59,"chai":6}],82:[function(require,module,exports){ +},{"../..":59,"chai":10}],82:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -14619,7 +14782,7 @@ describe('sh.ls and deep directory trees', function() { done(); }); }); - }); + }).timeout(15000); it('should not crash when calling sh.ls() on wide directory layouts', function(done) { var fs = util.fs(); @@ -14649,10 +14812,10 @@ describe('sh.ls and deep directory trees', function() { }); }); }); - }); + }).timeout(15000); }); -},{"../..":59,"../../lib/async.js":1,"../lib/test-utils.js":87,"chai":6}],83:[function(require,module,exports){ +},{"../..":59,"../../lib/async.js":1,"../lib/test-utils.js":87,"chai":10}],83:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -14682,7 +14845,7 @@ describe('trailing slashes in path names to work when renaming a dir', function( }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],84:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],84:[function(require,module,exports){ /** * Add your test spec files to the list in order to * get them running by default. @@ -14790,20 +14953,26 @@ function IndexedDBTestProvider(name) { return callback(); } - // We have to force any other connections to close - // before we can delete a db. - if(that.provider.db) { - that.provider.db.close(); - } - - var request = indexedDB.deleteDatabase(name); function finished() { that.provider = null; _done = true; callback(); } - request.onsuccess = finished; - request.onerror = finished; + + try { + // We have to force any other connections to close + // before we can delete a db. + if(that.provider.db) { + that.provider.db.close(); + } + + var request = indexedDB.deleteDatabase(name); + request.onsuccess = finished; + request.onerror = finished; + } catch(e) { + console.log("Failed to delete test database", e); + finished(); + } } function init() { @@ -14894,6 +15063,7 @@ function getUrlParams() { } function getProviderType() { + var defaultProvider = 'default'; var queryString = getUrlParams(); // If the environment is node or the query string is empty, @@ -14902,7 +15072,7 @@ function getProviderType() { return defaultProvider; } - return queryString['filer-provider'] || 'default'; + return queryString['filer-provider'] || defaultProvider; } function setup(callback) { @@ -14925,7 +15095,6 @@ function setup(callback) { break; case 'default': default: - console.log('default'); var BestProvider = findBestProvider(); _provider = new BestProvider(name); break; @@ -15013,7 +15182,7 @@ module.exports = { }; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"../..":59,"./indexeddb.js":85,"./memory.js":86,"./websql.js":88,"url":47}],88:[function(require,module,exports){ +},{"../..":59,"./indexeddb.js":85,"./memory.js":86,"./websql.js":88,"url":50}],88:[function(require,module,exports){ (function (global){ var Filer = require('../..'); @@ -15249,7 +15418,7 @@ describe("Filer.Errors", function() { }); }); -},{"../..":59,"chai":6}],90:[function(require,module,exports){ +},{"../..":59,"chai":10}],90:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -15297,7 +15466,7 @@ describe("Filer.FileSystem", function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],91:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],91:[function(require,module,exports){ var Filer = require('../..'); var expect = require('chai').expect; @@ -15315,7 +15484,7 @@ describe("Filer", function() { }); }); -},{"../..":59,"chai":6}],92:[function(require,module,exports){ +},{"../..":59,"chai":10}],92:[function(require,module,exports){ (function (Buffer){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); @@ -15449,7 +15618,7 @@ describe('fs.appendFile', function() { }); }).call(this,require("buffer").Buffer) -},{"../..":59,"../lib/test-utils.js":87,"buffer":38,"chai":6}],93:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"buffer":8,"chai":10}],93:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -15481,7 +15650,7 @@ describe('fs.close', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],94:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],94:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -15543,7 +15712,7 @@ describe('fs.exists', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],95:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],95:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -15588,6 +15757,30 @@ describe('fs.link', function() { }); }); + it('should create hard link to identical data node', function(done) { + var fs = util.fs(); + var contents = "Hello World!"; + + fs.writeFile('/file', contents, function(err) { + if(err) throw err; + + fs.link('/file', '/hlink', function(err) { + if(err) throw err; + + fs.readFile('/file', 'utf8', function(err, fileData) { + if(err) throw err; + + fs.readFile('/hlink', 'utf8', function(err, hlinkData) { + if(err) throw err; + + expect(fileData).to.equal(hlinkData); + done(); + }); + }); + }); + }); + }); + it('should not follow symbolic links', function(done) { var fs = util.fs(); @@ -15631,7 +15824,7 @@ describe('fs.link', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],96:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],96:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -15800,7 +15993,7 @@ describe('fs.lseek', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],97:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],97:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -15853,7 +16046,7 @@ describe('fs.lstat', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],98:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],98:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -15904,7 +16097,7 @@ describe('fs.mkdir', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],99:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],99:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -15987,7 +16180,7 @@ describe('fs.mknod', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],100:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],100:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -16129,7 +16322,7 @@ describe('fs.open', function() { }); }); -},{"../..":59,"../../src/constants.js":52,"../lib/test-utils.js":87,"chai":6}],101:[function(require,module,exports){ +},{"../..":59,"../../src/constants.js":52,"../lib/test-utils.js":87,"chai":10}],101:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -16219,7 +16412,7 @@ describe('fs.read', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],102:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],102:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -16279,7 +16472,7 @@ describe('fs.readdir', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],103:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],103:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -16328,7 +16521,7 @@ describe('fs.readlink', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],104:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],104:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -16484,7 +16677,7 @@ describe('fs.rename', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],105:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],105:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -16587,7 +16780,7 @@ describe('fs.rmdir', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],106:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],106:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -16622,7 +16815,7 @@ describe("fs.Shell", function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],107:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],107:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -16648,7 +16841,7 @@ describe("fs", function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],108:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],108:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -16745,7 +16938,7 @@ describe('fs.stat', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],109:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],109:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -16755,11 +16948,12 @@ describe('fs.stats', function() { beforeEach(util.setup); afterEach(util.cleanup); - it('should be a function', function() { + it('should be a function', function(done) { var fs = util.fs(); fs.stat('/', function(error, stats) { if(error) throw error; expect(stats.isFile).to.be.a('function'); + done(); }); }); @@ -16808,11 +17002,12 @@ describe('fs.stats', function() { beforeEach(util.setup); afterEach(util.cleanup); - it('should be a function', function() { + it('should be a function', function(done) { var fs = util.fs(); fs.stat('/', function(error, stats) { if(error) throw error; expect(stats.isDirectory).to.be.a('function'); + done(); }); }); @@ -16861,19 +17056,21 @@ describe('fs.stats', function() { beforeEach(util.setup); afterEach(util.cleanup); - it('should be a function', function() { + it('should be a function', function(done) { var fs = util.fs(); fs.stat('/', function(error, stats) { if(error) throw error; expect(stats.isBlockDevice).to.be.a('function'); + done(); }); }); - it('should return false', function() { + it('should return false', function(done) { var fs = util.fs(); fs.stat('/', function(error, stats) { if(error) throw error; expect(stats.isBlockDevice()).to.be.false; + done(); }); }); }); @@ -16882,19 +17079,21 @@ describe('fs.stats', function() { beforeEach(util.setup); afterEach(util.cleanup); - it('should be a function', function() { + it('should be a function', function(done) { var fs = util.fs(); fs.stat('/', function(error, stats) { if(error) throw error; expect(stats.isCharacterDevice).to.be.a('function'); + done(); }); }); - it('should return false', function() { + it('should return false', function(done) { var fs = util.fs(); fs.stat('/', function(error, stats) { if(error) throw error; expect(stats.isCharacterDevice()).to.be.false; + done(); }); }); }); @@ -16903,11 +17102,12 @@ describe('fs.stats', function() { beforeEach(util.setup); afterEach(util.cleanup); - it('should be a function', function() { + it('should be a function', function(done) { var fs = util.fs(); fs.stat('/', function(error, stats) { if(error) throw error; expect(stats.isSymbolicLink).to.be.a('function'); + done(); }); }); @@ -16956,19 +17156,21 @@ describe('fs.stats', function() { beforeEach(util.setup); afterEach(util.cleanup); - it('should be a function', function() { + it('should be a function', function(done) { var fs = util.fs(); fs.stat('/', function(error, stats) { if(error) throw error; expect(stats.isFIFO).to.be.a('function'); + done(); }); }); - it('should return false', function() { + it('should return false', function(done) { var fs = util.fs(); fs.stat('/', function(error, stats) { if(error) throw error; expect(stats.isFIFO()).to.be.false; + done(); }); }); }); @@ -16977,25 +17179,27 @@ describe('fs.stats', function() { beforeEach(util.setup); afterEach(util.cleanup); - it('should be a function', function() { + it('should be a function', function(done) { var fs = util.fs(); fs.stat('/', function(error, stats) { if(error) throw error; expect(stats.isSocket).to.be.a('function'); + done(); }); }); - it('should return false', function() { + it('should return false', function(done) { var fs = util.fs(); fs.stat('/', function(error, stats) { if(error) throw error; expect(stats.isSocket()).to.be.false; + done(); }); }); }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],110:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],110:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -17044,7 +17248,7 @@ describe('fs.symlink', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],111:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],111:[function(require,module,exports){ (function (Buffer){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); @@ -17238,7 +17442,7 @@ describe('fs.truncate', function() { }); }).call(this,require("buffer").Buffer) -},{"../..":59,"../lib/test-utils.js":87,"buffer":38,"chai":6}],112:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"buffer":8,"chai":10}],112:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -17345,7 +17549,7 @@ describe('fs.unlink', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],113:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],113:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -17527,7 +17731,7 @@ describe('fs.utimes', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],114:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],114:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -17597,7 +17801,7 @@ describe('fs.watch', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],115:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],115:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -17661,7 +17865,7 @@ describe('fs.write', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],116:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],116:[function(require,module,exports){ (function (Buffer){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); @@ -17769,7 +17973,7 @@ describe('fs.writeFile, fs.readFile', function() { }); }).call(this,require("buffer").Buffer) -},{"../..":59,"../lib/test-utils.js":87,"buffer":38,"chai":6}],117:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"buffer":8,"chai":10}],117:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -18165,7 +18369,7 @@ describe('fs.xattr', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],118:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],118:[function(require,module,exports){ var Filer = require('../../../..'); var util = require('../../../lib/test-utils.js'); var expect = require('chai').expect; @@ -18207,7 +18411,7 @@ describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/ }); }); -},{"../../../..":59,"../../../lib/test-utils.js":87,"chai":6}],119:[function(require,module,exports){ +},{"../../../..":59,"../../../lib/test-utils.js":87,"chai":10}],119:[function(require,module,exports){ var Filer = require('../../../..'); var util = require('../../../lib/test-utils.js'); var expect = require('chai').expect; @@ -18271,7 +18475,7 @@ describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/ }); }); -},{"../../../..":59,"../../../lib/test-utils.js":87,"chai":6}],120:[function(require,module,exports){ +},{"../../../..":59,"../../../lib/test-utils.js":87,"chai":10}],120:[function(require,module,exports){ var Filer = require('../../../..'); var util = require('../../../lib/test-utils.js'); var expect = require('chai').expect; @@ -18309,7 +18513,7 @@ describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/ }); }); -},{"../../../..":59,"../../../lib/test-utils.js":87,"chai":6}],121:[function(require,module,exports){ +},{"../../../..":59,"../../../lib/test-utils.js":87,"chai":10}],121:[function(require,module,exports){ var Filer = require('../../../..'); var util = require('../../../lib/test-utils.js'); var expect = require('chai').expect; @@ -18384,7 +18588,7 @@ describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/ }); }); -},{"../../../..":59,"../../../lib/test-utils.js":87,"chai":6}],122:[function(require,module,exports){ +},{"../../../..":59,"../../../lib/test-utils.js":87,"chai":10}],122:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -18630,7 +18834,7 @@ describe('path resolution', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],123:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],123:[function(require,module,exports){ var Buffer = require('../../..').Buffer; var util = require('../../lib/test-utils.js'); var expect = require('chai').expect; @@ -18797,7 +19001,7 @@ module.exports = function createProviderTestsFor(providerName, testProvider) { }); }; -},{"../../..":59,"../../lib/test-utils.js":87,"chai":6}],124:[function(require,module,exports){ +},{"../../..":59,"../../lib/test-utils.js":87,"chai":10}],124:[function(require,module,exports){ var util = require('../../lib/test-utils.js'); var providerBase = require('./providers.base.js'); @@ -18839,7 +19043,7 @@ describe("Filer.FileSystem.providers", function() { }); }); -},{"../../..":59,"chai":6}],127:[function(require,module,exports){ +},{"../../..":59,"chai":10}],127:[function(require,module,exports){ var util = require('../../lib/test-utils.js'); var providerBase = require('./providers.base.js'); @@ -18931,7 +19135,7 @@ describe('FileSystemShell.cat', function() { }); }); -},{"../../..":59,"../../lib/test-utils.js":87,"chai":6}],129:[function(require,module,exports){ +},{"../../..":59,"../../lib/test-utils.js":87,"chai":10}],129:[function(require,module,exports){ var Filer = require('../../..'); var util = require('../../lib/test-utils.js'); var expect = require('chai').expect; @@ -19056,7 +19260,7 @@ describe('FileSystemShell.cd', function() { }); }); -},{"../../..":59,"../../lib/test-utils.js":87,"chai":6}],130:[function(require,module,exports){ +},{"../../..":59,"../../lib/test-utils.js":87,"chai":10}],130:[function(require,module,exports){ var Filer = require('../../..'); var util = require('../../lib/test-utils.js'); var expect = require('chai').expect; @@ -19171,7 +19375,7 @@ describe('FileSystemShell.env', function() { }); }); -},{"../../..":59,"../../lib/test-utils.js":87,"chai":6}],131:[function(require,module,exports){ +},{"../../..":59,"../../lib/test-utils.js":87,"chai":10}],131:[function(require,module,exports){ var Filer = require('../../..'); var util = require('../../lib/test-utils.js'); var expect = require('chai').expect; @@ -19206,7 +19410,7 @@ describe('FileSystemShell.exec', function() { }); }); -},{"../../..":59,"../../lib/test-utils.js":87,"chai":6}],132:[function(require,module,exports){ +},{"../../..":59,"../../lib/test-utils.js":87,"chai":10}],132:[function(require,module,exports){ var Filer = require('../../..'); var util = require('../../lib/test-utils.js'); var expect = require('chai').expect; @@ -19414,7 +19618,7 @@ describe('FileSystemShell.find', function() { }); -},{"../../..":59,"../../lib/test-utils.js":87,"chai":6}],133:[function(require,module,exports){ +},{"../../..":59,"../../lib/test-utils.js":87,"chai":10}],133:[function(require,module,exports){ var Filer = require('../../..'); var util = require('../../lib/test-utils.js'); var expect = require('chai').expect; @@ -19457,18 +19661,18 @@ describe('FileSystemShell.ls', function() { expect(list.length).to.equal(2); var item0 = list[0]; - expect(item0.path).to.equal('file'); - expect(item0.links).to.equal(1); + expect(item0.name).to.equal('file'); + expect(item0.nlinks).to.equal(1); expect(item0.size).to.equal(1); - expect(item0.modified).to.be.a('number'); + expect(item0.mtime).to.be.a('number'); expect(item0.type).to.equal('FILE'); expect(item0.contents).not.to.exist; var item1 = list[1]; - expect(item1.path).to.equal('file2'); - expect(item1.links).to.equal(1); + expect(item1.name).to.equal('file2'); + expect(item1.nlinks).to.equal(1); expect(item1.size).to.equal(2); - expect(item1.modified).to.be.a('number'); + expect(item1.mtime).to.be.a('number'); expect(item1.type).to.equal('FILE'); expect(item0.contents).not.to.exist; @@ -19501,19 +19705,19 @@ describe('FileSystemShell.ls', function() { // We shouldn't rely on the order we'll get the listing list.forEach(function(item, i, arr) { - switch(item.path) { + switch(item.name) { case 'dir2': - expect(item.links).to.equal(1); + expect(item.nlinks).to.equal(1); expect(item.size).to.be.a('number'); - expect(item.modified).to.be.a('number'); + expect(item.mtime).to.be.a('number'); expect(item.type).to.equal('DIRECTORY'); expect(item.contents).not.to.exist; break; case 'file': case 'file2': - expect(item.links).to.equal(1); + expect(item.nlinks).to.equal(1); expect(item.size).to.equal(1); - expect(item.modified).to.be.a('number'); + expect(item.mtime).to.be.a('number'); expect(item.type).to.equal('FILE'); expect(item.contents).not.to.exist; break; @@ -19560,27 +19764,27 @@ describe('FileSystemShell.ls', function() { // We shouldn't rely on the order we'll get the listing list.forEach(function(item, i, arr) { - switch(item.path) { + switch(item.name) { case 'dir2': - expect(item.links).to.equal(1); + expect(item.nlinks).to.equal(1); expect(item.size).to.be.a('number'); - expect(item.modified).to.be.a('number'); + expect(item.mtime).to.be.a('number'); expect(item.type).to.equal('DIRECTORY'); expect(item.contents).to.exist; expect(item.contents.length).to.equal(1); var contents0 = item.contents[0]; - expect(contents0.path).to.equal('file'); - expect(contents0.links).to.equal(1); + expect(contents0.name).to.equal('file'); + expect(contents0.nlinks).to.equal(1); expect(contents0.size).to.equal(1); - expect(contents0.modified).to.be.a('number'); + expect(contents0.mtime).to.be.a('number'); expect(contents0.type).to.equal('FILE'); expect(contents0.contents).not.to.exist; break; case 'file': case 'file2': - expect(item.links).to.equal(1); + expect(item.nlinks).to.equal(1); expect(item.size).to.equal(1); - expect(item.modified).to.be.a('number'); + expect(item.mtime).to.be.a('number'); expect(item.type).to.equal('FILE'); expect(item.contents).not.to.exist; break; @@ -19603,7 +19807,7 @@ describe('FileSystemShell.ls', function() { }); }); -},{"../../..":59,"../../lib/test-utils.js":87,"chai":6}],134:[function(require,module,exports){ +},{"../../..":59,"../../lib/test-utils.js":87,"chai":10}],134:[function(require,module,exports){ var Filer = require('../../..'); var util = require('../../lib/test-utils.js'); var expect = require('chai').expect; @@ -19703,7 +19907,7 @@ describe('FileSystemShell.mkdirp', function() { }); }); -},{"../../..":59,"../../lib/test-utils.js":87,"chai":6}],135:[function(require,module,exports){ +},{"../../..":59,"../../lib/test-utils.js":87,"chai":10}],135:[function(require,module,exports){ var Filer = require('../../..'); var util = require('../../lib/test-utils.js'); var expect = require('chai').expect; @@ -19843,7 +20047,7 @@ describe('FileSystemShell.rm', function() { }); }); -},{"../../..":59,"../../lib/test-utils.js":87,"chai":6}],136:[function(require,module,exports){ +},{"../../..":59,"../../lib/test-utils.js":87,"chai":10}],136:[function(require,module,exports){ var Filer = require('../../..'); var util = require('../../lib/test-utils.js'); var expect = require('chai').expect; @@ -19948,7 +20152,7 @@ describe('FileSystemShell.touch', function() { }); }); -},{"../../..":59,"../../lib/test-utils.js":87,"chai":6}],137:[function(require,module,exports){ +},{"../../..":59,"../../lib/test-utils.js":87,"chai":10}],137:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -20056,7 +20260,7 @@ describe('node times (atime, mtime, ctime) with mount flags', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],138:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],138:[function(require,module,exports){ var Filer = require('../..'); var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -20681,7 +20885,7 @@ describe('node times (atime, mtime, ctime)', function() { }); }); -},{"../..":59,"../lib/test-utils.js":87,"chai":6}],139:[function(require,module,exports){ +},{"../..":59,"../lib/test-utils.js":87,"chai":10}],139:[function(require,module,exports){ var Path = require('../..').Path; var expect = require('chai').expect; @@ -20698,4 +20902,4 @@ describe('Path.normalize and trailing slashes', function() { }); -},{"../..":59,"chai":6}]},{},[84]); +},{"../..":59,"chai":10}]},{},[84]); diff --git a/dist/filer.js b/dist/filer.js index e0fb44b..5ed90d2 100644 --- a/dist/filer.js +++ b/dist/filer.js @@ -587,9 +587,17 @@ module.exports = nodash; * Copyright (c) 2012 Niklas von Hertzen * Licensed under the MIT license. */ -(function(chars){ +(function(){ "use strict"; + var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + + // Use a lookup table to find the index. + var lookup = new Uint8Array(256); + for (var i = 0; i < chars.length; i++) { + lookup[chars.charCodeAt(i)] = i; + } + exports.encode = function(arraybuffer) { var bytes = new Uint8Array(arraybuffer), i, len = bytes.length, base64 = ""; @@ -626,10 +634,10 @@ module.exports = nodash; bytes = new Uint8Array(arraybuffer); for (i = 0; i < len; i+=4) { - encoded1 = chars.indexOf(base64[i]); - encoded2 = chars.indexOf(base64[i+1]); - encoded3 = chars.indexOf(base64[i+2]); - encoded4 = chars.indexOf(base64[i+3]); + encoded1 = lookup[base64.charCodeAt(i)]; + encoded2 = lookup[base64.charCodeAt(i+1)]; + encoded3 = lookup[base64.charCodeAt(i+2)]; + encoded4 = lookup[base64.charCodeAt(i+3)]; bytes[p++] = (encoded1 << 2) | (encoded2 >> 4); bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2); @@ -638,26 +646,155 @@ module.exports = nodash; return arraybuffer; }; -})("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); +})(); },{}],6:[function(require,module,exports){ +var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; + +;(function (exports) { + 'use strict'; + + var Arr = (typeof Uint8Array !== 'undefined') + ? Uint8Array + : Array + + var PLUS = '+'.charCodeAt(0) + var SLASH = '/'.charCodeAt(0) + var NUMBER = '0'.charCodeAt(0) + var LOWER = 'a'.charCodeAt(0) + var UPPER = 'A'.charCodeAt(0) + var PLUS_URL_SAFE = '-'.charCodeAt(0) + var SLASH_URL_SAFE = '_'.charCodeAt(0) + + function decode (elt) { + var code = elt.charCodeAt(0) + if (code === PLUS || + code === PLUS_URL_SAFE) + return 62 // '+' + if (code === SLASH || + code === SLASH_URL_SAFE) + return 63 // '/' + if (code < NUMBER) + return -1 //no match + if (code < NUMBER + 10) + return code - NUMBER + 26 + 26 + if (code < UPPER + 26) + return code - UPPER + if (code < LOWER + 26) + return code - LOWER + 26 + } + + function b64ToByteArray (b64) { + var i, j, l, tmp, placeHolders, arr + + if (b64.length % 4 > 0) { + throw new Error('Invalid string. Length must be a multiple of 4') + } + + // the number of equal signs (place holders) + // if there are two placeholders, than the two characters before it + // represent one byte + // if there is only one, then the three characters before it represent 2 bytes + // this is just a cheap hack to not do indexOf twice + var len = b64.length + placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0 + + // base64 is 4/3 + up to two characters of the original data + arr = new Arr(b64.length * 3 / 4 - placeHolders) + + // if there are placeholders, only get up to the last complete 4 chars + l = placeHolders > 0 ? b64.length - 4 : b64.length + + var L = 0 + + function push (v) { + arr[L++] = v + } + + for (i = 0, j = 0; i < l; i += 4, j += 3) { + tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3)) + push((tmp & 0xFF0000) >> 16) + push((tmp & 0xFF00) >> 8) + push(tmp & 0xFF) + } + + if (placeHolders === 2) { + tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4) + push(tmp & 0xFF) + } else if (placeHolders === 1) { + tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2) + push((tmp >> 8) & 0xFF) + push(tmp & 0xFF) + } + + return arr + } + + function uint8ToBase64 (uint8) { + var i, + extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes + output = "", + temp, length + + function encode (num) { + return lookup.charAt(num) + } + + function tripletToBase64 (num) { + return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F) + } + + // go through the array every three bytes, we'll deal with trailing stuff later + for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { + temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) + output += tripletToBase64(temp) + } + + // pad the end with zeros, but make sure to not forget the extra bytes + switch (extraBytes) { + case 1: + temp = uint8[uint8.length - 1] + output += encode(temp >> 2) + output += encode((temp << 4) & 0x3F) + output += '==' + break + case 2: + temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]) + output += encode(temp >> 10) + output += encode((temp >> 4) & 0x3F) + output += encode((temp << 2) & 0x3F) + output += '=' + break + } + + return output + } + + exports.toByteArray = b64ToByteArray + exports.fromByteArray = uint8ToBase64 +}(typeof exports === 'undefined' ? (this.base64js = {}) : exports)) + +},{}],7:[function(require,module,exports){ +(function (global){ /*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh * @license MIT */ +/* eslint-disable no-proto */ + +'use strict' var base64 = require('base64-js') var ieee754 = require('ieee754') -var isArray = require('is-array') +var isArray = require('isarray') exports.Buffer = Buffer exports.SlowBuffer = SlowBuffer exports.INSPECT_MAX_BYTES = 50 Buffer.poolSize = 8192 // not used by this implementation -var kMaxLength = 0x3fffffff var rootParent = {} /** @@ -668,32 +805,49 @@ var rootParent = {} * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, * Opera 11.6+, iOS 4.2+. * + * Due to various browser bugs, sometimes the Object implementation will be used even + * when the browser supports typed arrays. + * * Note: * - * - Implementation must support adding new properties to `Uint8Array` instances. - * Firefox 4-29 lacked support, fixed in Firefox 30+. - * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. + * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, + * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. * - * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. + * - Safari 5-7 lacks support for changing the `Object.prototype.constructor` property + * on objects. * - * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of - * incorrect length in some situations. + * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. * - * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they will - * get the Object implementation, which is slower but will work correctly. + * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of + * incorrect length in some situations. + + * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they + * get the Object implementation, which is slower but behaves correctly. */ -Buffer.TYPED_ARRAY_SUPPORT = (function () { +Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined + ? global.TYPED_ARRAY_SUPPORT + : typedArraySupport() + +function typedArraySupport () { + function Bar () {} try { - var buf = new ArrayBuffer(0) - var arr = new Uint8Array(buf) + var arr = new Uint8Array(1) arr.foo = function () { return 42 } + arr.constructor = Bar return arr.foo() === 42 && // typed array instances can be augmented + arr.constructor === Bar && // constructor can be set typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` - new Uint8Array(1).subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` + arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` } catch (e) { return false } -})() +} + +function kMaxLength () { + return Buffer.TYPED_ARRAY_SUPPORT + ? 0x7fffffff + : 0x3fffffff +} /** * Class: Buffer @@ -714,8 +868,10 @@ function Buffer (arg) { return new Buffer(arg) } - this.length = 0 - this.parent = undefined + if (!Buffer.TYPED_ARRAY_SUPPORT) { + this.length = 0 + this.parent = undefined + } // Common case. if (typeof arg === 'number') { @@ -761,8 +917,13 @@ function fromObject (that, object) { throw new TypeError('must start with number, buffer, array or string') } - if (typeof ArrayBuffer !== 'undefined' && object.buffer instanceof ArrayBuffer) { - return fromTypedArray(that, object) + if (typeof ArrayBuffer !== 'undefined') { + if (object.buffer instanceof ArrayBuffer) { + return fromTypedArray(that, object) + } + if (object instanceof ArrayBuffer) { + return fromArrayBuffer(that, object) + } } if (object.length) return fromArrayLike(that, object) @@ -799,6 +960,18 @@ function fromTypedArray (that, array) { return that } +function fromArrayBuffer (that, array) { + if (Buffer.TYPED_ARRAY_SUPPORT) { + // Return an augmented `Uint8Array` instance, for best performance + array.byteLength + that = Buffer._augment(new Uint8Array(array)) + } else { + // Fallback: Return an object instance of the Buffer class + that = fromTypedArray(that, new Uint8Array(array)) + } + return that +} + function fromArrayLike (that, array) { var length = checked(array.length) | 0 that = allocate(that, length) @@ -826,10 +999,20 @@ function fromJsonObject (that, object) { return that } +if (Buffer.TYPED_ARRAY_SUPPORT) { + Buffer.prototype.__proto__ = Uint8Array.prototype + Buffer.__proto__ = Uint8Array +} else { + // pre-set for values that may exist in the future + Buffer.prototype.length = undefined + Buffer.prototype.parent = undefined +} + function allocate (that, length) { if (Buffer.TYPED_ARRAY_SUPPORT) { // Return an augmented `Uint8Array` instance, for best performance that = Buffer._augment(new Uint8Array(length)) + that.__proto__ = Buffer.prototype } else { // Fallback: Return an object instance of the Buffer class that.length = length @@ -845,9 +1028,9 @@ function allocate (that, length) { function checked (length) { // Note: cannot use `length < kMaxLength` here because that fails when // length is NaN (which is otherwise coerced to zero.) - if (length >= kMaxLength) { + if (length >= kMaxLength()) { throw new RangeError('Attempt to allocate Buffer larger than maximum ' + - 'size: 0x' + kMaxLength.toString(16) + ' bytes') + 'size: 0x' + kMaxLength().toString(16) + ' bytes') } return length | 0 } @@ -916,8 +1099,6 @@ Buffer.concat = function concat (list, length) { if (list.length === 0) { return new Buffer(0) - } else if (list.length === 1) { - return list[0] } var i @@ -939,39 +1120,43 @@ Buffer.concat = function concat (list, length) { } function byteLength (string, encoding) { - if (typeof string !== 'string') string = String(string) + if (typeof string !== 'string') string = '' + string - if (string.length === 0) return 0 + var len = string.length + if (len === 0) return 0 - switch (encoding || 'utf8') { - case 'ascii': - case 'binary': - case 'raw': - return string.length - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return string.length * 2 - case 'hex': - return string.length >>> 1 - case 'utf8': - case 'utf-8': - return utf8ToBytes(string).length - case 'base64': - return base64ToBytes(string).length - default: - return string.length + // Use a for loop to avoid recursion + var loweredCase = false + for (;;) { + switch (encoding) { + case 'ascii': + case 'binary': + // Deprecated + case 'raw': + case 'raws': + return len + case 'utf8': + case 'utf-8': + return utf8ToBytes(string).length + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return len * 2 + case 'hex': + return len >>> 1 + case 'base64': + return base64ToBytes(string).length + default: + if (loweredCase) return utf8ToBytes(string).length // assume utf8 + encoding = ('' + encoding).toLowerCase() + loweredCase = true + } } } Buffer.byteLength = byteLength -// pre-set for values that may exist in the future -Buffer.prototype.length = undefined -Buffer.prototype.parent = undefined - -// toString(encoding, start=0, end=buffer.length) -Buffer.prototype.toString = function toString (encoding, start, end) { +function slowToString (encoding, start, end) { var loweredCase = false start = start | 0 @@ -1014,6 +1199,13 @@ Buffer.prototype.toString = function toString (encoding, start, end) { } } +Buffer.prototype.toString = function toString () { + var length = this.length | 0 + if (length === 0) return '' + if (arguments.length === 0) return utf8Slice(this, 0, length) + return slowToString.apply(this, arguments) +} + Buffer.prototype.equals = function equals (b) { if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') if (this === b) return true @@ -1077,13 +1269,13 @@ Buffer.prototype.indexOf = function indexOf (val, byteOffset) { throw new TypeError('val must be string, number or Buffer') } -// `get` will be removed in Node 0.13+ +// `get` is deprecated Buffer.prototype.get = function get (offset) { console.log('.get() is deprecated. Access using array indexes instead.') return this.readUInt8(offset) } -// `set` will be removed in Node 0.13+ +// `set` is deprecated Buffer.prototype.set = function set (v, offset) { console.log('.set() is deprecated. Access using array indexes instead.') return this.writeUInt8(v, offset) @@ -1224,20 +1416,99 @@ function base64Slice (buf, start, end) { } function utf8Slice (buf, start, end) { - var res = '' - var tmp = '' end = Math.min(buf.length, end) + var res = [] - for (var i = start; i < end; i++) { - if (buf[i] <= 0x7F) { - res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i]) - tmp = '' - } else { - tmp += '%' + buf[i].toString(16) + var i = start + while (i < end) { + var firstByte = buf[i] + var codePoint = null + var bytesPerSequence = (firstByte > 0xEF) ? 4 + : (firstByte > 0xDF) ? 3 + : (firstByte > 0xBF) ? 2 + : 1 + + if (i + bytesPerSequence <= end) { + var secondByte, thirdByte, fourthByte, tempCodePoint + + switch (bytesPerSequence) { + case 1: + if (firstByte < 0x80) { + codePoint = firstByte + } + break + case 2: + secondByte = buf[i + 1] + if ((secondByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) + if (tempCodePoint > 0x7F) { + codePoint = tempCodePoint + } + } + break + case 3: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) + if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { + codePoint = tempCodePoint + } + } + break + case 4: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + fourthByte = buf[i + 3] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) + if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { + codePoint = tempCodePoint + } + } + } } + + if (codePoint === null) { + // we did not generate a valid codePoint so insert a + // replacement char (U+FFFD) and advance only 1 byte + codePoint = 0xFFFD + bytesPerSequence = 1 + } else if (codePoint > 0xFFFF) { + // encode to utf16 (surrogate pair dance) + codePoint -= 0x10000 + res.push(codePoint >>> 10 & 0x3FF | 0xD800) + codePoint = 0xDC00 | codePoint & 0x3FF + } + + res.push(codePoint) + i += bytesPerSequence } - return res + decodeUtf8Char(tmp) + return decodeCodePointsArray(res) +} + +// Based on http://stackoverflow.com/a/22747272/680742, the browser with +// the lowest limit is Chrome, with 0x10000 args. +// We go 1 magnitude less, for safety +var MAX_ARGUMENTS_LENGTH = 0x1000 + +function decodeCodePointsArray (codePoints) { + var len = codePoints.length + if (len <= MAX_ARGUMENTS_LENGTH) { + return String.fromCharCode.apply(String, codePoints) // avoid extra slice() + } + + // Decode in chunks to avoid "call stack size exceeded". + var res = '' + var i = 0 + while (i < len) { + res += String.fromCharCode.apply( + String, + codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) + ) + } + return res } function asciiSlice (buf, start, end) { @@ -1526,7 +1797,7 @@ Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) - this[offset] = value + this[offset] = (value & 0xff) return offset + 1 } @@ -1543,7 +1814,7 @@ Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = value + this[offset] = (value & 0xff) this[offset + 1] = (value >>> 8) } else { objectWriteUInt16(this, value, offset, true) @@ -1557,7 +1828,7 @@ Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = (value >>> 8) - this[offset + 1] = value + this[offset + 1] = (value & 0xff) } else { objectWriteUInt16(this, value, offset, false) } @@ -1579,7 +1850,7 @@ Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert this[offset + 3] = (value >>> 24) this[offset + 2] = (value >>> 16) this[offset + 1] = (value >>> 8) - this[offset] = value + this[offset] = (value & 0xff) } else { objectWriteUInt32(this, value, offset, true) } @@ -1594,7 +1865,7 @@ Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert this[offset] = (value >>> 24) this[offset + 1] = (value >>> 16) this[offset + 2] = (value >>> 8) - this[offset + 3] = value + this[offset + 3] = (value & 0xff) } else { objectWriteUInt32(this, value, offset, false) } @@ -1647,7 +1918,7 @@ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) if (value < 0) value = 0xff + value + 1 - this[offset] = value + this[offset] = (value & 0xff) return offset + 1 } @@ -1656,7 +1927,7 @@ Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = value + this[offset] = (value & 0xff) this[offset + 1] = (value >>> 8) } else { objectWriteUInt16(this, value, offset, true) @@ -1670,7 +1941,7 @@ Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = (value >>> 8) - this[offset + 1] = value + this[offset + 1] = (value & 0xff) } else { objectWriteUInt16(this, value, offset, false) } @@ -1682,7 +1953,7 @@ Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = value + this[offset] = (value & 0xff) this[offset + 1] = (value >>> 8) this[offset + 2] = (value >>> 16) this[offset + 3] = (value >>> 24) @@ -1701,7 +1972,7 @@ Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) this[offset] = (value >>> 24) this[offset + 1] = (value >>> 16) this[offset + 2] = (value >>> 8) - this[offset + 3] = value + this[offset + 3] = (value & 0xff) } else { objectWriteUInt32(this, value, offset, false) } @@ -1772,9 +2043,16 @@ Buffer.prototype.copy = function copy (target, targetStart, start, end) { } var len = end - start + var i - if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { - for (var i = 0; i < len; i++) { + if (this === target && start < targetStart && targetStart < end) { + // descending copy from end + for (i = len - 1; i >= 0; i--) { + target[i + targetStart] = this[i + start] + } + } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { + // ascending copy from start + for (i = 0; i < len; i++) { target[i + targetStart] = this[i + start] } } else { @@ -1850,7 +2128,7 @@ Buffer._augment = function _augment (arr) { // save reference to original Uint8Array set method before overwriting arr._set = arr.set - // deprecated, will be removed in node 0.13+ + // deprecated arr.get = BP.get arr.set = BP.set @@ -1906,7 +2184,7 @@ Buffer._augment = function _augment (arr) { return arr } -var INVALID_BASE64_RE = /[^+\/0-9A-z\-]/g +var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g function base64clean (str) { // Node strips out invalid characters like \n and \t from the string, base64-js does not @@ -1936,28 +2214,15 @@ function utf8ToBytes (string, units) { var length = string.length var leadSurrogate = null var bytes = [] - var i = 0 - for (; i < length; i++) { + for (var i = 0; i < length; i++) { codePoint = string.charCodeAt(i) // is surrogate component if (codePoint > 0xD7FF && codePoint < 0xE000) { // last char was a lead - if (leadSurrogate) { - // 2 leads in a row - if (codePoint < 0xDC00) { - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - leadSurrogate = codePoint - continue - } else { - // valid surrogate pair - codePoint = leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00 | 0x10000 - leadSurrogate = null - } - } else { + if (!leadSurrogate) { // no lead yet - if (codePoint > 0xDBFF) { // unexpected trail if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) @@ -1966,18 +2231,30 @@ function utf8ToBytes (string, units) { // unpaired lead if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) continue - } else { - // valid lead - leadSurrogate = codePoint - continue } + + // valid lead + leadSurrogate = codePoint + + continue } + + // 2 leads in a row + if (codePoint < 0xDC00) { + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + leadSurrogate = codePoint + continue + } + + // valid surrogate pair + codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 } else if (leadSurrogate) { // valid bmp char, but last char was a lead if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - leadSurrogate = null } + leadSurrogate = null + // encode utf8 if (codePoint < 0x80) { if ((units -= 1) < 0) break @@ -1995,7 +2272,7 @@ function utf8ToBytes (string, units) { codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80 ) - } else if (codePoint < 0x200000) { + } else if (codePoint < 0x110000) { if ((units -= 4) < 0) break bytes.push( codePoint >> 0x12 | 0xF0, @@ -2048,144 +2325,18 @@ function blitBuffer (src, dst, offset, length) { return i } -function decodeUtf8Char (str) { - try { - return decodeURIComponent(str) - } catch (err) { - return String.fromCharCode(0xFFFD) // UTF 8 invalid char - } -} +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"base64-js":6,"ieee754":9,"isarray":8}],8:[function(require,module,exports){ +var toString = {}.toString; -},{"base64-js":7,"ieee754":8,"is-array":9}],7:[function(require,module,exports){ -var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; +module.exports = Array.isArray || function (arr) { + return toString.call(arr) == '[object Array]'; +}; -;(function (exports) { - 'use strict'; - - var Arr = (typeof Uint8Array !== 'undefined') - ? Uint8Array - : Array - - var PLUS = '+'.charCodeAt(0) - var SLASH = '/'.charCodeAt(0) - var NUMBER = '0'.charCodeAt(0) - var LOWER = 'a'.charCodeAt(0) - var UPPER = 'A'.charCodeAt(0) - var PLUS_URL_SAFE = '-'.charCodeAt(0) - var SLASH_URL_SAFE = '_'.charCodeAt(0) - - function decode (elt) { - var code = elt.charCodeAt(0) - if (code === PLUS || - code === PLUS_URL_SAFE) - return 62 // '+' - if (code === SLASH || - code === SLASH_URL_SAFE) - return 63 // '/' - if (code < NUMBER) - return -1 //no match - if (code < NUMBER + 10) - return code - NUMBER + 26 + 26 - if (code < UPPER + 26) - return code - UPPER - if (code < LOWER + 26) - return code - LOWER + 26 - } - - function b64ToByteArray (b64) { - var i, j, l, tmp, placeHolders, arr - - if (b64.length % 4 > 0) { - throw new Error('Invalid string. Length must be a multiple of 4') - } - - // the number of equal signs (place holders) - // if there are two placeholders, than the two characters before it - // represent one byte - // if there is only one, then the three characters before it represent 2 bytes - // this is just a cheap hack to not do indexOf twice - var len = b64.length - placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0 - - // base64 is 4/3 + up to two characters of the original data - arr = new Arr(b64.length * 3 / 4 - placeHolders) - - // if there are placeholders, only get up to the last complete 4 chars - l = placeHolders > 0 ? b64.length - 4 : b64.length - - var L = 0 - - function push (v) { - arr[L++] = v - } - - for (i = 0, j = 0; i < l; i += 4, j += 3) { - tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3)) - push((tmp & 0xFF0000) >> 16) - push((tmp & 0xFF00) >> 8) - push(tmp & 0xFF) - } - - if (placeHolders === 2) { - tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4) - push(tmp & 0xFF) - } else if (placeHolders === 1) { - tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2) - push((tmp >> 8) & 0xFF) - push(tmp & 0xFF) - } - - return arr - } - - function uint8ToBase64 (uint8) { - var i, - extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes - output = "", - temp, length - - function encode (num) { - return lookup.charAt(num) - } - - function tripletToBase64 (num) { - return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F) - } - - // go through the array every three bytes, we'll deal with trailing stuff later - for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { - temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) - output += tripletToBase64(temp) - } - - // pad the end with zeros, but make sure to not forget the extra bytes - switch (extraBytes) { - case 1: - temp = uint8[uint8.length - 1] - output += encode(temp >> 2) - output += encode((temp << 4) & 0x3F) - output += '==' - break - case 2: - temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]) - output += encode(temp >> 10) - output += encode((temp >> 4) & 0x3F) - output += encode((temp << 2) & 0x3F) - output += '=' - break - } - - return output - } - - exports.toByteArray = b64ToByteArray - exports.fromByteArray = uint8ToBase64 -}(typeof exports === 'undefined' ? (this.base64js = {}) : exports)) - -},{}],8:[function(require,module,exports){ +},{}],9:[function(require,module,exports){ exports.read = function (buffer, offset, isLE, mLen, nBytes) { var e, m - var eLen = nBytes * 8 - mLen - 1 + var eLen = (nBytes * 8) - mLen - 1 var eMax = (1 << eLen) - 1 var eBias = eMax >> 1 var nBits = -7 @@ -2198,12 +2349,12 @@ exports.read = function (buffer, offset, isLE, mLen, nBytes) { e = s & ((1 << (-nBits)) - 1) s >>= (-nBits) nBits += eLen - for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} + for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {} m = e & ((1 << (-nBits)) - 1) e >>= (-nBits) nBits += mLen - for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} + for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {} if (e === 0) { e = 1 - eBias @@ -2218,7 +2369,7 @@ exports.read = function (buffer, offset, isLE, mLen, nBytes) { exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { var e, m, c - var eLen = nBytes * 8 - mLen - 1 + var eLen = (nBytes * 8) - mLen - 1 var eMax = (1 << eLen) - 1 var eBias = eMax >> 1 var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) @@ -2251,7 +2402,7 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { m = 0 e = eMax } else if (e + eBias >= 1) { - m = (value * c - 1) * Math.pow(2, mLen) + m = ((value * c) - 1) * Math.pow(2, mLen) e = e + eBias } else { m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) @@ -2268,266 +2419,260 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { buffer[offset + i - d] |= s * 128 } -},{}],9:[function(require,module,exports){ - -/** - * isArray - */ - -var isArray = Array.isArray; - -/** - * toString - */ - -var str = Object.prototype.toString; - -/** - * Whether or not the given `val` - * is an array. - * - * example: - * - * isArray([]); - * // > true - * isArray(arguments); - * // > false - * isArray(''); - * // > false - * - * @param {mixed} val - * @return {bool} - */ - -module.exports = isArray || function (val) { - return !! val && '[object Array]' == str.call(val); -}; - },{}],10:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +;(function () { // closure for web browsers -// resolves . and .. elements in a path array with directory names there -// must be no slashes, empty elements, or device names (c:\) in the array -// (so also no leading and trailing slashes - it does not distinguish -// relative and absolute paths) -function normalizeArray(parts, allowAboveRoot) { - // if the path tries to go above the root, `up` ends up > 0 - var up = 0; - for (var i = parts.length - 1; i >= 0; i--) { - var last = parts[i]; - if (last === '.') { - parts.splice(i, 1); - } else if (last === '..') { - parts.splice(i, 1); - up++; - } else if (up) { - parts.splice(i, 1); - up--; - } - } - - // if the path is allowed to go above the root, restore leading ..s - if (allowAboveRoot) { - for (; up--; up) { - parts.unshift('..'); - } - } - - return parts; +if (typeof module === 'object' && module.exports) { + module.exports = LRUCache +} else { + // just set the global for non-node platforms. + this.LRUCache = LRUCache } -// Split a filename into [root, dir, basename, ext], unix version -// 'root' is just a slash, or nothing. -var splitPathRe = - /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/; -var splitPath = function(filename) { - return splitPathRe.exec(filename).slice(1); -}; - -// path.resolve([from ...], to) -// posix version -exports.resolve = function() { - var resolvedPath = '', - resolvedAbsolute = false; - - for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { - var path = (i >= 0) ? arguments[i] : process.cwd(); - - // Skip empty and invalid entries - if (typeof path !== 'string') { - throw new TypeError('Arguments to path.resolve must be strings'); - } else if (!path) { - continue; - } - - resolvedPath = path + '/' + resolvedPath; - resolvedAbsolute = path.charAt(0) === '/'; - } - - // At this point the path should be resolved to a full absolute path, but - // handle relative paths to be safe (might happen when process.cwd() fails) - - // Normalize the path - resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) { - return !!p; - }), !resolvedAbsolute).join('/'); - - return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; -}; - -// path.normalize(path) -// posix version -exports.normalize = function(path) { - var isAbsolute = exports.isAbsolute(path), - trailingSlash = substr(path, -1) === '/'; - - // Normalize the path - path = normalizeArray(filter(path.split('/'), function(p) { - return !!p; - }), !isAbsolute).join('/'); - - if (!path && !isAbsolute) { - path = '.'; - } - if (path && trailingSlash) { - path += '/'; - } - - return (isAbsolute ? '/' : '') + path; -}; - -// posix version -exports.isAbsolute = function(path) { - return path.charAt(0) === '/'; -}; - -// posix version -exports.join = function() { - var paths = Array.prototype.slice.call(arguments, 0); - return exports.normalize(filter(paths, function(p, index) { - if (typeof p !== 'string') { - throw new TypeError('Arguments to path.join must be strings'); - } - return p; - }).join('/')); -}; - - -// path.relative(from, to) -// posix version -exports.relative = function(from, to) { - from = exports.resolve(from).substr(1); - to = exports.resolve(to).substr(1); - - function trim(arr) { - var start = 0; - for (; start < arr.length; start++) { - if (arr[start] !== '') break; - } - - var end = arr.length - 1; - for (; end >= 0; end--) { - if (arr[end] !== '') break; - } - - if (start > end) return []; - return arr.slice(start, end - start + 1); - } - - var fromParts = trim(from.split('/')); - var toParts = trim(to.split('/')); - - var length = Math.min(fromParts.length, toParts.length); - var samePartsLength = length; - for (var i = 0; i < length; i++) { - if (fromParts[i] !== toParts[i]) { - samePartsLength = i; - break; - } - } - - var outputParts = []; - for (var i = samePartsLength; i < fromParts.length; i++) { - outputParts.push('..'); - } - - outputParts = outputParts.concat(toParts.slice(samePartsLength)); - - return outputParts.join('/'); -}; - -exports.sep = '/'; -exports.delimiter = ':'; - -exports.dirname = function(path) { - var result = splitPath(path), - root = result[0], - dir = result[1]; - - if (!root && !dir) { - // No dirname whatsoever - return '.'; - } - - if (dir) { - // It has a dirname, strip trailing slash - dir = dir.substr(0, dir.length - 1); - } - - return root + dir; -}; - - -exports.basename = function(path, ext) { - var f = splitPath(path)[2]; - // TODO: make this comparison case-insensitive on windows? - if (ext && f.substr(-1 * ext.length) === ext) { - f = f.substr(0, f.length - ext.length); - } - return f; -}; - - -exports.extname = function(path) { - return splitPath(path)[3]; -}; - -function filter (xs, f) { - if (xs.filter) return xs.filter(f); - var res = []; - for (var i = 0; i < xs.length; i++) { - if (f(xs[i], i, xs)) res.push(xs[i]); - } - return res; +function hOP (obj, key) { + return Object.prototype.hasOwnProperty.call(obj, key) } -// String.prototype.substr - negative index don't work in IE8 -var substr = 'ab'.substr(-1) === 'b' - ? function (str, start, len) { return str.substr(start, len) } - : function (str, start, len) { - if (start < 0) start = str.length + start; - return str.substr(start, len); +function naiveLength () { return 1 } + +function LRUCache (options) { + if (!(this instanceof LRUCache)) + return new LRUCache(options) + + if (typeof options === 'number') + options = { max: options } + + if (!options) + options = {} + + this._max = options.max + // Kind of weird to have a default max of Infinity, but oh well. + if (!this._max || !(typeof this._max === "number") || this._max <= 0 ) + this._max = Infinity + + this._lengthCalculator = options.length || naiveLength + if (typeof this._lengthCalculator !== "function") + this._lengthCalculator = naiveLength + + this._allowStale = options.stale || false + this._maxAge = options.maxAge || null + this._dispose = options.dispose + this.reset() +} + +// resize the cache when the max changes. +Object.defineProperty(LRUCache.prototype, "max", + { set : function (mL) { + if (!mL || !(typeof mL === "number") || mL <= 0 ) mL = Infinity + this._max = mL + if (this._length > this._max) trim(this) } -; + , get : function () { return this._max } + , enumerable : true + }) + +// resize the cache when the lengthCalculator changes. +Object.defineProperty(LRUCache.prototype, "lengthCalculator", + { set : function (lC) { + if (typeof lC !== "function") { + this._lengthCalculator = naiveLength + this._length = this._itemCount + for (var key in this._cache) { + this._cache[key].length = 1 + } + } else { + this._lengthCalculator = lC + this._length = 0 + for (var key in this._cache) { + this._cache[key].length = this._lengthCalculator(this._cache[key].value) + this._length += this._cache[key].length + } + } + + if (this._length > this._max) trim(this) + } + , get : function () { return this._lengthCalculator } + , enumerable : true + }) + +Object.defineProperty(LRUCache.prototype, "length", + { get : function () { return this._length } + , enumerable : true + }) + + +Object.defineProperty(LRUCache.prototype, "itemCount", + { get : function () { return this._itemCount } + , enumerable : true + }) + +LRUCache.prototype.forEach = function (fn, thisp) { + thisp = thisp || this + var i = 0; + for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) { + i++ + var hit = this._lruList[k] + if (this._maxAge && (Date.now() - hit.now > this._maxAge)) { + del(this, hit) + if (!this._allowStale) hit = undefined + } + if (hit) { + fn.call(thisp, hit.value, hit.key, this) + } + } +} + +LRUCache.prototype.keys = function () { + var keys = new Array(this._itemCount) + var i = 0 + for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) { + var hit = this._lruList[k] + keys[i++] = hit.key + } + return keys +} + +LRUCache.prototype.values = function () { + var values = new Array(this._itemCount) + var i = 0 + for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) { + var hit = this._lruList[k] + values[i++] = hit.value + } + return values +} + +LRUCache.prototype.reset = function () { + if (this._dispose && this._cache) { + for (var k in this._cache) { + this._dispose(k, this._cache[k].value) + } + } + + this._cache = Object.create(null) // hash of items by key + this._lruList = Object.create(null) // list of items in order of use recency + this._mru = 0 // most recently used + this._lru = 0 // least recently used + this._length = 0 // number of items in the list + this._itemCount = 0 +} + +// Provided for debugging/dev purposes only. No promises whatsoever that +// this API stays stable. +LRUCache.prototype.dump = function () { + return this._cache +} + +LRUCache.prototype.dumpLru = function () { + return this._lruList +} + +LRUCache.prototype.set = function (key, value) { + if (hOP(this._cache, key)) { + // dispose of the old one before overwriting + if (this._dispose) this._dispose(key, this._cache[key].value) + if (this._maxAge) this._cache[key].now = Date.now() + this._cache[key].value = value + this.get(key) + return true + } + + var len = this._lengthCalculator(value) + var age = this._maxAge ? Date.now() : 0 + var hit = new Entry(key, value, this._mru++, len, age) + + // oversized objects fall out of cache automatically. + if (hit.length > this._max) { + if (this._dispose) this._dispose(key, value) + return false + } + + this._length += hit.length + this._lruList[hit.lu] = this._cache[key] = hit + this._itemCount ++ + + if (this._length > this._max) trim(this) + return true +} + +LRUCache.prototype.has = function (key) { + if (!hOP(this._cache, key)) return false + var hit = this._cache[key] + if (this._maxAge && (Date.now() - hit.now > this._maxAge)) { + return false + } + return true +} + +LRUCache.prototype.get = function (key) { + return get(this, key, true) +} + +LRUCache.prototype.peek = function (key) { + return get(this, key, false) +} + +LRUCache.prototype.pop = function () { + var hit = this._lruList[this._lru] + del(this, hit) + return hit || null +} + +LRUCache.prototype.del = function (key) { + del(this, this._cache[key]) +} + +function get (self, key, doUse) { + var hit = self._cache[key] + if (hit) { + if (self._maxAge && (Date.now() - hit.now > self._maxAge)) { + del(self, hit) + if (!self._allowStale) hit = undefined + } else { + if (doUse) use(self, hit) + } + if (hit) hit = hit.value + } + return hit +} + +function use (self, hit) { + shiftLU(self, hit) + hit.lu = self._mru ++ + if (self._maxAge) hit.now = Date.now() + self._lruList[hit.lu] = hit +} + +function trim (self) { + while (self._lru < self._mru && self._length > self._max) + del(self, self._lruList[self._lru]) +} + +function shiftLU (self, hit) { + delete self._lruList[ hit.lu ] + while (self._lru < self._mru && !self._lruList[self._lru]) self._lru ++ +} + +function del (self, hit) { + if (hit) { + if (self._dispose) self._dispose(hit.key, hit.value) + self._length -= hit.length + self._itemCount -- + delete self._cache[ hit.key ] + shiftLU(self, hit) + } +} + +// classy, since V8 prefers predictable objects. +function Entry (key, value, lu, length, now) { + this.key = key + this.value = value + this.lu = lu + this.length = length + this.now = now +} + +})() },{}],11:[function(require,module,exports){ ;(function (require, exports, module, platform) { @@ -3604,281 +3749,231 @@ function regExpEscape (s) { typeof process === "object" ? process.platform : "win32" ) -},{"lru-cache":12,"path":10,"sigmund":13}],12:[function(require,module,exports){ -;(function () { // closure for web browsers +},{"lru-cache":10,"path":12,"sigmund":13}],12:[function(require,module,exports){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. -if (typeof module === 'object' && module.exports) { - module.exports = LRUCache -} else { - // just set the global for non-node platforms. - this.LRUCache = LRUCache -} - -function hOP (obj, key) { - return Object.prototype.hasOwnProperty.call(obj, key) -} - -function naiveLength () { return 1 } - -function LRUCache (options) { - if (!(this instanceof LRUCache)) - return new LRUCache(options) - - if (typeof options === 'number') - options = { max: options } - - if (!options) - options = {} - - this._max = options.max - // Kind of weird to have a default max of Infinity, but oh well. - if (!this._max || !(typeof this._max === "number") || this._max <= 0 ) - this._max = Infinity - - this._lengthCalculator = options.length || naiveLength - if (typeof this._lengthCalculator !== "function") - this._lengthCalculator = naiveLength - - this._allowStale = options.stale || false - this._maxAge = options.maxAge || null - this._dispose = options.dispose - this.reset() -} - -// resize the cache when the max changes. -Object.defineProperty(LRUCache.prototype, "max", - { set : function (mL) { - if (!mL || !(typeof mL === "number") || mL <= 0 ) mL = Infinity - this._max = mL - if (this._length > this._max) trim(this) - } - , get : function () { return this._max } - , enumerable : true - }) - -// resize the cache when the lengthCalculator changes. -Object.defineProperty(LRUCache.prototype, "lengthCalculator", - { set : function (lC) { - if (typeof lC !== "function") { - this._lengthCalculator = naiveLength - this._length = this._itemCount - for (var key in this._cache) { - this._cache[key].length = 1 - } - } else { - this._lengthCalculator = lC - this._length = 0 - for (var key in this._cache) { - this._cache[key].length = this._lengthCalculator(this._cache[key].value) - this._length += this._cache[key].length - } - } - - if (this._length > this._max) trim(this) - } - , get : function () { return this._lengthCalculator } - , enumerable : true - }) - -Object.defineProperty(LRUCache.prototype, "length", - { get : function () { return this._length } - , enumerable : true - }) - - -Object.defineProperty(LRUCache.prototype, "itemCount", - { get : function () { return this._itemCount } - , enumerable : true - }) - -LRUCache.prototype.forEach = function (fn, thisp) { - thisp = thisp || this - var i = 0 - var itemCount = this._itemCount - - for (var k = this._mru - 1; k >= 0 && i < itemCount; k--) if (this._lruList[k]) { - i++ - var hit = this._lruList[k] - if (isStale(this, hit)) { - del(this, hit) - if (!this._allowStale) hit = undefined - } - if (hit) { - fn.call(thisp, hit.value, hit.key, this) - } - } -} - -LRUCache.prototype.keys = function () { - var keys = new Array(this._itemCount) - var i = 0 - for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) { - var hit = this._lruList[k] - keys[i++] = hit.key - } - return keys -} - -LRUCache.prototype.values = function () { - var values = new Array(this._itemCount) - var i = 0 - for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) { - var hit = this._lruList[k] - values[i++] = hit.value - } - return values -} - -LRUCache.prototype.reset = function () { - if (this._dispose && this._cache) { - for (var k in this._cache) { - this._dispose(k, this._cache[k].value) +// resolves . and .. elements in a path array with directory names there +// must be no slashes, empty elements, or device names (c:\) in the array +// (so also no leading and trailing slashes - it does not distinguish +// relative and absolute paths) +function normalizeArray(parts, allowAboveRoot) { + // if the path tries to go above the root, `up` ends up > 0 + var up = 0; + for (var i = parts.length - 1; i >= 0; i--) { + var last = parts[i]; + if (last === '.') { + parts.splice(i, 1); + } else if (last === '..') { + parts.splice(i, 1); + up++; + } else if (up) { + parts.splice(i, 1); + up--; } } - this._cache = Object.create(null) // hash of items by key - this._lruList = Object.create(null) // list of items in order of use recency - this._mru = 0 // most recently used - this._lru = 0 // least recently used - this._length = 0 // number of items in the list - this._itemCount = 0 -} - -// Provided for debugging/dev purposes only. No promises whatsoever that -// this API stays stable. -LRUCache.prototype.dump = function () { - return this._cache -} - -LRUCache.prototype.dumpLru = function () { - return this._lruList -} - -LRUCache.prototype.set = function (key, value, maxAge) { - maxAge = maxAge || this._maxAge - var now = maxAge ? Date.now() : 0 - - if (hOP(this._cache, key)) { - // dispose of the old one before overwriting - if (this._dispose) - this._dispose(key, this._cache[key].value) - - this._cache[key].now = now - this._cache[key].maxAge = maxAge - this._cache[key].value = value - this.get(key) - return true - } - - var len = this._lengthCalculator(value) - var hit = new Entry(key, value, this._mru++, len, now, maxAge) - - // oversized objects fall out of cache automatically. - if (hit.length > this._max) { - if (this._dispose) this._dispose(key, value) - return false - } - - this._length += hit.length - this._lruList[hit.lu] = this._cache[key] = hit - this._itemCount ++ - - if (this._length > this._max) - trim(this) - - return true -} - -LRUCache.prototype.has = function (key) { - if (!hOP(this._cache, key)) return false - var hit = this._cache[key] - if (isStale(this, hit)) { - return false - } - return true -} - -LRUCache.prototype.get = function (key) { - return get(this, key, true) -} - -LRUCache.prototype.peek = function (key) { - return get(this, key, false) -} - -LRUCache.prototype.pop = function () { - var hit = this._lruList[this._lru] - del(this, hit) - return hit || null -} - -LRUCache.prototype.del = function (key) { - del(this, this._cache[key]) -} - -function get (self, key, doUse) { - var hit = self._cache[key] - if (hit) { - if (isStale(self, hit)) { - del(self, hit) - if (!self._allowStale) hit = undefined - } else { - if (doUse) use(self, hit) + // if the path is allowed to go above the root, restore leading ..s + if (allowAboveRoot) { + for (; up--; up) { + parts.unshift('..'); } - if (hit) hit = hit.value } - return hit + + return parts; } -function isStale(self, hit) { - if (!hit || (!hit.maxAge && !self._maxAge)) return false - var stale = false; - var diff = Date.now() - hit.now - if (hit.maxAge) { - stale = diff > hit.maxAge - } else { - stale = self._maxAge && (diff > self._maxAge) +// Split a filename into [root, dir, basename, ext], unix version +// 'root' is just a slash, or nothing. +var splitPathRe = + /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/; +var splitPath = function(filename) { + return splitPathRe.exec(filename).slice(1); +}; + +// path.resolve([from ...], to) +// posix version +exports.resolve = function() { + var resolvedPath = '', + resolvedAbsolute = false; + + for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { + var path = (i >= 0) ? arguments[i] : process.cwd(); + + // Skip empty and invalid entries + if (typeof path !== 'string') { + throw new TypeError('Arguments to path.resolve must be strings'); + } else if (!path) { + continue; + } + + resolvedPath = path + '/' + resolvedPath; + resolvedAbsolute = path.charAt(0) === '/'; } - return stale; -} -function use (self, hit) { - shiftLU(self, hit) - hit.lu = self._mru ++ - self._lruList[hit.lu] = hit -} + // At this point the path should be resolved to a full absolute path, but + // handle relative paths to be safe (might happen when process.cwd() fails) -function trim (self) { - while (self._lru < self._mru && self._length > self._max) - del(self, self._lruList[self._lru]) -} + // Normalize the path + resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) { + return !!p; + }), !resolvedAbsolute).join('/'); -function shiftLU (self, hit) { - delete self._lruList[ hit.lu ] - while (self._lru < self._mru && !self._lruList[self._lru]) self._lru ++ -} + return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; +}; -function del (self, hit) { - if (hit) { - if (self._dispose) self._dispose(hit.key, hit.value) - self._length -= hit.length - self._itemCount -- - delete self._cache[ hit.key ] - shiftLU(self, hit) +// path.normalize(path) +// posix version +exports.normalize = function(path) { + var isAbsolute = exports.isAbsolute(path), + trailingSlash = substr(path, -1) === '/'; + + // Normalize the path + path = normalizeArray(filter(path.split('/'), function(p) { + return !!p; + }), !isAbsolute).join('/'); + + if (!path && !isAbsolute) { + path = '.'; } + if (path && trailingSlash) { + path += '/'; + } + + return (isAbsolute ? '/' : '') + path; +}; + +// posix version +exports.isAbsolute = function(path) { + return path.charAt(0) === '/'; +}; + +// posix version +exports.join = function() { + var paths = Array.prototype.slice.call(arguments, 0); + return exports.normalize(filter(paths, function(p, index) { + if (typeof p !== 'string') { + throw new TypeError('Arguments to path.join must be strings'); + } + return p; + }).join('/')); +}; + + +// path.relative(from, to) +// posix version +exports.relative = function(from, to) { + from = exports.resolve(from).substr(1); + to = exports.resolve(to).substr(1); + + function trim(arr) { + var start = 0; + for (; start < arr.length; start++) { + if (arr[start] !== '') break; + } + + var end = arr.length - 1; + for (; end >= 0; end--) { + if (arr[end] !== '') break; + } + + if (start > end) return []; + return arr.slice(start, end - start + 1); + } + + var fromParts = trim(from.split('/')); + var toParts = trim(to.split('/')); + + var length = Math.min(fromParts.length, toParts.length); + var samePartsLength = length; + for (var i = 0; i < length; i++) { + if (fromParts[i] !== toParts[i]) { + samePartsLength = i; + break; + } + } + + var outputParts = []; + for (var i = samePartsLength; i < fromParts.length; i++) { + outputParts.push('..'); + } + + outputParts = outputParts.concat(toParts.slice(samePartsLength)); + + return outputParts.join('/'); +}; + +exports.sep = '/'; +exports.delimiter = ':'; + +exports.dirname = function(path) { + var result = splitPath(path), + root = result[0], + dir = result[1]; + + if (!root && !dir) { + // No dirname whatsoever + return '.'; + } + + if (dir) { + // It has a dirname, strip trailing slash + dir = dir.substr(0, dir.length - 1); + } + + return root + dir; +}; + + +exports.basename = function(path, ext) { + var f = splitPath(path)[2]; + // TODO: make this comparison case-insensitive on windows? + if (ext && f.substr(-1 * ext.length) === ext) { + f = f.substr(0, f.length - ext.length); + } + return f; +}; + + +exports.extname = function(path) { + return splitPath(path)[3]; +}; + +function filter (xs, f) { + if (xs.filter) return xs.filter(f); + var res = []; + for (var i = 0; i < xs.length; i++) { + if (f(xs[i], i, xs)) res.push(xs[i]); + } + return res; } -// classy, since V8 prefers predictable objects. -function Entry (key, value, lu, length, now, maxAge) { - this.key = key - this.value = value - this.lu = lu - this.length = length - this.now = now - if (maxAge) this.maxAge = maxAge -} - -})() +// String.prototype.substr - negative index don't work in IE8 +var substr = 'ab'.substr(-1) === 'b' + ? function (str, start, len) { return str.substr(start, len) } + : function (str, start, len) { + if (start < 0) start = str.length + start; + return str.substr(start, len); + } +; },{}],13:[function(require,module,exports){ module.exports = sigmund @@ -3948,7 +4043,7 @@ Object.keys(Buffer).forEach(function (p) { module.exports = FilerBuffer; }).call(this,require("buffer").Buffer) -},{"buffer":6}],15:[function(require,module,exports){ +},{"buffer":7}],15:[function(require,module,exports){ var O_READ = 'READ'; var O_WRITE = 'WRITE'; var O_CREATE = 'CREATE'; @@ -3970,11 +4065,20 @@ module.exports = { WSQL_SIZE: 5 * 1024 * 1024, WSQL_DESC: "FileSystem Storage", - MODE_FILE: 'FILE', - MODE_DIRECTORY: 'DIRECTORY', - MODE_SYMBOLIC_LINK: 'SYMLINK', - MODE_META: 'META', + NODE_TYPE_FILE: 'FILE', + NODE_TYPE_DIRECTORY: 'DIRECTORY', + NODE_TYPE_SYMBOLIC_LINK: 'SYMLINK', + NODE_TYPE_META: 'META', + S_IFREG: 0x8000, + S_IFDIR: 0x4000, + S_IFLNK: 0xA000, + + DEFAULT_DIR_PERMISSIONS: 0x1ED, // 755 + DEFAULT_FILE_PERMISSIONS: 0x1A4, // 644 + FULL_READ_WRITE_EXEC_PERMISSIONS: 0x1FF, // 777 + READ_WRITE_PERMISSIONS: 0x1B6, /// 666 + SYMLOOP_MAX: 10, BINARY_MIME_TYPE: 'application/octet-stream', @@ -4027,15 +4131,59 @@ module.exports = { ENVIRONMENT: { TMP: '/tmp', PATH: '' + }, + + // Duplicate Node's fs.constants + fsConstants: { + O_RDONLY: 0, + O_WRONLY: 1, + O_RDWR: 2, + S_IFMT: 61440, + S_IFREG: 32768, + S_IFDIR: 16384, + S_IFCHR: 8192, + S_IFBLK: 24576, + S_IFIFO: 4096, + S_IFLNK: 40960, + S_IFSOCK: 49152, + O_CREAT: 512, + O_EXCL: 2048, + O_NOCTTY: 131072, + O_TRUNC: 1024, + O_APPEND: 8, + O_DIRECTORY: 1048576, + O_NOFOLLOW: 256, + O_SYNC: 128, + O_DSYNC: 4194304, + O_SYMLINK: 2097152, + O_NONBLOCK: 4, + S_IRWXU: 448, + S_IRUSR: 256, + S_IWUSR: 128, + S_IXUSR: 64, + S_IRWXG: 56, + S_IRGRP: 32, + S_IWGRP: 16, + S_IXGRP: 8, + S_IRWXO: 7, + S_IROTH: 4, + S_IWOTH: 2, + S_IXOTH: 1, + F_OK: 0, + R_OK: 4, + W_OK: 2, + X_OK: 1, + UV_FS_COPYFILE_EXCL: 1, + COPYFILE_EXCL: 1 } }; },{}],16:[function(require,module,exports){ -var MODE_FILE = require('./constants.js').MODE_FILE; +var NODE_TYPE_FILE = require('./constants.js').NODE_TYPE_FILE; module.exports = function DirectoryEntry(id, type) { this.id = id; - this.type = type || MODE_FILE; + this.type = type || NODE_TYPE_FILE; }; },{"./constants.js":15}],17:[function(require,module,exports){ @@ -4055,7 +4203,7 @@ module.exports = { }; }).call(this,require("buffer").Buffer) -},{"buffer":6}],18:[function(require,module,exports){ +},{"buffer":7}],18:[function(require,module,exports){ var errors = {}; [ /** @@ -4172,10 +4320,14 @@ var isAbsolutePath = Path.isAbsolute; var isNullPath = Path.isNull; var Constants = require('../constants.js'); -var MODE_FILE = Constants.MODE_FILE; -var MODE_DIRECTORY = Constants.MODE_DIRECTORY; -var MODE_SYMBOLIC_LINK = Constants.MODE_SYMBOLIC_LINK; -var MODE_META = Constants.MODE_META; +var NODE_TYPE_FILE = Constants.NODE_TYPE_FILE; +var NODE_TYPE_DIRECTORY = Constants.NODE_TYPE_DIRECTORY; +var NODE_TYPE_SYMBOLIC_LINK = Constants.NODE_TYPE_SYMBOLIC_LINK; +var NODE_TYPE_META = Constants.NODE_TYPE_META; + +var DEFAULT_FILE_PERMISSIONS = Constants.DEFAULT_FILE_PERMISSIONS; +var DEFAULT_DIR_PERMISSIONS = Constants.DEFAULT_DIR_PERMISSIONS; +var FULL_READ_WRITE_EXEC_PERMISSIONS = Constants.FULL_READ_WRITE_EXEC_PERMISSIONS; var ROOT_DIRECTORY_NAME = Constants.ROOT_DIRECTORY_NAME; var SUPER_NODE_ID = Constants.SUPER_NODE_ID; @@ -4208,17 +4360,17 @@ var Buffer = require('../buffer.js'); * and filesystem flags are examined in order to override update logic. */ function update_node_times(context, path, node, times, callback) { + var update = false; + // Honour mount flags for how we update times var flags = context.flags; if(_(flags).contains(FS_NOCTIME)) { delete times.ctime; } - if(_(flags).contains(FS_NOMTIME)) { + if(_(flags).contains(FS_NOMTIME)) { delete times.mtime; } - // Only do the update if required (i.e., times are still present) - var update = false; if(times.ctime) { node.ctime = times.ctime; // We don't do atime tracking for perf reasons, but do mirror ctime @@ -4237,8 +4389,6 @@ function update_node_times(context, path, node, times, callback) { } function complete(error) { - // Queue this change so we can send watch events. - // Unlike node.js, we send the full path vs. basename/dirname only. context.changes.push({ event: 'change', path: path }); callback(error); } @@ -4255,9 +4405,9 @@ function update_node_times(context, path, node, times, callback) { */ // in: file or directory path // out: new node representing file/directory -function make_node(context, path, mode, callback) { - if(mode !== MODE_DIRECTORY && mode !== MODE_FILE) { - return callback(new Errors.EINVAL('mode must be a directory or file', path)); +function make_node(context, path, type, callback) { + if(type !== NODE_TYPE_DIRECTORY && type !== NODE_TYPE_FILE) { + return callback(new Errors.EINVAL('type must be a directory or file', path)); } path = normalize(path); @@ -4272,7 +4422,7 @@ function make_node(context, path, mode, callback) { function create_node_in_parent(error, parentDirectoryNode) { if(error) { callback(error); - } else if(parentDirectoryNode.mode !== MODE_DIRECTORY) { + } else if(parentDirectoryNode.type !== NODE_TYPE_DIRECTORY) { callback(new Errors.ENOTDIR('a component of the path prefix is not a directory', path)); } else { parentNode = parentDirectoryNode; @@ -4297,7 +4447,10 @@ function make_node(context, path, mode, callback) { callback(error); } else { parentNodeData = result; - Node.create({guid: context.guid, mode: mode}, function(error, result) { + Node.create({ + guid: context.guid, + type: type + }, function(error, result) { if(error) { callback(error); return; @@ -4324,7 +4477,7 @@ function make_node(context, path, mode, callback) { if(error) { callback(error); } else { - parentNodeData[name] = new DirectoryEntry(node.id, mode); + parentNodeData[name] = new DirectoryEntry(node.id, type); context.putObject(parentNode.data, parentNodeData, update_time); } } @@ -4350,7 +4503,7 @@ function find_node(context, path, callback) { function read_root_directory_node(error, superNode) { if(error) { callback(error); - } else if(!superNode || superNode.mode !== MODE_META || !superNode.rnode) { + } else if(!superNode || superNode.type !== NODE_TYPE_META || !superNode.rnode) { callback(new Errors.EFILESYSTEMERROR()); } else { context.getObject(superNode.rnode, check_root_directory_node); @@ -4372,7 +4525,7 @@ function find_node(context, path, callback) { function read_parent_directory_data(error, parentDirectoryNode) { if(error) { callback(error); - } else if(parentDirectoryNode.mode !== MODE_DIRECTORY || !parentDirectoryNode.data) { + } else if(parentDirectoryNode.type !== NODE_TYPE_DIRECTORY || !parentDirectoryNode.data) { callback(new Errors.ENOTDIR('a component of the path prefix is not a directory', path)); } else { context.getObject(parentDirectoryNode.data, get_node_from_parent_directory_data); @@ -4398,7 +4551,7 @@ function find_node(context, path, callback) { if(error) { callback(error); } else { - if(node.mode == MODE_SYMBOLIC_LINK) { + if(node.type == NODE_TYPE_SYMBOLIC_LINK) { followedCount++; if(followedCount > SYMLOOP_MAX){ callback(new Errors.ELOOP(null, path)); @@ -4475,7 +4628,7 @@ function ensure_root_directory(context, callback) { } else if(error && !(error instanceof Errors.ENOENT)) { callback(error); } else { - SuperNode.create({guid: context.guid}, function(error, result) { + SuperNode.create({ guid: context.guid }, function(error, result) { if(error) { callback(error); return; @@ -4490,7 +4643,11 @@ function ensure_root_directory(context, callback) { if(error) { callback(error); } else { - Node.create({guid: context.guid, id: superNode.rnode, mode: MODE_DIRECTORY}, function(error, result) { + Node.create({ + guid: context.guid, + id: superNode.rnode, + type: NODE_TYPE_DIRECTORY + }, function(error, result) { if(error) { callback(error); return; @@ -4551,7 +4708,10 @@ function make_directory(context, path, callback) { callback(error); } else { parentDirectoryData = result; - Node.create({guid: context.guid, mode: MODE_DIRECTORY}, function(error, result) { + Node.create({ + guid: context.guid, + type: NODE_TYPE_DIRECTORY + }, function(error, result) { if(error) { callback(error); return; @@ -4585,7 +4745,7 @@ function make_directory(context, path, callback) { if(error) { callback(error); } else { - parentDirectoryData[name] = new DirectoryEntry(directoryNode.id, MODE_DIRECTORY); + parentDirectoryData[name] = new DirectoryEntry(directoryNode.id, NODE_TYPE_DIRECTORY); context.putObject(parentDirectoryNode.data, parentDirectoryData, update_time); } } @@ -4632,7 +4792,7 @@ function remove_directory(context, path, callback) { function check_if_node_is_directory(error, result) { if(error) { callback(error); - } else if(result.mode != MODE_DIRECTORY) { + } else if(result.type != NODE_TYPE_DIRECTORY) { callback(new Errors.ENOTDIR(null, path)); } else { directoryNode = result; @@ -4712,7 +4872,7 @@ function open_file(context, path, flags, callback) { function read_directory_data(error, result) { if(error) { callback(error); - } else if(result.mode !== MODE_DIRECTORY) { + } else if(result.type !== NODE_TYPE_DIRECTORY) { callback(new Errors.ENOENT(null, path)); } else { directoryNode = result; @@ -4730,7 +4890,7 @@ function open_file(context, path, flags, callback) { callback(new Errors.ENOENT('O_CREATE and O_EXCLUSIVE are set, and the named file exists', path)); } else { directoryEntry = directoryData[name]; - if(directoryEntry.type == MODE_DIRECTORY && _(flags).contains(O_WRITE)) { + if(directoryEntry.type == NODE_TYPE_DIRECTORY && _(flags).contains(O_WRITE)) { callback(new Errors.EISDIR('the named file is a directory and O_WRITE is set', path)); } else { context.getObject(directoryEntry.id, check_if_symbolic_link); @@ -4751,7 +4911,7 @@ function open_file(context, path, flags, callback) { callback(error); } else { var node = result; - if(node.mode == MODE_SYMBOLIC_LINK) { + if(node.type == NODE_TYPE_SYMBOLIC_LINK) { followedCount++; if(followedCount > SYMLOOP_MAX){ callback(new Errors.ELOOP(null, path)); @@ -4788,7 +4948,10 @@ function open_file(context, path, flags, callback) { } function write_file_node() { - Node.create({guid: context.guid, mode: MODE_FILE}, function(error, result) { + Node.create({ + guid: context.guid, + type: NODE_TYPE_FILE + }, function(error, result) { if(error) { callback(error); return; @@ -4822,7 +4985,7 @@ function open_file(context, path, flags, callback) { if(error) { callback(error); } else { - directoryData[name] = new DirectoryEntry(fileNode.id, MODE_FILE); + directoryData[name] = new DirectoryEntry(fileNode.id, NODE_TYPE_FILE); context.putObject(directoryNode.data, directoryData, update_time); } } @@ -4977,7 +5140,7 @@ function read_data(context, ofd, buffer, offset, length, position, callback) { function read_file_data(error, result) { if(error) { callback(error); - } else if(result.mode === 'DIRECTORY') { + } else if(result.type === NODE_TYPE_DIRECTORY) { callback(new Errors.EISDIR('the named file is a directory', ofd.path)); } else { fileNode = result; @@ -5043,18 +5206,20 @@ function link_node(context, oldpath, newpath, callback) { newpath = normalize(newpath); var newname = basename(newpath); var newParentPath = dirname(newpath); + var ctime = Date.now(); var oldDirectoryNode; var oldDirectoryData; var newDirectoryNode; var newDirectoryData; + var fileNodeID; var fileNode; function update_time(error) { if(error) { callback(error); } else { - update_node_times(context, newpath, fileNode, { ctime: Date.now() }, callback); + update_node_times(context, newpath, fileNode, { ctime: ctime }, callback); } } @@ -5068,11 +5233,11 @@ function link_node(context, oldpath, newpath, callback) { } } - function read_directory_entry(error, result) { + function read_file_node(error, result) { if(error) { callback(error); } else { - context.getObject(newDirectoryData[newname].id, update_file_node); + context.getObject(fileNodeID, update_file_node); } } @@ -5085,7 +5250,8 @@ function link_node(context, oldpath, newpath, callback) { callback(new Errors.EEXIST('newpath resolves to an existing file', newname)); } else { newDirectoryData[newname] = oldDirectoryData[oldname]; - context.putObject(newDirectoryNode.data, newDirectoryData, read_directory_entry); + fileNodeID = newDirectoryData[newname].id; + context.putObject(newDirectoryNode.data, newDirectoryData, read_file_node); } } } @@ -5106,7 +5272,7 @@ function link_node(context, oldpath, newpath, callback) { oldDirectoryData = result; if(!_(oldDirectoryData).has(oldname)) { callback(new Errors.ENOENT('a component of either path prefix does not exist', oldname)); - } else if(oldDirectoryData[oldname].type === 'DIRECTORY') { + } else if(oldDirectoryData[oldname].type === NODE_TYPE_DIRECTORY) { callback(new Errors.EPERM('oldpath refers to a directory')); } else { find_node(context, newParentPath, read_new_directory_data); @@ -5174,7 +5340,7 @@ function unlink_node(context, path, callback) { function check_if_node_is_directory(error, result) { if(error) { callback(error); - } else if(result.mode === 'DIRECTORY') { + } else if(result.type === NODE_TYPE_DIRECTORY) { callback(new Errors.EPERM('unlink not permitted on directories', name)); } else { update_file_node(null, result); @@ -5226,7 +5392,7 @@ function read_directory(context, path, callback) { function read_directory_data(error, result) { if(error) { callback(error); - } else if(result.mode !== MODE_DIRECTORY) { + } else if(result.type !== NODE_TYPE_DIRECTORY) { callback(new Errors.ENOTDIR(null, path)); } else { directoryNode = result; @@ -5275,15 +5441,27 @@ function make_symbolic_link(context, srcpath, dstpath, callback) { } function write_file_node() { - Node.create({guid: context.guid, mode: MODE_SYMBOLIC_LINK}, function(error, result) { + Node.create({ + guid: context.guid, + type: NODE_TYPE_SYMBOLIC_LINK + }, function(error, result) { if(error) { callback(error); return; } fileNode = result; fileNode.nlinks += 1; + + // If the srcpath isn't absolute, resolve it relative to the dstpath + // but store both versions, since we'll use the relative one in readlink(). + if(!isAbsolutePath(srcpath)) { + fileNode.symlink_relpath = srcpath; + srcpath = Path.resolve(parentPath, srcpath); + } + fileNode.size = srcpath.length; fileNode.data = srcpath; + context.putObject(fileNode.id, fileNode, update_directory_data); }); } @@ -5301,7 +5479,7 @@ function make_symbolic_link(context, srcpath, dstpath, callback) { if(error) { callback(error); } else { - directoryData[name] = new DirectoryEntry(fileNode.id, MODE_SYMBOLIC_LINK); + directoryData[name] = new DirectoryEntry(fileNode.id, NODE_TYPE_SYMBOLIC_LINK); context.putObject(directoryNode.data, directoryData, update_time); } } @@ -5339,14 +5517,17 @@ function read_link(context, path, callback) { } } - function check_if_symbolic(error, result) { + function check_if_symbolic(error, fileNode) { if(error) { callback(error); } else { - if(result.mode != MODE_SYMBOLIC_LINK) { + if(fileNode.type != NODE_TYPE_SYMBOLIC_LINK) { callback(new Errors.EINVAL('path not a symbolic link', path)); } else { - callback(null, result.data); + // If we were originally given a relative path, return that now vs. the + // absolute path we've generated and use elsewhere internally. + var target = fileNode.symlink_relpath ? fileNode.symlink_relpath : fileNode.data; + callback(null, target); } } } @@ -5360,7 +5541,7 @@ function truncate_file(context, path, length, callback) { function read_file_data (error, node) { if (error) { callback(error); - } else if(node.mode == MODE_DIRECTORY ) { + } else if(node.type == NODE_TYPE_DIRECTORY ) { callback(new Errors.EISDIR(null, path)); } else{ fileNode = node; @@ -5416,7 +5597,7 @@ function ftruncate_file(context, ofd, length, callback) { function read_file_data (error, node) { if (error) { callback(error); - } else if(node.mode == MODE_DIRECTORY ) { + } else if(node.type == NODE_TYPE_DIRECTORY ) { callback(new Errors.EISDIR()); } else{ fileNode = node; @@ -5709,14 +5890,19 @@ function validate_file_options(options, enc, fileMode){ return options; } -function pathCheck(path, callback) { +function pathCheck(path, allowRelative, callback) { var err; + if(typeof allowRelative === 'function') { + callback = allowRelative; + allowRelative = false; + } + if(!path) { err = new Errors.EINVAL('Path must be a string', path); } else if(isNullPath(path)) { err = new Errors.EINVAL('Path must be a string without null bytes.', path); - } else if(!isAbsolutePath(path)) { + } else if(!allowRelative && !isAbsolutePath(path)) { err = new Errors.EINVAL('Path must be absolute.', path); } @@ -5729,8 +5915,22 @@ function pathCheck(path, callback) { function open(fs, context, path, flags, mode, callback) { - // NOTE: we support the same signature as node with a `mode` arg, - // but ignore it. + /** + * NOTE: we support the same signature as node with a `mode` arg, + * but ignore it. We need to add it. Here is what node.js does: + * function open(path, flags, mode, callback) { + * path = getPathFromURL(path); + * validatePath(path); + * const flagsNumber = stringToFlags(flags); + * if (arguments.length < 4) { + * callback = makeCallback(mode); + * mode = 0o666; + * } else { + * mode = validateAndMaskMode(mode, 'mode', 0o666); + * callback = makeCallback(callback); + * } + */ + callback = arguments[arguments.length - 1]; if(!pathCheck(path, callback)) return; @@ -5767,14 +5967,20 @@ function close(fs, context, fd, callback) { } } -function mknod(fs, context, path, mode, callback) { +function mknod(fs, context, path, type, callback) { if(!pathCheck(path, callback)) return; - make_node(context, path, mode, callback); + make_node(context, path, type, callback); } function mkdir(fs, context, path, mode, callback) { - // NOTE: we support passing a mode arg, but we ignore it internally for now. - callback = arguments[arguments.length - 1]; + if (arguments.length < 5) { + callback = mode; + mode = FULL_READ_WRITE_EXEC_PERMISSIONS; + } else { + mode = validateAndMaskMode(mode, FULL_READ_WRITE_EXEC_PERMISSIONS, callback); + if(!mode) return; + } + if(!pathCheck(path, callback)) return; make_directory(context, path, callback); } @@ -5791,7 +5997,7 @@ function stat(fs, context, path, callback) { if(error) { callback(error); } else { - var stats = new Stats(result, fs.name); + var stats = new Stats(path, result, fs.name); callback(null, stats); } } @@ -5804,7 +6010,7 @@ function fstat(fs, context, fd, callback) { if(error) { callback(error); } else { - var stats = new Stats(result, fs.name); + var stats = new Stats(ofd.path, result, fs.name); callback(null, stats); } } @@ -5877,7 +6083,7 @@ function readFile(fs, context, path, options, callback) { return callback(err); } - var stats = new Stats(fstatResult, fs.name); + var stats = new Stats(ofd.path, fstatResult, fs.name); if(stats.isDirectory()) { cleanup(); @@ -6005,6 +6211,121 @@ function exists(fs, context, path, callback) { stat(fs, context, path, cb); } +// Based on https://github.com/nodejs/node/blob/c700cc42da9cf73af9fec2098520a6c0a631d901/lib/internal/validators.js#L21 +var octalReg = /^[0-7]+$/; +var modeDesc = 'must be a 32-bit unsigned integer or an octal string'; +function isUint32(value) { + return value === (value >>> 0); +} +// Validator for mode_t (the S_* constants). Valid numbers or octal strings +// will be masked with 0o777 to be consistent with the behavior in POSIX APIs. +function validateAndMaskMode(value, def, callback) { + if(typeof def === 'function') { + callback = def; + def = undefined; + } + + if (isUint32(value)) { + return value & FULL_READ_WRITE_EXEC_PERMISSIONS; + } + + if (typeof value === 'number') { + if (!Number.isInteger(value)) { + callback(new Errors.EINVAL('mode not a valid an integer value', value)); + return false; + } else { + // 2 ** 32 === 4294967296 + callback(new Errors.EINVAL('mode not a valid an integer value', value)); + return false; + } + } + + if (typeof value === 'string') { + if (!octalReg.test(value)) { + callback(new Errors.EINVAL('mode not a valid octal string', value)); + return false; + } + var parsed = parseInt(value, 8); + return parsed & FULL_READ_WRITE_EXEC_PERMISSIONS; + } + + // TODO(BridgeAR): Only return `def` in case `value == null` + if (def !== undefined) { + return def; + } + + callback(new Errors.EINVAL('mode not valid', value)); + return false; +} + +function chmod_file(context, path, mode, callback) { + path = normalize(path); + + function update_mode(error, node) { + if (error) { + callback(error); + } else { + Node.setMode(mode, node); + update_node_times(context, path, node, { mtime: Date.now() }, callback); + } + } + + if (typeof mode != 'number') { + callback(new Errors.EINVAL('mode must be number', path)); + } + else { + find_node(context, path, update_mode); + } +} + +function fchmod_file(context, ofd, mode, callback) { + function update_mode(error, node) { + if (error) { + callback(error); + } else { + node.mode = mode; + update_node_times(context, ofd.path, node, { mtime: Date.now() }, callback); + } + } + + if (typeof mode != 'number') { + callback(new Errors.EINVAL('mode must be a number')); + } + else { + ofd.getNode(context, update_mode); + } +} + +function chown_file(context, path, uid, gid, callback) { + path = normalize(path); + + function update_owner(error, node) { + if (error) { + callback(error); + } else { + node.uid = uid; + node.gid = gid; + update_node_times(context, path, node, { mtime: Date.now() }, callback); + } + } + + find_node(context, path, update_owner); +} + +function fchown_file(context, ofd, uid, gid, callback) { + function update_owner(error, node) { + if (error) { + callback(error); + } else { + node.uid = uid; + node.gid = gid; + update_node_times(context, ofd.path, node, { mtime: Date.now() }, callback); + } + } + + ofd.getNode(context, update_owner); +} + function getxattr(fs, context, path, name, callback) { if (!pathCheck(path, callback)) return; getxattr_file(context, path, name, callback); @@ -6019,7 +6340,7 @@ function fgetxattr(fs, context, fd, name, callback) { fgetxattr_file(context, ofd, name, callback); } } - + function setxattr(fs, context, path, name, value, flag, callback) { if(typeof flag === 'function') { callback = flag; @@ -6136,6 +6457,58 @@ function futimes(fs, context, fd, atime, mtime, callback) { } } +function chmod(fs, context, path, mode, callback) { + if(!pathCheck(path, callback)) return; + mode = validateAndMaskMode(mode, 'mode'); + if(!mode) return; + + chmod_file(context, path, mode, callback); +} + +function fchmod(fs, context, fd, mode, callback) { + mode = validateAndMaskMode(mode, 'mode'); + if(!mode) return; + + var ofd = fs.openFiles[fd]; + if(!ofd) { + callback(new Errors.EBADF()); + } else if(!_(ofd.flags).contains(O_WRITE)) { + callback(new Errors.EBADF('descriptor does not permit writing')); + } else { + fchmod_file(context, ofd, mode, callback); + } +} + +function chown(fs, context, path, uid, gid, callback) { + if(!pathCheck(path, callback)) return; + if(!isUint32(uid)) { + return callback(new Errors.EINVAL('uid must be a valid integer', uid)); + } + if(!isUint32(gid)) { + return callback(new Errors.EINVAL('gid must be a valid integer', gid)); + } + + chown_file(context, path, uid, gid, callback); +} + +function fchown(fs, context, fd, uid, gid, callback) { + if(!isUint32(uid)) { + return callback(new Errors.EINVAL('uid must be a valid integer', uid)); + } + if(!isUint32(gid)) { + return callback(new Errors.EINVAL('gid must be a valid integer', gid)); + } + + var ofd = fs.openFiles[fd]; + if(!ofd) { + callback(new Errors.EBADF()); + } else if(!_(ofd.flags).contains(O_WRITE)) { + callback(new Errors.EBADF('descriptor does not permit writing')); + } else { + fchown_file(context, ofd, uid, gid, callback); + } +} + function rename(fs, context, oldpath, newpath, callback) { if(!pathCheck(oldpath, callback)) return; if(!pathCheck(newpath, callback)) return; @@ -6149,12 +6522,15 @@ function rename(fs, context, oldpath, newpath, callback) { var newName = Path.basename(newpath); var oldParentDirectory, oldParentData; var newParentDirectory, newParentData; + var ctime = Date.now(); + var fileNode; - function update_times(error, newNode) { + function update_times(error, result) { if(error) { callback(error); } else { - update_node_times(context, newpath, newNode, { ctime: Date.now() }, callback); + fileNode = result; + update_node_times(context, newpath, fileNode, { ctime: ctime }, callback); } } @@ -6238,7 +6614,7 @@ function rename(fs, context, oldpath, newpath, callback) { function check_node_type(error, node) { if(error) { callback(error); - } else if(node.mode === 'DIRECTORY') { + } else if(node.type === NODE_TYPE_DIRECTORY) { find_node(context, oldParentPath, read_parent_directory_data); } else { link_node(context, oldpath, newpath, unlink_old_file); @@ -6251,8 +6627,13 @@ function rename(fs, context, oldpath, newpath, callback) { function symlink(fs, context, srcpath, dstpath, type, callback) { // NOTE: we support passing the `type` arg, but ignore it. callback = arguments[arguments.length - 1]; - if(!pathCheck(srcpath, callback)) return; + + // Special Case: allow srcpath to be relative, which we normally don't permit. + // If the srcpath is relative, we assume it's relative to the dirpath of + // dstpath. + if(!pathCheck(srcpath, true, callback)) return; if(!pathCheck(dstpath, callback)) return; + make_symbolic_link(context, srcpath, dstpath, callback); } @@ -6268,7 +6649,7 @@ function lstat(fs, context, path, callback) { if(error) { callback(error); } else { - var stats = new Stats(result, fs.name); + var stats = new Stats(path, result, fs.name); callback(null, stats); } } @@ -6303,6 +6684,10 @@ function ftruncate(fs, context, fd, length, callback) { module.exports = { ensureRootDirectory: ensure_root_directory, open: open, + chmod: chmod, + fchmod: fchmod, + chown: chown, + fchown: fchown, close: close, mknod: mknod, mkdir: mkdir, @@ -6432,6 +6817,9 @@ function FileSystem(options, callback) { fs.stdout = STDOUT; fs.stderr = STDERR; + // Expose Node's fs.constants to users + fs.constants = Constants.fsConstants; + // Expose Shell constructor this.Shell = Shell.bind(undefined, this); @@ -6606,6 +6994,10 @@ FileSystem.providers = providers; */ [ 'open', + 'chmod', + 'fchmod', + 'chown', + 'fchown', 'close', 'mknod', 'mkdir', @@ -6758,13 +7150,39 @@ module.exports = { }; },{"./buffer.js":14,"./errors.js":18,"./filesystem/interface.js":20,"./path.js":25,"./shell/shell.js":32}],23:[function(require,module,exports){ -var MODE_FILE = require('./constants.js').MODE_FILE; +var NODE_TYPE_FILE = require('./constants.js').NODE_TYPE_FILE; +var NODE_TYPE_DIRECTORY = require('./constants.js').NODE_TYPE_DIRECTORY; +var NODE_TYPE_SYMBOLIC_LINK = require('./constants.js').NODE_TYPE_SYMBOLIC_LINK; +var NODE_TYPE_META = require('./constants.js').NODE_TYPE_META; + +var ROOT_DIRECTORY_NAME = require('./constants.js').ROOT_DIRECTORY_NAME; + +var S_IFREG = require('./constants.js').S_IFREG; +var S_IFDIR = require('./constants.js').S_IFDIR; +var S_IFLNK = require('./constants.js').S_IFLNK; + +var DEFAULT_FILE_PERMISSIONS = require('./constants.js').DEFAULT_FILE_PERMISSIONS; +var DEFAULT_DIR_PERMISSIONS = require('./constants.js').DEFAULT_DIR_PERMISSIONS; + +function getMode(type, mode) { + switch(type) { + case NODE_TYPE_DIRECTORY: + return (mode || DEFAULT_DIR_PERMISSIONS) | S_IFDIR; + case NODE_TYPE_SYMBOLIC_LINK: + return (mode || DEFAULT_FILE_PERMISSIONS) | S_IFLNK; + /* jshint -W086 */ + case NODE_TYPE_FILE: + // falls through + default: + return (mode || DEFAULT_FILE_PERMISSIONS) | S_IFREG; + } +} function Node(options) { var now = Date.now(); this.id = options.id; - this.mode = options.mode || MODE_FILE; // node type (file, directory, etc) + this.type = options.type || NODE_TYPE_FILE; // node type (file, directory, etc) this.size = options.size || 0; // size (bytes for files, entries for directories) this.atime = options.atime || now; // access time (will mirror ctime after creation) this.ctime = options.ctime || now; // creation/change time @@ -6772,10 +7190,13 @@ function Node(options) { this.flags = options.flags || []; // file flags this.xattrs = options.xattrs || {}; // extended attributes this.nlinks = options.nlinks || 0; // links count - this.version = options.version || 0; // node version - this.blksize = undefined; // block size - this.nblocks = 1; // blocks count this.data = options.data; // id for data object + this.version = options.version || 1; + + // permissions and flags + this.mode = options.mode || (getMode(this.type)); + this.uid = options.uid || 0x0; // owner name + this.gid = options.gid || 0x0; // group name } // Make sure the options object has an id on property, @@ -6810,6 +7231,11 @@ Node.create = function(options, callback) { }); }; +// Update the node's mode (permissions), taking file type bits into account. +Node.setMode = function(mode, node) { + node.mode = getMode(node.type, mode); +}; + module.exports = Node; },{"./constants.js":15}],24:[function(require,module,exports){ @@ -7124,7 +7550,7 @@ module.exports = { }; },{"./indexeddb.js":27,"./memory.js":28,"./websql.js":29}],27:[function(require,module,exports){ -(function (global,Buffer){ +(function (global){ var FILE_SYSTEM_NAME = require('../constants.js').FILE_SYSTEM_NAME; var FILE_STORE_NAME = require('../constants.js').FILE_STORE_NAME; var IDB_RW = require('../constants.js').IDB_RW; @@ -7216,12 +7642,7 @@ IndexedDBContext.prototype.putObject = function(key, value, callback) { this._put(key, value, callback); }; IndexedDBContext.prototype.putBuffer = function(key, uint8BackedBuffer, callback) { - var buf; - if(!Buffer._useTypedArrays) { // workaround for fxos 1.3 - buf = uint8BackedBuffer.toArrayBuffer(); - } else { - buf = uint8BackedBuffer.buffer; - } + var buf = uint8BackedBuffer.buffer; this._put(key, buf, callback); }; @@ -7295,8 +7716,8 @@ IndexedDB.prototype.getReadWriteContext = function() { module.exports = IndexedDB; -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer) -},{"../buffer.js":14,"../constants.js":15,"../errors.js":18,"buffer":6}],28:[function(require,module,exports){ +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../buffer.js":14,"../constants.js":15,"../errors.js":18}],28:[function(require,module,exports){ var FILE_SYSTEM_NAME = require('../constants.js').FILE_SYSTEM_NAME; // NOTE: prefer setImmediate to nextTick for proper recursion yielding. // see https://github.com/js-platform/filer/pull/24 @@ -7844,16 +8265,10 @@ Shell.prototype.ls = function(dir, options, callback) { callback(error); return; } - var entry = { - path: Path.basename(name), - links: stats.nlinks, - size: stats.size, - modified: stats.mtime, - type: stats.type - }; + var entry = stats; if(options.recursive && stats.type === 'DIRECTORY') { - list(Path.join(pathname, entry.path), function(error, items) { + list(Path.join(pathname, entry.name), function(error, items) { if(error) { callback(error); return; @@ -8158,28 +8573,35 @@ module.exports = Shell; },{"../../lib/async.js":1,"../encoding.js":17,"../errors.js":18,"../path.js":25,"./environment.js":31,"minimatch":11}],33:[function(require,module,exports){ var Constants = require('./constants.js'); +var Path = require('./path.js'); -function Stats(fileNode, devName) { - this.node = fileNode.id; +function Stats(path, fileNode, devName) { this.dev = devName; + this.node = fileNode.id; + this.type = fileNode.type; + this.name = fileNode.name; this.size = fileNode.size; this.nlinks = fileNode.nlinks; this.atime = fileNode.atime; this.mtime = fileNode.mtime; this.ctime = fileNode.ctime; - this.type = fileNode.mode; + this.version = fileNode.version; + this.mode = fileNode.mode; + this.uid = fileNode.uid; + this.gid = fileNode.gid; + this.name = Path.basename(path); } Stats.prototype.isFile = function() { - return this.type === Constants.MODE_FILE; + return this.type === Constants.NODE_TYPE_FILE; }; Stats.prototype.isDirectory = function() { - return this.type === Constants.MODE_DIRECTORY; + return this.type === Constants.NODE_TYPE_DIRECTORY; }; Stats.prototype.isSymbolicLink = function() { - return this.type === Constants.MODE_SYMBOLIC_LINK; + return this.type === Constants.NODE_TYPE_SYMBOLIC_LINK; }; // These will always be false in Filer. @@ -8193,14 +8615,14 @@ function() { module.exports = Stats; -},{"./constants.js":15}],34:[function(require,module,exports){ +},{"./constants.js":15,"./path.js":25}],34:[function(require,module,exports){ var Constants = require('./constants.js'); function SuperNode(options) { var now = Date.now(); this.id = Constants.SUPER_NODE_ID; - this.mode = Constants.MODE_META; + this.type = Constants.NODE_TYPE_META; this.atime = options.atime || now; this.ctime = options.ctime || now; this.mtime = options.mtime || now; @@ -8222,4 +8644,4 @@ SuperNode.create = function(options, callback) { module.exports = SuperNode; },{"./constants.js":15}]},{},[22])(22) -}); \ No newline at end of file +}); diff --git a/dist/filer.min.js b/dist/filer.min.js index f1388ed..d51be7c 100644 --- a/dist/filer.min.js +++ b/dist/filer.min.js @@ -1,4 +1,4 @@ -/*! filer 0.0.44 2017-05-25 */ -!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Filer=a()}}(function(){var a;return function b(a,c,d){function e(g,h){if(!c[g]){if(!a[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};a[g][0].call(k.exports,function(b){var c=a[g][1][b];return e(c?c:b)},k,k.exports,b,a,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g=a.length?c():e())})};e()},b.forEachSeries=b.eachSeries,"undefined"!=typeof a&&a.amd?a([],function(){return b}):"undefined"!=typeof c&&c.exports?c.exports=b:root.async=b}()},{}],2:[function(a,b,c){function d(a,b){for(var c=b.length-1;c>=0;c--)b[c]===a&&b.splice(c,1);return b}var e=function(){};e.createInterface=function(a){var b={};return b.on=function(b,c){"undefined"==typeof this[a]&&(this[a]={}),this[a].hasOwnProperty(b)||(this[a][b]=[]),this[a][b].push(c)},b.off=function(b,c){"undefined"!=typeof this[a]&&this[a].hasOwnProperty(b)&&d(c,this[a][b])},b.trigger=function(b){if("undefined"!=typeof this[a]&&this[a].hasOwnProperty(b))for(var c=Array.prototype.slice.call(arguments,1),d=0;da&&(c=d,b.apply(this,arguments))}}function e(a,b){if("undefined"!=typeof a&&a||(a={}),"object"==typeof b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}function f(){var a=this,b=Date.now();this.origin=h(),this.lastMessage=b,this.receivedIDs={},this.previousValues={};var d=function(){a._onStorageEvent.apply(a,arguments)};"undefined"!=typeof document&&(document.attachEvent?document.attachEvent("onstorage",d):c.addEventListener("storage",d,!1))}var g=a("./eventemitter.js"),h=a("../src/shared.js").guid,i=function(a){return"undefined"==typeof a||"undefined"==typeof a.localStorage?{getItem:function(){},setItem:function(){},removeItem:function(){}}:a.localStorage}(c);f.prototype._transaction=function(a){function b(){if(!g){var k=Date.now(),m=0|i.getItem(l);if(m&&d>k-m)return h||(f._on("storage",b),h=!0),void(j=setTimeout(b,e));g=!0,i.setItem(l,k),a(),c()}}function c(){h&&f._off("storage",b),j&&clearTimeout(j),i.removeItem(l)}var d=1e3,e=20,f=this,g=!1,h=!1,j=null;b()},f.prototype._cleanup_emit=d(100,function(){var a=this;a._transaction(function(){var a,b=Date.now(),c=b-m,d=0;try{a=JSON.parse(i.getItem(j)||"[]")}catch(e){a=[]}for(var f=a.length-1;f>=0;f--)a[f].timestamp0&&i.setItem(j,JSON.stringify(a))})}),f.prototype._cleanup_once=d(100,function(){var a=this;a._transaction(function(){var b,c,d=(Date.now(),0);try{c=JSON.parse(i.getItem(k)||"{}")}catch(e){c={}}for(b in c)a._once_expired(b,c)&&(delete c[b],d++);d>0&&i.setItem(k,JSON.stringify(c))})}),f.prototype._once_expired=function(a,b){if(!b)return!0;if(!b.hasOwnProperty(a))return!0;if("object"!=typeof b[a])return!0;var c=b[a].ttl||n,d=Date.now(),e=b[a].timestamp;return d-c>e},f.prototype._localStorageChanged=function(a,b){if(a&&a.key)return a.key===b;var c=i.getItem(b);return c===this.previousValues[b]?!1:(this.previousValues[b]=c,!0)},f.prototype._onStorageEvent=function(a){a=a||c.event;var b=this;this._localStorageChanged(a,j)&&this._transaction(function(){var a,c=Date.now(),d=i.getItem(j);try{a=JSON.parse(d||"[]")}catch(e){a=[]}for(var f=0;fd;d++)if(b.call(c,a[d],d,a)===s)return}else{var f=f(a);for(d=0,e=f.length;e>d;d++)if(b.call(c,a[f[d]],f[d],a)===s)return}}function h(a,b,c){b||(b=f);var d=!1;return null==a?d:o&&a.some===o?a.some(b,c):(g(a,function(a,e,f){return d||(d=b.call(c,a,e,f))?s:void 0}),!!d)}function i(a,b){return null==a?!1:n&&a.indexOf===n?-1!=a.indexOf(b):h(a,function(a){return a===b})}function j(a){this.value=a}function k(a){return a&&"object"==typeof a&&!Array.isArray(a)&&q.call(a,"__wrapped__")?a:new j(a)}var l=Array.prototype,m=l.forEach,n=l.indexOf,o=l.some,p=Object.prototype,q=p.hasOwnProperty,r=Object.keys,s={},t=r||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var b=[];for(var c in a)d(a,c)&&b.push(c);return b};j.prototype.has=function(a){return d(this.value,a)},j.prototype.contains=function(a){return i(this.value,a)},j.prototype.size=function(){return e(this.value)},b.exports=k},{}],5:[function(a,b,c){!function(a){"use strict";c.encode=function(b){var c,d=new Uint8Array(b),e=d.length,f="";for(c=0;e>c;c+=3)f+=a[d[c]>>2],f+=a[(3&d[c])<<4|d[c+1]>>4],f+=a[(15&d[c+1])<<2|d[c+2]>>6],f+=a[63&d[c+2]];return e%3===2?f=f.substring(0,f.length-1)+"=":e%3===1&&(f=f.substring(0,f.length-2)+"=="),f},c.decode=function(b){var c,d,e,f,g,h=.75*b.length,i=b.length,j=0;"="===b[b.length-1]&&(h--,"="===b[b.length-2]&&h--);var k=new ArrayBuffer(h),l=new Uint8Array(k);for(c=0;i>c;c+=4)d=a.indexOf(b[c]),e=a.indexOf(b[c+1]),f=a.indexOf(b[c+2]),g=a.indexOf(b[c+3]),l[j++]=d<<2|e>>4,l[j++]=(15&e)<<4|f>>2,l[j++]=(3&f)<<6|63&g;return k}}("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")},{}],6:[function(a,b,c){function d(a){return this instanceof d?(this.length=0,this.parent=void 0,"number"==typeof a?e(this,a):"string"==typeof a?f(this,a,arguments.length>1?arguments[1]:"utf8"):g(this,a)):arguments.length>1?new d(a,arguments[1]):new d(a)}function e(a,b){if(a=m(a,0>b?0:0|n(b)),!d.TYPED_ARRAY_SUPPORT)for(var c=0;b>c;c++)a[c]=0;return a}function f(a,b,c){("string"!=typeof c||""===c)&&(c="utf8");var d=0|p(b,c);return a=m(a,d),a.write(b,c),a}function g(a,b){if(d.isBuffer(b))return h(a,b);if(U(b))return i(a,b);if(null==b)throw new TypeError("must start with number, buffer, array or string");return"undefined"!=typeof ArrayBuffer&&b.buffer instanceof ArrayBuffer?j(a,b):b.length?k(a,b):l(a,b)}function h(a,b){var c=0|n(b.length);return a=m(a,c),b.copy(a,0,0,c),a}function i(a,b){var c=0|n(b.length);a=m(a,c);for(var d=0;c>d;d+=1)a[d]=255&b[d];return a}function j(a,b){var c=0|n(b.length);a=m(a,c);for(var d=0;c>d;d+=1)a[d]=255&b[d];return a}function k(a,b){var c=0|n(b.length);a=m(a,c);for(var d=0;c>d;d+=1)a[d]=255&b[d];return a}function l(a,b){var c,d=0;"Buffer"===b.type&&U(b.data)&&(c=b.data,d=0|n(c.length)),a=m(a,d);for(var e=0;d>e;e+=1)a[e]=255&c[e];return a}function m(a,b){d.TYPED_ARRAY_SUPPORT?a=d._augment(new Uint8Array(b)):(a.length=b,a._isBuffer=!0);var c=0!==b&&b<=d.poolSize>>>1;return c&&(a.parent=W),a}function n(a){if(a>=V)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+V.toString(16)+" bytes");return 0|a}function o(a,b){if(!(this instanceof o))return new o(a,b);var c=new d(a,b);return delete c.parent,c}function p(a,b){if("string"!=typeof a&&(a=String(a)),0===a.length)return 0;switch(b||"utf8"){case"ascii":case"binary":case"raw":return a.length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*a.length;case"hex":return a.length>>>1;case"utf8":case"utf-8":return M(a).length;case"base64":return P(a).length;default:return a.length}}function q(a,b,c,d){c=Number(c)||0;var e=a.length-c;d?(d=Number(d),d>e&&(d=e)):d=e;var f=b.length;if(f%2!==0)throw new Error("Invalid hex string");d>f/2&&(d=f/2);for(var g=0;d>g;g++){var h=parseInt(b.substr(2*g,2),16);if(isNaN(h))throw new Error("Invalid hex string");a[c+g]=h}return g}function r(a,b,c,d){return Q(M(b,a.length-c),a,c,d)}function s(a,b,c,d){return Q(N(b),a,c,d)}function t(a,b,c,d){return s(a,b,c,d)}function u(a,b,c,d){return Q(P(b),a,c,d)}function v(a,b,c,d){return Q(O(b,a.length-c),a,c,d)}function w(a,b,c){return 0===b&&c===a.length?S.fromByteArray(a):S.fromByteArray(a.slice(b,c))}function x(a,b,c){var d="",e="";c=Math.min(a.length,c);for(var f=b;c>f;f++)a[f]<=127?(d+=R(e)+String.fromCharCode(a[f]),e=""):e+="%"+a[f].toString(16);return d+R(e)}function y(a,b,c){var d="";c=Math.min(a.length,c);for(var e=b;c>e;e++)d+=String.fromCharCode(127&a[e]);return d}function z(a,b,c){var d="";c=Math.min(a.length,c);for(var e=b;c>e;e++)d+=String.fromCharCode(a[e]);return d}function A(a,b,c){var d=a.length;(!b||0>b)&&(b=0),(!c||0>c||c>d)&&(c=d);for(var e="",f=b;c>f;f++)e+=L(a[f]);return e}function B(a,b,c){for(var d=a.slice(b,c),e="",f=0;fa)throw new RangeError("offset is not uint");if(a+b>c)throw new RangeError("Trying to access beyond buffer length")}function D(a,b,c,e,f,g){if(!d.isBuffer(a))throw new TypeError("buffer must be a Buffer instance");if(b>f||g>b)throw new RangeError("value is out of bounds");if(c+e>a.length)throw new RangeError("index out of range")}function E(a,b,c,d){0>b&&(b=65535+b+1);for(var e=0,f=Math.min(a.length-c,2);f>e;e++)a[c+e]=(b&255<<8*(d?e:1-e))>>>8*(d?e:1-e)}function F(a,b,c,d){0>b&&(b=4294967295+b+1);for(var e=0,f=Math.min(a.length-c,4);f>e;e++)a[c+e]=b>>>8*(d?e:3-e)&255}function G(a,b,c,d,e,f){if(b>e||f>b)throw new RangeError("value is out of bounds");if(c+d>a.length)throw new RangeError("index out of range");if(0>c)throw new RangeError("index out of range")}function H(a,b,c,d,e){return e||G(a,b,c,4,3.4028234663852886e38,-3.4028234663852886e38),T.write(a,b,c,d,23,4),c+4}function I(a,b,c,d,e){return e||G(a,b,c,8,1.7976931348623157e308,-1.7976931348623157e308),T.write(a,b,c,d,52,8),c+8}function J(a){if(a=K(a).replace(Y,""),a.length<2)return"";for(;a.length%4!==0;)a+="=";return a}function K(a){return a.trim?a.trim():a.replace(/^\s+|\s+$/g,"")}function L(a){return 16>a?"0"+a.toString(16):a.toString(16)}function M(a,b){b=b||1/0;for(var c,d=a.length,e=null,f=[],g=0;d>g;g++){if(c=a.charCodeAt(g),c>55295&&57344>c){if(!e){if(c>56319){(b-=3)>-1&&f.push(239,191,189);continue}if(g+1===d){(b-=3)>-1&&f.push(239,191,189);continue}e=c;continue}if(56320>c){(b-=3)>-1&&f.push(239,191,189),e=c;continue}c=e-55296<<10|c-56320|65536,e=null}else e&&((b-=3)>-1&&f.push(239,191,189),e=null);if(128>c){if((b-=1)<0)break;f.push(c)}else if(2048>c){if((b-=2)<0)break;f.push(c>>6|192,63&c|128)}else if(65536>c){if((b-=3)<0)break;f.push(c>>12|224,c>>6&63|128,63&c|128)}else{if(!(2097152>c))throw new Error("Invalid code point");if((b-=4)<0)break;f.push(c>>18|240,c>>12&63|128,c>>6&63|128,63&c|128)}}return f}function N(a){for(var b=[],c=0;c>8,e=c%256,f.push(e),f.push(d);return f}function P(a){return S.toByteArray(J(a))}function Q(a,b,c,d){for(var e=0;d>e&&!(e+c>=b.length||e>=a.length);e++)b[e+c]=a[e];return e}function R(a){try{return decodeURIComponent(a)}catch(b){return String.fromCharCode(65533)}}var S=a("base64-js"),T=a("ieee754"),U=a("is-array");c.Buffer=d,c.SlowBuffer=o,c.INSPECT_MAX_BYTES=50,d.poolSize=8192;var V=1073741823,W={};d.TYPED_ARRAY_SUPPORT=function(){try{var a=new ArrayBuffer(0),b=new Uint8Array(a);return b.foo=function(){return 42},42===b.foo()&&"function"==typeof b.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(c){return!1}}(),d.isBuffer=function(a){return!(null==a||!a._isBuffer)},d.compare=function(a,b){if(!d.isBuffer(a)||!d.isBuffer(b))throw new TypeError("Arguments must be Buffers");if(a===b)return 0;for(var c=a.length,e=b.length,f=0,g=Math.min(c,e);g>f&&a[f]===b[f];)++f;return f!==g&&(c=a[f],e=b[f]),e>c?-1:c>e?1:0},d.isEncoding=function(a){switch(String(a).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},d.concat=function(a,b){if(!U(a))throw new TypeError("list argument must be an Array of Buffers.");if(0===a.length)return new d(0);if(1===a.length)return a[0];var c;if(void 0===b)for(b=0,c=0;cb&&(b=0),c>this.length&&(c=this.length),b>=c)return"";for(;;)switch(a){case"hex":return A(this,b,c);case"utf8":case"utf-8":return x(this,b,c);case"ascii":return y(this,b,c);case"binary":return z(this,b,c);case"base64":return w(this,b,c);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,b,c);default:if(d)throw new TypeError("Unknown encoding: "+a);a=(a+"").toLowerCase(),d=!0}},d.prototype.equals=function(a){if(!d.isBuffer(a))throw new TypeError("Argument must be a Buffer");return this===a?!0:0===d.compare(this,a)},d.prototype.inspect=function(){var a="",b=c.INSPECT_MAX_BYTES;return this.length>0&&(a=this.toString("hex",0,b).match(/.{2}/g).join(" "),this.length>b&&(a+=" ... ")),""},d.prototype.compare=function(a){if(!d.isBuffer(a))throw new TypeError("Argument must be a Buffer");return this===a?0:d.compare(this,a)},d.prototype.indexOf=function(a,b){function c(a,b,c){for(var d=-1,e=0;c+e2147483647?b=2147483647:-2147483648>b&&(b=-2147483648),b>>=0,0===this.length)return-1;if(b>=this.length)return-1;if(0>b&&(b=Math.max(this.length+b,0)),"string"==typeof a)return 0===a.length?-1:String.prototype.indexOf.call(this,a,b);if(d.isBuffer(a))return c(this,a,b);if("number"==typeof a)return d.TYPED_ARRAY_SUPPORT&&"function"===Uint8Array.prototype.indexOf?Uint8Array.prototype.indexOf.call(this,a,b):c(this,[a],b);throw new TypeError("val must be string, number or Buffer")},d.prototype.get=function(a){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(a)},d.prototype.set=function(a,b){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(a,b)},d.prototype.write=function(a,b,c,d){if(void 0===b)d="utf8",c=this.length,b=0;else if(void 0===c&&"string"==typeof b)d=b,c=this.length,b=0;else if(isFinite(b))b=0|b,isFinite(c)?(c=0|c,void 0===d&&(d="utf8")):(d=c,c=void 0);else{var e=d;d=b,b=0|c,c=e}var f=this.length-b;if((void 0===c||c>f)&&(c=f),a.length>0&&(0>c||0>b)||b>this.length)throw new RangeError("attempt to write outside buffer bounds");d||(d="utf8");for(var g=!1;;)switch(d){case"hex":return q(this,a,b,c);case"utf8":case"utf-8":return r(this,a,b,c);case"ascii":return s(this,a,b,c);case"binary":return t(this,a,b,c);case"base64":return u(this,a,b,c);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return v(this,a,b,c);default:if(g)throw new TypeError("Unknown encoding: "+d);d=(""+d).toLowerCase(),g=!0}},d.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},d.prototype.slice=function(a,b){var c=this.length;a=~~a,b=void 0===b?c:~~b,0>a?(a+=c,0>a&&(a=0)):a>c&&(a=c),0>b?(b+=c,0>b&&(b=0)):b>c&&(b=c),a>b&&(b=a);var e;if(d.TYPED_ARRAY_SUPPORT)e=d._augment(this.subarray(a,b));else{var f=b-a;e=new d(f,void 0);for(var g=0;f>g;g++)e[g]=this[g+a]}return e.length&&(e.parent=this.parent||this),e},d.prototype.readUIntLE=function(a,b,c){a=0|a,b=0|b,c||C(a,b,this.length);for(var d=this[a],e=1,f=0;++f0&&(e*=256);)d+=this[a+--b]*e;return d},d.prototype.readUInt8=function(a,b){return b||C(a,1,this.length),this[a]},d.prototype.readUInt16LE=function(a,b){return b||C(a,2,this.length),this[a]|this[a+1]<<8},d.prototype.readUInt16BE=function(a,b){return b||C(a,2,this.length),this[a]<<8|this[a+1]},d.prototype.readUInt32LE=function(a,b){return b||C(a,4,this.length),(this[a]|this[a+1]<<8|this[a+2]<<16)+16777216*this[a+3]},d.prototype.readUInt32BE=function(a,b){return b||C(a,4,this.length),16777216*this[a]+(this[a+1]<<16|this[a+2]<<8|this[a+3])},d.prototype.readIntLE=function(a,b,c){a=0|a,b=0|b,c||C(a,b,this.length);for(var d=this[a],e=1,f=0;++f=e&&(d-=Math.pow(2,8*b)),d},d.prototype.readIntBE=function(a,b,c){a=0|a,b=0|b,c||C(a,b,this.length);for(var d=b,e=1,f=this[a+--d];d>0&&(e*=256);)f+=this[a+--d]*e;return e*=128,f>=e&&(f-=Math.pow(2,8*b)),f},d.prototype.readInt8=function(a,b){return b||C(a,1,this.length),128&this[a]?-1*(255-this[a]+1):this[a]},d.prototype.readInt16LE=function(a,b){b||C(a,2,this.length);var c=this[a]|this[a+1]<<8;return 32768&c?4294901760|c:c},d.prototype.readInt16BE=function(a,b){b||C(a,2,this.length);var c=this[a+1]|this[a]<<8;return 32768&c?4294901760|c:c},d.prototype.readInt32LE=function(a,b){return b||C(a,4,this.length),this[a]|this[a+1]<<8|this[a+2]<<16|this[a+3]<<24},d.prototype.readInt32BE=function(a,b){return b||C(a,4,this.length),this[a]<<24|this[a+1]<<16|this[a+2]<<8|this[a+3]},d.prototype.readFloatLE=function(a,b){return b||C(a,4,this.length),T.read(this,a,!0,23,4)},d.prototype.readFloatBE=function(a,b){return b||C(a,4,this.length),T.read(this,a,!1,23,4)},d.prototype.readDoubleLE=function(a,b){return b||C(a,8,this.length),T.read(this,a,!0,52,8)},d.prototype.readDoubleBE=function(a,b){return b||C(a,8,this.length),T.read(this,a,!1,52,8)},d.prototype.writeUIntLE=function(a,b,c,d){a=+a,b=0|b,c=0|c,d||D(this,a,b,c,Math.pow(2,8*c),0);var e=1,f=0;for(this[b]=255&a;++f=0&&(f*=256);)this[b+e]=a/f&255;return b+c},d.prototype.writeUInt8=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,1,255,0),d.TYPED_ARRAY_SUPPORT||(a=Math.floor(a)),this[b]=a,b+1},d.prototype.writeUInt16LE=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,2,65535,0),d.TYPED_ARRAY_SUPPORT?(this[b]=a,this[b+1]=a>>>8):E(this,a,b,!0),b+2},d.prototype.writeUInt16BE=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,2,65535,0),d.TYPED_ARRAY_SUPPORT?(this[b]=a>>>8,this[b+1]=a):E(this,a,b,!1),b+2},d.prototype.writeUInt32LE=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,4,4294967295,0),d.TYPED_ARRAY_SUPPORT?(this[b+3]=a>>>24,this[b+2]=a>>>16,this[b+1]=a>>>8,this[b]=a):F(this,a,b,!0),b+4},d.prototype.writeUInt32BE=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,4,4294967295,0),d.TYPED_ARRAY_SUPPORT?(this[b]=a>>>24,this[b+1]=a>>>16,this[b+2]=a>>>8,this[b+3]=a):F(this,a,b,!1),b+4},d.prototype.writeIntLE=function(a,b,c,d){if(a=+a,b=0|b,!d){var e=Math.pow(2,8*c-1);D(this,a,b,c,e-1,-e)}var f=0,g=1,h=0>a?1:0;for(this[b]=255&a;++f>0)-h&255;return b+c},d.prototype.writeIntBE=function(a,b,c,d){if(a=+a,b=0|b,!d){var e=Math.pow(2,8*c-1);D(this,a,b,c,e-1,-e)}var f=c-1,g=1,h=0>a?1:0;for(this[b+f]=255&a;--f>=0&&(g*=256);)this[b+f]=(a/g>>0)-h&255;return b+c},d.prototype.writeInt8=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,1,127,-128),d.TYPED_ARRAY_SUPPORT||(a=Math.floor(a)),0>a&&(a=255+a+1),this[b]=a,b+1},d.prototype.writeInt16LE=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,2,32767,-32768),d.TYPED_ARRAY_SUPPORT?(this[b]=a,this[b+1]=a>>>8):E(this,a,b,!0),b+2},d.prototype.writeInt16BE=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,2,32767,-32768),d.TYPED_ARRAY_SUPPORT?(this[b]=a>>>8,this[b+1]=a):E(this,a,b,!1),b+2},d.prototype.writeInt32LE=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,4,2147483647,-2147483648),d.TYPED_ARRAY_SUPPORT?(this[b]=a,this[b+1]=a>>>8,this[b+2]=a>>>16,this[b+3]=a>>>24):F(this,a,b,!0),b+4},d.prototype.writeInt32BE=function(a,b,c){return a=+a,b=0|b,c||D(this,a,b,4,2147483647,-2147483648),0>a&&(a=4294967295+a+1),d.TYPED_ARRAY_SUPPORT?(this[b]=a>>>24,this[b+1]=a>>>16,this[b+2]=a>>>8,this[b+3]=a):F(this,a,b,!1),b+4},d.prototype.writeFloatLE=function(a,b,c){return H(this,a,b,!0,c)},d.prototype.writeFloatBE=function(a,b,c){return H(this,a,b,!1,c)},d.prototype.writeDoubleLE=function(a,b,c){return I(this,a,b,!0,c)},d.prototype.writeDoubleBE=function(a,b,c){return I(this,a,b,!1,c)},d.prototype.copy=function(a,b,c,e){if(c||(c=0),e||0===e||(e=this.length),b>=a.length&&(b=a.length),b||(b=0),e>0&&c>e&&(e=c),e===c)return 0;if(0===a.length||0===this.length)return 0;if(0>b)throw new RangeError("targetStart out of bounds");if(0>c||c>=this.length)throw new RangeError("sourceStart out of bounds");if(0>e)throw new RangeError("sourceEnd out of bounds");e>this.length&&(e=this.length),a.length-bf||!d.TYPED_ARRAY_SUPPORT)for(var g=0;f>g;g++)a[g+b]=this[g+c];else a._set(this.subarray(c,c+f),b);return f},d.prototype.fill=function(a,b,c){if(a||(a=0),b||(b=0),c||(c=this.length),b>c)throw new RangeError("end < start");if(c!==b&&0!==this.length){if(0>b||b>=this.length)throw new RangeError("start out of bounds");if(0>c||c>this.length)throw new RangeError("end out of bounds");var d;if("number"==typeof a)for(d=b;c>d;d++)this[d]=a;else{var e=M(a.toString()),f=e.length;for(d=b;c>d;d++)this[d]=e[d%f]}return this}},d.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(d.TYPED_ARRAY_SUPPORT)return new d(this).buffer;for(var a=new Uint8Array(this.length),b=0,c=a.length;c>b;b+=1)a[b]=this[b];return a.buffer}throw new TypeError("Buffer.toArrayBuffer not supported in this browser")};var X=d.prototype;d._augment=function(a){return a.constructor=d,a._isBuffer=!0,a._set=a.set,a.get=X.get,a.set=X.set,a.write=X.write,a.toString=X.toString,a.toLocaleString=X.toString,a.toJSON=X.toJSON,a.equals=X.equals,a.compare=X.compare,a.indexOf=X.indexOf,a.copy=X.copy,a.slice=X.slice,a.readUIntLE=X.readUIntLE,a.readUIntBE=X.readUIntBE,a.readUInt8=X.readUInt8,a.readUInt16LE=X.readUInt16LE,a.readUInt16BE=X.readUInt16BE,a.readUInt32LE=X.readUInt32LE,a.readUInt32BE=X.readUInt32BE,a.readIntLE=X.readIntLE,a.readIntBE=X.readIntBE,a.readInt8=X.readInt8,a.readInt16LE=X.readInt16LE,a.readInt16BE=X.readInt16BE,a.readInt32LE=X.readInt32LE,a.readInt32BE=X.readInt32BE,a.readFloatLE=X.readFloatLE,a.readFloatBE=X.readFloatBE,a.readDoubleLE=X.readDoubleLE,a.readDoubleBE=X.readDoubleBE,a.writeUInt8=X.writeUInt8,a.writeUIntLE=X.writeUIntLE,a.writeUIntBE=X.writeUIntBE,a.writeUInt16LE=X.writeUInt16LE,a.writeUInt16BE=X.writeUInt16BE,a.writeUInt32LE=X.writeUInt32LE,a.writeUInt32BE=X.writeUInt32BE,a.writeIntLE=X.writeIntLE,a.writeIntBE=X.writeIntBE,a.writeInt8=X.writeInt8,a.writeInt16LE=X.writeInt16LE,a.writeInt16BE=X.writeInt16BE,a.writeInt32LE=X.writeInt32LE,a.writeInt32BE=X.writeInt32BE,a.writeFloatLE=X.writeFloatLE,a.writeFloatBE=X.writeFloatBE,a.writeDoubleLE=X.writeDoubleLE,a.writeDoubleBE=X.writeDoubleBE,a.fill=X.fill,a.inspect=X.inspect,a.toArrayBuffer=X.toArrayBuffer,a};var Y=/[^+\/0-9A-z\-]/g},{"base64-js":7,ieee754:8,"is-array":9}],7:[function(a,b,c){var d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(a){"use strict";function b(a){var b=a.charCodeAt(0);return b===g||b===l?62:b===h||b===m?63:i>b?-1:i+10>b?b-i+26+26:k+26>b?b-k:j+26>b?b-j+26:void 0}function c(a){function c(a){j[l++]=a}var d,e,g,h,i,j;if(a.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var k=a.length;i="="===a.charAt(k-2)?2:"="===a.charAt(k-1)?1:0,j=new f(3*a.length/4-i),g=i>0?a.length-4:a.length;var l=0;for(d=0,e=0;g>d;d+=4,e+=3)h=b(a.charAt(d))<<18|b(a.charAt(d+1))<<12|b(a.charAt(d+2))<<6|b(a.charAt(d+3)),c((16711680&h)>>16),c((65280&h)>>8),c(255&h);return 2===i?(h=b(a.charAt(d))<<2|b(a.charAt(d+1))>>4,c(255&h)):1===i&&(h=b(a.charAt(d))<<10|b(a.charAt(d+1))<<4|b(a.charAt(d+2))>>2,c(h>>8&255),c(255&h)),j}function e(a){function b(a){return d.charAt(a)}function c(a){return b(a>>18&63)+b(a>>12&63)+b(a>>6&63)+b(63&a)}var e,f,g,h=a.length%3,i="";for(e=0,g=a.length-h;g>e;e+=3)f=(a[e]<<16)+(a[e+1]<<8)+a[e+2],i+=c(f);switch(h){case 1:f=a[a.length-1],i+=b(f>>2),i+=b(f<<4&63),i+="==";break;case 2:f=(a[a.length-2]<<8)+a[a.length-1],i+=b(f>>10),i+=b(f>>4&63),i+=b(f<<2&63),i+="="}return i}var f="undefined"!=typeof Uint8Array?Uint8Array:Array,g="+".charCodeAt(0),h="/".charCodeAt(0),i="0".charCodeAt(0),j="a".charCodeAt(0),k="A".charCodeAt(0),l="-".charCodeAt(0),m="_".charCodeAt(0);a.toByteArray=c,a.fromByteArray=e}("undefined"==typeof c?this.base64js={}:c)},{}],8:[function(a,b,c){c.read=function(a,b,c,d,e){var f,g,h=8*e-d-1,i=(1<>1,k=-7,l=c?e-1:0,m=c?-1:1,n=a[b+l];for(l+=m,f=n&(1<<-k)-1,n>>=-k,k+=h;k>0;f=256*f+a[b+l],l+=m,k-=8);for(g=f&(1<<-k)-1,f>>=-k,k+=d;k>0;g=256*g+a[b+l],l+=m,k-=8);if(0===f)f=1-j;else{if(f===i)return g?NaN:(n?-1:1)*(1/0);g+=Math.pow(2,d),f-=j}return(n?-1:1)*g*Math.pow(2,f-d)},c.write=function(a,b,c,d,e,f){var g,h,i,j=8*f-e-1,k=(1<>1,m=23===e?Math.pow(2,-24)-Math.pow(2,-77):0,n=d?0:f-1,o=d?1:-1,p=0>b||0===b&&0>1/b?1:0;for(b=Math.abs(b),isNaN(b)||b===1/0?(h=isNaN(b)?1:0,g=k):(g=Math.floor(Math.log(b)/Math.LN2),b*(i=Math.pow(2,-g))<1&&(g--,i*=2),b+=g+l>=1?m/i:m*Math.pow(2,1-l),b*i>=2&&(g++,i/=2),g+l>=k?(h=0,g=k):g+l>=1?(h=(b*i-1)*Math.pow(2,e),g+=l):(h=b*Math.pow(2,l-1)*Math.pow(2,e),g=0));e>=8;a[c+n]=255&h,n+=o,h/=256,e-=8);for(g=g<0;a[c+n]=255&g,n+=o,g/=256,j-=8);a[c+n-o]|=128*p}},{}],9:[function(a,b,c){var d=Array.isArray,e=Object.prototype.toString;b.exports=d||function(a){return!!a&&"[object Array]"==e.call(a)}},{}],10:[function(a,b,c){function d(a,b){for(var c=0,d=a.length-1;d>=0;d--){var e=a[d];"."===e?a.splice(d,1):".."===e?(a.splice(d,1),c++):c&&(a.splice(d,1),c--)}if(b)for(;c--;c)a.unshift("..");return a}function e(a,b){if(a.filter)return a.filter(b);for(var c=[],d=0;d=-1&&!b;c--){var f=c>=0?arguments[c]:process.cwd();if("string"!=typeof f)throw new TypeError("Arguments to path.resolve must be strings");f&&(a=f+"/"+a,b="/"===f.charAt(0))}return a=d(e(a.split("/"),function(a){return!!a}),!b).join("/"),(b?"/":"")+a||"."},c.normalize=function(a){var b=c.isAbsolute(a),f="/"===h(a,-1);return a=d(e(a.split("/"),function(a){return!!a}),!b).join("/"),a||b||(a="."),a&&f&&(a+="/"),(b?"/":"")+a},c.isAbsolute=function(a){return"/"===a.charAt(0)},c.join=function(){var a=Array.prototype.slice.call(arguments,0);return c.normalize(e(a,function(a,b){if("string"!=typeof a)throw new TypeError("Arguments to path.join must be strings");return a}).join("/"))},c.relative=function(a,b){function d(a){for(var b=0;b=0&&""===a[c];c--);return b>c?[]:a.slice(b,c-b+1)}a=c.resolve(a).substr(1),b=c.resolve(b).substr(1);for(var e=d(a.split("/")),f=d(b.split("/")),g=Math.min(e.length,f.length),h=g,i=0;g>i;i++)if(e[i]!==f[i]){h=i;break}for(var j=[],i=h;ib&&(b=a.length+b),a.substr(b,c)}},{}],11:[function(a,b,c){!function(a,b,c,d){function e(a){return a.split("").reduce(function(a,b){return a[b]=!0,a},{})}function f(a,b){return b=b||{},function(c,d,e){return h(c,a,b)}}function g(a,b){a=a||{},b=b||{};var c={};return Object.keys(b).forEach(function(a){c[a]=b[a]}),Object.keys(a).forEach(function(b){c[b]=a[b]}),c}function h(a,b,c){if("string"!=typeof b)throw new TypeError("glob pattern string required");return c||(c={}),c.nocomment||"#"!==b.charAt(0)?""===b.trim()?""===a:new i(b,c).match(a):!1}function i(a,b){if(!(this instanceof i))return new i(a,b,t);if("string"!=typeof a)throw new TypeError("glob pattern string required");b||(b={}),a=a.trim(),"win32"===d&&(a=a.split("\\").join("/"));var c=a+"\n"+v(b),e=h.cache.get(c);return e?e:(h.cache.set(c,this),this.options=b,this.set=[],this.pattern=a,this.regexp=null,this.negate=!1,this.comment=!1,this.empty=!1,void this.make())}function j(){if(!this._made){var a=this.pattern,b=this.options;if(!b.nocomment&&"#"===a.charAt(0))return void(this.comment=!0);if(!a)return void(this.empty=!0);this.parseNegate();var c=this.globSet=this.braceExpand();b.debug&&(this.debug=console.error),this.debug(this.pattern,c),c=this.globParts=c.map(function(a){return a.split(B)}),this.debug(this.pattern,c),c=c.map(function(a,b,c){return a.map(this.parse,this)},this),this.debug(this.pattern,c),c=c.filter(function(a){return-1===a.indexOf(!1)}),this.debug(this.pattern,c),this.set=c}}function k(){var a=this.pattern,b=!1,c=this.options,d=0;if(!c.nonegate){for(var e=0,f=a.length;f>e&&"!"===a.charAt(e);e++)b=!b,d++;d&&(this.pattern=a.substr(d)),this.negate=b}}function l(a,b,c){return c=c||"0",a+="",a.length>=b?a:new Array(b-a.length+1).join(c)+a}function m(a,b){function c(){t.push(x),x=""}if(b=b||this.options,a="undefined"==typeof a?this.pattern:a,"undefined"==typeof a)throw new Error("undefined pattern");if(b.nobrace||!a.match(/\{.*\}/))return[a];var d=!1;if("{"!==a.charAt(0)){this.debug(a);for(var e=null,f=0,g=a.length;g>f;f++){ -var h=a.charAt(f);if(this.debug(f,h),"\\"===h)d=!d;else if("{"===h&&!d){e=a.substr(0,f);break}}if(null===e)return this.debug("no sets"),[a];var i=m.call(this,a.substr(f),b);return i.map(function(a){return e+a})}var j=a.match(/^\{(-?[0-9]+)\.\.(-?[0-9]+)\}/);if(j){this.debug("numset",j[1],j[2]);for(var k,n=m.call(this,a.substr(j[0].length),b),o=+j[1],p="0"===j[1][0],q=j[1].length,r=+j[2],s=o>r?-1:1,t=[],f=o;f!=r+s;f+=s){k=p?l(f,q):f+"";for(var u=0,v=n.length;v>u;u++)t.push(k+n[u])}return t}var f=1,w=1,t=[],x="",d=!1;this.debug("Entering for");a:for(f=1,g=a.length;g>f;f++){var h=a.charAt(f);if(this.debug("",f,h),d)d=!1,x+="\\"+h;else switch(h){case"\\":d=!0;continue;case"{":w++,x+="{";continue;case"}":if(w--,0===w){c(),f++;break a}x+=h;continue;case",":1===w?c():x+=h;continue;default:x+=h;continue}}if(0!==w)return this.debug("didn't close",a),m.call(this,"\\"+a,b);this.debug("set",t),this.debug("suffix",a.substr(f));var n=m.call(this,a.substr(f),b),y=1===t.length;this.debug("set pre-expanded",t),t=t.map(function(a){return m.call(this,a,b)},this),this.debug("set expanded",t),t=t.reduce(function(a,b){return a.concat(b)}),y&&(t=t.map(function(a){return"{"+a+"}"}));for(var z=[],f=0,g=t.length;g>f;f++)for(var u=0,v=n.length;v>u;u++)z.push(t[f]+n[u]);return z}function n(a,b){function c(){if(f){switch(f){case"*":h+=x,i=!0;break;case"?":h+=w,i=!0;break;default:h+="\\"+f}p.debug("clearStateChar %j %j",f,h),f=!1}}var d=this.options;if(!d.noglobstar&&"**"===a)return u;if(""===a)return"";for(var e,f,g,h="",i=!!d.nocase,j=!1,k=[],l=!1,m=-1,n=-1,o="."===a.charAt(0)?"":d.dot?"(?!(?:^|\\/)\\.{1,2}(?:$|\\/))":"(?!\\.)",p=this,r=0,s=a.length;s>r&&(g=a.charAt(r));r++)if(this.debug("%s %s %s %j",a,r,h,g),j&&A[g])h+="\\"+g,j=!1;else switch(g){case"/":return!1;case"\\":c(),j=!0;continue;case"?":case"*":case"+":case"@":case"!":if(this.debug("%s %s %s %j <-- stateChar",a,r,h,g),l){this.debug(" in class"),"!"===g&&r===n+1&&(g="^"),h+=g;continue}p.debug("call clearStateChar %j",f),c(),f=g,d.noext&&c();continue;case"(":if(l){h+="(";continue}if(!f){h+="\\(";continue}e=f,k.push({type:e,start:r-1,reStart:h.length}),h+="!"===f?"(?:(?!":"(?:",this.debug("plType %j %j",f,h),f=!1;continue;case")":if(l||!k.length){h+="\\)";continue}switch(c(),i=!0,h+=")",e=k.pop().type){case"!":h+="[^/]*?)";break;case"?":case"+":case"*":h+=e;case"@":}continue;case"|":if(l||!k.length||j){h+="\\|",j=!1;continue}c(),h+="|";continue;case"[":if(c(),l){h+="\\"+g;continue}l=!0,n=r,m=h.length,h+=g;continue;case"]":if(r===n+1||!l){h+="\\"+g,j=!1;continue}i=!0,l=!1,h+=g;continue;default:c(),j?j=!1:!A[g]||"^"===g&&l||(h+="\\"),h+=g}if(l){var t=a.substr(n+1),v=this.parse(t,C);h=h.substr(0,m)+"\\["+v[0],i=i||v[1]}for(var y;y=k.pop();){var z=h.slice(y.reStart+3);z=z.replace(/((?:\\{2})*)(\\?)\|/g,function(a,b,c){return c||(c="\\"),b+b+c+"|"}),this.debug("tail=%j\n %s",z,z);var B="*"===y.type?x:"?"===y.type?w:"\\"+y.type;i=!0,h=h.slice(0,y.reStart)+B+"\\("+z}c(),j&&(h+="\\\\");var D=!1;switch(h.charAt(0)){case".":case"[":case"(":D=!0}if(""!==h&&i&&(h="(?=.)"+h),D&&(h=o+h),b===C)return[h,i];if(!i)return q(a);var E=d.nocase?"i":"",F=new RegExp("^"+h+"$",E);return F._glob=a,F._src=h,F}function o(){if(this.regexp||this.regexp===!1)return this.regexp;var a=this.set;if(!a.length)return this.regexp=!1;var b=this.options,c=b.noglobstar?x:b.dot?y:z,d=b.nocase?"i":"",e=a.map(function(a){return a.map(function(a){return a===u?c:"string"==typeof a?r(a):a._src}).join("\\/")}).join("|");e="^(?:"+e+")$",this.negate&&(e="^(?!"+e+").*$");try{return this.regexp=new RegExp(e,d)}catch(f){return this.regexp=!1}}function p(a,b){if(this.debug("match",a,this.pattern),this.comment)return!1;if(this.empty)return""===a;if("/"===a&&b)return!0;var c=this.options;"win32"===d&&(a=a.split("\\").join("/")),a=a.split(B),this.debug(this.pattern,"split",a);var e=this.set;this.debug(this.pattern,"set",e);for(var f,g=a.length-1;g>=0&&!(f=a[g]);g--);for(var g=0,h=e.length;h>g;g++){var i=e[g],j=a;c.matchBase&&1===i.length&&(j=[f]);var k=this.matchOne(j,i,b);if(k)return c.flipNegate?!0:!this.negate}return c.flipNegate?!1:this.negate}function q(a){return a.replace(/\\(.)/g,"$1")}function r(a){return a.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}c?c.exports=h:b.minimatch=h,a||(a=function(a){switch(a){case"sigmund":return function(a){return JSON.stringify(a)};case"path":return{basename:function(a){a=a.split(/[\/\\]/);var b=a.pop();return b||(b=a.pop()),b}};case"lru-cache":return function(){var a={},b=0;this.set=function(c,d){b++,b>=100&&(a={}),a[c]=d},this.get=function(b){return a[b]}}}}),h.Minimatch=i;var s=a("lru-cache"),t=h.cache=new s({max:100}),u=h.GLOBSTAR=i.GLOBSTAR={},v=a("sigmund"),w=(a("path"),"[^/]"),x=w+"*?",y="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",z="(?:(?!(?:\\/|^)\\.).)*?",A=e("().*{}+?[]^$\\!"),B=/\/+/;h.filter=f,h.defaults=function(a){if(!a||!Object.keys(a).length)return h;var b=h,c=function(c,d,e){return b.minimatch(c,d,g(a,e))};return c.Minimatch=function(c,d){return new b.Minimatch(c,g(a,d))},c},i.defaults=function(a){return a&&Object.keys(a).length?h.defaults(a).Minimatch:i},i.prototype.debug=function(){},i.prototype.make=j,i.prototype.parseNegate=k,h.braceExpand=function(a,b){return new i(a,b).braceExpand()},i.prototype.braceExpand=m,i.prototype.parse=n;var C={};h.makeRe=function(a,b){return new i(a,b||{}).makeRe()},i.prototype.makeRe=o,h.match=function(a,b,c){c=c||{};var d=new i(b,c);return a=a.filter(function(a){return d.match(a)}),d.options.nonull&&!a.length&&a.push(b),a},i.prototype.match=p,i.prototype.matchOne=function(a,b,c){var d=this.options;this.debug("matchOne",{"this":this,file:a,pattern:b}),this.debug("matchOne",a.length,b.length);for(var e=0,f=0,g=a.length,h=b.length;g>e&&h>f;e++,f++){this.debug("matchOne loop");var i=b[f],j=a[e];if(this.debug(b,i,j),i===!1)return!1;if(i===u){this.debug("GLOBSTAR",[b,i,j]);var k=e,l=f+1;if(l===h){for(this.debug("** at the end");g>e;e++)if("."===a[e]||".."===a[e]||!d.dot&&"."===a[e].charAt(0))return!1;return!0}a:for(;g>k;){var m=a[k];if(this.debug("\nglobstar while",a,k,b,l,m),this.matchOne(a.slice(k),b.slice(l),c))return this.debug("globstar found match!",k,g,m),!0;if("."===m||".."===m||!d.dot&&"."===m.charAt(0)){this.debug("dot detected!",a,k,b,l);break a}this.debug("globstar swallow a segment, and continue"),k++}return c&&(this.debug("\n>>> no match, partial?",a,k,b,l),k===g)?!0:!1}var n;if("string"==typeof i?(n=d.nocase?j.toLowerCase()===i.toLowerCase():j===i,this.debug("string match",i,j,n)):(n=j.match(i),this.debug("pattern match",i,j,n)),!n)return!1}if(e===g&&f===h)return!0;if(e===g)return c;if(f===h){var o=e===g-1&&""===a[e];return o}throw new Error("wtf?")}}("function"==typeof a?a:null,this,"object"==typeof b?b:null,"object"==typeof process?process.platform:"win32")},{"lru-cache":12,path:10,sigmund:13}],12:[function(a,b,c){!function(){function a(a,b){return Object.prototype.hasOwnProperty.call(a,b)}function c(){return 1}function d(a){return this instanceof d?("number"==typeof a&&(a={max:a}),a||(a={}),this._max=a.max,(!this._max||"number"!=typeof this._max||this._max<=0)&&(this._max=1/0),this._lengthCalculator=a.length||c,"function"!=typeof this._lengthCalculator&&(this._lengthCalculator=c),this._allowStale=a.stale||!1,this._maxAge=a.maxAge||null,this._dispose=a.dispose,void this.reset()):new d(a)}function e(a,b,c){var d=a._cache[b];return d&&(f(a,d)?(j(a,d),a._allowStale||(d=void 0)):c&&g(a,d),d&&(d=d.value)),d}function f(a,b){if(!b||!b.maxAge&&!a._maxAge)return!1;var c=!1,d=Date.now()-b.now;return c=b.maxAge?d>b.maxAge:a._maxAge&&d>a._maxAge}function g(a,b){i(a,b),b.lu=a._mru++,a._lruList[b.lu]=b}function h(a){for(;a._lrua._max;)j(a,a._lruList[a._lru])}function i(a,b){for(delete a._lruList[b.lu];a._lru=a)&&(a=1/0),this._max=a,this._length>this._max&&h(this)},get:function(){return this._max},enumerable:!0}),Object.defineProperty(d.prototype,"lengthCalculator",{set:function(a){if("function"!=typeof a){this._lengthCalculator=c,this._length=this._itemCount;for(var b in this._cache)this._cache[b].length=1}else{this._lengthCalculator=a,this._length=0;for(var b in this._cache)this._cache[b].length=this._lengthCalculator(this._cache[b].value),this._length+=this._cache[b].length}this._length>this._max&&h(this)},get:function(){return this._lengthCalculator},enumerable:!0}),Object.defineProperty(d.prototype,"length",{get:function(){return this._length},enumerable:!0}),Object.defineProperty(d.prototype,"itemCount",{get:function(){return this._itemCount},enumerable:!0}),d.prototype.forEach=function(a,b){b=b||this;for(var c=0,d=this._itemCount,e=this._mru-1;e>=0&&d>c;e--)if(this._lruList[e]){c++;var g=this._lruList[e];f(this,g)&&(j(this,g),this._allowStale||(g=void 0)),g&&a.call(b,g.value,g.key,this)}},d.prototype.keys=function(){for(var a=new Array(this._itemCount),b=0,c=this._mru-1;c>=0&&b=0&&bthis._max?(this._dispose&&this._dispose(b,c),!1):(this._length+=g.length,this._lruList[g.lu]=this._cache[b]=g,this._itemCount++,this._length>this._max&&h(this),!0)},d.prototype.has=function(b){if(!a(this._cache,b))return!1;var c=this._cache[b];return f(this,c)?!1:!0},d.prototype.get=function(a){return e(this,a,!0)},d.prototype.peek=function(a){return e(this,a,!1)},d.prototype.pop=function(){var a=this._lruList[this._lru];return j(this,a),a||null},d.prototype.del=function(a){j(this,this._cache[a])}}()},{}],13:[function(a,b,c){function d(a,b){function c(a,g){return g>b||"function"==typeof a||"undefined"==typeof a?void 0:"object"!=typeof a||!a||a instanceof f?void(e+=a):void(-1===d.indexOf(a)&&g!==b&&(d.push(a),e+="{",Object.keys(a).forEach(function(b,d,f){if("_"!==b.charAt(0)){var h=typeof a[b];"function"!==h&&"undefined"!==h&&(e+=b,c(a[b],g+1))}})))}b=b||10;var d=[],e="",f=RegExp;return c(a,0),e}b.exports=d},{}],14:[function(a,b,c){(function(a){function c(b,c,d){return b instanceof ArrayBuffer&&(b=new Uint8Array(b)),new a(b,c,d)}c.prototype=Object.create(a.prototype),c.prototype.constructor=c,Object.keys(a).forEach(function(b){a.hasOwnProperty(b)&&(c[b]=a[b])}),b.exports=c}).call(this,a("buffer").Buffer)},{buffer:6}],15:[function(a,b,c){var d="READ",e="WRITE",f="CREATE",g="EXCLUSIVE",h="TRUNCATE",i="APPEND",j="CREATE",k="REPLACE";b.exports={FILE_SYSTEM_NAME:"local",FILE_STORE_NAME:"files",IDB_RO:"readonly",IDB_RW:"readwrite",WSQL_VERSION:"1",WSQL_SIZE:5242880,WSQL_DESC:"FileSystem Storage",MODE_FILE:"FILE",MODE_DIRECTORY:"DIRECTORY",MODE_SYMBOLIC_LINK:"SYMLINK",MODE_META:"META",SYMLOOP_MAX:10,BINARY_MIME_TYPE:"application/octet-stream",JSON_MIME_TYPE:"application/json",ROOT_DIRECTORY_NAME:"/",FS_FORMAT:"FORMAT",FS_NOCTIME:"NOCTIME",FS_NOMTIME:"NOMTIME",FS_NODUPEIDCHECK:"FS_NODUPEIDCHECK",O_READ:d,O_WRITE:e,O_CREATE:f,O_EXCLUSIVE:g,O_TRUNCATE:h,O_APPEND:i,O_FLAGS:{r:[d],"r+":[d,e],w:[e,f,h],"w+":[e,d,f,h],wx:[e,f,g,h],"wx+":[e,d,f,g,h],a:[e,f,i],"a+":[e,d,f,i],ax:[e,f,g,i],"ax+":[e,d,f,g,i]},XATTR_CREATE:j,XATTR_REPLACE:k,FS_READY:"READY",FS_PENDING:"PENDING",FS_ERROR:"ERROR",SUPER_NODE_ID:"00000000-0000-0000-0000-000000000000",STDIN:0,STDOUT:1,STDERR:2,FIRST_DESCRIPTOR:3,ENVIRONMENT:{TMP:"/tmp",PATH:""}}},{}],16:[function(a,b,c){var d=a("./constants.js").MODE_FILE;b.exports=function(a,b){this.id=a,this.type=b||d}},{"./constants.js":15}],17:[function(a,b,c){(function(a){function c(a){return a.toString("utf8")}function d(b){return new a(b,"utf8")}b.exports={encode:d,decode:c}}).call(this,a("buffer").Buffer)},{buffer:6}],18:[function(a,b,c){var d={};["9:EBADF:bad file descriptor","10:EBUSY:resource busy or locked","18:EINVAL:invalid argument","27:ENOTDIR:not a directory","28:EISDIR:illegal operation on a directory","34:ENOENT:no such file or directory","47:EEXIST:file already exists","50:EPERM:operation not permitted","51:ELOOP:too many symbolic links encountered","53:ENOTEMPTY:directory not empty","55:EIO:i/o error","1000:ENOTMOUNTED:not mounted","1001:EFILESYSTEMERROR:missing super node, use 'FORMAT' flag to format filesystem.","1002:ENOATTR:attribute does not exist"].forEach(function(a){function b(a,b){Error.call(this),this.name=e,this.code=e,this.errno=c,this.message=a||f,b&&(this.path=b),this.stack=new Error(this.message).stack}a=a.split(":");var c=+a[0],e=a[1],f=a[2];b.prototype=Object.create(Error.prototype),b.prototype.constructor=b,b.prototype.toString=function(){var a=this.path?", '"+this.path+"'":"";return this.name+": "+this.message+a},d[e]=d[c]=b}),b.exports=d},{}],19:[function(a,b,c){function d(a,b,c,d,e){function f(c){a.changes.push({event:"change",path:b}),e(c)}var g=a.flags;ma(g).contains(Ka)&&delete d.ctime,ma(g).contains(Ja)&&delete d.mtime;var h=!1;d.ctime&&(c.ctime=d.ctime,c.atime=d.ctime,h=!0),d.atime&&(c.atime=d.atime,h=!0),d.mtime&&(c.mtime=d.mtime,h=!0),h?a.putObject(c.id,c,f):f()}function e(a,b,c,e){function g(c,d){c?e(c):d.mode!==va?e(new Ma.ENOTDIR("a component of the path prefix is not a directory",b)):(l=d,f(a,b,h))}function h(c,d){!c&&d?e(new Ma.EEXIST("path name already exists",b)):!c||c instanceof Ma.ENOENT?a.getObject(l.data,i):e(c)}function i(b,d){b?e(b):(m=d,Qa.create({guid:a.guid,mode:c},function(b,c){return b?void e(b):(n=c,n.nlinks+=1,void a.putObject(n.id,n,k))}))}function j(b){if(b)e(b);else{var c=Date.now();d(a,p,n,{mtime:c,ctime:c},e)}}function k(b){b?e(b):(m[o]=new Na(n.id,c),a.putObject(l.data,m,j))}if(c!==va&&c!==ua)return e(new Ma.EINVAL("mode must be a directory or file",b));b=oa(b);var l,m,n,o=qa(b),p=pa(b);f(a,p,g)}function f(a,b,c){function d(b,d){b?c(b):d&&d.mode===xa&&d.rnode?a.getObject(d.rnode,e):c(new Ma.EFILESYSTEMERROR)}function e(a,b){a?c(a):b?c(null,b):c(new Ma.ENOENT)}function g(d,e){d?c(d):e.mode===va&&e.data?a.getObject(e.data,h):c(new Ma.ENOTDIR("a component of the path prefix is not a directory",b))}function h(d,e){if(d)c(d);else if(ma(e).has(k)){var f=e[k].id;a.getObject(f,i)}else c(new Ma.ENOENT(null,b))}function i(a,d){a?c(a):d.mode==wa?(m++,m>Aa?c(new Ma.ELOOP(null,b)):j(d.data)):c(null,d)}function j(b){b=oa(b),l=pa(b),k=qa(b),ya==k?a.getObject(za,d):f(a,l,g)}if(b=oa(b),!b)return c(new Ma.ENOENT("path is an empty string"));var k=qa(b),l=pa(b),m=0;ya==k?a.getObject(za,d):f(a,l,g)}function g(a,b,c,e,f,g,h){function i(e){e?h(e):d(a,b,c,{ctime:Date.now()},h)}var j=c.xattrs;g===Ha&&j.hasOwnProperty(e)?h(new Ma.EEXIST("attribute already exists",b)):g!==Ia||j.hasOwnProperty(e)?(j[e]=f,a.putObject(c.id,c,i)):h(new Ma.ENOATTR(null,b))}function h(a,b){function c(c,e){!c&&e?b():!c||c instanceof Ma.ENOENT?Pa.create({guid:a.guid},function(c,e){return c?void b(c):(f=e,void a.putObject(f.id,f,d))}):b(c)}function d(c){c?b(c):Qa.create({guid:a.guid,id:f.rnode,mode:va},function(c,d){return c?void b(c):(g=d,g.nlinks+=1,void a.putObject(g.id,g,e))})}function e(c){c?b(c):(h={},a.putObject(g.data,h,b))}var f,g,h;a.getObject(za,c)}function i(a,b,c){function e(d,e){!d&&e?c(new Ma.EEXIST(null,b)):!d||d instanceof Ma.ENOENT?f(a,q,g):c(d)}function g(b,d){b?c(b):(n=d,a.getObject(n.data,h))}function h(b,d){b?c(b):(o=d,Qa.create({guid:a.guid,mode:va},function(b,d){return b?void c(b):(l=d,l.nlinks+=1,void a.putObject(l.id,l,i))}))}function i(b){b?c(b):(m={},a.putObject(l.data,m,k))}function j(b){if(b)c(b);else{var e=Date.now();d(a,q,n,{mtime:e,ctime:e},c)}}function k(b){b?c(b):(o[p]=new Na(l.id,va),a.putObject(n.data,o,j))}b=oa(b);var l,m,n,o,p=qa(b),q=pa(b);f(a,b,e)}function j(a,b,c){function e(b,d){b?c(b):(p=d,a.getObject(p.data,g))}function g(d,e){d?c(d):ya==r?c(new Ma.EBUSY(null,b)):ma(e).has(r)?(q=e,n=q[r].id,a.getObject(n,h)):c(new Ma.ENOENT(null,b))}function h(d,e){d?c(d):e.mode!=va?c(new Ma.ENOTDIR(null,b)):(n=e,a.getObject(n.data,i))}function i(a,d){a?c(a):(o=d,ma(o).size()>0?c(new Ma.ENOTEMPTY(null,b)):k())}function j(b){if(b)c(b);else{var e=Date.now();d(a,s,p,{mtime:e,ctime:e},l)}}function k(){delete q[r],a.putObject(p.data,q,j)}function l(b){b?c(b):a["delete"](n.id,m)}function m(b){b?c(b):a["delete"](n.data,c)}b=oa(b);var n,o,p,q,r=qa(b),s=pa(b);f(a,s,e)}function k(a,b,c,e){function g(c,d){c?e(c):d.mode!==va?e(new Ma.ENOENT(null,b)):(q=d,a.getObject(q.data,h))}function h(d,f){d?e(d):(r=f,ma(r).has(v)?ma(c).contains(Ea)?e(new Ma.ENOENT("O_CREATE and O_EXCLUSIVE are set, and the named file exists",b)):(s=r[v],s.type==va&&ma(c).contains(Ca)?e(new Ma.EISDIR("the named file is a directory and O_WRITE is set",b)):a.getObject(s.id,i)):ma(c).contains(Da)?l():e(new Ma.ENOENT("O_CREATE is not set and the named file does not exist",b)))}function i(a,c){if(a)e(a);else{var d=c;d.mode==wa?(x++,x>Aa?e(new Ma.ELOOP(null,b)):j(d.data)):k(void 0,d)}}function j(d){d=oa(d),w=pa(d),v=qa(d),ya==v&&(ma(c).contains(Ca)?e(new Ma.EISDIR("the named file is a directory and O_WRITE is set",b)):f(a,b,k)),f(a,w,g)}function k(a,b){a?e(a):(t=b,e(null,t))}function l(){Qa.create({guid:a.guid,mode:ua},function(b,c){return b?void e(b):(t=c,t.nlinks+=1,void a.putObject(t.id,t,m))})}function m(b){b?e(b):(u=new Sa(0),u.fill(0),a.putBuffer(t.data,u,o))}function n(b){if(b)e(b);else{var c=Date.now();d(a,w,q,{mtime:c,ctime:c},p)}}function o(b){b?e(b):(r[v]=new Na(t.id,ua),a.putObject(q.data,r,n))}function p(a){a?e(a):e(null,t)}b=oa(b);var q,r,s,t,u,v=qa(b),w=pa(b),x=0;ya==v?ma(c).contains(Ca)?e(new Ma.EISDIR("the named file is a directory and O_WRITE is set",b)):f(a,b,k):f(a,w,g)}function l(a,b,c,e,f,g){function h(a){a?g(a):g(null,f)}function i(c){if(c)g(c);else{var e=Date.now();d(a,b.path,l,{mtime:e,ctime:e},h)}}function j(b){b?g(b):a.putObject(l.id,l,i)}function k(d,h){if(d)g(d);else{l=h;var i=new Sa(f);i.fill(0),c.copy(i,0,e,e+f),b.position=f,l.size=f,l.version+=1,a.putBuffer(l.data,i,j)}}var l;a.getObject(b.id,k)}function m(a,b,c,e,f,g,h){function i(a){a?h(a):h(null,f)}function j(c){if(c)h(c);else{var e=Date.now();d(a,b.path,n,{mtime:e,ctime:e},i)}}function k(b){b?h(b):a.putObject(n.id,n,j)}function l(d,i){if(d)h(d);else{if(o=i,!o)return h(new Ma.EIO("Expected Buffer"));var j=void 0!==g&&null!==g?g:b.position,l=Math.max(o.length,j+f),m=new Sa(l);m.fill(0),o&&o.copy(m),c.copy(m,j,e,e+f),void 0===g&&(b.position+=f),n.size=l,n.version+=1,a.putBuffer(n.data,m,k)}}function m(b,c){b?h(b):(n=c,a.getBuffer(n.data,l))}var n,o;a.getObject(b.id,m)}function n(a,b,c,d,e,f,g){function h(a,h){if(a)g(a);else{if(k=h,!k)return g(new Ma.EIO("Expected Buffer"));var i=void 0!==f&&null!==f?f:b.position;e=i+e>c.length?e-i:e,k.copy(c,d,i,i+e),void 0===f&&(b.position+=e),g(null,e)}}function i(c,d){c?g(c):"DIRECTORY"===d.mode?g(new Ma.EISDIR("the named file is a directory",b.path)):(j=d,a.getBuffer(j.data,h))}var j,k;a.getObject(b.id,i)}function o(a,b,c){b=oa(b);qa(b);f(a,b,c)}function p(a,b,c){b.getNode(a,c)}function q(a,b,c){function d(b,d){b?c(b):(g=d,a.getObject(g.data,e))}function e(d,e){d?c(d):(h=e,ma(h).has(i)?a.getObject(h[i].id,c):c(new Ma.ENOENT("a component of the path does not name an existing file",b)))}b=oa(b);var g,h,i=qa(b),j=pa(b);ya==i?f(a,b,c):f(a,j,d)}function r(a,b,c,e){function g(b){b?e(b):d(a,c,t,{ctime:Date.now()},e)}function h(b,c){b?e(b):(t=c,t.nlinks+=1,a.putObject(t.id,t,g))}function i(b,c){b?e(b):a.getObject(s[u].id,h)}function j(b,c){b?e(b):(s=c,ma(s).has(u)?e(new Ma.EEXIST("newpath resolves to an existing file",u)):(s[u]=q[n],a.putObject(r.data,s,i)))}function k(b,c){b?e(b):(r=c,a.getObject(r.data,j))}function l(b,c){b?e(b):(q=c,ma(q).has(n)?"DIRECTORY"===q[n].type?e(new Ma.EPERM("oldpath refers to a directory")):f(a,v,k):e(new Ma.ENOENT("a component of either path prefix does not exist",n)))}function m(b,c){b?e(b):(p=c,a.getObject(p.data,l))}b=oa(b);var n=qa(b),o=pa(b);c=oa(c);var p,q,r,s,t,u=qa(c),v=pa(c);f(a,o,m)}function s(a,b,c){function e(b){b?c(b):(delete m[o],a.putObject(l.data,m,function(b){var e=Date.now();d(a,p,l,{mtime:e,ctime:e},c)}))}function g(b){b?c(b):a["delete"](n.data,e)}function h(f,h){f?c(f):(n=h,n.nlinks-=1,n.nlinks<1?a["delete"](n.id,g):a.putObject(n.id,n,function(c){d(a,b,n,{ctime:Date.now()},e)}))}function i(a,b){a?c(a):"DIRECTORY"===b.mode?c(new Ma.EPERM("unlink not permitted on directories",o)):h(null,b)}function j(b,d){b?c(b):(m=d,ma(m).has(o)?a.getObject(m[o].id,i):c(new Ma.ENOENT("a component of the path does not name an existing file",o)))}function k(b,d){b?c(b):(l=d,a.getObject(l.data,j))}b=oa(b);var l,m,n,o=qa(b),p=pa(b);f(a,p,k)}function t(a,b,c){function d(a,b){if(a)c(a);else{h=b;var d=Object.keys(h);c(null,d)}}function e(e,f){e?c(e):f.mode!==va?c(new Ma.ENOTDIR(null,b)):(g=f,a.getObject(g.data,d))}b=oa(b);var g,h;qa(b);f(a,b,e)}function u(a,b,c,e){function g(b,c){b?e(b):(l=c,a.getObject(l.data,h))}function h(a,b){a?e(a):(m=b,ma(m).has(o)?e(new Ma.EEXIST(null,o)):i())}function i(){Qa.create({guid:a.guid,mode:wa},function(c,d){return c?void e(c):(n=d,n.nlinks+=1,n.size=b.length,n.data=b,void a.putObject(n.id,n,k))})}function j(b){if(b)e(b);else{var c=Date.now();d(a,p,l,{mtime:c,ctime:c},e)}}function k(b){b?e(b):(m[o]=new Na(n.id,wa),a.putObject(l.data,m,j))}c=oa(c);var l,m,n,o=qa(c),p=pa(c);ya==o?e(new Ma.EEXIST(null,o)):f(a,p,g)}function v(a,b,c){function d(b,d){b?c(b):(h=d,a.getObject(h.data,e))}function e(b,d){b?c(b):(i=d,ma(i).has(j)?a.getObject(i[j].id,g):c(new Ma.ENOENT("a component of the path does not name an existing file",j)))}function g(a,d){a?c(a):d.mode!=wa?c(new Ma.EINVAL("path not a symbolic link",b)):c(null,d.data)}b=oa(b);var h,i,j=qa(b),k=pa(b);f(a,k,d)}function w(a,b,c,e){function g(c,d){c?e(c):d.mode==va?e(new Ma.EISDIR(null,b)):(k=d,a.getBuffer(k.data,h))}function h(b,d){if(b)e(b);else{if(!d)return e(new Ma.EIO("Expected Buffer"));var f=new Sa(c);f.fill(0),d&&d.copy(f),a.putBuffer(k.data,f,j)}}function i(c){if(c)e(c);else{var f=Date.now();d(a,b,k,{mtime:f,ctime:f},e)}}function j(b){b?e(b):(k.size=c,k.version+=1,a.putObject(k.id,k,i))}b=oa(b);var k;0>c?e(new Ma.EINVAL("length cannot be negative")):f(a,b,g)}function x(a,b,c,e){function f(b,c){b?e(b):c.mode==va?e(new Ma.EISDIR):(j=c,a.getBuffer(j.data,g))}function g(b,d){if(b)e(b);else{var f;if(!d)return e(new Ma.EIO("Expected Buffer"));d?f=d.slice(0,c):(f=new Sa(c),f.fill(0)),a.putBuffer(j.data,f,i)}}function h(c){if(c)e(c);else{var f=Date.now();d(a,b.path,j,{mtime:f,ctime:f},e)}}function i(b){b?e(b):(j.size=c,j.version+=1,a.putObject(j.id,j,h))}var j;0>c?e(new Ma.EINVAL("length cannot be negative")):b.getNode(a,f)}function y(a,b,c,e,g){function h(f,h){f?g(f):d(a,b,h,{atime:c,ctime:e,mtime:e},g)}b=oa(b),"number"!=typeof c||"number"!=typeof e?g(new Ma.EINVAL("atime and mtime must be number",b)):0>c||0>e?g(new Ma.EINVAL("atime and mtime must be positive integers",b)):f(a,b,h)}function z(a,b,c,e,f){function g(g,h){g?f(g):d(a,b.path,h,{atime:c,ctime:e,mtime:e},f)}"number"!=typeof c||"number"!=typeof e?f(new Ma.EINVAL("atime and mtime must be a number")):0>c||0>e?f(new Ma.EINVAL("atime and mtime must be positive integers")):b.getNode(a,g)}function A(a,b,c,d,e,h){function i(f,i){return f?h(f):void g(a,b,i,c,d,e,h)}b=oa(b),"string"!=typeof c?h(new Ma.EINVAL("attribute name must be a string",b)):c?null!==e&&e!==Ha&&e!==Ia?h(new Ma.EINVAL("invalid flag, must be null, XATTR_CREATE or XATTR_REPLACE",b)):f(a,b,i):h(new Ma.EINVAL("attribute name cannot be an empty string",b))}function B(a,b,c,d,e,f){function h(h,i){return h?f(h):void g(a,b.path,i,c,d,e,f)}"string"!=typeof c?f(new Ma.EINVAL("attribute name must be a string")):c?null!==e&&e!==Ha&&e!==Ia?f(new Ma.EINVAL("invalid flag, must be null, XATTR_CREATE or XATTR_REPLACE")):b.getNode(a,h):f(new Ma.EINVAL("attribute name cannot be an empty string"))}function C(a,b,c,d){function e(a,e){if(a)return d(a);var f=e.xattrs;f.hasOwnProperty(c)?d(null,f[c]):d(new Ma.ENOATTR(null,b))}b=oa(b),"string"!=typeof c?d(new Ma.EINVAL("attribute name must be a string",b)):c?f(a,b,e):d(new Ma.EINVAL("attribute name cannot be an empty string",b))}function D(a,b,c,d){function e(a,b){if(a)return d(a);var e=b.xattrs;e.hasOwnProperty(c)?d(null,e[c]):d(new Ma.ENOATTR)}"string"!=typeof c?d(new Ma.EINVAL):c?b.getNode(a,e):d(new Ma.EINVAL("attribute name cannot be an empty string"))}function E(a,b,c,e){function g(f,g){function h(c){c?e(c):d(a,b,g,{ctime:Date.now()},e)}if(f)return e(f);var i=g.xattrs;i.hasOwnProperty(c)?(delete i[c],a.putObject(g.id,g,h)):e(new Ma.ENOATTR(null,b))}b=oa(b),"string"!=typeof c?e(new Ma.EINVAL("attribute name must be a string",b)):c?f(a,b,g):e(new Ma.EINVAL("attribute name cannot be an empty string",b))}function F(a,b,c,e){function f(f,g){function h(c){c?e(c):d(a,b.path,g,{ctime:Date.now()},e)}if(f)return e(f);var i=g.xattrs;i.hasOwnProperty(c)?(delete i[c],a.putObject(g.id,g,h)):e(new Ma.ENOATTR)}"string"!=typeof c?e(new Ma.EINVAL("attribute name must be a string")):c?b.getNode(a,f):e(new Ma.EINVAL("attribute name cannot be an empty string"))}function G(a){return ma(Ga).has(a)?Ga[a]:null}function H(a,b,c){return a?"function"==typeof a?a={encoding:b,flag:c}:"string"==typeof a&&(a={encoding:a,flag:c}):a={encoding:b,flag:c},a}function I(a,b){var c;return a?sa(a)?c=new Ma.EINVAL("Path must be a string without null bytes.",a):ra(a)||(c=new Ma.EINVAL("Path must be absolute.",a)):c=new Ma.EINVAL("Path must be a string",a),c?(b(c),!1):!0}function J(a,b,c,d,e,f){function g(b,e){if(b)f(b);else{var g;g=ma(d).contains(Fa)?e.size:0;var h=new Oa(c,e.id,d,g),i=a.allocDescriptor(h);f(null,i)}}f=arguments[arguments.length-1],I(c,f)&&(d=G(d),d||f(new Ma.EINVAL("flags is not valid"),c),k(b,c,d,g))}function K(a,b,c,d){ma(a.openFiles).has(c)?(a.releaseDescriptor(c),d(null)):d(new Ma.EBADF)}function L(a,b,c,d,f){I(c,f)&&e(b,c,d,f)}function M(a,b,c,d,e){e=arguments[arguments.length-1],I(c,e)&&i(b,c,e)}function N(a,b,c,d){I(c,d)&&j(b,c,d)}function O(a,b,c,d){function e(b,c){if(b)d(b);else{var e=new Ra(c,a.name);d(null,e)}}I(c,d)&&o(b,c,e)}function P(a,b,c,d){function e(b,c){if(b)d(b);else{var e=new Ra(c,a.name);d(null,e)}}var f=a.openFiles[c];f?p(b,f,e):d(new Ma.EBADF)}function Q(a,b,c,d,e){I(c,e)&&I(d,e)&&r(b,c,d,e)}function R(a,b,c,d){I(c,d)&&s(b,c,d)}function S(a,b,c,d,e,f,g,h){function i(a,b){h(a,b||0,d)}e=void 0===e?0:e,f=void 0===f?d.length-e:f,h=arguments[arguments.length-1];var j=a.openFiles[c];j?ma(j.flags).contains(Ba)?n(b,j,d,e,f,g,i):h(new Ma.EBADF("descriptor does not permit reading")):h(new Ma.EBADF)}function T(a,b,c,d,e){if(e=arguments[arguments.length-1],d=H(d,null,"r"),I(c,e)){var f=G(d.flag||"r");return f?void k(b,c,f,function(g,h){function i(){a.releaseDescriptor(k)}if(g)return e(g);var j=new Oa(c,h.id,f,0),k=a.allocDescriptor(j);p(b,j,function(f,g){if(f)return i(),e(f);var h=new Ra(g,a.name);if(h.isDirectory())return i(),e(new Ma.EISDIR("illegal operation on directory",c));var k=h.size,l=new Sa(k);l.fill(0),n(b,j,l,0,k,0,function(a,b){if(i(),a)return e(a);var c;c="utf8"===d.encoding?La.decode(l):l,e(null,c)})})}):e(new Ma.EINVAL("flags is not valid",c))}}function U(a,b,c,d,e,f,g,h){h=arguments[arguments.length-1],e=void 0===e?0:e,f=void 0===f?d.length-e:f;var i=a.openFiles[c];i?ma(i.flags).contains(Ca)?d.length-ed?f(new Ma.EINVAL("resulting file offset would be negative")):(h.position=d,f(null,h.position)):"CUR"===e?h.position+d<0?f(new Ma.EINVAL("resulting file offset would be negative")):(h.position+=d,f(null,h.position)):"END"===e?p(b,h,g):f(new Ma.EINVAL("whence argument is not a proper value"))}function da(a,b,c,d){I(c,d)&&t(b,c,d)}function ea(a,b,c,d,e,f){if(I(c,f)){var g=Date.now();d=d?d:g,e=e?e:g,y(b,c,d,e,f)}}function fa(a,b,c,d,e,f){var g=Date.now();d=d?d:g,e=e?e:g;var h=a.openFiles[c];h?ma(h.flags).contains(Ca)?z(b,h,d,e,f):f(new Ma.EBADF("descriptor does not permit writing")):f(new Ma.EBADF)}function ga(a,b,c,e,g){function h(a,c){a?g(a):d(b,e,c,{ctime:Date.now()},g)}function i(a){a?g(a):b.getObject(x[B].id,h)}function k(a){a?g(a):(u.id===w.id&&(v=x),delete v[A],b.putObject(u.data,v,i))}function l(a){a?g(a):(x[B]=v[A],b.putObject(w.data,x,k))}function m(a,c){a?g(a):(x=c,ma(x).has(B)?j(b,e,l):l())}function n(a,c){a?g(a):(w=c,b.getObject(w.data,m))}function o(a,c){a?g(a):(v=c,f(b,z,n))}function p(a,c){a?g(a):(u=c,b.getObject(c.data,o))}function q(a){a?g(a):s(b,c,g)}function t(a,d){a?g(a):"DIRECTORY"===d.mode?f(b,y,p):r(b,c,e,q)}if(I(c,g)&&I(e,g)){c=oa(c),e=oa(e);var u,v,w,x,y=na.dirname(c),z=na.dirname(c),A=na.basename(c),B=na.basename(e);f(b,c,t)}}function ha(a,b,c,d,e,f){f=arguments[arguments.length-1],I(c,f)&&I(d,f)&&u(b,c,d,f)}function ia(a,b,c,d){I(c,d)&&v(b,c,d)}function ja(a,b,c,d){function e(b,c){if(b)d(b);else{var e=new Ra(c,a.name);d(null,e)}}I(c,d)&&q(b,c,e)}function ka(a,b,c,d,e){e=arguments[arguments.length-1],d=d||0,I(c,e)&&w(b,c,d,e)}function la(a,b,c,d,e){e=arguments[arguments.length-1],d=d||0;var f=a.openFiles[c];f?ma(f.flags).contains(Ca)?x(b,f,d,e):e(new Ma.EBADF("descriptor does not permit writing")):e(new Ma.EBADF)}var ma=a("../../lib/nodash.js"),na=a("../path.js"),oa=na.normalize,pa=na.dirname,qa=na.basename,ra=na.isAbsolute,sa=na.isNull,ta=a("../constants.js"),ua=ta.MODE_FILE,va=ta.MODE_DIRECTORY,wa=ta.MODE_SYMBOLIC_LINK,xa=ta.MODE_META,ya=ta.ROOT_DIRECTORY_NAME,za=ta.SUPER_NODE_ID,Aa=ta.SYMLOOP_MAX,Ba=ta.O_READ,Ca=ta.O_WRITE,Da=ta.O_CREATE,Ea=ta.O_EXCLUSIVE,Fa=(ta.O_TRUNCATE, -ta.O_APPEND),Ga=ta.O_FLAGS,Ha=ta.XATTR_CREATE,Ia=ta.XATTR_REPLACE,Ja=ta.FS_NOMTIME,Ka=ta.FS_NOCTIME,La=a("../encoding.js"),Ma=a("../errors.js"),Na=a("../directory-entry.js"),Oa=a("../open-file-description.js"),Pa=a("../super-node.js"),Qa=a("../node.js"),Ra=a("../stats.js"),Sa=a("../buffer.js");b.exports={ensureRootDirectory:h,open:J,close:K,mknod:L,mkdir:M,rmdir:N,unlink:R,stat:O,fstat:P,link:Q,read:S,readFile:T,write:U,writeFile:V,appendFile:W,exists:X,getxattr:Y,fgetxattr:Z,setxattr:$,fsetxattr:_,removexattr:aa,fremovexattr:ba,lseek:ca,readdir:da,utimes:ea,futimes:fa,rename:ga,symlink:ha,readlink:ia,lstat:ja,truncate:ka,ftruncate:la}},{"../../lib/nodash.js":4,"../buffer.js":14,"../constants.js":15,"../directory-entry.js":16,"../encoding.js":17,"../errors.js":18,"../node.js":23,"../open-file-description.js":24,"../path.js":25,"../stats.js":33,"../super-node.js":34}],20:[function(a,b,c){function d(a){return"function"==typeof a?a:function(a){if(a)throw a}}function e(a){a&&console.error("Filer error: ",a)}function f(a,b){function c(){I.forEach(function(a){a.call(this)}.bind(F)),I=null}function d(a){return function(b){function c(b){var d=B();a.getObject(d,function(a,e){return a?void b(a):void(e?c(b):b(null,d))})}return g(j).contains(p)?void b(null,B()):void c(b)}}function f(a){if(a.length){var b=s.getInstance();a.forEach(function(a){b.emit(a.event,a.path)})}}a=a||{},b=b||e;var j=a.flags,B=a.guid?a.guid:v,C=a.provider||new q.Default(a.name||k),D=a.name||C.name,E=g(j).contains(l),F=this;F.readyState=n,F.name=D,F.error=null,F.stdin=w,F.stdout=x,F.stderr=y,this.Shell=r.bind(void 0,this);var G={},H=z;Object.defineProperty(this,"openFiles",{get:function(){return G}}),this.allocDescriptor=function(a){var b=H++;return G[b]=a,b},this.releaseDescriptor=function(a){delete G[a]};var I=[];this.queueOrRun=function(a){var b;return m==F.readyState?a.call(F):o==F.readyState?b=new u.EFILESYSTEMERROR("unknown error"):I.push(a),b},this.watch=function(a,b,c){if(h(a))throw new Error("Path must be a string without null bytes.");"function"==typeof b&&(c=b,b={}),b=b||{},c=c||i;var d=new t;return d.start(a,!1,b.recursive),d.on("change",c),d},C.open(function(a){function e(a){function e(a){var b=C[a]();return b.flags=j,b.changes=[],b.guid=d(b),b.close=function(){var a=b.changes;f(a),a.length=0},b}F.provider={openReadWriteContext:function(){return e("getReadWriteContext")},openReadOnlyContext:function(){return e("getReadOnlyContext")}},a?F.readyState=o:F.readyState=m,c(),b(a,F)}if(a)return e(a);var g=C.getReadWriteContext();g.guid=d(g),E?g.clear(function(a){return a?e(a):void A.ensureRootDirectory(g,e)}):A.ensureRootDirectory(g,e)})}var g=a("../../lib/nodash.js"),h=a("../path.js").isNull,i=a("../shared.js").nop,j=a("../constants.js"),k=j.FILE_SYSTEM_NAME,l=j.FS_FORMAT,m=j.FS_READY,n=j.FS_PENDING,o=j.FS_ERROR,p=j.FS_NODUPEIDCHECK,q=a("../providers/index.js"),r=a("../shell/shell.js"),s=a("../../lib/intercom.js"),t=a("../fs-watcher.js"),u=a("../errors.js"),v=a("../shared.js").guid,w=j.STDIN,x=j.STDOUT,y=j.STDERR,z=j.FIRST_DESCRIPTOR,A=a("./implementation.js");f.providers=q,["open","close","mknod","mkdir","rmdir","stat","fstat","link","unlink","read","readFile","write","writeFile","appendFile","exists","lseek","readdir","rename","readlink","symlink","lstat","truncate","ftruncate","utimes","futimes","setxattr","getxattr","fsetxattr","fgetxattr","removexattr","fremovexattr"].forEach(function(a){f.prototype[a]=function(){var b=this,c=Array.prototype.slice.call(arguments,0),e=c.length-1,f="function"!=typeof c[e],g=d(c[e]),h=b.queueOrRun(function(){function d(){h.close(),g.apply(b,arguments)}var h=b.provider.openReadWriteContext();if(o===b.readyState){var i=new u.EFILESYSTEMERROR("filesystem unavailable, operation canceled");return g.call(b,i)}f?c.push(d):c[e]=d;var j=[b,h].concat(c);A[a].apply(null,j)});h&&g(h)}}),b.exports=f},{"../../lib/intercom.js":3,"../../lib/nodash.js":4,"../constants.js":15,"../errors.js":18,"../fs-watcher.js":21,"../path.js":25,"../providers/index.js":26,"../shared.js":30,"../shell/shell.js":32,"./implementation.js":19}],21:[function(a,b,c){function d(){function a(a){(c===a||h&&0===a.indexOf(b))&&d.trigger("change","change",a)}e.call(this);var b,c,d=this,h=!1;d.start=function(d,e,i){if(!c){if(f.isNull(d))throw new Error("Path must be a string without null bytes.");c=f.normalize(d),h=i===!0,h&&(b="/"===c?"/":c+"/");var j=g.getInstance();j.on("change",a)}},d.close=function(){var b=g.getInstance();b.off("change",a),d.removeAllListeners("change")}}var e=a("../lib/eventemitter.js"),f=a("./path.js"),g=a("../lib/intercom.js");d.prototype=new e,d.prototype.constructor=d,b.exports=d},{"../lib/eventemitter.js":2,"../lib/intercom.js":3,"./path.js":25}],22:[function(a,b,c){b.exports={FileSystem:a("./filesystem/interface.js"),Buffer:a("./buffer.js"),Path:a("./path.js"),Errors:a("./errors.js"),Shell:a("./shell/shell.js")}},{"./buffer.js":14,"./errors.js":18,"./filesystem/interface.js":20,"./path.js":25,"./shell/shell.js":32}],23:[function(a,b,c){function d(a){var b=Date.now();this.id=a.id,this.mode=a.mode||f,this.size=a.size||0,this.atime=a.atime||b,this.ctime=a.ctime||b,this.mtime=a.mtime||b,this.flags=a.flags||[],this.xattrs=a.xattrs||{},this.nlinks=a.nlinks||0,this.version=a.version||0,this.blksize=void 0,this.nblocks=1,this.data=a.data}function e(a,b,c){a[b]?c(null):a.guid(function(d,e){a[b]=e,c(d)})}var f=a("./constants.js").MODE_FILE;d.create=function(a,b){e(a,"id",function(c){return c?void b(c):void e(a,"data",function(c){return c?void b(c):void b(null,new d(a))})})},b.exports=d},{"./constants.js":15}],24:[function(a,b,c){function d(a,b,c,d){this.path=a,this.id=b,this.flags=c,this.position=d}var e=a("./errors.js");d.prototype.getNode=function(a,b){function c(a,c){return a?b(a):c?void b(null,c):b(new e.EBADF("file descriptor refers to unknown node",f))}var d=this.id,f=this.path;a.getObject(d,c)},b.exports=d},{"./errors.js":18}],25:[function(a,b,c){function d(a,b){for(var c=0,d=a.length-1;d>=0;d--){var e=a[d];"."===e?a.splice(d,1):".."===e?(a.splice(d,1),c++):c&&(a.splice(d,1),c--)}if(b)for(;c--;c)a.unshift("..");return a}function e(){for(var a="",b=!1,c=arguments.length-1;c>=-1&&!b;c--){var e=c>=0?arguments[c]:"/";"string"==typeof e&&e&&(a=e+"/"+a,b="/"===e.charAt(0))}return a=d(a.split("/").filter(function(a){return!!a}),!b).join("/"),(b?"/":"")+a||"."}function f(a){var b="/"===a.charAt(0);"/"===a.substr(-1);return a=d(a.split("/").filter(function(a){return!!a}),!b).join("/"),a||b||(a="."),(b?"/":"")+a}function g(){var a=Array.prototype.slice.call(arguments,0);return f(a.filter(function(a,b){return a&&"string"==typeof a}).join("/"))}function h(a,b){function c(a){for(var b=0;b=0&&""===a[c];c--);return b>c?[]:a.slice(b,c-b+1)}a=e(a).substr(1),b=e(b).substr(1);for(var d=c(a.split("/")),f=c(b.split("/")),g=Math.min(d.length,f.length),h=g,i=0;g>i;i++)if(d[i]!==f[i]){h=i;break}for(var j=[],i=h;id;d++)b[d]=a[d];return b}b.exports={guid:d,u8toArray:f,nop:e}},{}],31:[function(a,b,c){var d=a("../constants.js").ENVIRONMENT;b.exports=function(a){a=a||{},a.TMP=a.TMP||d.TMP,a.PATH=a.PATH||d.PATH,this.get=function(b){return a[b]},this.set=function(b,c){a[b]=c}}},{"../constants.js":15}],32:[function(a,b,c){function d(a,b){b=b||{};var c=new g(b.env),d="/";Object.defineProperty(this,"fs",{get:function(){return a},enumerable:!0}),Object.defineProperty(this,"env",{get:function(){return c},enumerable:!0}),this.cd=function(b,c){b=e.resolve(d,b),a.stat(b,function(a,e){return a?void c(new f.ENOTDIR(null,b)):void("DIRECTORY"===e.type?(d=b,c()):c(new f.ENOTDIR(null,b)))})},this.pwd=function(){return d}}var e=a("../path.js"),f=a("../errors.js"),g=a("./environment.js"),h=a("../../lib/async.js"),i=(a("../encoding.js"),a("minimatch"));d.prototype.exec=function(a,b,c){var d=this,f=d.fs;"function"==typeof b&&(c=b,b=[]),b=b||[],c=c||function(){},a=e.resolve(d.pwd(),a),f.readFile(a,"utf8",function(a,d){if(a)return void c(a);try{var e=new Function("fs","args","callback",d);e(f,b,c)}catch(g){c(g)}})},d.prototype.touch=function(a,b,c){function d(a){h.writeFile(a,"",c)}function f(a){var d=Date.now(),e=b.date||d,f=b.date||d;h.utimes(a,e,f,c)}var g=this,h=g.fs;"function"==typeof b&&(c=b,b={}),b=b||{},c=c||function(){},a=e.resolve(g.pwd(),a),h.stat(a,function(e,g){e?b.updateOnly===!0?c():d(a):f(a)})},d.prototype.cat=function(a,b){function c(a,b){var c=e.resolve(d.pwd(),a);g.readFile(c,"utf8",function(a,c){return a?void b(a):(i+=c+"\n",void b())})}var d=this,g=d.fs,i="";return b=b||function(){},a?(a="string"==typeof a?[a]:a,void h.eachSeries(a,c,function(a){a?b(a):b(null,i.replace(/\n$/,""))})):void b(new f.EINVAL("Missing files argument"))},d.prototype.ls=function(a,b,c){function d(a,c){var f=e.resolve(g.pwd(),a),j=[];i.readdir(f,function(a,g){function k(a,c){a=e.join(f,a),i.stat(a,function(g,h){if(g)return void c(g);var i={path:e.basename(a),links:h.nlinks,size:h.size,modified:h.mtime,type:h.type};b.recursive&&"DIRECTORY"===h.type?d(e.join(f,i.path),function(a,b){return a?void c(a):(i.contents=b,j.push(i),void c())}):(j.push(i),c())})}return a?void c(a):void h.eachSeries(g,k,function(a){c(a,j)})})}var g=this,i=g.fs;return"function"==typeof b&&(c=b,b={}),b=b||{},c=c||function(){},a?void d(a,c):void c(new f.EINVAL("Missing dir argument"))},d.prototype.rm=function(a,b,c){function d(a,c){a=e.resolve(g.pwd(),a),i.stat(a,function(g,j){return g?void c(g):"FILE"===j.type?void i.unlink(a,c):void i.readdir(a,function(g,j){return g?void c(g):0===j.length?void i.rmdir(a,c):b.recursive?(j=j.map(function(b){return e.join(a,b)}),void h.eachSeries(j,d,function(b){return b?void c(b):void i.rmdir(a,c)})):void c(new f.ENOTEMPTY(null,a))})})}var g=this,i=g.fs;return"function"==typeof b&&(c=b,b={}),b=b||{},c=c||function(){},a?void d(a,c):void c(new f.EINVAL("Missing path argument"))},d.prototype.tempDir=function(a){var b=this,c=b.fs,d=b.env.get("TMP");a=a||function(){},c.mkdir(d,function(b){a(null,d)})},d.prototype.mkdirp=function(a,b){function c(a,b){g.stat(a,function(d,h){if(h){if(h.isDirectory())return void b();if(h.isFile())return void b(new f.ENOTDIR(null,a))}else{if(d&&"ENOENT"!==d.code)return void b(d);var i=e.dirname(a);"/"===i?g.mkdir(a,function(a){return a&&"EEXIST"!=a.code?void b(a):void b()}):c(i,function(c){return c?b(c):void g.mkdir(a,function(a){return a&&"EEXIST"!=a.code?void b(a):void b()})})}})}var d=this,g=d.fs;return b=b||function(){},a?"/"===a?void b():void c(a,b):void b(new f.EINVAL("Missing path argument"))},d.prototype.find=function(a,b,c){function d(a,b){m(a,function(c){return c?void b(c):(n.push(a),void b())})}function g(a,c){var f=e.removeTrailing(a);return b.regex&&!b.regex.test(f)?void c():b.name&&!i(e.basename(f),b.name)?void c():b.path&&!i(e.dirname(f),b.path)?void c():void d(a,c)}function j(a,b){a=e.resolve(k.pwd(),a),l.readdir(a,function(c,d){return c?void("ENOTDIR"===c.code?g(a,b):b(c)):void g(e.addTrailing(a),function(c){return c?void b(c):(d=d.map(function(b){return e.join(a,b)}),void h.eachSeries(d,j,function(a){b(a,n)}))})})}var k=this,l=k.fs;"function"==typeof b&&(c=b,b={}),b=b||{},c=c||function(){};var m=b.exec||function(a,b){b()},n=[];return a?void l.stat(a,function(b,d){return b?void c(b):d.isDirectory()?void j(a,c):void c(new f.ENOTDIR(null,a))}):void c(new f.EINVAL("Missing path argument"))},b.exports=d},{"../../lib/async.js":1,"../encoding.js":17,"../errors.js":18,"../path.js":25,"./environment.js":31,minimatch:11}],33:[function(a,b,c){function d(a,b){this.node=a.id,this.dev=b,this.size=a.size,this.nlinks=a.nlinks,this.atime=a.atime,this.mtime=a.mtime,this.ctime=a.ctime,this.type=a.mode}var e=a("./constants.js");d.prototype.isFile=function(){return this.type===e.MODE_FILE},d.prototype.isDirectory=function(){return this.type===e.MODE_DIRECTORY},d.prototype.isSymbolicLink=function(){return this.type===e.MODE_SYMBOLIC_LINK},d.prototype.isSocket=d.prototype.isFIFO=d.prototype.isCharacterDevice=d.prototype.isBlockDevice=function(){return!1},b.exports=d},{"./constants.js":15}],34:[function(a,b,c){function d(a){var b=Date.now();this.id=e.SUPER_NODE_ID,this.mode=e.MODE_META,this.atime=a.atime||b,this.ctime=a.ctime||b,this.mtime=a.mtime||b,this.rnode=a.rnode}var e=a("./constants.js");d.create=function(a,b){a.guid(function(c,e){return c?void b(c):(a.rnode=a.rnode||e,void b(null,new d(a)))})},b.exports=d},{"./constants.js":15}]},{},[22])(22)}); \ No newline at end of file +/*! filer 0.0.44 2018-05-29 */ +!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Filer=a()}}(function(){var a;return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c||a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g=a.length?c():e())})};e()},b.forEachSeries=b.eachSeries,void 0!==a&&a.amd?a([],function(){return b}):void 0!==c&&c.exports?c.exports=b:root.async=b}()},{}],2:[function(a,b,c){function d(a,b){for(var c=b.length-1;c>=0;c--)b[c]===a&&b.splice(c,1);return b}var e=function(){};e.createInterface=function(a){var b={};return b.on=function(b,c){void 0===this[a]&&(this[a]={}),this[a].hasOwnProperty(b)||(this[a][b]=[]),this[a][b].push(c)},b.off=function(b,c){void 0!==this[a]&&this[a].hasOwnProperty(b)&&d(c,this[a][b])},b.trigger=function(b){if(void 0!==this[a]&&this[a].hasOwnProperty(b))for(var c=Array.prototype.slice.call(arguments,1),d=0;da&&(c=d,b.apply(this,arguments))}}function e(a,b){if(void 0!==a&&a||(a={}),"object"==typeof b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}function f(){var a=this,b=Date.now();this.origin=h(),this.lastMessage=b,this.receivedIDs={},this.previousValues={};var d=function(){a._onStorageEvent.apply(a,arguments)};"undefined"!=typeof document&&(document.attachEvent?document.attachEvent("onstorage",d):c.addEventListener("storage",d,!1))}var g=a("./eventemitter.js"),h=a("../src/shared.js").guid,i=function(a){return void 0===a||void 0===a.localStorage?{getItem:function(){},setItem:function(){},removeItem:function(){}}:a.localStorage}(c);f.prototype._transaction=function(a){function b(){if(!g){var k=Date.now(),m=0|i.getItem(l);if(m&&k-m=0;e--)a[e].timestamp0&&i.setItem(j,JSON.stringify(a))})}),f.prototype._cleanup_once=d(100,function(){var a=this;a._transaction(function(){var b,c,d=(Date.now(),0);try{c=JSON.parse(i.getItem(k)||"{}")}catch(e){c={}}for(b in c)a._once_expired(b,c)&&(delete c[b],d++);d>0&&i.setItem(k,JSON.stringify(c))})}),f.prototype._once_expired=function(a,b){if(!b)return!0;if(!b.hasOwnProperty(a))return!0;if("object"!=typeof b[a])return!0;var c=b[a].ttl||n,d=Date.now();return b[a].timestamp>2],f+=a[(3&d[c])<<4|d[c+1]>>4],f+=a[(15&d[c+1])<<2|d[c+2]>>6],f+=a[63&d[c+2]];return e%3==2?f=f.substring(0,f.length-1)+"=":e%3==1&&(f=f.substring(0,f.length-2)+"=="),f},c.decode=function(a){var c,d,e,f,g,h=.75*a.length,i=a.length,j=0;"="===a[a.length-1]&&(h--,"="===a[a.length-2]&&h--);var k=new ArrayBuffer(h),l=new Uint8Array(k);for(c=0;c>4,l[j++]=(15&e)<<4|f>>2,l[j++]=(3&f)<<6|63&g;return k}}()},{}],6:[function(a,b,c){!function(a){"use strict";function b(a){var b=a.charCodeAt(0);return b===f||b===k?62:b===g||b===l?63:b0)throw new Error("Invalid string. Length must be a multiple of 4");var k=a.length;i="="===a.charAt(k-2)?2:"="===a.charAt(k-1)?1:0,j=new e(3*a.length/4-i),g=i>0?a.length-4:a.length;var l=0;for(d=0,f=0;d>16),c((65280&h)>>8),c(255&h);return 2===i?(h=b(a.charAt(d))<<2|b(a.charAt(d+1))>>4,c(255&h)):1===i&&(h=b(a.charAt(d))<<10|b(a.charAt(d+1))<<4|b(a.charAt(d+2))>>2,c(h>>8&255),c(255&h)),j}function d(a){function b(a){return"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(a)}function c(a){return b(a>>18&63)+b(a>>12&63)+b(a>>6&63)+b(63&a)}var d,e,f,g=a.length%3,h="";for(d=0,f=a.length-g;d>2),h+=b(e<<4&63),h+="==";break;case 2:e=(a[a.length-2]<<8)+a[a.length-1],h+=b(e>>10),h+=b(e>>4&63),h+=b(e<<2&63),h+="="}return h}var e="undefined"!=typeof Uint8Array?Uint8Array:Array,f="+".charCodeAt(0),g="/".charCodeAt(0),h="0".charCodeAt(0),i="a".charCodeAt(0),j="A".charCodeAt(0),k="-".charCodeAt(0),l="_".charCodeAt(0);a.toByteArray=c,a.fromByteArray=d}(void 0===c?this.base64js={}:c)},{}],7:[function(a,b,c){(function(b){"use strict";function d(){function a(){}try{var b=new Uint8Array(1);return b.foo=function(){return 42},b.constructor=a,42===b.foo()&&b.constructor===a&&"function"==typeof b.subarray&&0===b.subarray(1,1).byteLength}catch(c){return!1}}function e(){return f.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function f(a){return this instanceof f?(f.TYPED_ARRAY_SUPPORT||(this.length=0,this.parent=void 0),"number"==typeof a?g(this,a):"string"==typeof a?h(this,a,arguments.length>1?arguments[1]:"utf8"):i(this,a)):arguments.length>1?new f(a,arguments[1]):new f(a)}function g(a,b){if(a=p(a,b<0?0:0|q(b)),!f.TYPED_ARRAY_SUPPORT)for(var c=0;c>>1&&(a.parent=Z),a}function q(a){if(a>=e())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+e().toString(16)+" bytes");return 0|a}function r(a,b){if(!(this instanceof r))return new r(a,b);var c=new f(a,b);return delete c.parent,c}function s(a,b){"string"!=typeof a&&(a=""+a);var c=a.length;if(0===c)return 0;for(var d=!1;;)switch(b){case"ascii":case"binary":case"raw":case"raws":return c;case"utf8":case"utf-8":return R(a).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*c;case"hex":return c>>>1;case"base64":return U(a).length;default:if(d)return R(a).length;b=(""+b).toLowerCase(),d=!0}}function t(a,b,c){var d=!1;if(b|=0,c=void 0===c||c===1/0?this.length:0|c,a||(a="utf8"),b<0&&(b=0),c>this.length&&(c=this.length),c<=b)return"";for(;;)switch(a){case"hex":return F(this,b,c);case"utf8":case"utf-8":return B(this,b,c);case"ascii":return D(this,b,c);case"binary":return E(this,b,c);case"base64":return A(this,b,c);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return G(this,b,c);default:if(d)throw new TypeError("Unknown encoding: "+a);a=(a+"").toLowerCase(),d=!0}}function u(a,b,c,d){c=Number(c)||0;var e=a.length-c;d?(d=Number(d))>e&&(d=e):d=e;var f=b.length;if(f%2!=0)throw new Error("Invalid hex string");d>f/2&&(d=f/2);for(var g=0;g239?4:f>223?3:f>191?2:1;if(e+h<=c){var i,j,k,l;switch(h){case 1:f<128&&(g=f);break;case 2:i=a[e+1],128==(192&i)&&(l=(31&f)<<6|63&i)>127&&(g=l);break;case 3:i=a[e+1],j=a[e+2],128==(192&i)&&128==(192&j)&&(l=(15&f)<<12|(63&i)<<6|63&j)>2047&&(l<55296||l>57343)&&(g=l);break;case 4:i=a[e+1],j=a[e+2],k=a[e+3],128==(192&i)&&128==(192&j)&&128==(192&k)&&(l=(15&f)<<18|(63&i)<<12|(63&j)<<6|63&k)>65535&&l<1114112&&(g=l)}}null===g?(g=65533,h=1):g>65535&&(g-=65536,d.push(g>>>10&1023|55296),g=56320|1023&g),d.push(g),e+=h}return C(d)}function C(a){var b=a.length;if(b<=$)return String.fromCharCode.apply(String,a);for(var c="",d=0;dd)&&(c=d);for(var e="",f=b;fc)throw new RangeError("Trying to access beyond buffer length")}function I(a,b,c,d,e,g){if(!f.isBuffer(a))throw new TypeError("buffer must be a Buffer instance");if(b>e||ba.length)throw new RangeError("index out of range")}function J(a,b,c,d){b<0&&(b=65535+b+1);for(var e=0,f=Math.min(a.length-c,2);e>>8*(d?e:1-e)}function K(a,b,c,d){b<0&&(b=4294967295+b+1);for(var e=0,f=Math.min(a.length-c,4);e>>8*(d?e:3-e)&255}function L(a,b,c,d,e,f){if(b>e||ba.length)throw new RangeError("index out of range");if(c<0)throw new RangeError("index out of range")}function M(a,b,c,d,e){return e||L(a,b,c,4,3.4028234663852886e38,-3.4028234663852886e38),X.write(a,b,c,d,23,4),c+4}function N(a,b,c,d,e){return e||L(a,b,c,8,1.7976931348623157e308,-1.7976931348623157e308),X.write(a,b,c,d,52,8),c+8}function O(a){if(a=P(a).replace(aa,""),a.length<2)return"";for(;a.length%4!=0;)a+="=";return a}function P(a){return a.trim?a.trim():a.replace(/^\s+|\s+$/g,"")}function Q(a){return a<16?"0"+a.toString(16):a.toString(16)}function R(a,b){b=b||1/0;for(var c,d=a.length,e=null,f=[],g=0;g55295&&c<57344){if(!e){if(c>56319){(b-=3)>-1&&f.push(239,191,189);continue}if(g+1===d){(b-=3)>-1&&f.push(239,191,189);continue}e=c;continue}if(c<56320){(b-=3)>-1&&f.push(239,191,189),e=c;continue}c=65536+(e-55296<<10|c-56320)}else e&&(b-=3)>-1&&f.push(239,191,189);if(e=null,c<128){if((b-=1)<0)break;f.push(c)}else if(c<2048){if((b-=2)<0)break;f.push(c>>6|192,63&c|128)}else if(c<65536){if((b-=3)<0)break;f.push(c>>12|224,c>>6&63|128,63&c|128)}else{if(!(c<1114112))throw new Error("Invalid code point");if((b-=4)<0)break;f.push(c>>18|240,c>>12&63|128,c>>6&63|128,63&c|128)}}return f}function S(a){for(var b=[],c=0;c>8,e=c%256,f.push(e),f.push(d);return f}function U(a){return W.toByteArray(O(a))}function V(a,b,c,d){for(var e=0;e=b.length||e>=a.length);e++)b[e+c]=a[e];return e}var W=a("base64-js"),X=a("ieee754"),Y=a("isarray");c.Buffer=f,c.SlowBuffer=r,c.INSPECT_MAX_BYTES=50,f.poolSize=8192;var Z={};f.TYPED_ARRAY_SUPPORT=void 0!==b.TYPED_ARRAY_SUPPORT?b.TYPED_ARRAY_SUPPORT:d(),f.TYPED_ARRAY_SUPPORT?(f.prototype.__proto__=Uint8Array.prototype,f.__proto__=Uint8Array):(f.prototype.length=void 0,f.prototype.parent=void 0),f.isBuffer=function(a){return!(null==a||!a._isBuffer)},f.compare=function(a,b){if(!f.isBuffer(a)||!f.isBuffer(b))throw new TypeError("Arguments must be Buffers");if(a===b)return 0;for(var c=a.length,d=b.length,e=0,g=Math.min(c,d);e0&&(a=this.toString("hex",0,b).match(/.{2}/g).join(" "),this.length>b&&(a+=" ... ")),""},f.prototype.compare=function(a){if(!f.isBuffer(a))throw new TypeError("Argument must be a Buffer");return this===a?0:f.compare(this,a)},f.prototype.indexOf=function(a,b){function c(a,b,c){for(var d=-1,e=0;c+e2147483647?b=2147483647:b<-2147483648&&(b=-2147483648),b>>=0,0===this.length)return-1;if(b>=this.length)return-1;if(b<0&&(b=Math.max(this.length+b,0)),"string"==typeof a)return 0===a.length?-1:String.prototype.indexOf.call(this,a,b);if(f.isBuffer(a))return c(this,a,b);if("number"==typeof a)return f.TYPED_ARRAY_SUPPORT&&"function"===Uint8Array.prototype.indexOf?Uint8Array.prototype.indexOf.call(this,a,b):c(this,[a],b);throw new TypeError("val must be string, number or Buffer")},f.prototype.get=function(a){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(a)},f.prototype.set=function(a,b){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(a,b)},f.prototype.write=function(a,b,c,d){if(void 0===b)d="utf8",c=this.length,b=0;else if(void 0===c&&"string"==typeof b)d=b,c=this.length,b=0;else if(isFinite(b))b|=0,isFinite(c)?(c|=0,void 0===d&&(d="utf8")):(d=c,c=void 0);else{var e=d;d=b,b=0|c,c=e}var f=this.length-b;if((void 0===c||c>f)&&(c=f),a.length>0&&(c<0||b<0)||b>this.length)throw new RangeError("attempt to write outside buffer bounds");d||(d="utf8");for(var g=!1;;)switch(d){case"hex":return u(this,a,b,c);case"utf8":case"utf-8":return v(this,a,b,c);case"ascii":return w(this,a,b,c);case"binary":return x(this,a,b,c);case"base64":return y(this,a,b,c);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return z(this,a,b,c);default:if(g)throw new TypeError("Unknown encoding: "+d);d=(""+d).toLowerCase(),g=!0}},f.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var $=4096;f.prototype.slice=function(a,b){var c=this.length;a=~~a,b=void 0===b?c:~~b,a<0?(a+=c)<0&&(a=0):a>c&&(a=c),b<0?(b+=c)<0&&(b=0):b>c&&(b=c),b0&&(e*=256);)d+=this[a+--b]*e;return d},f.prototype.readUInt8=function(a,b){return b||H(a,1,this.length),this[a]},f.prototype.readUInt16LE=function(a,b){return b||H(a,2,this.length),this[a]|this[a+1]<<8},f.prototype.readUInt16BE=function(a,b){return b||H(a,2,this.length),this[a]<<8|this[a+1]},f.prototype.readUInt32LE=function(a,b){return b||H(a,4,this.length),(this[a]|this[a+1]<<8|this[a+2]<<16)+16777216*this[a+3]},f.prototype.readUInt32BE=function(a,b){return b||H(a,4,this.length),16777216*this[a]+(this[a+1]<<16|this[a+2]<<8|this[a+3])},f.prototype.readIntLE=function(a,b,c){a|=0,b|=0,c||H(a,b,this.length);for(var d=this[a],e=1,f=0;++f=e&&(d-=Math.pow(2,8*b)),d},f.prototype.readIntBE=function(a,b,c){a|=0,b|=0,c||H(a,b,this.length);for(var d=b,e=1,f=this[a+--d];d>0&&(e*=256);)f+=this[a+--d]*e;return e*=128,f>=e&&(f-=Math.pow(2,8*b)),f},f.prototype.readInt8=function(a,b){return b||H(a,1,this.length),128&this[a]?-1*(255-this[a]+1):this[a]},f.prototype.readInt16LE=function(a,b){b||H(a,2,this.length);var c=this[a]|this[a+1]<<8;return 32768&c?4294901760|c:c},f.prototype.readInt16BE=function(a,b){b||H(a,2,this.length);var c=this[a+1]|this[a]<<8;return 32768&c?4294901760|c:c},f.prototype.readInt32LE=function(a,b){return b||H(a,4,this.length),this[a]|this[a+1]<<8|this[a+2]<<16|this[a+3]<<24},f.prototype.readInt32BE=function(a,b){return b||H(a,4,this.length),this[a]<<24|this[a+1]<<16|this[a+2]<<8|this[a+3]},f.prototype.readFloatLE=function(a,b){return b||H(a,4,this.length),X.read(this,a,!0,23,4)},f.prototype.readFloatBE=function(a,b){return b||H(a,4,this.length),X.read(this,a,!1,23,4)},f.prototype.readDoubleLE=function(a,b){return b||H(a,8,this.length),X.read(this,a,!0,52,8)},f.prototype.readDoubleBE=function(a,b){return b||H(a,8,this.length),X.read(this,a,!1,52,8)},f.prototype.writeUIntLE=function(a,b,c,d){a=+a,b|=0,c|=0,d||I(this,a,b,c,Math.pow(2,8*c),0);var e=1,f=0;for(this[b]=255&a;++f=0&&(f*=256);)this[b+e]=a/f&255;return b+c},f.prototype.writeUInt8=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,1,255,0),f.TYPED_ARRAY_SUPPORT||(a=Math.floor(a)),this[b]=255&a,b+1},f.prototype.writeUInt16LE=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,2,65535,0),f.TYPED_ARRAY_SUPPORT?(this[b]=255&a,this[b+1]=a>>>8):J(this,a,b,!0),b+2},f.prototype.writeUInt16BE=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,2,65535,0),f.TYPED_ARRAY_SUPPORT?(this[b]=a>>>8,this[b+1]=255&a):J(this,a,b,!1),b+2},f.prototype.writeUInt32LE=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,4,4294967295,0),f.TYPED_ARRAY_SUPPORT?(this[b+3]=a>>>24,this[b+2]=a>>>16,this[b+1]=a>>>8,this[b]=255&a):K(this,a,b,!0),b+4},f.prototype.writeUInt32BE=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,4,4294967295,0),f.TYPED_ARRAY_SUPPORT?(this[b]=a>>>24,this[b+1]=a>>>16,this[b+2]=a>>>8,this[b+3]=255&a):K(this,a,b,!1),b+4},f.prototype.writeIntLE=function(a,b,c,d){if(a=+a,b|=0,!d){var e=Math.pow(2,8*c-1);I(this,a,b,c,e-1,-e)}var f=0,g=1,h=a<0?1:0;for(this[b]=255&a;++f>0)-h&255;return b+c},f.prototype.writeIntBE=function(a,b,c,d){if(a=+a,b|=0,!d){var e=Math.pow(2,8*c-1);I(this,a,b,c,e-1,-e)}var f=c-1,g=1,h=a<0?1:0;for(this[b+f]=255&a;--f>=0&&(g*=256);)this[b+f]=(a/g>>0)-h&255;return b+c},f.prototype.writeInt8=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,1,127,-128),f.TYPED_ARRAY_SUPPORT||(a=Math.floor(a)),a<0&&(a=255+a+1),this[b]=255&a,b+1},f.prototype.writeInt16LE=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,2,32767,-32768),f.TYPED_ARRAY_SUPPORT?(this[b]=255&a,this[b+1]=a>>>8):J(this,a,b,!0),b+2},f.prototype.writeInt16BE=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,2,32767,-32768),f.TYPED_ARRAY_SUPPORT?(this[b]=a>>>8,this[b+1]=255&a):J(this,a,b,!1),b+2},f.prototype.writeInt32LE=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,4,2147483647,-2147483648),f.TYPED_ARRAY_SUPPORT?(this[b]=255&a,this[b+1]=a>>>8,this[b+2]=a>>>16,this[b+3]=a>>>24):K(this,a,b,!0),b+4},f.prototype.writeInt32BE=function(a,b,c){return a=+a,b|=0,c||I(this,a,b,4,2147483647,-2147483648),a<0&&(a=4294967295+a+1),f.TYPED_ARRAY_SUPPORT?(this[b]=a>>>24,this[b+1]=a>>>16,this[b+2]=a>>>8,this[b+3]=255&a):K(this,a,b,!1),b+4},f.prototype.writeFloatLE=function(a,b,c){return M(this,a,b,!0,c)},f.prototype.writeFloatBE=function(a,b,c){return M(this,a,b,!1,c)},f.prototype.writeDoubleLE=function(a,b,c){return N(this,a,b,!0,c)},f.prototype.writeDoubleBE=function(a,b,c){return N(this,a,b,!1,c)},f.prototype.copy=function(a,b,c,d){if(c||(c=0),d||0===d||(d=this.length),b>=a.length&&(b=a.length),b||(b=0),d>0&&d=this.length)throw new RangeError("sourceStart out of bounds");if(d<0)throw new RangeError("sourceEnd out of bounds");d>this.length&&(d=this.length),a.length-b=0;e--)a[e+b]=this[e+c];else if(g<1e3||!f.TYPED_ARRAY_SUPPORT)for(e=0;e=this.length)throw new RangeError("start out of bounds");if(c<0||c>this.length)throw new RangeError("end out of bounds");var d;if("number"==typeof a)for(d=b;d>1,k=-7,l=c?e-1:0,m=c?-1:1,n=a[b+l];for(l+=m,f=n&(1<<-k)-1,n>>=-k,k+=h;k>0;f=256*f+a[b+l],l+=m,k-=8);for(g=f&(1<<-k)-1,f>>=-k,k+=d;k>0;g=256*g+a[b+l],l+=m,k-=8);if(0===f)f=1-j;else{if(f===i)return g?NaN:1/0*(n?-1:1);g+=Math.pow(2,d),f-=j}return(n?-1:1)*g*Math.pow(2,f-d)},c.write=function(a,b,c,d,e,f){var g,h,i,j=8*f-e-1,k=(1<>1,m=23===e?Math.pow(2,-24)-Math.pow(2,-77):0,n=d?0:f-1,o=d?1:-1,p=b<0||0===b&&1/b<0?1:0;for(b=Math.abs(b),isNaN(b)||b===1/0?(h=isNaN(b)?1:0,g=k):(g=Math.floor(Math.log(b)/Math.LN2),b*(i=Math.pow(2,-g))<1&&(g--,i*=2),b+=g+l>=1?m/i:m*Math.pow(2,1-l),b*i>=2&&(g++,i/=2),g+l>=k?(h=0,g=k):g+l>=1?(h=(b*i-1)*Math.pow(2,e),g+=l):(h=b*Math.pow(2,l-1)*Math.pow(2,e),g=0));e>=8;a[c+n]=255&h,n+=o,h/=256,e-=8);for(g=g<0;a[c+n]=255&g,n+=o,g/=256,j-=8);a[c+n-o]|=128*p}},{}],10:[function(a,b,c){!function(){function a(a,b){return Object.prototype.hasOwnProperty.call(a,b)}function c(){return 1}function d(a){if(!(this instanceof d))return new d(a);"number"==typeof a&&(a={max:a}),a||(a={}),this._max=a.max,(!this._max||"number"!=typeof this._max||this._max<=0)&&(this._max=1/0),this._lengthCalculator=a.length||c,"function"!=typeof this._lengthCalculator&&(this._lengthCalculator=c),this._allowStale=a.stale||!1,this._maxAge=a.maxAge||null,this._dispose=a.dispose,this.reset()}function e(a,b,c){var d=a._cache[b];return d&&(a._maxAge&&Date.now()-d.now>a._maxAge?(i(a,d),a._allowStale||(d=void 0)):c&&f(a,d),d&&(d=d.value)),d}function f(a,b){h(a,b),b.lu=a._mru++,a._maxAge&&(b.now=Date.now()),a._lruList[b.lu]=b}function g(a){for(;a._lrua._max;)i(a,a._lruList[a._lru])}function h(a,b){for(delete a._lruList[b.lu];a._lruthis._max&&g(this)},get:function(){return this._max},enumerable:!0}),Object.defineProperty(d.prototype,"lengthCalculator",{set:function(a){if("function"!=typeof a){this._lengthCalculator=c,this._length=this._itemCount;for(var b in this._cache)this._cache[b].length=1}else{this._lengthCalculator=a,this._length=0;for(var b in this._cache)this._cache[b].length=this._lengthCalculator(this._cache[b].value),this._length+=this._cache[b].length}this._length>this._max&&g(this)},get:function(){return this._lengthCalculator},enumerable:!0}),Object.defineProperty(d.prototype,"length",{get:function(){return this._length},enumerable:!0}),Object.defineProperty(d.prototype,"itemCount",{get:function(){return this._itemCount},enumerable:!0}),d.prototype.forEach=function(a,b){b=b||this;for(var c=0,d=this._mru-1;d>=0&&cthis._maxAge&&(i(this,e),this._allowStale||(e=void 0)),e&&a.call(b,e.value,e.key,this)}},d.prototype.keys=function(){for(var a=new Array(this._itemCount),b=0,c=this._mru-1;c>=0&&b=0&&bthis._max?(this._dispose&&this._dispose(b,c),!1):(this._length+=f.length,this._lruList[f.lu]=this._cache[b]=f,this._itemCount++,this._length>this._max&&g(this),!0)},d.prototype.has=function(b){if(!a(this._cache,b))return!1;var c=this._cache[b];return!(this._maxAge&&Date.now()-c.now>this._maxAge)},d.prototype.get=function(a){return e(this,a,!0)},d.prototype.peek=function(a){return e(this,a,!1)},d.prototype.pop=function(){var a=this._lruList[this._lru];return i(this,a),a||null},d.prototype.del=function(a){i(this,this._cache[a])}}()},{}],11:[function(a,b,c){!function(a,b,c,d){function e(a){return a.split("").reduce(function(a,b){return a[b]=!0,a},{})}function f(a,b){return b=b||{},function(c,d,e){return h(c,a,b)}}function g(a,b){a=a||{},b=b||{};var c={};return Object.keys(b).forEach(function(a){c[a]=b[a]}),Object.keys(a).forEach(function(b){c[b]=a[b]}),c}function h(a,b,c){if("string"!=typeof b)throw new TypeError("glob pattern string required");return c||(c={}),!(!c.nocomment&&"#"===b.charAt(0))&&(""===b.trim()?""===a:new i(b,c).match(a))}function i(a,b){if(!(this instanceof i))return new i(a,b,t);if("string"!=typeof a)throw new TypeError("glob pattern string required");b||(b={}),a=a.trim(),"win32"===d&&(a=a.split("\\").join("/"));var c=a+"\n"+v(b),e=h.cache.get(c);if(e)return e;h.cache.set(c,this),this.options=b,this.set=[],this.pattern=a,this.regexp=null,this.negate=!1,this.comment=!1,this.empty=!1,this.make()}function j(){if(!this._made){var a=this.pattern,b=this.options;if(!b.nocomment&&"#"===a.charAt(0))return void(this.comment=!0);if(!a)return void(this.empty=!0);this.parseNegate();var c=this.globSet=this.braceExpand();b.debug&&(this.debug=console.error),this.debug(this.pattern,c),c=this.globParts=c.map(function(a){return a.split(B)}),this.debug(this.pattern,c),c=c.map(function(a,b,c){return a.map(this.parse,this)},this),this.debug(this.pattern,c),c=c.filter(function(a){return-1===a.indexOf(!1)}),this.debug(this.pattern,c),this.set=c}}function k(){var a=this.pattern,b=!1,c=this.options,d=0;if(!c.nonegate){for(var e=0,f=a.length;e=b?a:new Array(b-a.length+1).join(c)+a}function m(a,b){function c(){s.push(w),w=""}if(b=b||this.options,void 0===(a=void 0===a?this.pattern:a))throw new Error("undefined pattern");if(b.nobrace||!a.match(/\{.*\}/))return[a];var d=!1;if("{"!==a.charAt(0)){this.debug(a);for(var e=null,f=0,g=a.length;fq?-1:1,s=[],f=n;f!=q+r;f+=r){j=o?l(f,p):f+"";for(var t=0,u=k.length;t=0&&!(f=a[g]);g--);for(var g=0,h=e.length;g=100&&(a={}),a[c]=d},this.get=function(b){return a[b]}}}}),h.Minimatch=i;var s=a("lru-cache"),t=h.cache=new s({max:100}),u=h.GLOBSTAR=i.GLOBSTAR={},v=a("sigmund"),w=(a("path"),"[^/]"),x=w+"*?",y="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",z="(?:(?!(?:\\/|^)\\.).)*?",A=e("().*{}+?[]^$\\!"),B=/\/+/;h.filter=f,h.defaults=function(a){if(!a||!Object.keys(a).length)return h;var b=h,c=function(c,d,e){return b.minimatch(c,d,g(a,e))};return c.Minimatch=function(c,d){return new b.Minimatch(c,g(a,d))},c},i.defaults=function(a){return a&&Object.keys(a).length?h.defaults(a).Minimatch:i},i.prototype.debug=function(){},i.prototype.make=j,i.prototype.parseNegate=k,h.braceExpand=function(a,b){return new i(a,b).braceExpand()},i.prototype.braceExpand=m,i.prototype.parse=n;var C={};h.makeRe=function(a,b){return new i(a,b||{}).makeRe()},i.prototype.makeRe=o,h.match=function(a,b,c){c=c||{};var d=new i(b,c);return a=a.filter(function(a){return d.match(a)}),d.options.nonull&&!a.length&&a.push(b),a},i.prototype.match=p,i.prototype.matchOne=function(a,b,c){var d=this.options;this.debug("matchOne",{this:this,file:a,pattern:b}),this.debug("matchOne",a.length,b.length);for(var e=0,f=0,g=a.length,h=b.length;e>> no match, partial?",a,k,b,l),k!==g))}var n;if("string"==typeof i?(n=d.nocase?j.toLowerCase()===i.toLowerCase():j===i,this.debug("string match",i,j,n)):(n=j.match(i),this.debug("pattern match",i,j,n)),!n)return!1}if(e===g&&f===h)return!0;if(e===g)return c;if(f===h){return e===g-1&&""===a[e]}throw new Error("wtf?")}}("function"==typeof a?a:null,this,"object"==typeof b?b:null,"object"==typeof process?process.platform:"win32")},{"lru-cache":10,path:12,sigmund:13}],12:[function(a,b,c){function d(a,b){for(var c=0,d=a.length-1;d>=0;d--){var e=a[d];"."===e?a.splice(d,1):".."===e?(a.splice(d,1),c++):c&&(a.splice(d,1),c--)}if(b)for(;c--;c)a.unshift("..");return a}function e(a,b){if(a.filter)return a.filter(b);for(var c=[],d=0;d=-1&&!b;c--){var f=c>=0?arguments[c]:process.cwd();if("string"!=typeof f)throw new TypeError("Arguments to path.resolve must be strings");f&&(a=f+"/"+a,b="/"===f.charAt(0))}return a=d(e(a.split("/"),function(a){return!!a}),!b).join("/"),(b?"/":"")+a||"."},c.normalize=function(a){var b=c.isAbsolute(a),f="/"===h(a,-1);return a=d(e(a.split("/"),function(a){return!!a}),!b).join("/"),a||b||(a="."),a&&f&&(a+="/"),(b?"/":"")+a},c.isAbsolute=function(a){return"/"===a.charAt(0)},c.join=function(){var a=Array.prototype.slice.call(arguments,0);return c.normalize(e(a,function(a,b){if("string"!=typeof a)throw new TypeError("Arguments to path.join must be strings");return a}).join("/"))},c.relative=function(a,b){function d(a){for(var b=0;b=0&&""===a[c];c--);return b>c?[]:a.slice(b,c-b+1)}a=c.resolve(a).substr(1),b=c.resolve(b).substr(1);for(var e=d(a.split("/")),f=d(b.split("/")),g=Math.min(e.length,f.length),h=g,i=0;ib)&&"function"!=typeof a&&void 0!==a)return"object"!=typeof a||!a||a instanceof f?void(e+=a):void(-1===d.indexOf(a)&&g!==b&&(d.push(a),e+="{",Object.keys(a).forEach(function(b,d,f){if("_"!==b.charAt(0)){var h=typeof a[b];"function"!==h&&"undefined"!==h&&(e+=b,c(a[b],g+1))}})))}b=b||10;var d=[],e="",f=RegExp;return c(a,0),e}b.exports=d},{}],14:[function(a,b,c){(function(a){function c(b,c,d){return b instanceof ArrayBuffer&&(b=new Uint8Array(b)),new a(b,c,d)}c.prototype=Object.create(a.prototype),c.prototype.constructor=c,Object.keys(a).forEach(function(b){a.hasOwnProperty(b)&&(c[b]=a[b])}),b.exports=c}).call(this,a("buffer").Buffer)},{buffer:7}],15:[function(a,b,c){var d="READ",e="WRITE",f="CREATE",g="EXCLUSIVE",h="TRUNCATE",i="APPEND";b.exports={FILE_SYSTEM_NAME:"local",FILE_STORE_NAME:"files",IDB_RO:"readonly",IDB_RW:"readwrite",WSQL_VERSION:"1",WSQL_SIZE:5242880,WSQL_DESC:"FileSystem Storage",NODE_TYPE_FILE:"FILE",NODE_TYPE_DIRECTORY:"DIRECTORY",NODE_TYPE_SYMBOLIC_LINK:"SYMLINK",NODE_TYPE_META:"META",S_IFREG:32768,S_IFDIR:16384,S_IFLNK:40960,DEFAULT_DIR_PERMISSIONS:493,DEFAULT_FILE_PERMISSIONS:420,FULL_READ_WRITE_EXEC_PERMISSIONS:511,READ_WRITE_PERMISSIONS:438,SYMLOOP_MAX:10,BINARY_MIME_TYPE:"application/octet-stream",JSON_MIME_TYPE:"application/json",ROOT_DIRECTORY_NAME:"/",FS_FORMAT:"FORMAT",FS_NOCTIME:"NOCTIME",FS_NOMTIME:"NOMTIME",FS_NODUPEIDCHECK:"FS_NODUPEIDCHECK",O_READ:d,O_WRITE:e,O_CREATE:f,O_EXCLUSIVE:g,O_TRUNCATE:h,O_APPEND:i,O_FLAGS:{r:[d],"r+":[d,e],w:[e,f,h],"w+":[e,d,f,h],wx:[e,f,g,h],"wx+":[e,d,f,g,h],a:[e,f,i],"a+":[e,d,f,i],ax:[e,f,g,i],"ax+":[e,d,f,g,i]},XATTR_CREATE:"CREATE",XATTR_REPLACE:"REPLACE",FS_READY:"READY",FS_PENDING:"PENDING",FS_ERROR:"ERROR",SUPER_NODE_ID:"00000000-0000-0000-0000-000000000000",STDIN:0,STDOUT:1,STDERR:2,FIRST_DESCRIPTOR:3,ENVIRONMENT:{TMP:"/tmp",PATH:""},fsConstants:{O_RDONLY:0,O_WRONLY:1,O_RDWR:2,S_IFMT:61440,S_IFREG:32768,S_IFDIR:16384,S_IFCHR:8192,S_IFBLK:24576,S_IFIFO:4096,S_IFLNK:40960,S_IFSOCK:49152,O_CREAT:512,O_EXCL:2048,O_NOCTTY:131072,O_TRUNC:1024,O_APPEND:8,O_DIRECTORY:1048576,O_NOFOLLOW:256,O_SYNC:128,O_DSYNC:4194304,O_SYMLINK:2097152,O_NONBLOCK:4,S_IRWXU:448,S_IRUSR:256,S_IWUSR:128,S_IXUSR:64,S_IRWXG:56,S_IRGRP:32,S_IWGRP:16,S_IXGRP:8,S_IRWXO:7,S_IROTH:4,S_IWOTH:2,S_IXOTH:1,F_OK:0,R_OK:4,W_OK:2,X_OK:1,UV_FS_COPYFILE_EXCL:1,COPYFILE_EXCL:1}}},{}],16:[function(a,b,c){var d=a("./constants.js").NODE_TYPE_FILE;b.exports=function(a,b){this.id=a,this.type=b||d}},{"./constants.js":15}],17:[function(a,b,c){(function(a){function c(a){return a.toString("utf8")}function d(b){return new a(b,"utf8")}b.exports={encode:d,decode:c}}).call(this,a("buffer").Buffer)},{buffer:7}],18:[function(a,b,c){var d={};["9:EBADF:bad file descriptor","10:EBUSY:resource busy or locked","18:EINVAL:invalid argument","27:ENOTDIR:not a directory","28:EISDIR:illegal operation on a directory","34:ENOENT:no such file or directory","47:EEXIST:file already exists","50:EPERM:operation not permitted","51:ELOOP:too many symbolic links encountered","53:ENOTEMPTY:directory not empty","55:EIO:i/o error","1000:ENOTMOUNTED:not mounted","1001:EFILESYSTEMERROR:missing super node, use 'FORMAT' flag to format filesystem.","1002:ENOATTR:attribute does not exist"].forEach(function(a){function b(a,b){Error.call(this),this.name=e,this.code=e,this.errno=c,this.message=a||f,b&&(this.path=b),this.stack=new Error(this.message).stack}a=a.split(":");var c=+a[0],e=a[1],f=a[2];b.prototype=Object.create(Error.prototype),b.prototype.constructor=b,b.prototype.toString=function(){var a=this.path?", '"+this.path+"'":"";return this.name+": "+this.message+a},d[e]=d[c]=b}),b.exports=d},{}],19:[function(a,b,c){function d(a,b,c,d,e){function f(c){a.changes.push({event:"change",path:b}),e(c)}var g=!1,h=a.flags;wa(h).contains(Va)&&delete d.ctime,wa(h).contains(Ua)&&delete d.mtime,d.ctime&&(c.ctime=d.ctime,c.atime=d.ctime,g=!0),d.atime&&(c.atime=d.atime,g=!0),d.mtime&&(c.mtime=d.mtime,g=!0),g?a.putObject(c.id,c,f):f()}function e(a,b,c,e){function g(c,d){c?e(c):d.type!==Fa?e(new Xa.ENOTDIR("a component of the path prefix is not a directory",b)):(l=d,f(a,b,h))}function h(c,d){!c&&d?e(new Xa.EEXIST("path name already exists",b)):!c||c instanceof Xa.ENOENT?a.getObject(l.data,i):e(c)}function i(b,d){b?e(b):(m=d,_a.create({guid:a.guid,type:c},function(b,c){if(b)return void e(b);n=c,n.nlinks+=1,a.putObject(n.id,n,k)}))}function j(b){if(b)e(b);else{var c=Date.now();d(a,p,n,{mtime:c,ctime:c},e)}}function k(b){b?e(b):(m[o]=new Ya(n.id,c),a.putObject(l.data,m,j))}if(c!==Fa&&c!==Ea)return e(new Xa.EINVAL("type must be a directory or file",b));b=ya(b);var l,m,n,o=Aa(b),p=za(b);f(a,p,g)}function f(a,b,c){function d(b,d){b?c(b):d&&d.type===Ha&&d.rnode?a.getObject(d.rnode,e):c(new Xa.EFILESYSTEMERROR)}function e(a,b){a?c(a):b?c(null,b):c(new Xa.ENOENT)}function g(d,e){d?c(d):e.type===Fa&&e.data?a.getObject(e.data,h):c(new Xa.ENOTDIR("a component of the path prefix is not a directory",b))}function h(d,e){if(d)c(d);else if(wa(e).has(k)){var f=e[k].id;a.getObject(f,i)}else c(new Xa.ENOENT(null,b))}function i(a,d){a?c(a):d.type==Ga?(m++,m>La?c(new Xa.ELOOP(null,b)):j(d.data)):c(null,d)}function j(b){b=ya(b),l=za(b),k=Aa(b),Ja==k?a.getObject(Ka,d):f(a,l,g)}if(!(b=ya(b)))return c(new Xa.ENOENT("path is an empty string"));var k=Aa(b),l=za(b),m=0;Ja==k?a.getObject(Ka,d):f(a,l,g)}function g(a,b,c,e,f,g,h){function i(e){e?h(e):d(a,b,c,{ctime:Date.now()},h)}var j=c.xattrs;g===Sa&&j.hasOwnProperty(e)?h(new Xa.EEXIST("attribute already exists",b)):g!==Ta||j.hasOwnProperty(e)?(j[e]=f,a.putObject(c.id,c,i)):h(new Xa.ENOATTR(null,b))}function h(a,b){function c(c,e){!c&&e?b():!c||c instanceof Xa.ENOENT?$a.create({guid:a.guid},function(c,e){if(c)return void b(c);f=e,a.putObject(f.id,f,d)}):b(c)}function d(c){c?b(c):_a.create({guid:a.guid,id:f.rnode,type:Fa},function(c,d){if(c)return void b(c);g=d,g.nlinks+=1,a.putObject(g.id,g,e)})}function e(c){c?b(c):(h={},a.putObject(g.data,h,b))}var f,g,h;a.getObject(Ka,c)}function i(a,b,c){function e(d,e){!d&&e?c(new Xa.EEXIST(null,b)):!d||d instanceof Xa.ENOENT?f(a,q,g):c(d)}function g(b,d){b?c(b):(n=d,a.getObject(n.data,h))}function h(b,d){b?c(b):(o=d,_a.create({guid:a.guid,type:Fa},function(b,d){if(b)return void c(b);l=d,l.nlinks+=1,a.putObject(l.id,l,i)}))}function i(b){b?c(b):(m={},a.putObject(l.data,m,k))}function j(b){if(b)c(b);else{var e=Date.now();d(a,q,n,{mtime:e,ctime:e},c)}}function k(b){b?c(b):(o[p]=new Ya(l.id,Fa),a.putObject(n.data,o,j))}b=ya(b);var l,m,n,o,p=Aa(b),q=za(b);f(a,b,e)}function j(a,b,c){function e(b,d){b?c(b):(p=d,a.getObject(p.data,g))}function g(d,e){d?c(d):Ja==r?c(new Xa.EBUSY(null,b)):wa(e).has(r)?(q=e,n=q[r].id,a.getObject(n,h)):c(new Xa.ENOENT(null,b))}function h(d,e){d?c(d):e.type!=Fa?c(new Xa.ENOTDIR(null,b)):(n=e,a.getObject(n.data,i))}function i(a,d){a?c(a):(o=d,wa(o).size()>0?c(new Xa.ENOTEMPTY(null,b)):k())}function j(b){if(b)c(b);else{var e=Date.now();d(a,s,p,{mtime:e,ctime:e},l)}}function k(){delete q[r],a.putObject(p.data,q,j)}function l(b){b?c(b):a.delete(n.id,m)}function m(b){b?c(b):a.delete(n.data,c)}b=ya(b);var n,o,p,q,r=Aa(b),s=za(b);f(a,s,e)}function k(a,b,c,e){function g(c,d){c?e(c):d.type!==Fa?e(new Xa.ENOENT(null,b)):(q=d,a.getObject(q.data,h))}function h(d,f){d?e(d):(r=f,wa(r).has(v)?wa(c).contains(Pa)?e(new Xa.ENOENT("O_CREATE and O_EXCLUSIVE are set, and the named file exists",b)):(s=r[v],s.type==Fa&&wa(c).contains(Na)?e(new Xa.EISDIR("the named file is a directory and O_WRITE is set",b)):a.getObject(s.id,i)):wa(c).contains(Oa)?l():e(new Xa.ENOENT("O_CREATE is not set and the named file does not exist",b)))}function i(a,c){if(a)e(a);else{var d=c;d.type==Ga?(x++,x>La?e(new Xa.ELOOP(null,b)):j(d.data)):k(void 0,d)}}function j(d){d=ya(d),w=za(d),v=Aa(d),Ja==v&&(wa(c).contains(Na)?e(new Xa.EISDIR("the named file is a directory and O_WRITE is set",b)):f(a,b,k)),f(a,w,g)}function k(a,b){a?e(a):(t=b,e(null,t))}function l(){_a.create({guid:a.guid,type:Ea},function(b,c){if(b)return void e(b);t=c,t.nlinks+=1,a.putObject(t.id,t,m)})}function m(b){b?e(b):(u=new bb(0),u.fill(0),a.putBuffer(t.data,u,o))}function n(b){if(b)e(b);else{var c=Date.now();d(a,w,q,{mtime:c,ctime:c},p)}}function o(b){b?e(b):(r[v]=new Ya(t.id,Ea),a.putObject(q.data,r,n))}function p(a){a?e(a):e(null,t)}b=ya(b);var q,r,s,t,u,v=Aa(b),w=za(b),x=0;Ja==v?wa(c).contains(Na)?e(new Xa.EISDIR("the named file is a directory and O_WRITE is set",b)):f(a,b,k):f(a,w,g)}function l(a,b,c,e,f,g){function h(a){a?g(a):g(null,f)}function i(c){if(c)g(c);else{var e=Date.now();d(a,b.path,l,{mtime:e,ctime:e},h)}}function j(b){b?g(b):a.putObject(l.id,l,i)}function k(d,h){if(d)g(d);else{l=h;var i=new bb(f);i.fill(0),c.copy(i,0,e,e+f),b.position=f,l.size=f,l.version+=1,a.putBuffer(l.data,i,j)}}var l;a.getObject(b.id,k)}function m(a,b,c,e,f,g,h){function i(a){a?h(a):h(null,f)}function j(c){if(c)h(c);else{var e=Date.now();d(a,b.path,n,{mtime:e,ctime:e},i)}}function k(b){b?h(b):a.putObject(n.id,n,j)}function l(d,i){if(d)h(d);else{if(!(o=i))return h(new Xa.EIO("Expected Buffer"));var j=void 0!==g&&null!==g?g:b.position,l=Math.max(o.length,j+f),m=new bb(l);m.fill(0),o&&o.copy(m),c.copy(m,j,e,e+f),void 0===g&&(b.position+=f),n.size=l,n.version+=1,a.putBuffer(n.data,m,k)}}function m(b,c){b?h(b):(n=c,a.getBuffer(n.data,l))}var n,o;a.getObject(b.id,m)}function n(a,b,c,d,e,f,g){function h(a,h){if(a)g(a);else{if(!(k=h))return g(new Xa.EIO("Expected Buffer"));var i=void 0!==f&&null!==f?f:b.position;e=i+e>c.length?e-i:e,k.copy(c,d,i,i+e),void 0===f&&(b.position+=e),g(null,e)}}function i(c,d){c?g(c):d.type===Fa?g(new Xa.EISDIR("the named file is a directory",b.path)):(j=d,a.getBuffer(j.data,h))}var j,k;a.getObject(b.id,i)}function o(a,b,c){b=ya(b);Aa(b);f(a,b,c)}function p(a,b,c){b.getNode(a,c)}function q(a,b,c){function d(b,d){b?c(b):(g=d,a.getObject(g.data,e))}function e(d,e){d?c(d):(h=e,wa(h).has(i)?a.getObject(h[i].id,c):c(new Xa.ENOENT("a component of the path does not name an existing file",b)))}b=ya(b);var g,h,i=Aa(b),j=za(b);Ja==i?f(a,b,c):f(a,j,d)}function r(a,b,c,e){function g(b){b?e(b):d(a,c,u,{ctime:x},e)}function h(b,c){b?e(b):(u=c,u.nlinks+=1,a.putObject(u.id,u,g))}function i(b,c){b?e(b):a.getObject(t,h)}function j(b,c){b?e(b):(s=c,wa(s).has(v)?e(new Xa.EEXIST("newpath resolves to an existing file",v)):(s[v]=q[n],t=s[v].id,a.putObject(r.data,s,i)))}function k(b,c){b?e(b):(r=c,a.getObject(r.data,j))}function l(b,c){b?e(b):(q=c,wa(q).has(n)?q[n].type===Fa?e(new Xa.EPERM("oldpath refers to a directory")):f(a,w,k):e(new Xa.ENOENT("a component of either path prefix does not exist",n)))}function m(b,c){b?e(b):(p=c,a.getObject(p.data,l))}b=ya(b);var n=Aa(b),o=za(b);c=ya(c);var p,q,r,s,t,u,v=Aa(c),w=za(c),x=Date.now();f(a,o,m)}function s(a,b,c){function e(b){b?c(b):(delete m[o],a.putObject(l.data,m,function(b){var e=Date.now();d(a,p,l,{mtime:e,ctime:e},c)}))}function g(b){b?c(b):a.delete(n.data,e)}function h(f,h){f?c(f):(n=h,n.nlinks-=1,n.nlinks<1?a.delete(n.id,g):a.putObject(n.id,n,function(c){d(a,b,n,{ctime:Date.now()},e)}))}function i(a,b){a?c(a):b.type===Fa?c(new Xa.EPERM("unlink not permitted on directories",o)):h(null,b)}function j(b,d){b?c(b):(m=d,wa(m).has(o)?a.getObject(m[o].id,i):c(new Xa.ENOENT("a component of the path does not name an existing file",o)))}function k(b,d){b?c(b):(l=d,a.getObject(l.data,j))}b=ya(b);var l,m,n,o=Aa(b),p=za(b);f(a,p,k)}function t(a,b,c){function d(a,b){if(a)c(a);else{h=b;var d=Object.keys(h);c(null,d)}}function e(e,f){e?c(e):f.type!==Fa?c(new Xa.ENOTDIR(null,b)):(g=f,a.getObject(g.data,d))}b=ya(b);var g,h;Aa(b);f(a,b,e)}function u(a,b,c,e){function g(b,c){b?e(b):(l=c,a.getObject(l.data,h))}function h(a,b){a?e(a):(m=b,wa(m).has(o)?e(new Xa.EEXIST(null,o)):i())}function i(){_a.create({guid:a.guid,type:Ga},function(c,d){if(c)return void e(c);n=d,n.nlinks+=1,Ba(b)||(n.symlink_relpath=b,b=xa.resolve(p,b)),n.size=b.length,n.data=b,a.putObject(n.id,n,k)})}function j(b){if(b)e(b);else{var c=Date.now();d(a,p,l,{mtime:c,ctime:c},e)}}function k(b){b?e(b):(m[o]=new Ya(n.id,Ga),a.putObject(l.data,m,j))}c=ya(c);var l,m,n,o=Aa(c),p=za(c);Ja==o?e(new Xa.EEXIST(null,o)):f(a,p,g)}function v(a,b,c){function d(b,d){b?c(b):(h=d,a.getObject(h.data,e))}function e(b,d){b?c(b):(i=d,wa(i).has(j)?a.getObject(i[j].id,g):c(new Xa.ENOENT("a component of the path does not name an existing file",j)))}function g(a,d){if(a)c(a);else if(d.type!=Ga)c(new Xa.EINVAL("path not a symbolic link",b));else{var e=d.symlink_relpath?d.symlink_relpath:d.data;c(null,e)}}b=ya(b);var h,i,j=Aa(b),k=za(b);f(a,k,d)}function w(a,b,c,e){function g(c,d){c?e(c):d.type==Fa?e(new Xa.EISDIR(null,b)):(k=d,a.getBuffer(k.data,h))}function h(b,d){if(b)e(b);else{if(!d)return e(new Xa.EIO("Expected Buffer"));var f=new bb(c);f.fill(0),d&&d.copy(f),a.putBuffer(k.data,f,j)}}function i(c){if(c)e(c);else{var f=Date.now();d(a,b,k,{mtime:f,ctime:f},e)}}function j(b){b?e(b):(k.size=c,k.version+=1,a.putObject(k.id,k,i))}b=ya(b);var k;c<0?e(new Xa.EINVAL("length cannot be negative")):f(a,b,g)}function x(a,b,c,e){function f(b,c){b?e(b):c.type==Fa?e(new Xa.EISDIR):(j=c,a.getBuffer(j.data,g))}function g(b,d){if(b)e(b);else{var f;if(!d)return e(new Xa.EIO("Expected Buffer"));d?f=d.slice(0,c):(f=new bb(c),f.fill(0)),a.putBuffer(j.data,f,i)}}function h(c){if(c)e(c);else{var f=Date.now();d(a,b.path,j,{mtime:f,ctime:f},e)}}function i(b){b?e(b):(j.size=c,j.version+=1,a.putObject(j.id,j,h))}var j;c<0?e(new Xa.EINVAL("length cannot be negative")):b.getNode(a,f)}function y(a,b,c,e,g){function h(f,h){f?g(f):d(a,b,h,{atime:c,ctime:e,mtime:e},g)}b=ya(b),"number"!=typeof c||"number"!=typeof e?g(new Xa.EINVAL("atime and mtime must be number",b)):c<0||e<0?g(new Xa.EINVAL("atime and mtime must be positive integers",b)):f(a,b,h)}function z(a,b,c,e,f){function g(g,h){g?f(g):d(a,b.path,h,{atime:c,ctime:e,mtime:e},f)}"number"!=typeof c||"number"!=typeof e?f(new Xa.EINVAL("atime and mtime must be a number")):c<0||e<0?f(new Xa.EINVAL("atime and mtime must be positive integers")):b.getNode(a,g)}function A(a,b,c,d,e,h){function i(f,i){if(f)return h(f);g(a,b,i,c,d,e,h)}b=ya(b),"string"!=typeof c?h(new Xa.EINVAL("attribute name must be a string",b)):c?null!==e&&e!==Sa&&e!==Ta?h(new Xa.EINVAL("invalid flag, must be null, XATTR_CREATE or XATTR_REPLACE",b)):f(a,b,i):h(new Xa.EINVAL("attribute name cannot be an empty string",b))}function B(a,b,c,d,e,f){function h(h,i){if(h)return f(h);g(a,b.path,i,c,d,e,f)}"string"!=typeof c?f(new Xa.EINVAL("attribute name must be a string")):c?null!==e&&e!==Sa&&e!==Ta?f(new Xa.EINVAL("invalid flag, must be null, XATTR_CREATE or XATTR_REPLACE")):b.getNode(a,h):f(new Xa.EINVAL("attribute name cannot be an empty string"))}function C(a,b,c,d){function e(a,e){if(a)return d(a);var f=e.xattrs;f.hasOwnProperty(c)?d(null,f[c]):d(new Xa.ENOATTR(null,b))}b=ya(b),"string"!=typeof c?d(new Xa.EINVAL("attribute name must be a string",b)):c?f(a,b,e):d(new Xa.EINVAL("attribute name cannot be an empty string",b))}function D(a,b,c,d){function e(a,b){if(a)return d(a);var e=b.xattrs;e.hasOwnProperty(c)?d(null,e[c]):d(new Xa.ENOATTR)}"string"!=typeof c?d(new Xa.EINVAL):c?b.getNode(a,e):d(new Xa.EINVAL("attribute name cannot be an empty string"))}function E(a,b,c,e){function g(f,g){function h(c){c?e(c):d(a,b,g,{ctime:Date.now()},e)}if(f)return e(f);var i=g.xattrs;i.hasOwnProperty(c)?(delete i[c],a.putObject(g.id,g,h)):e(new Xa.ENOATTR(null,b))}b=ya(b),"string"!=typeof c?e(new Xa.EINVAL("attribute name must be a string",b)):c?f(a,b,g):e(new Xa.EINVAL("attribute name cannot be an empty string",b))}function F(a,b,c,e){function f(f,g){function h(c){c?e(c):d(a,b.path,g,{ctime:Date.now()},e)}if(f)return e(f);var i=g.xattrs;i.hasOwnProperty(c)?(delete i[c],a.putObject(g.id,g,h)):e(new Xa.ENOATTR)}"string"!=typeof c?e(new Xa.EINVAL("attribute name must be a string")):c?b.getNode(a,f):e(new Xa.EINVAL("attribute name cannot be an empty string"))}function G(a){return wa(Ra).has(a)?Ra[a]:null}function H(a,b,c){return a?"function"==typeof a?a={encoding:b,flag:c}:"string"==typeof a&&(a={encoding:a,flag:c}):a={encoding:b,flag:c},a}function I(a,b,c){var d;return"function"==typeof b&&(c=b,b=!1),a?Ca(a)?d=new Xa.EINVAL("Path must be a string without null bytes.",a):b||Ba(a)||(d=new Xa.EINVAL("Path must be absolute.",a)):d=new Xa.EINVAL("Path must be a string",a),!d||(c(d),!1)}function J(a,b,c,d,e,f){function g(b,e){if(b)f(b);else{var g;g=wa(d).contains(Qa)?e.size:0;var h=new Za(c,e.id,d,g),i=a.allocDescriptor(h);f(null,i)}}f=arguments[arguments.length-1],I(c,f)&&(d=G(d),d||f(new Xa.EINVAL("flags is not valid"),c),k(b,c,d,g))}function K(a,b,c,d){wa(a.openFiles).has(c)?(a.releaseDescriptor(c),d(null)):d(new Xa.EBADF)}function L(a,b,c,d,f){I(c,f)&&e(b,c,d,f)}function M(a,b,c,d,e){if(arguments.length<5)e=d,d=Ia;else if(!(d=Z(d,Ia,e)))return;I(c,e)&&i(b,c,e)}function N(a,b,c,d){I(c,d)&&j(b,c,d)}function O(a,b,c,d){function e(b,e){if(b)d(b);else{var f=new ab(c,e,a.name);d(null,f)}}I(c,d)&&o(b,c,e)}function P(a,b,c,d){function e(b,c){if(b)d(b);else{var e=new ab(f.path,c,a.name);d(null,e)}}var f=a.openFiles[c];f?p(b,f,e):d(new Xa.EBADF)}function Q(a,b,c,d,e){I(c,e)&&I(d,e)&&r(b,c,d,e)}function R(a,b,c,d){I(c,d)&&s(b,c,d)}function S(a,b,c,d,e,f,g,h){function i(a,b){h(a,b||0,d)}e=void 0===e?0:e,f=void 0===f?d.length-e:f,h=arguments[arguments.length-1];var j=a.openFiles[c];j?wa(j.flags).contains(Ma)?n(b,j,d,e,f,g,i):h(new Xa.EBADF("descriptor does not permit reading")):h(new Xa.EBADF)}function T(a,b,c,d,e){if(e=arguments[arguments.length-1],d=H(d,null,"r"),I(c,e)){var f=G(d.flag||"r");if(!f)return e(new Xa.EINVAL("flags is not valid",c));k(b,c,f,function(g,h){function i(){a.releaseDescriptor(k)}if(g)return e(g);var j=new Za(c,h.id,f,0),k=a.allocDescriptor(j);p(b,j,function(f,g){if(f)return i(),e(f);var h=new ab(j.path,g,a.name);if(h.isDirectory())return i(),e(new Xa.EISDIR("illegal operation on directory",c));var k=h.size,l=new bb(k);l.fill(0),n(b,j,l,0,k,0,function(a,b){if(i(),a)return e(a);var c;c="utf8"===d.encoding?Wa.decode(l):l,e(null,c)})})})}}function U(a,b,c,d,e,f,g,h){h=arguments[arguments.length-1],e=void 0===e?0:e,f=void 0===f?d.length-e:f;var i=a.openFiles[c];i?wa(i.flags).contains(Na)?d.length-e>>0}function Z(a,b,c){if("function"==typeof b&&(c=b,b=void 0),Y(a))return a&Ia;if("number"==typeof a)return Number.isInteger(a),c(new Xa.EINVAL("mode not a valid an integer value",a)),!1;if("string"==typeof a){if(!cb.test(a))return c(new Xa.EINVAL("mode not a valid octal string",a)),!1;return parseInt(a,8)&Ia}return void 0!==b?b:(c(new Xa.EINVAL("mode not valid",a)),!1)}function $(a,b,c,e){function g(f,g){f?e(f):(_a.setMode(c,g),d(a,b,g,{mtime:Date.now()},e))}b=ya(b),"number"!=typeof c?e(new Xa.EINVAL("mode must be number",b)):f(a,b,g)}function _(a,b,c,e){function f(f,g){f?e(f):(g.mode=c,d(a,b.path,g,{mtime:Date.now()},e))}"number"!=typeof c?e(new Xa.EINVAL("mode must be a number")):b.getNode(a,f)}function aa(a,b,c,e,g){function h(f,h){f?g(f):(h.uid=c,h.gid=e,d(a,b,h,{mtime:Date.now()},g))}b=ya(b),f(a,b,h)}function ba(a,b,c,e,f){function g(g,h){g?f(g):(h.uid=c,h.gid=e,d(a,b.path,h,{mtime:Date.now()},f))}b.getNode(a,g)} +function ca(a,b,c,d,e){I(c,e)&&C(b,c,d,e)}function da(a,b,c,d,e){var f=a.openFiles[c];f?D(b,f,d,e):e(new Xa.EBADF)}function ea(a,b,c,d,e,f,g){"function"==typeof f&&(g=f,f=null),I(c,g)&&A(b,c,d,e,f,g)}function fa(a,b,c,d,e,f,g){"function"==typeof f&&(g=f,f=null);var h=a.openFiles[c];h?wa(h.flags).contains(Na)?B(b,h,d,e,f,g):g(new Xa.EBADF("descriptor does not permit writing")):g(new Xa.EBADF)}function ga(a,b,c,d,e){I(c,e)&&E(b,c,d,e)}function ha(a,b,c,d,e){var f=a.openFiles[c];f?wa(f.flags).contains(Na)?F(b,f,d,e):e(new Xa.EBADF("descriptor does not permit writing")):e(new Xa.EBADF)}function ia(a,b,c,d,e,f){function g(a,b){a?f(a):b.size+d<0?f(new Xa.EINVAL("resulting file offset would be negative")):(h.position=b.size+d,f(null,h.position))}var h=a.openFiles[c];h||f(new Xa.EBADF),"SET"===e?d<0?f(new Xa.EINVAL("resulting file offset would be negative")):(h.position=d,f(null,h.position)):"CUR"===e?h.position+d<0?f(new Xa.EINVAL("resulting file offset would be negative")):(h.position+=d,f(null,h.position)):"END"===e?p(b,h,g):f(new Xa.EINVAL("whence argument is not a proper value"))}function ja(a,b,c,d){I(c,d)&&t(b,c,d)}function ka(a,b,c,d,e,f){if(I(c,f)){var g=Date.now();d=d||g,e=e||g,y(b,c,d,e,f)}}function la(a,b,c,d,e,f){var g=Date.now();d=d||g,e=e||g;var h=a.openFiles[c];h?wa(h.flags).contains(Na)?z(b,h,d,e,f):f(new Xa.EBADF("descriptor does not permit writing")):f(new Xa.EBADF)}function ma(a,b,c,d,e){I(c,e)&&(d=Z(d,"mode"))&&$(b,c,d,e)}function na(a,b,c,d,e){if(d=Z(d,"mode")){var f=a.openFiles[c];f?wa(f.flags).contains(Na)?_(b,f,d,e):e(new Xa.EBADF("descriptor does not permit writing")):e(new Xa.EBADF)}}function oa(a,b,c,d,e,f){if(I(c,f))return Y(d)?Y(e)?void aa(b,c,d,e,f):f(new Xa.EINVAL("gid must be a valid integer",e)):f(new Xa.EINVAL("uid must be a valid integer",d))}function pa(a,b,c,d,e,f){if(!Y(d))return f(new Xa.EINVAL("uid must be a valid integer",d));if(!Y(e))return f(new Xa.EINVAL("gid must be a valid integer",e));var g=a.openFiles[c];g?wa(g.flags).contains(Na)?ba(b,g,d,e,f):f(new Xa.EBADF("descriptor does not permit writing")):f(new Xa.EBADF)}function qa(a,b,c,e,g){function h(a,c){a?g(a):(y=c,d(b,e,y,{ctime:D},g))}function i(a){a?g(a):b.getObject(x[C].id,h)}function k(a){a?g(a):(u.id===w.id&&(v=x),delete v[B],b.putObject(u.data,v,i))}function l(a){a?g(a):(x[C]=v[B],b.putObject(w.data,x,k))}function m(a,c){a?g(a):(x=c,wa(x).has(C)?j(b,e,l):l())}function n(a,c){a?g(a):(w=c,b.getObject(w.data,m))}function o(a,c){a?g(a):(v=c,f(b,A,n))}function p(a,c){a?g(a):(u=c,b.getObject(c.data,o))}function q(a){a?g(a):s(b,c,g)}function t(a,d){a?g(a):d.type===Fa?f(b,z,p):r(b,c,e,q)}if(I(c,g)&&I(e,g)){c=ya(c),e=ya(e);var u,v,w,x,y,z=xa.dirname(c),A=xa.dirname(c),B=xa.basename(c),C=xa.basename(e),D=Date.now();f(b,c,t)}}function ra(a,b,c,d,e,f){f=arguments[arguments.length-1],I(c,!0,f)&&I(d,f)&&u(b,c,d,f)}function sa(a,b,c,d){I(c,d)&&v(b,c,d)}function ta(a,b,c,d){function e(b,e){if(b)d(b);else{var f=new ab(c,e,a.name);d(null,f)}}I(c,d)&&q(b,c,e)}function ua(a,b,c,d,e){e=arguments[arguments.length-1],d=d||0,I(c,e)&&w(b,c,d,e)}function va(a,b,c,d,e){e=arguments[arguments.length-1],d=d||0;var f=a.openFiles[c];f?wa(f.flags).contains(Na)?x(b,f,d,e):e(new Xa.EBADF("descriptor does not permit writing")):e(new Xa.EBADF)}var wa=a("../../lib/nodash.js"),xa=a("../path.js"),ya=xa.normalize,za=xa.dirname,Aa=xa.basename,Ba=xa.isAbsolute,Ca=xa.isNull,Da=a("../constants.js"),Ea=Da.NODE_TYPE_FILE,Fa=Da.NODE_TYPE_DIRECTORY,Ga=Da.NODE_TYPE_SYMBOLIC_LINK,Ha=Da.NODE_TYPE_META,Ia=(Da.DEFAULT_FILE_PERMISSIONS,Da.DEFAULT_DIR_PERMISSIONS,Da.FULL_READ_WRITE_EXEC_PERMISSIONS),Ja=Da.ROOT_DIRECTORY_NAME,Ka=Da.SUPER_NODE_ID,La=Da.SYMLOOP_MAX,Ma=Da.O_READ,Na=Da.O_WRITE,Oa=Da.O_CREATE,Pa=Da.O_EXCLUSIVE,Qa=(Da.O_TRUNCATE,Da.O_APPEND),Ra=Da.O_FLAGS,Sa=Da.XATTR_CREATE,Ta=Da.XATTR_REPLACE,Ua=Da.FS_NOMTIME,Va=Da.FS_NOCTIME,Wa=a("../encoding.js"),Xa=a("../errors.js"),Ya=a("../directory-entry.js"),Za=a("../open-file-description.js"),$a=a("../super-node.js"),_a=a("../node.js"),ab=a("../stats.js"),bb=a("../buffer.js"),cb=/^[0-7]+$/;b.exports={ensureRootDirectory:h,open:J,chmod:ma,fchmod:na,chown:oa,fchown:pa,close:K,mknod:L,mkdir:M,rmdir:N,unlink:R,stat:O,fstat:P,link:Q,read:S,readFile:T,write:U,writeFile:V,appendFile:W,exists:X,getxattr:ca,fgetxattr:da,setxattr:ea,fsetxattr:fa,removexattr:ga,fremovexattr:ha,lseek:ia,readdir:ja,utimes:ka,futimes:la,rename:qa,symlink:ra,readlink:sa,lstat:ta,truncate:ua,ftruncate:va}},{"../../lib/nodash.js":4,"../buffer.js":14,"../constants.js":15,"../directory-entry.js":16,"../encoding.js":17,"../errors.js":18,"../node.js":23,"../open-file-description.js":24,"../path.js":25,"../stats.js":33,"../super-node.js":34}],20:[function(a,b,c){function d(a){return"function"==typeof a?a:function(a){if(a)throw a}}function e(a){a&&console.error("Filer error: ",a)}function f(a,b){function c(){J.forEach(function(a){a.call(this)}.bind(G)),J=null}function d(a){return function(b){function c(b){var d=C();a.getObject(d,function(a,e){if(a)return void b(a);e?c(b):b(null,d)})}if(g(B).contains(p))return void b(null,C());c(b)}}function f(a){if(a.length){var b=s.getInstance();a.forEach(function(a){b.emit(a.event,a.path)})}}a=a||{},b=b||e;var B=a.flags,C=a.guid?a.guid:v,D=a.provider||new q.Default(a.name||k),E=a.name||D.name,F=g(B).contains(l),G=this;G.readyState=n,G.name=E,G.error=null,G.stdin=w,G.stdout=x,G.stderr=y,G.constants=j.fsConstants,this.Shell=r.bind(void 0,this);var H={},I=z;Object.defineProperty(this,"openFiles",{get:function(){return H}}),this.allocDescriptor=function(a){var b=I++;return H[b]=a,b},this.releaseDescriptor=function(a){delete H[a]};var J=[];this.queueOrRun=function(a){var b;return m==G.readyState?a.call(G):o==G.readyState?b=new u.EFILESYSTEMERROR("unknown error"):J.push(a),b},this.watch=function(a,b,c){if(h(a))throw new Error("Path must be a string without null bytes.");"function"==typeof b&&(c=b,b={}),b=b||{},c=c||i;var d=new t;return d.start(a,!1,b.recursive),d.on("change",c),d},D.open(function(a){function e(a){function e(a){var b=D[a]();return b.flags=B,b.changes=[],b.guid=d(b),b.close=function(){var a=b.changes;f(a),a.length=0},b}G.provider={openReadWriteContext:function(){return e("getReadWriteContext")},openReadOnlyContext:function(){return e("getReadOnlyContext")}},G.readyState=a?o:m,c(),b(a,G)}if(a)return e(a);var g=D.getReadWriteContext();g.guid=d(g),F?g.clear(function(a){if(a)return e(a);A.ensureRootDirectory(g,e)}):A.ensureRootDirectory(g,e)})}var g=a("../../lib/nodash.js"),h=a("../path.js").isNull,i=a("../shared.js").nop,j=a("../constants.js"),k=j.FILE_SYSTEM_NAME,l=j.FS_FORMAT,m=j.FS_READY,n=j.FS_PENDING,o=j.FS_ERROR,p=j.FS_NODUPEIDCHECK,q=a("../providers/index.js"),r=a("../shell/shell.js"),s=a("../../lib/intercom.js"),t=a("../fs-watcher.js"),u=a("../errors.js"),v=a("../shared.js").guid,w=j.STDIN,x=j.STDOUT,y=j.STDERR,z=j.FIRST_DESCRIPTOR,A=a("./implementation.js");f.providers=q,["open","chmod","fchmod","chown","fchown","close","mknod","mkdir","rmdir","stat","fstat","link","unlink","read","readFile","write","writeFile","appendFile","exists","lseek","readdir","rename","readlink","symlink","lstat","truncate","ftruncate","utimes","futimes","setxattr","getxattr","fsetxattr","fgetxattr","removexattr","fremovexattr"].forEach(function(a){f.prototype[a]=function(){var b=this,c=Array.prototype.slice.call(arguments,0),e=c.length-1,f="function"!=typeof c[e],g=d(c[e]),h=b.queueOrRun(function(){function d(){h.close(),g.apply(b,arguments)}var h=b.provider.openReadWriteContext();if(o===b.readyState){var i=new u.EFILESYSTEMERROR("filesystem unavailable, operation canceled");return g.call(b,i)}f?c.push(d):c[e]=d;var j=[b,h].concat(c);A[a].apply(null,j)});h&&g(h)}}),b.exports=f},{"../../lib/intercom.js":3,"../../lib/nodash.js":4,"../constants.js":15,"../errors.js":18,"../fs-watcher.js":21,"../path.js":25,"../providers/index.js":26,"../shared.js":30,"../shell/shell.js":32,"./implementation.js":19}],21:[function(a,b,c){function d(){function a(a){(c===a||h&&0===a.indexOf(b))&&d.trigger("change","change",a)}e.call(this);var b,c,d=this,h=!1;d.start=function(d,e,i){if(!c){if(f.isNull(d))throw new Error("Path must be a string without null bytes.");c=f.normalize(d),h=!0===i,h&&(b="/"===c?"/":c+"/");g.getInstance().on("change",a)}},d.close=function(){g.getInstance().off("change",a),d.removeAllListeners("change")}}var e=a("../lib/eventemitter.js"),f=a("./path.js"),g=a("../lib/intercom.js");d.prototype=new e,d.prototype.constructor=d,b.exports=d},{"../lib/eventemitter.js":2,"../lib/intercom.js":3,"./path.js":25}],22:[function(a,b,c){b.exports={FileSystem:a("./filesystem/interface.js"),Buffer:a("./buffer.js"),Path:a("./path.js"),Errors:a("./errors.js"),Shell:a("./shell/shell.js")}},{"./buffer.js":14,"./errors.js":18,"./filesystem/interface.js":20,"./path.js":25,"./shell/shell.js":32}],23:[function(a,b,c){function d(a,b){switch(a){case h:return(b||n)|k;case i:return(b||m)|l;case g:default:return(b||m)|j}}function e(a){var b=Date.now();this.id=a.id,this.type=a.type||g,this.size=a.size||0,this.atime=a.atime||b,this.ctime=a.ctime||b,this.mtime=a.mtime||b,this.flags=a.flags||[],this.xattrs=a.xattrs||{},this.nlinks=a.nlinks||0,this.data=a.data,this.version=a.version||1,this.mode=a.mode||d(this.type),this.uid=a.uid||0,this.gid=a.gid||0}function f(a,b,c){a[b]?c(null):a.guid(function(d,e){a[b]=e,c(d)})}var g=a("./constants.js").NODE_TYPE_FILE,h=a("./constants.js").NODE_TYPE_DIRECTORY,i=a("./constants.js").NODE_TYPE_SYMBOLIC_LINK,j=(a("./constants.js").NODE_TYPE_META,a("./constants.js").ROOT_DIRECTORY_NAME,a("./constants.js").S_IFREG),k=a("./constants.js").S_IFDIR,l=a("./constants.js").S_IFLNK,m=a("./constants.js").DEFAULT_FILE_PERMISSIONS,n=a("./constants.js").DEFAULT_DIR_PERMISSIONS;e.create=function(a,b){f(a,"id",function(c){if(c)return void b(c);f(a,"data",function(c){if(c)return void b(c);b(null,new e(a))})})},e.setMode=function(a,b){b.mode=d(b.type,a)},b.exports=e},{"./constants.js":15}],24:[function(a,b,c){function d(a,b,c,d){this.path=a,this.id=b,this.flags=c,this.position=d}var e=a("./errors.js");d.prototype.getNode=function(a,b){function c(a,c){return a?b(a):c?void b(null,c):b(new e.EBADF("file descriptor refers to unknown node",f))}var d=this.id,f=this.path;a.getObject(d,c)},b.exports=d},{"./errors.js":18}],25:[function(a,b,c){function d(a,b){for(var c=0,d=a.length-1;d>=0;d--){var e=a[d];"."===e?a.splice(d,1):".."===e?(a.splice(d,1),c++):c&&(a.splice(d,1),c--)}if(b)for(;c--;c)a.unshift("..");return a}function e(){for(var a="",b=!1,c=arguments.length-1;c>=-1&&!b;c--){var e=c>=0?arguments[c]:"/";"string"==typeof e&&e&&(a=e+"/"+a,b="/"===e.charAt(0))}return a=d(a.split("/").filter(function(a){return!!a}),!b).join("/"),(b?"/":"")+a||"."}function f(a){var b="/"===a.charAt(0);a.substr(-1);return a=d(a.split("/").filter(function(a){return!!a}),!b).join("/"),a||b||(a="."),(b?"/":"")+a}function g(){return f(Array.prototype.slice.call(arguments,0).filter(function(a,b){return a&&"string"==typeof a}).join("/"))}function h(a,b){function c(a){for(var b=0;b=0&&""===a[c];c--);return b>c?[]:a.slice(b,c-b+1)}a=e(a).substr(1),b=e(b).substr(1);for(var d=c(a.split("/")),f=c(b.split("/")),g=Math.min(d.length,f.length),h=g,i=0;i=0;d--){var e=a[d];"."===e?a.splice(d,1):".."===e?(a.splice(d,1),c++):c&&(a.splice(d,1),c--)}if(b)for(;c--;c)a.unshift("..");return a}function e(){for(var a="",b=!1,c=arguments.length-1;c>=-1&&!b;c--){var e=c>=0?arguments[c]:"/";"string"==typeof e&&e&&(a=e+"/"+a,b="/"===e.charAt(0))}return a=d(a.split("/").filter(function(a){return!!a}),!b).join("/"),(b?"/":"")+a||"."}function f(a){var b="/"===a.charAt(0);"/"===a.substr(-1);return a=d(a.split("/").filter(function(a){return!!a}),!b).join("/"),a||b||(a="."),(b?"/":"")+a}function g(){var a=Array.prototype.slice.call(arguments,0);return f(a.filter(function(a,b){return a&&"string"==typeof a}).join("/"))}function h(a,b){function c(a){for(var b=0;b=0&&""===a[c];c--);return b>c?[]:a.slice(b,c-b+1)}a=e(a).substr(1),b=e(b).substr(1);for(var d=c(a.split("/")),f=c(b.split("/")),g=Math.min(d.length,f.length),h=g,i=0;g>i;i++)if(d[i]!==f[i]){h=i;break}for(var j=[],i=h;i=0;d--){var e=a[d];"."===e?a.splice(d,1):".."===e?(a.splice(d,1),c++):c&&(a.splice(d,1),c--)}if(b)for(;c--;c)a.unshift("..");return a}function e(){for(var a="",b=!1,c=arguments.length-1;c>=-1&&!b;c--){var e=c>=0?arguments[c]:"/";"string"==typeof e&&e&&(a=e+"/"+a,b="/"===e.charAt(0))}return a=d(a.split("/").filter(function(a){return!!a}),!b).join("/"),(b?"/":"")+a||"."}function f(a){var b="/"===a.charAt(0);a.substr(-1);return a=d(a.split("/").filter(function(a){return!!a}),!b).join("/"),a||b||(a="."),(b?"/":"")+a}function g(){return f(Array.prototype.slice.call(arguments,0).filter(function(a,b){return a&&"string"==typeof a}).join("/"))}function h(a,b){function c(a){for(var b=0;b=0&&""===a[c];c--);return b>c?[]:a.slice(b,c-b+1)}a=e(a).substr(1),b=e(b).substr(1);for(var d=c(a.split("/")),f=c(b.split("/")),g=Math.min(d.length,f.length),h=g,i=0;i