diff --git a/src/html5/index.html b/src/html5/index.html index 4677662e3e..3fca162c3a 100644 --- a/src/html5/index.html +++ b/src/html5/index.html @@ -147,7 +147,7 @@ - + diff --git a/src/html5/js/lib/lz4.js b/src/html5/js/lib/lz4.js new file mode 100644 index 0000000000..d9ecbe9a0a --- /dev/null +++ b/src/html5/js/lib/lz4.js @@ -0,0 +1,7746 @@ +require=(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> 8) & 0xFF +} + +exports.blockChecksum = function (d) { + return XXH(d, CHECKSUM_SEED).toNumber() +} + +exports.streamChecksum = function (d, c) { + if (d === null) + return c.digest().toNumber() + + if (c === null) + c = XXH(CHECKSUM_SEED) + + return c.update(d) +} + +// Provide simple readInt32LE as the Buffer ones from node and browserify are incompatible +exports.readInt32LE = function (buffer, offset) { + return (buffer[offset]) | + (buffer[offset + 1] << 8) | + (buffer[offset + 2] << 16) | + (buffer[offset + 3] << 24) +} + +exports.bindings = require('./binding') + +},{"./binding":1,"xxhashjs":10}],1:[function(require,module,exports){ +/** + Javascript version of the key LZ4 C functions + */ +var uint32 = require('cuint').UINT32 + +if (!Math.imul) Math.imul = function imul(a, b) { + var ah = a >>> 16; + var al = a & 0xffff; + var bh = b >>> 16; + var bl = b & 0xffff; + return (al*bl + ((ah*bl + al*bh) << 16))|0; +}; + +/** + * Decode a block. Assumptions: input contains all sequences of a + * chunk, output is large enough to receive the decoded data. + * If the output buffer is too small, an error will be thrown. + * If the returned value is negative, an error occured at the returned offset. + * + * @param input {Buffer} input data + * @param output {Buffer} output data + * @return {Number} number of decoded bytes + * @private + */ +exports.uncompress = function (input, output, sIdx, eIdx) { + sIdx = sIdx || 0 + eIdx = eIdx || (input.length - sIdx) + // Process each sequence in the incoming data + for (var i = sIdx, n = eIdx, j = 0; i < n;) { + var token = input[i++] + + // Literals + var literals_length = (token >> 4) + if (literals_length > 0) { + // length of literals + var l = literals_length + 240 + while (l === 255) { + l = input[i++] + literals_length += l + } + + // Copy the literals + var end = i + literals_length + while (i < end) output[j++] = input[i++] + + // End of buffer? + if (i === n) return j + } + + // Match copy + // 2 bytes offset (little endian) + var offset = input[i++] | (input[i++] << 8) + + // 0 is an invalid offset value + if (offset === 0 || offset > j) return -(i-2) + + // length of match copy + var match_length = (token & 0xf) + var l = match_length + 240 + while (l === 255) { + l = input[i++] + match_length += l + } + + // Copy the match + var pos = j - offset // position of the match copy in the current output + var end = j + match_length + 4 // minmatch = 4 + while (j < end) output[j++] = output[pos++] + } + + return j +} + +var + maxInputSize = 0x7E000000 +, minMatch = 4 +// uint32() optimization +, hashLog = 16 +, hashShift = (minMatch * 8) - hashLog +, hashSize = 1 << hashLog + +, copyLength = 8 +, lastLiterals = 5 +, mfLimit = copyLength + minMatch +, skipStrength = 6 + +, mlBits = 4 +, mlMask = (1 << mlBits) - 1 +, runBits = 8 - mlBits +, runMask = (1 << runBits) - 1 + +, hasher = 2654435761 + +// CompressBound returns the maximum length of a lz4 block, given it's uncompressed length +exports.compressBound = function (isize) { + return isize > maxInputSize + ? 0 + : (isize + (isize/255) + 16) | 0 +} + +exports.compress = function (src, dst, sIdx, eIdx) { + // V8 optimization: non sparse array with integers + var hashTable = new Array(hashSize) + for (var i = 0; i < hashSize; i++) { + hashTable[i] = 0 + } + return compressBlock(src, dst, 0, hashTable, sIdx || 0, eIdx || dst.length) +} + +exports.compressHC = exports.compress + +exports.compressDependent = compressBlock + +function compressBlock (src, dst, pos, hashTable, sIdx, eIdx) { + var dpos = sIdx + var dlen = eIdx - sIdx + var anchor = 0 + + if (src.length >= maxInputSize) throw new Error("input too large") + + // Minimum of input bytes for compression (LZ4 specs) + if (src.length > mfLimit) { + var n = exports.compressBound(src.length) + if ( dlen < n ) throw Error("output too small: " + dlen + " < " + n) + + var + step = 1 + , findMatchAttempts = (1 << skipStrength) + 3 + // Keep last few bytes incompressible (LZ4 specs): + // last 5 bytes must be literals + , srcLength = src.length - mfLimit + + while (pos + minMatch < srcLength) { + // Find a match + // min match of 4 bytes aka sequence + var sequenceLowBits = src[pos+1]<<8 | src[pos] + var sequenceHighBits = src[pos+3]<<8 | src[pos+2] + // compute hash for the current sequence + var hash = Math.imul(sequenceLowBits | (sequenceHighBits << 16), hasher) >>> hashShift + // get the position of the sequence matching the hash + // NB. since 2 different sequences may have the same hash + // it is double-checked below + // do -1 to distinguish between initialized and uninitialized values + var ref = hashTable[hash] - 1 + // save position of current sequence in hash table + hashTable[hash] = pos + 1 + + // first reference or within 64k limit or current sequence !== hashed one: no match + if ( ref < 0 || + ((pos - ref) >>> 16) > 0 || + ( + ((src[ref+3]<<8 | src[ref+2]) != sequenceHighBits) || + ((src[ref+1]<<8 | src[ref]) != sequenceLowBits ) + ) + ) { + // increase step if nothing found within limit + step = findMatchAttempts++ >> skipStrength + pos += step + continue + } + + findMatchAttempts = (1 << skipStrength) + 3 + + // got a match + var literals_length = pos - anchor + var offset = pos - ref + + // minMatch already verified + pos += minMatch + ref += minMatch + + // move to the end of the match (>=minMatch) + var match_length = pos + while (pos < srcLength && src[pos] == src[ref]) { + pos++ + ref++ + } + + // match length + match_length = pos - match_length + + // token + var token = match_length < mlMask ? match_length : mlMask + + // encode literals length + if (literals_length >= runMask) { + // add match length to the token + dst[dpos++] = (runMask << mlBits) + token + for (var len = literals_length - runMask; len > 254; len -= 255) { + dst[dpos++] = 255 + } + dst[dpos++] = len + } else { + // add match length to the token + dst[dpos++] = (literals_length << mlBits) + token + } + + // write literals + for (var i = 0; i < literals_length; i++) { + dst[dpos++] = src[anchor+i] + } + + // encode offset + dst[dpos++] = offset + dst[dpos++] = (offset >> 8) + + // encode match length + if (match_length >= mlMask) { + match_length -= mlMask + while (match_length >= 255) { + match_length -= 255 + dst[dpos++] = 255 + } + + dst[dpos++] = match_length + } + + anchor = pos + } + } + + // cannot compress input + if (anchor == 0) return 0 + + // Write last literals + // encode literals length + literals_length = src.length - anchor + if (literals_length >= runMask) { + // add match length to the token + dst[dpos++] = (runMask << mlBits) + for (var ln = literals_length - runMask; ln > 254; ln -= 255) { + dst[dpos++] = 255 + } + dst[dpos++] = ln + } else { + // add match length to the token + dst[dpos++] = (literals_length << mlBits) + } + + // write literals + pos = anchor + while (pos < src.length) { + dst[dpos++] = src[pos++] + } + + return dpos +} + +},{"cuint":7}],2:[function(require,module,exports){ +(function (Buffer){ +var Decoder = require('./decoder_stream') + +/** + Decode an LZ4 stream + */ +function LZ4_uncompress (input, options) { + var output = [] + var decoder = new Decoder(options) + + decoder.on('data', function (chunk) { + output.push(chunk) + }) + + decoder.end(input) + + return Buffer.concat(output) +} + +exports.LZ4_uncompress = LZ4_uncompress +}).call(this,require("buffer").Buffer) +},{"./decoder_stream":3,"buffer":"buffer"}],3:[function(require,module,exports){ +(function (Buffer){ +var Transform = require('stream').Transform +var inherits = require('util').inherits + +var lz4_static = require('./static') +var utils = lz4_static.utils +var lz4_binding = utils.bindings +var lz4_jsbinding = require('./binding') + +var STATES = lz4_static.STATES +var SIZES = lz4_static.SIZES + +function Decoder (options) { + if ( !(this instanceof Decoder) ) + return new Decoder(options) + + Transform.call(this, options) + // Options + this.options = options || {} + + this.binding = this.options.useJS ? lz4_jsbinding : lz4_binding + + // Encoded data being processed + this.buffer = null + // Current position within the data + this.pos = 0 + this.descriptor = null + + // Current state of the parsing + this.state = STATES.MAGIC + + this.notEnoughData = false + this.descriptorStart = 0 + this.streamSize = null + this.dictId = null + this.currentStreamChecksum = null + this.dataBlockSize = 0 + this.skippableSize = 0 +} +inherits(Decoder, Transform) + +Decoder.prototype._transform = function (data, encoding, done) { + // Handle skippable data + if (this.skippableSize > 0) { + this.skippableSize -= data.length + if (this.skippableSize > 0) { + // More to skip + done() + return + } + + data = data.slice(-this.skippableSize) + this.skippableSize = 0 + this.state = STATES.MAGIC + } + // Buffer the incoming data + this.buffer = this.buffer + ? Buffer.concat( [ this.buffer, data ], this.buffer.length + data.length ) + : data + + this._main(done) +} + +Decoder.prototype.emit_Error = function (msg) { + this.emit( 'error', new Error(msg + ' @' + this.pos) ) +} + +Decoder.prototype.check_Size = function (n) { + var delta = this.buffer.length - this.pos + if (delta <= 0 || delta < n) { + if (this.notEnoughData) this.emit_Error( 'Unexpected end of LZ4 stream' ) + return true + } + + this.pos += n + return false +} + +Decoder.prototype.read_MagicNumber = function () { + var pos = this.pos + if ( this.check_Size(SIZES.MAGIC) ) return true + + var magic = utils.readInt32LE(this.buffer, pos) + + // Skippable chunk + if ( (magic & 0xFFFFFFF0) === lz4_static.MAGICNUMBER_SKIPPABLE ) { + this.state = STATES.SKIP_SIZE + return + } + + // LZ4 stream + if ( magic !== lz4_static.MAGICNUMBER ) { + this.pos = pos + this.emit_Error( 'Invalid magic number: ' + magic.toString(16).toUpperCase() ) + return true + } + + this.state = STATES.DESCRIPTOR +} + +Decoder.prototype.read_SkippableSize = function () { + var pos = this.pos + if ( this.check_Size(SIZES.SKIP_SIZE) ) return true + this.state = STATES.SKIP_DATA + this.skippableSize = utils.readInt32LE(this.buffer, pos) +} + +Decoder.prototype.read_Descriptor = function () { + // Flags + var pos = this.pos + if ( this.check_Size(SIZES.DESCRIPTOR) ) return true + + this.descriptorStart = pos + + // version + var descriptor_flg = this.buffer[pos] + var version = descriptor_flg >> 6 + if ( version !== lz4_static.VERSION ) { + this.pos = pos + this.emit_Error( 'Invalid version: ' + version + ' != ' + lz4_static.VERSION ) + return true + } + + // flags + // reserved bit should not be set + if ( (descriptor_flg >> 1) & 0x1 ) { + this.pos = pos + this.emit_Error('Reserved bit set') + return true + } + + var blockMaxSizeIndex = (this.buffer[pos+1] >> 4) & 0x7 + var blockMaxSize = lz4_static.blockMaxSizes[ blockMaxSizeIndex ] + if ( blockMaxSize === null ) { + this.pos = pos + this.emit_Error( 'Invalid block max size: ' + blockMaxSizeIndex ) + return true + } + + this.descriptor = { + blockIndependence: Boolean( (descriptor_flg >> 5) & 0x1 ) + , blockChecksum: Boolean( (descriptor_flg >> 4) & 0x1 ) + , blockMaxSize: blockMaxSize + , streamSize: Boolean( (descriptor_flg >> 3) & 0x1 ) + , streamChecksum: Boolean( (descriptor_flg >> 2) & 0x1 ) + , dict: Boolean( descriptor_flg & 0x1 ) + , dictId: 0 + } + + this.state = STATES.SIZE +} + +Decoder.prototype.read_Size = function () { + if (this.descriptor.streamSize) { + var pos = this.pos + if ( this.check_Size(SIZES.SIZE) ) return true + //TODO max size is unsigned 64 bits + this.streamSize = this.buffer.slice(pos, pos + 8) + } + + this.state = STATES.DICTID +} + +Decoder.prototype.read_DictId = function () { + if (this.descriptor.dictId) { + var pos = this.pos + if ( this.check_Size(SIZES.DICTID) ) return true + this.dictId = utils.readInt32LE(this.buffer, pos) + } + + this.state = STATES.DESCRIPTOR_CHECKSUM +} + +Decoder.prototype.read_DescriptorChecksum = function () { + var pos = this.pos + if ( this.check_Size(SIZES.DESCRIPTOR_CHECKSUM) ) return true + + var checksum = this.buffer[pos] + var currentChecksum = utils.descriptorChecksum( this.buffer.slice(this.descriptorStart, pos) ) + if (currentChecksum !== checksum) { + this.pos = pos + this.emit_Error( 'Invalid stream descriptor checksum' ) + return true + } + + this.state = STATES.DATABLOCK_SIZE +} + +Decoder.prototype.read_DataBlockSize = function () { + var pos = this.pos + if ( this.check_Size(SIZES.DATABLOCK_SIZE) ) return true + var datablock_size = utils.readInt32LE(this.buffer, pos) + // Uncompressed + if ( datablock_size === lz4_static.EOS ) { + this.state = STATES.EOS + return + } + +// if (datablock_size > this.descriptor.blockMaxSize) { +// this.emit_Error( 'ASSERTION: invalid datablock_size: ' + datablock_size.toString(16).toUpperCase() + ' > ' + this.descriptor.blockMaxSize.toString(16).toUpperCase() ) +// } + this.dataBlockSize = datablock_size + + this.state = STATES.DATABLOCK_DATA +} + +Decoder.prototype.read_DataBlockData = function () { + var pos = this.pos + var datablock_size = this.dataBlockSize + if ( datablock_size & 0x80000000 ) { + // Uncompressed size + datablock_size = datablock_size & 0x7FFFFFFF + } + if ( this.check_Size(datablock_size) ) return true + + this.dataBlock = this.buffer.slice(pos, pos + datablock_size) + + this.state = STATES.DATABLOCK_CHECKSUM +} + +Decoder.prototype.read_DataBlockChecksum = function () { + var pos = this.pos + if (this.descriptor.blockChecksum) { + if ( this.check_Size(SIZES.DATABLOCK_CHECKSUM) ) return true + var checksum = utils.readInt32LE(this.buffer, this.pos-4) + var currentChecksum = utils.blockChecksum( this.dataBlock ) + if (currentChecksum !== checksum) { + this.pos = pos + this.emit_Error( 'Invalid block checksum' ) + return true + } + } + + this.state = STATES.DATABLOCK_UNCOMPRESS +} + +Decoder.prototype.uncompress_DataBlock = function () { + var uncompressed + // uncompressed? + if ( this.dataBlockSize & 0x80000000 ) { + uncompressed = this.dataBlock + } else { + uncompressed = new Buffer(this.descriptor.blockMaxSize) + var decodedSize = this.binding.uncompress( this.dataBlock, uncompressed ) + if (decodedSize < 0) { + this.emit_Error( 'Invalid data block: ' + (-decodedSize) ) + return true + } + if ( decodedSize < this.descriptor.blockMaxSize ) + uncompressed = uncompressed.slice(0, decodedSize) + } + this.dataBlock = null + this.push( uncompressed ) + + // Stream checksum + if (this.descriptor.streamChecksum) { + this.currentStreamChecksum = utils.streamChecksum(uncompressed, this.currentStreamChecksum) + } + + this.state = STATES.DATABLOCK_SIZE +} + +Decoder.prototype.read_EOS = function () { + if (this.descriptor.streamChecksum) { + var pos = this.pos + if ( this.check_Size(SIZES.EOS) ) return true + var checksum = utils.readInt32LE(this.buffer, pos) + if ( checksum !== utils.streamChecksum(null, this.currentStreamChecksum) ) { + this.pos = pos + this.emit_Error( 'Invalid stream checksum: ' + checksum.toString(16).toUpperCase() ) + return true + } + } + + this.state = STATES.MAGIC +} + +Decoder.prototype._flush = function (done) { + // Error on missing data as no more will be coming + this.notEnoughData = true + this._main(done) +} + +Decoder.prototype._main = function (done) { + var pos = this.pos + var notEnoughData + + while ( !notEnoughData && this.pos < this.buffer.length ) { + if (this.state === STATES.MAGIC) + notEnoughData = this.read_MagicNumber() + + if (this.state === STATES.SKIP_SIZE) + notEnoughData = this.read_SkippableSize() + + if (this.state === STATES.DESCRIPTOR) + notEnoughData = this.read_Descriptor() + + if (this.state === STATES.SIZE) + notEnoughData = this.read_Size() + + if (this.state === STATES.DICTID) + notEnoughData = this.read_DictId() + + if (this.state === STATES.DESCRIPTOR_CHECKSUM) + notEnoughData = this.read_DescriptorChecksum() + + if (this.state === STATES.DATABLOCK_SIZE) + notEnoughData = this.read_DataBlockSize() + + if (this.state === STATES.DATABLOCK_DATA) + notEnoughData = this.read_DataBlockData() + + if (this.state === STATES.DATABLOCK_CHECKSUM) + notEnoughData = this.read_DataBlockChecksum() + + if (this.state === STATES.DATABLOCK_UNCOMPRESS) + notEnoughData = this.uncompress_DataBlock() + + if (this.state === STATES.EOS) + notEnoughData = this.read_EOS() + } + + if (this.pos > pos) { + this.buffer = this.buffer.slice(this.pos) + this.pos = 0 + } + + done() +} + +module.exports = Decoder + +}).call(this,require("buffer").Buffer) +},{"./binding":1,"./static":6,"buffer":"buffer","stream":33,"util":36}],4:[function(require,module,exports){ +(function (Buffer){ +var Encoder = require('./encoder_stream') + +/** + Encode an LZ4 stream + */ +function LZ4_compress (input, options) { + var output = [] + var encoder = new Encoder(options) + + encoder.on('data', function (chunk) { + output.push(chunk) + }) + + encoder.end(input) + + return Buffer.concat(output) +} + +exports.LZ4_compress = LZ4_compress + +}).call(this,require("buffer").Buffer) +},{"./encoder_stream":5,"buffer":"buffer"}],5:[function(require,module,exports){ +(function (Buffer){ +var Transform = require('stream').Transform +var inherits = require('util').inherits + +var lz4_static = require('./static') +var utils = lz4_static.utils +var lz4_binding = utils.bindings +var lz4_jsbinding = require('./binding') + +var STATES = lz4_static.STATES +var SIZES = lz4_static.SIZES + +var defaultOptions = { + blockIndependence: true +, blockChecksum: false +, blockMaxSize: 4<<20 +, streamSize: false +, streamChecksum: true +, dict: false +, dictId: 0 +, highCompression: false +} + +function Encoder (options) { + if ( !(this instanceof Encoder) ) + return new Encoder(options) + + Transform.call(this, options) + + // Set the options + var o = options || defaultOptions + if (o !== defaultOptions) + Object.keys(defaultOptions).forEach(function (p) { + if ( !o.hasOwnProperty(p) ) o[p] = defaultOptions[p] + }) + + this.options = o + + this.binding = this.options.useJS ? lz4_jsbinding : lz4_binding + this.compress = o.highCompression ? this.binding.compressHC : this.binding.compress + + // Build the stream descriptor from the options + // flags + var descriptor_flg = 0 + descriptor_flg = descriptor_flg | (lz4_static.VERSION << 6) // Version + descriptor_flg = descriptor_flg | ((o.blockIndependence & 1) << 5) // Block independence + descriptor_flg = descriptor_flg | ((o.blockChecksum & 1) << 4) // Block checksum + descriptor_flg = descriptor_flg | ((o.streamSize & 1) << 3) // Stream size + descriptor_flg = descriptor_flg | ((o.streamChecksum & 1) << 2) // Stream checksum + // Reserved bit + descriptor_flg = descriptor_flg | (o.dict & 1) // Preset dictionary + + // block maximum size + var descriptor_bd = lz4_static.blockMaxSizes.indexOf(o.blockMaxSize) + if (descriptor_bd < 0) + throw new Error('Invalid blockMaxSize: ' + o.blockMaxSize) + + this.descriptor = { flg: descriptor_flg, bd: (descriptor_bd & 0x7) << 4 } + + // Data being processed + this.buffer = [] + this.length = 0 + + this.first = true + this.checksum = null +} +inherits(Encoder, Transform) + +// Header = magic number + stream descriptor +Encoder.prototype.headerSize = function () { + var streamSizeSize = this.options.streamSize ? SIZES.DESCRIPTOR : 0 + var dictSize = this.options.dict ? SIZES.DICTID : 0 + + return SIZES.MAGIC + 1 + 1 + streamSizeSize + dictSize + 1 +} + +Encoder.prototype.header = function () { + var headerSize = this.headerSize() + var output = new Buffer(headerSize) + + this.state = STATES.MAGIC + output.writeInt32LE(lz4_static.MAGICNUMBER, 0, true) + + this.state = STATES.DESCRIPTOR + var descriptor = output.slice(SIZES.MAGIC, output.length - 1) + + // Update the stream descriptor + descriptor.writeUInt8(this.descriptor.flg, 0, true) + descriptor.writeUInt8(this.descriptor.bd, 1, true) + + var pos = 2 + this.state = STATES.SIZE + if (this.options.streamSize) { + //TODO only 32bits size supported + descriptor.writeInt32LE(0, pos, true) + descriptor.writeInt32LE(this.size, pos + 4, true) + pos += SIZES.SIZE + } + this.state = STATES.DICTID + if (this.options.dict) { + descriptor.writeInt32LE(this.dictId, pos, true) + pos += SIZES.DICTID + } + + this.state = STATES.DESCRIPTOR_CHECKSUM + output.writeUInt8( + utils.descriptorChecksum( descriptor ) + , SIZES.MAGIC + pos, false + ) + + return output +} + +Encoder.prototype.update_Checksum = function (data) { + // Calculate the stream checksum + this.state = STATES.CHECKSUM_UPDATE + if (this.options.streamChecksum) { + this.checksum = utils.streamChecksum(data, this.checksum) + } +} + +Encoder.prototype.compress_DataBlock = function (data) { + this.state = STATES.DATABLOCK_COMPRESS + var dbChecksumSize = this.options.blockChecksum ? SIZES.DATABLOCK_CHECKSUM : 0 + var maxBufSize = this.binding.compressBound(data.length) + var buf = new Buffer( SIZES.DATABLOCK_SIZE + maxBufSize + dbChecksumSize ) + var compressed = buf.slice(SIZES.DATABLOCK_SIZE, SIZES.DATABLOCK_SIZE + maxBufSize) + var compressedSize = this.compress(data, compressed) + + // Set the block size + this.state = STATES.DATABLOCK_SIZE + // Block size shall never be larger than blockMaxSize + // console.log("blockMaxSize", this.options.blockMaxSize, "compressedSize", compressedSize) + if (compressedSize > 0 && compressedSize <= this.options.blockMaxSize) { + // highest bit is 0 (compressed data) + buf.writeUInt32LE(compressedSize, 0, true) + buf = buf.slice(0, SIZES.DATABLOCK_SIZE + compressedSize + dbChecksumSize) + } else { + // Cannot compress the data, leave it as is + // highest bit is 1 (uncompressed data) + buf.writeInt32LE( 0x80000000 | data.length, 0, true) + buf = buf.slice(0, SIZES.DATABLOCK_SIZE + data.length + dbChecksumSize) + data.copy(buf, SIZES.DATABLOCK_SIZE); + } + + // Set the block checksum + this.state = STATES.DATABLOCK_CHECKSUM + if (this.options.blockChecksum) { + // xxHash checksum on undecoded data with a seed of 0 + var checksum = buf.slice(-dbChecksumSize) + checksum.writeInt32LE( utils.blockChecksum(compressed), 0, true ) + } + + // Update the stream checksum + this.update_Checksum(data) + + this.size += data.length + + return buf +} + +Encoder.prototype._transform = function (data, encoding, done) { + if (data) { + // Buffer the incoming data + this.buffer.push(data) + this.length += data.length + } + + // Stream header + if (this.first) { + this.push( this.header() ) + this.first = false + } + + var blockMaxSize = this.options.blockMaxSize + // Not enough data for a block + if ( this.length < blockMaxSize ) return done() + + // Build the data to be compressed + var buf = Buffer.concat(this.buffer, this.length) + + for (var j = 0, i = buf.length; i >= blockMaxSize; i -= blockMaxSize, j += blockMaxSize) { + // Compress the block + this.push( this.compress_DataBlock( buf.slice(j, j + blockMaxSize) ) ) + } + + // Set the remaining data + if (i > 0) { + this.buffer = [ buf.slice(j) ] + this.length = this.buffer[0].length + } else { + this.buffer = [] + this.length = 0 + } + + done() +} + +Encoder.prototype._flush = function (done) { + if (this.first) { + this.push( this.header() ) + this.first = false + } + + if (this.length > 0) { + var buf = Buffer.concat(this.buffer, this.length) + this.buffer = [] + this.length = 0 + var cc = this.compress_DataBlock(buf) + this.push( cc ) + } + + if (this.options.streamChecksum) { + this.state = STATES.CHECKSUM + var eos = new Buffer(SIZES.EOS + SIZES.CHECKSUM) + eos.writeInt32LE( utils.streamChecksum(null, this.checksum), SIZES.EOS, true ) + } else { + var eos = new Buffer(SIZES.EOS) + } + + this.state = STATES.EOS + eos.writeInt32LE(lz4_static.EOS, 0, true) + this.push(eos) + + done() +} + +module.exports = Encoder + +}).call(this,require("buffer").Buffer) +},{"./binding":1,"./static":6,"buffer":"buffer","stream":33,"util":36}],6:[function(require,module,exports){ +(function (Buffer){ +/** + * LZ4 based compression and decompression + * Copyright (c) 2014 Pierre Curto + * MIT Licensed + */ + +// LZ4 stream constants +exports.MAGICNUMBER = 0x184D2204 +exports.MAGICNUMBER_BUFFER = new Buffer(4) +exports.MAGICNUMBER_BUFFER.writeUInt32LE(exports.MAGICNUMBER, 0, false) + +exports.EOS = 0 +exports.EOS_BUFFER = new Buffer(4) +exports.EOS_BUFFER.writeUInt32LE(exports.EOS, 0, false) + +exports.VERSION = 1 + +exports.MAGICNUMBER_SKIPPABLE = 0x184D2A50 + +// n/a, n/a, n/a, n/a, 64KB, 256KB, 1MB, 4MB +exports.blockMaxSizes = [ null, null, null, null, 64<<10, 256<<10, 1<<20, 4<<20 ] + +// Compressed file extension +exports.extension = '.lz4' + +// Internal stream states +exports.STATES = { +// Compressed stream + MAGIC: 0 +, DESCRIPTOR: 1 +, SIZE: 2 +, DICTID: 3 +, DESCRIPTOR_CHECKSUM: 4 +, DATABLOCK_SIZE: 5 +, DATABLOCK_DATA: 6 +, DATABLOCK_CHECKSUM: 7 +, DATABLOCK_UNCOMPRESS: 8 +, DATABLOCK_COMPRESS: 9 +, CHECKSUM: 10 +, CHECKSUM_UPDATE: 11 +, EOS: 90 +// Skippable chunk +, SKIP_SIZE: 101 +, SKIP_DATA: 102 +} + +exports.SIZES = { + MAGIC: 4 +, DESCRIPTOR: 2 +, SIZE: 8 +, DICTID: 4 +, DESCRIPTOR_CHECKSUM: 1 +, DATABLOCK_SIZE: 4 +, DATABLOCK_CHECKSUM: 4 +, CHECKSUM: 4 +, EOS: 4 +, SKIP_SIZE: 4 +} + +exports.utils = require('./utils') + +}).call(this,require("buffer").Buffer) +},{"./utils":"./utils","buffer":"buffer"}],7:[function(require,module,exports){ +exports.UINT32 = require('./lib/uint32') +exports.UINT64 = require('./lib/uint64') +},{"./lib/uint32":8,"./lib/uint64":9}],8:[function(require,module,exports){ +/** + C-like unsigned 32 bits integers in Javascript + Copyright (C) 2013, Pierre Curto + MIT license + */ +;(function (root) { + + // Local cache for typical radices + var radixPowerCache = { + 36: UINT32( Math.pow(36, 5) ) + , 16: UINT32( Math.pow(16, 7) ) + , 10: UINT32( Math.pow(10, 9) ) + , 2: UINT32( Math.pow(2, 30) ) + } + var radixCache = { + 36: UINT32(36) + , 16: UINT32(16) + , 10: UINT32(10) + , 2: UINT32(2) + } + + /** + * Represents an unsigned 32 bits integer + * @constructor + * @param {Number|String|Number} low bits | integer as a string | integer as a number + * @param {Number|Number|Undefined} high bits | radix (optional, default=10) + * @return + */ + function UINT32 (l, h) { + if ( !(this instanceof UINT32) ) + return new UINT32(l, h) + + this._low = 0 + this._high = 0 + this.remainder = null + if (typeof h == 'undefined') + return fromNumber.call(this, l) + + if (typeof l == 'string') + return fromString.call(this, l, h) + + fromBits.call(this, l, h) + } + + /** + * Set the current _UINT32_ object with its low and high bits + * @method fromBits + * @param {Number} low bits + * @param {Number} high bits + * @return ThisExpression + */ + function fromBits (l, h) { + this._low = l | 0 + this._high = h | 0 + + return this + } + UINT32.prototype.fromBits = fromBits + + /** + * Set the current _UINT32_ object from a number + * @method fromNumber + * @param {Number} number + * @return ThisExpression + */ + function fromNumber (value) { + this._low = value & 0xFFFF + this._high = value >>> 16 + + return this + } + UINT32.prototype.fromNumber = fromNumber + + /** + * Set the current _UINT32_ object from a string + * @method fromString + * @param {String} integer as a string + * @param {Number} radix (optional, default=10) + * @return ThisExpression + */ + function fromString (s, radix) { + var value = parseInt(s, radix || 10) + + this._low = value & 0xFFFF + this._high = value >>> 16 + + return this + } + UINT32.prototype.fromString = fromString + + /** + * Convert this _UINT32_ to a number + * @method toNumber + * @return {Number} the converted UINT32 + */ + UINT32.prototype.toNumber = function () { + return (this._high << 16) | this._low + } + + /** + * Convert this _UINT32_ to a string + * @method toString + * @param {Number} radix (optional, default=10) + * @return {String} the converted UINT32 + */ + UINT32.prototype.toString = function (radix) { + radix = radix || 10 + var radixUint = radixCache[radix] || new UINT32(radix) + + if ( !this.gt(radixUint) ) return this.toNumber().toString(radix) + + var self = this.clone() + var res = new Array(32) + for (var i = 31; i >= 0; i--) { + self.div(radixUint) + res[i] = self.remainder.toNumber().toString(radix) + if ( !self.gt(radixUint) ) break + } + res[i-1] = self.toNumber().toString(radix) + + return res.join('') + } + + /** + * Add two _UINT32_. The current _UINT32_ stores the result + * @method add + * @param {Object} other UINT32 + * @return ThisExpression + */ + UINT32.prototype.add = function (other) { + var a00 = this._low + other._low + var a16 = a00 >>> 16 + + a16 += this._high + other._high + + this._low = a00 & 0xFFFF + this._high = a16 & 0xFFFF + + return this + } + + /** + * Subtract two _UINT32_. The current _UINT32_ stores the result + * @method subtract + * @param {Object} other UINT32 + * @return ThisExpression + */ + UINT32.prototype.subtract = function (other) { + //TODO inline + return this.add( other.clone().negate() ) + } + + /** + * Multiply two _UINT32_. The current _UINT32_ stores the result + * @method multiply + * @param {Object} other UINT32 + * @return ThisExpression + */ + UINT32.prototype.multiply = function (other) { + /* + a = a00 + a16 + b = b00 + b16 + a*b = (a00 + a16)(b00 + b16) + = a00b00 + a00b16 + a16b00 + a16b16 + + a16b16 overflows the 32bits + */ + var a16 = this._high + var a00 = this._low + var b16 = other._high + var b00 = other._low + +/* Removed to increase speed under normal circumstances (i.e. not multiplying by 0 or 1) + // this == 0 or other == 1: nothing to do + if ((a00 == 0 && a16 == 0) || (b00 == 1 && b16 == 0)) return this + + // other == 0 or this == 1: this = other + if ((b00 == 0 && b16 == 0) || (a00 == 1 && a16 == 0)) { + this._low = other._low + this._high = other._high + return this + } +*/ + + var c16, c00 + c00 = a00 * b00 + c16 = c00 >>> 16 + + c16 += a16 * b00 + c16 &= 0xFFFF // Not required but improves performance + c16 += a00 * b16 + + this._low = c00 & 0xFFFF + this._high = c16 & 0xFFFF + + return this + } + + /** + * Divide two _UINT32_. The current _UINT32_ stores the result. + * The remainder is made available as the _remainder_ property on + * the _UINT32_ object. It can be null, meaning there are no remainder. + * @method div + * @param {Object} other UINT32 + * @return ThisExpression + */ + UINT32.prototype.div = function (other) { + if ( (other._low == 0) && (other._high == 0) ) throw Error('division by zero') + + // other == 1 + if (other._high == 0 && other._low == 1) { + this.remainder = new UINT32(0) + return this + } + + // other > this: 0 + if ( other.gt(this) ) { + this.remainder = new UINT32(0) + this._low = 0 + this._high = 0 + return this + } + // other == this: 1 + if ( this.eq(other) ) { + this.remainder = new UINT32(0) + this._low = 1 + this._high = 0 + return this + } + + // Shift the divisor left until it is higher than the dividend + var _other = other.clone() + var i = -1 + while ( !this.lt(_other) ) { + // High bit can overflow the default 16bits + // Its ok since we right shift after this loop + // The overflown bit must be kept though + _other.shiftLeft(1, true) + i++ + } + + // Set the remainder + this.remainder = this.clone() + // Initialize the current result to 0 + this._low = 0 + this._high = 0 + for (; i >= 0; i--) { + _other.shiftRight(1) + // If shifted divisor is smaller than the dividend + // then subtract it from the dividend + if ( !this.remainder.lt(_other) ) { + this.remainder.subtract(_other) + // Update the current result + if (i >= 16) { + this._high |= 1 << (i - 16) + } else { + this._low |= 1 << i + } + } + } + + return this + } + + /** + * Negate the current _UINT32_ + * @method negate + * @return ThisExpression + */ + UINT32.prototype.negate = function () { + var v = ( ~this._low & 0xFFFF ) + 1 + this._low = v & 0xFFFF + this._high = (~this._high + (v >>> 16)) & 0xFFFF + + return this + } + + /** + * Equals + * @method eq + * @param {Object} other UINT32 + * @return {Boolean} + */ + UINT32.prototype.equals = UINT32.prototype.eq = function (other) { + return (this._low == other._low) && (this._high == other._high) + } + + /** + * Greater than (strict) + * @method gt + * @param {Object} other UINT32 + * @return {Boolean} + */ + UINT32.prototype.greaterThan = UINT32.prototype.gt = function (other) { + if (this._high > other._high) return true + if (this._high < other._high) return false + return this._low > other._low + } + + /** + * Less than (strict) + * @method lt + * @param {Object} other UINT32 + * @return {Boolean} + */ + UINT32.prototype.lessThan = UINT32.prototype.lt = function (other) { + if (this._high < other._high) return true + if (this._high > other._high) return false + return this._low < other._low + } + + /** + * Bitwise OR + * @method or + * @param {Object} other UINT32 + * @return ThisExpression + */ + UINT32.prototype.or = function (other) { + this._low |= other._low + this._high |= other._high + + return this + } + + /** + * Bitwise AND + * @method and + * @param {Object} other UINT32 + * @return ThisExpression + */ + UINT32.prototype.and = function (other) { + this._low &= other._low + this._high &= other._high + + return this + } + + /** + * Bitwise NOT + * @method not + * @return ThisExpression + */ + UINT32.prototype.not = function() { + this._low = ~this._low & 0xFFFF + this._high = ~this._high & 0xFFFF + + return this + } + + /** + * Bitwise XOR + * @method xor + * @param {Object} other UINT32 + * @return ThisExpression + */ + UINT32.prototype.xor = function (other) { + this._low ^= other._low + this._high ^= other._high + + return this + } + + /** + * Bitwise shift right + * @method shiftRight + * @param {Number} number of bits to shift + * @return ThisExpression + */ + UINT32.prototype.shiftRight = UINT32.prototype.shiftr = function (n) { + if (n > 16) { + this._low = this._high >> (n - 16) + this._high = 0 + } else if (n == 16) { + this._low = this._high + this._high = 0 + } else { + this._low = (this._low >> n) | ( (this._high << (16-n)) & 0xFFFF ) + this._high >>= n + } + + return this + } + + /** + * Bitwise shift left + * @method shiftLeft + * @param {Number} number of bits to shift + * @param {Boolean} allow overflow + * @return ThisExpression + */ + UINT32.prototype.shiftLeft = UINT32.prototype.shiftl = function (n, allowOverflow) { + if (n > 16) { + this._high = this._low << (n - 16) + this._low = 0 + if (!allowOverflow) { + this._high &= 0xFFFF + } + } else if (n == 16) { + this._high = this._low + this._low = 0 + } else { + this._high = (this._high << n) | (this._low >> (16-n)) + this._low = (this._low << n) & 0xFFFF + if (!allowOverflow) { + // Overflow only allowed on the high bits... + this._high &= 0xFFFF + } + } + + return this + } + + /** + * Bitwise rotate left + * @method rotl + * @param {Number} number of bits to rotate + * @return ThisExpression + */ + UINT32.prototype.rotateLeft = UINT32.prototype.rotl = function (n) { + var v = (this._high << 16) | this._low + v = (v << n) | (v >>> (32 - n)) + this._low = v & 0xFFFF + this._high = v >>> 16 + + return this + } + + /** + * Bitwise rotate right + * @method rotr + * @param {Number} number of bits to rotate + * @return ThisExpression + */ + UINT32.prototype.rotateRight = UINT32.prototype.rotr = function (n) { + var v = (this._high << 16) | this._low + v = (v >>> n) | (v << (32 - n)) + this._low = v & 0xFFFF + this._high = v >>> 16 + + return this + } + + /** + * Clone the current _UINT32_ + * @method clone + * @return {Object} cloned UINT32 + */ + UINT32.prototype.clone = function () { + return new UINT32(this._low, this._high) + } + + if (typeof define != 'undefined' && define.amd) { + // AMD / RequireJS + define([], function () { + return UINT32 + }) + } else if (typeof module != 'undefined' && module.exports) { + // Node.js + module.exports = UINT32 + } else { + // Browser + root['UINT32'] = UINT32 + } + +})(this) + +},{}],9:[function(require,module,exports){ +/** + C-like unsigned 64 bits integers in Javascript + Copyright (C) 2013, Pierre Curto + MIT license + */ +;(function (root) { + + // Local cache for typical radices + var radixPowerCache = { + 16: UINT64( Math.pow(16, 5) ) + , 10: UINT64( Math.pow(10, 5) ) + , 2: UINT64( Math.pow(2, 5) ) + } + var radixCache = { + 16: UINT64(16) + , 10: UINT64(10) + , 2: UINT64(2) + } + + /** + * Represents an unsigned 64 bits integer + * @constructor + * @param {Number} first low bits (8) + * @param {Number} second low bits (8) + * @param {Number} first high bits (8) + * @param {Number} second high bits (8) + * or + * @param {Number} low bits (32) + * @param {Number} high bits (32) + * or + * @param {String|Number} integer as a string | integer as a number + * @param {Number|Undefined} radix (optional, default=10) + * @return + */ + function UINT64 (a00, a16, a32, a48) { + if ( !(this instanceof UINT64) ) + return new UINT64(a00, a16, a32, a48) + + this.remainder = null + if (typeof a00 == 'string') + return fromString.call(this, a00, a16) + + if (typeof a16 == 'undefined') + return fromNumber.call(this, a00) + + fromBits.apply(this, arguments) + } + + /** + * Set the current _UINT64_ object with its low and high bits + * @method fromBits + * @param {Number} first low bits (8) + * @param {Number} second low bits (8) + * @param {Number} first high bits (8) + * @param {Number} second high bits (8) + * or + * @param {Number} low bits (32) + * @param {Number} high bits (32) + * @return ThisExpression + */ + function fromBits (a00, a16, a32, a48) { + if (typeof a32 == 'undefined') { + this._a00 = a00 & 0xFFFF + this._a16 = a00 >>> 16 + this._a32 = a16 & 0xFFFF + this._a48 = a16 >>> 16 + return this + } + + this._a00 = a00 | 0 + this._a16 = a16 | 0 + this._a32 = a32 | 0 + this._a48 = a48 | 0 + + return this + } + UINT64.prototype.fromBits = fromBits + + /** + * Set the current _UINT64_ object from a number + * @method fromNumber + * @param {Number} number + * @return ThisExpression + */ + function fromNumber (value) { + this._a00 = value & 0xFFFF + this._a16 = value >>> 16 + this._a32 = 0 + this._a48 = 0 + + return this + } + UINT64.prototype.fromNumber = fromNumber + + /** + * Set the current _UINT64_ object from a string + * @method fromString + * @param {String} integer as a string + * @param {Number} radix (optional, default=10) + * @return ThisExpression + */ + function fromString (s, radix) { + radix = radix || 10 + + this._a00 = 0 + this._a16 = 0 + this._a32 = 0 + this._a48 = 0 + + /* + In Javascript, bitwise operators only operate on the first 32 bits + of a number, even though parseInt() encodes numbers with a 53 bits + mantissa. + Therefore UINT64() can only work on 32 bits. + The radix maximum value is 36 (as per ECMA specs) (26 letters + 10 digits) + maximum input value is m = 32bits as 1 = 2^32 - 1 + So the maximum substring length n is: + 36^(n+1) - 1 = 2^32 - 1 + 36^(n+1) = 2^32 + (n+1)ln(36) = 32ln(2) + n = 32ln(2)/ln(36) - 1 + n = 5.189644915687692 + n = 5 + */ + var radixUint = radixPowerCache[radix] || new UINT64( Math.pow(radix, 5) ) + + for (var i = 0, len = s.length; i < len; i += 5) { + var size = Math.min(5, len - i) + var value = parseInt( s.slice(i, i + size), radix ) + this.multiply( + size < 5 + ? new UINT64( Math.pow(radix, size) ) + : radixUint + ) + .add( new UINT64(value) ) + } + + return this + } + UINT64.prototype.fromString = fromString + + /** + * Convert this _UINT64_ to a number (last 32 bits are dropped) + * @method toNumber + * @return {Number} the converted UINT64 + */ + UINT64.prototype.toNumber = function () { + return (this._a16 << 16) | this._a00 + } + + /** + * Convert this _UINT64_ to a string + * @method toString + * @param {Number} radix (optional, default=10) + * @return {String} the converted UINT64 + */ + UINT64.prototype.toString = function (radix) { + radix = radix || 10 + var radixUint = radixCache[radix] || new UINT64(radix) + + if ( !this.gt(radixUint) ) return this.toNumber().toString(radix) + + var self = this.clone() + var res = new Array(64) + for (var i = 63; i >= 0; i--) { + self.div(radixUint) + res[i] = self.remainder.toNumber().toString(radix) + if ( !self.gt(radixUint) ) break + } + res[i-1] = self.toNumber().toString(radix) + + return res.join('') + } + + /** + * Add two _UINT64_. The current _UINT64_ stores the result + * @method add + * @param {Object} other UINT64 + * @return ThisExpression + */ + UINT64.prototype.add = function (other) { + var a00 = this._a00 + other._a00 + + var a16 = a00 >>> 16 + a16 += this._a16 + other._a16 + + var a32 = a16 >>> 16 + a32 += this._a32 + other._a32 + + var a48 = a32 >>> 16 + a48 += this._a48 + other._a48 + + this._a00 = a00 & 0xFFFF + this._a16 = a16 & 0xFFFF + this._a32 = a32 & 0xFFFF + this._a48 = a48 & 0xFFFF + + return this + } + + /** + * Subtract two _UINT64_. The current _UINT64_ stores the result + * @method subtract + * @param {Object} other UINT64 + * @return ThisExpression + */ + UINT64.prototype.subtract = function (other) { + return this.add( other.clone().negate() ) + } + + /** + * Multiply two _UINT64_. The current _UINT64_ stores the result + * @method multiply + * @param {Object} other UINT64 + * @return ThisExpression + */ + UINT64.prototype.multiply = function (other) { + /* + a = a00 + a16 + a32 + a48 + b = b00 + b16 + b32 + b48 + a*b = (a00 + a16 + a32 + a48)(b00 + b16 + b32 + b48) + = a00b00 + a00b16 + a00b32 + a00b48 + + a16b00 + a16b16 + a16b32 + a16b48 + + a32b00 + a32b16 + a32b32 + a32b48 + + a48b00 + a48b16 + a48b32 + a48b48 + + a16b48, a32b32, a48b16, a48b32 and a48b48 overflow the 64 bits + so it comes down to: + a*b = a00b00 + a00b16 + a00b32 + a00b48 + + a16b00 + a16b16 + a16b32 + + a32b00 + a32b16 + + a48b00 + = a00b00 + + a00b16 + a16b00 + + a00b32 + a16b16 + a32b00 + + a00b48 + a16b32 + a32b16 + a48b00 + */ + var a00 = this._a00 + var a16 = this._a16 + var a32 = this._a32 + var a48 = this._a48 + var b00 = other._a00 + var b16 = other._a16 + var b32 = other._a32 + var b48 = other._a48 + + var c00 = a00 * b00 + + var c16 = c00 >>> 16 + c16 += a00 * b16 + var c32 = c16 >>> 16 + c16 &= 0xFFFF + c16 += a16 * b00 + + c32 += c16 >>> 16 + c32 += a00 * b32 + var c48 = c32 >>> 16 + c32 &= 0xFFFF + c32 += a16 * b16 + c48 += c32 >>> 16 + c32 &= 0xFFFF + c32 += a32 * b00 + + c48 += c32 >>> 16 + c48 += a00 * b48 + c48 &= 0xFFFF + c48 += a16 * b32 + c48 &= 0xFFFF + c48 += a32 * b16 + c48 &= 0xFFFF + c48 += a48 * b00 + + this._a00 = c00 & 0xFFFF + this._a16 = c16 & 0xFFFF + this._a32 = c32 & 0xFFFF + this._a48 = c48 & 0xFFFF + + return this + } + + /** + * Divide two _UINT64_. The current _UINT64_ stores the result. + * The remainder is made available as the _remainder_ property on + * the _UINT64_ object. It can be null, meaning there are no remainder. + * @method div + * @param {Object} other UINT64 + * @return ThisExpression + */ + UINT64.prototype.div = function (other) { + if ( (other._a16 == 0) && (other._a32 == 0) && (other._a48 == 0) ) { + if (other._a00 == 0) throw Error('division by zero') + + // other == 1: this + if (other._a00 == 1) { + this.remainder = new UINT64(0) + return this + } + } + + // other > this: 0 + if ( other.gt(this) ) { + this.remainder = new UINT64(0) + this._a00 = 0 + this._a16 = 0 + this._a32 = 0 + this._a48 = 0 + return this + } + // other == this: 1 + if ( this.eq(other) ) { + this.remainder = new UINT64(0) + this._a00 = 1 + this._a16 = 0 + this._a32 = 0 + this._a48 = 0 + return this + } + + // Shift the divisor left until it is higher than the dividend + var _other = other.clone() + var i = -1 + while ( !this.lt(_other) ) { + // High bit can overflow the default 16bits + // Its ok since we right shift after this loop + // The overflown bit must be kept though + _other.shiftLeft(1, true) + i++ + } + + // Set the remainder + this.remainder = this.clone() + // Initialize the current result to 0 + this._a00 = 0 + this._a16 = 0 + this._a32 = 0 + this._a48 = 0 + for (; i >= 0; i--) { + _other.shiftRight(1) + // If shifted divisor is smaller than the dividend + // then subtract it from the dividend + if ( !this.remainder.lt(_other) ) { + this.remainder.subtract(_other) + // Update the current result + if (i >= 48) { + this._a48 |= 1 << (i - 48) + } else if (i >= 32) { + this._a32 |= 1 << (i - 32) + } else if (i >= 16) { + this._a16 |= 1 << (i - 16) + } else { + this._a00 |= 1 << i + } + } + } + + return this + } + + /** + * Negate the current _UINT64_ + * @method negate + * @return ThisExpression + */ + UINT64.prototype.negate = function () { + var v = ( ~this._a00 & 0xFFFF ) + 1 + this._a00 = v & 0xFFFF + v = (~this._a16 & 0xFFFF) + (v >>> 16) + this._a16 = v & 0xFFFF + v = (~this._a32 & 0xFFFF) + (v >>> 16) + this._a32 = v & 0xFFFF + this._a48 = (~this._a48 + (v >>> 16)) & 0xFFFF + + return this + } + + /** + + * @method eq + * @param {Object} other UINT64 + * @return {Boolean} + */ + UINT64.prototype.equals = UINT64.prototype.eq = function (other) { + return (this._a48 == other._a48) && (this._a00 == other._a00) + && (this._a32 == other._a32) && (this._a16 == other._a16) + } + + /** + * Greater than (strict) + * @method gt + * @param {Object} other UINT64 + * @return {Boolean} + */ + UINT64.prototype.greaterThan = UINT64.prototype.gt = function (other) { + if (this._a48 > other._a48) return true + if (this._a48 < other._a48) return false + if (this._a32 > other._a32) return true + if (this._a32 < other._a32) return false + if (this._a16 > other._a16) return true + if (this._a16 < other._a16) return false + return this._a00 > other._a00 + } + + /** + * Less than (strict) + * @method lt + * @param {Object} other UINT64 + * @return {Boolean} + */ + UINT64.prototype.lessThan = UINT64.prototype.lt = function (other) { + if (this._a48 < other._a48) return true + if (this._a48 > other._a48) return false + if (this._a32 < other._a32) return true + if (this._a32 > other._a32) return false + if (this._a16 < other._a16) return true + if (this._a16 > other._a16) return false + return this._a00 < other._a00 + } + + /** + * Bitwise OR + * @method or + * @param {Object} other UINT64 + * @return ThisExpression + */ + UINT64.prototype.or = function (other) { + this._a00 |= other._a00 + this._a16 |= other._a16 + this._a32 |= other._a32 + this._a48 |= other._a48 + + return this + } + + /** + * Bitwise AND + * @method and + * @param {Object} other UINT64 + * @return ThisExpression + */ + UINT64.prototype.and = function (other) { + this._a00 &= other._a00 + this._a16 &= other._a16 + this._a32 &= other._a32 + this._a48 &= other._a48 + + return this + } + + /** + * Bitwise XOR + * @method xor + * @param {Object} other UINT64 + * @return ThisExpression + */ + UINT64.prototype.xor = function (other) { + this._a00 ^= other._a00 + this._a16 ^= other._a16 + this._a32 ^= other._a32 + this._a48 ^= other._a48 + + return this + } + + /** + * Bitwise NOT + * @method not + * @return ThisExpression + */ + UINT64.prototype.not = function() { + this._a00 = ~this._a00 & 0xFFFF + this._a16 = ~this._a16 & 0xFFFF + this._a32 = ~this._a32 & 0xFFFF + this._a48 = ~this._a48 & 0xFFFF + + return this + } + + /** + * Bitwise shift right + * @method shiftRight + * @param {Number} number of bits to shift + * @return ThisExpression + */ + UINT64.prototype.shiftRight = UINT64.prototype.shiftr = function (n) { + n %= 64 + if (n >= 48) { + this._a00 = this._a48 >> (n - 48) + this._a16 = 0 + this._a32 = 0 + this._a48 = 0 + } else if (n >= 32) { + n -= 32 + this._a00 = ( (this._a32 >> n) | (this._a48 << (16-n)) ) & 0xFFFF + this._a16 = (this._a48 >> n) & 0xFFFF + this._a32 = 0 + this._a48 = 0 + } else if (n >= 16) { + n -= 16 + this._a00 = ( (this._a16 >> n) | (this._a32 << (16-n)) ) & 0xFFFF + this._a16 = ( (this._a32 >> n) | (this._a48 << (16-n)) ) & 0xFFFF + this._a32 = (this._a48 >> n) & 0xFFFF + this._a48 = 0 + } else { + this._a00 = ( (this._a00 >> n) | (this._a16 << (16-n)) ) & 0xFFFF + this._a16 = ( (this._a16 >> n) | (this._a32 << (16-n)) ) & 0xFFFF + this._a32 = ( (this._a32 >> n) | (this._a48 << (16-n)) ) & 0xFFFF + this._a48 = (this._a48 >> n) & 0xFFFF + } + + return this + } + + /** + * Bitwise shift left + * @method shiftLeft + * @param {Number} number of bits to shift + * @param {Boolean} allow overflow + * @return ThisExpression + */ + UINT64.prototype.shiftLeft = UINT64.prototype.shiftl = function (n, allowOverflow) { + n %= 64 + if (n >= 48) { + this._a48 = this._a00 << (n - 48) + this._a32 = 0 + this._a16 = 0 + this._a00 = 0 + } else if (n >= 32) { + n -= 32 + this._a48 = (this._a16 << n) | (this._a00 >> (16-n)) + this._a32 = (this._a00 << n) & 0xFFFF + this._a16 = 0 + this._a00 = 0 + } else if (n >= 16) { + n -= 16 + this._a48 = (this._a32 << n) | (this._a16 >> (16-n)) + this._a32 = ( (this._a16 << n) | (this._a00 >> (16-n)) ) & 0xFFFF + this._a16 = (this._a00 << n) & 0xFFFF + this._a00 = 0 + } else { + this._a48 = (this._a48 << n) | (this._a32 >> (16-n)) + this._a32 = ( (this._a32 << n) | (this._a16 >> (16-n)) ) & 0xFFFF + this._a16 = ( (this._a16 << n) | (this._a00 >> (16-n)) ) & 0xFFFF + this._a00 = (this._a00 << n) & 0xFFFF + } + if (!allowOverflow) { + this._a48 &= 0xFFFF + } + + return this + } + + /** + * Bitwise rotate left + * @method rotl + * @param {Number} number of bits to rotate + * @return ThisExpression + */ + UINT64.prototype.rotateLeft = UINT64.prototype.rotl = function (n) { + n %= 64 + if (n == 0) return this + if (n >= 32) { + // A.B.C.D + // B.C.D.A rotl(16) + // C.D.A.B rotl(32) + var v = this._a00 + this._a00 = this._a32 + this._a32 = v + v = this._a48 + this._a48 = this._a16 + this._a16 = v + if (n == 32) return this + n -= 32 + } + + var high = (this._a48 << 16) | this._a32 + var low = (this._a16 << 16) | this._a00 + + var _high = (high << n) | (low >>> (32 - n)) + var _low = (low << n) | (high >>> (32 - n)) + + this._a00 = _low & 0xFFFF + this._a16 = _low >>> 16 + this._a32 = _high & 0xFFFF + this._a48 = _high >>> 16 + + return this + } + + /** + * Bitwise rotate right + * @method rotr + * @param {Number} number of bits to rotate + * @return ThisExpression + */ + UINT64.prototype.rotateRight = UINT64.prototype.rotr = function (n) { + n %= 64 + if (n == 0) return this + if (n >= 32) { + // A.B.C.D + // D.A.B.C rotr(16) + // C.D.A.B rotr(32) + var v = this._a00 + this._a00 = this._a32 + this._a32 = v + v = this._a48 + this._a48 = this._a16 + this._a16 = v + if (n == 32) return this + n -= 32 + } + + var high = (this._a48 << 16) | this._a32 + var low = (this._a16 << 16) | this._a00 + + var _high = (high >>> n) | (low << (32 - n)) + var _low = (low >>> n) | (high << (32 - n)) + + this._a00 = _low & 0xFFFF + this._a16 = _low >>> 16 + this._a32 = _high & 0xFFFF + this._a48 = _high >>> 16 + + return this + } + + /** + * Clone the current _UINT64_ + * @method clone + * @return {Object} cloned UINT64 + */ + UINT64.prototype.clone = function () { + return new UINT64(this._a00, this._a16, this._a32, this._a48) + } + + if (typeof define != 'undefined' && define.amd) { + // AMD / RequireJS + define([], function () { + return UINT64 + }) + } else if (typeof module != 'undefined' && module.exports) { + // Node.js + module.exports = UINT64 + } else { + // Browser + root['UINT64'] = UINT64 + } + +})(this) + +},{}],10:[function(require,module,exports){ +(function (Buffer){ +/** + xxHash implementation in pure Javascript + + Copyright (C) 2013, Pierre Curto + MIT license + */ +;(function (root) { + + var UINT32 = require('cuint').UINT32 + + /* + Merged this sequence of method calls as it speeds up + the calculations by a factor of 2 + */ + // this.v1.add( other.multiply(PRIME32_2) ).rotl(13).multiply(PRIME32_1); + UINT32.prototype.xxh_update = function (low, high) { + var b00 = PRIME32_2._low + var b16 = PRIME32_2._high + + var c16, c00 + c00 = low * b00 + c16 = c00 >>> 16 + + c16 += high * b00 + c16 &= 0xFFFF // Not required but improves performance + c16 += low * b16 + + var a00 = this._low + (c00 & 0xFFFF) + var a16 = a00 >>> 16 + + a16 += this._high + (c16 & 0xFFFF) + + var v = (a16 << 16) | (a00 & 0xFFFF) + v = (v << 13) | (v >>> 19) + + a00 = v & 0xFFFF + a16 = v >>> 16 + + b00 = PRIME32_1._low + b16 = PRIME32_1._high + + c00 = a00 * b00 + c16 = c00 >>> 16 + + c16 += a16 * b00 + c16 &= 0xFFFF // Not required but improves performance + c16 += a00 * b16 + + this._low = c00 & 0xFFFF + this._high = c16 & 0xFFFF + } + + /* + * Constants + */ + var PRIME32_1 = UINT32( '2654435761' ) + var PRIME32_2 = UINT32( '2246822519' ) + var PRIME32_3 = UINT32( '3266489917' ) + var PRIME32_4 = UINT32( '668265263' ) + var PRIME32_5 = UINT32( '374761393' ) + + var PRIME32_1plus2 = PRIME32_1.clone().add(PRIME32_2) + + /** + * Convert string to proper UTF-8 array + * @param str Input string + * @returns {Uint8Array} UTF8 array is returned as uint8 array + */ + function toUTF8Array (str) { + var utf8 = [] + for (var i=0, n=str.length; i < n; i++) { + var charcode = str.charCodeAt(i) + if (charcode < 0x80) utf8.push(charcode) + else if (charcode < 0x800) { + utf8.push(0xc0 | (charcode >> 6), + 0x80 | (charcode & 0x3f)) + } + else if (charcode < 0xd800 || charcode >= 0xe000) { + utf8.push(0xe0 | (charcode >> 12), + 0x80 | ((charcode>>6) & 0x3f), + 0x80 | (charcode & 0x3f)) + } + // surrogate pair + else { + i++; + // UTF-16 encodes 0x10000-0x10FFFF by + // subtracting 0x10000 and splitting the + // 20 bits of 0x0-0xFFFFF into two halves + charcode = 0x10000 + (((charcode & 0x3ff)<<10) + | (str.charCodeAt(i) & 0x3ff)) + utf8.push(0xf0 | (charcode >>18), + 0x80 | ((charcode>>12) & 0x3f), + 0x80 | ((charcode>>6) & 0x3f), + 0x80 | (charcode & 0x3f)) + } + } + + return new Uint8Array(utf8) + } + + /** + * XXH object used as a constructor or a function + * @constructor + * or + * @param {Object|String} input data + * @param {Number|UINT32} seed + * @return ThisExpression + * or + * @return {UINT32} xxHash + */ + function XXH () { + if (arguments.length == 2) + return new XXH( arguments[1] ).update( arguments[0] ).digest() + + if (!(this instanceof XXH)) + return new XXH( arguments[0] ) + + init.call(this, arguments[0]) + } + + /** + * Initialize the XXH instance with the given seed + * @method init + * @param {Number|Object} seed as a number or an unsigned 32 bits integer + * @return ThisExpression + */ + function init (seed) { + this.seed = seed instanceof UINT32 ? seed.clone() : UINT32(seed) + this.v1 = this.seed.clone().add(PRIME32_1plus2) + this.v2 = this.seed.clone().add(PRIME32_2) + this.v3 = this.seed.clone() + this.v4 = this.seed.clone().subtract(PRIME32_1) + this.total_len = 0 + this.memsize = 0 + this.memory = null + + return this + } + XXH.prototype.init = init + + /** + * Add data to be computed for the XXH hash + * @method update + * @param {String|Buffer|ArrayBuffer} input as a string or nodejs Buffer or ArrayBuffer + * @return ThisExpression + */ + XXH.prototype.update = function (input) { + var isString = typeof input == 'string' + var isArrayBuffer + + // Convert all strings to utf-8 first (issue #5) + if (isString) { + input = toUTF8Array(input) + isString = false + isArrayBuffer = true + } + + if (typeof ArrayBuffer !== "undefined" && input instanceof ArrayBuffer) + { + isArrayBuffer = true + input = new Uint8Array(input); + } + + var p = 0 + var len = input.length + var bEnd = p + len + + if (len == 0) return this + + this.total_len += len + + if (this.memsize == 0) + { + if (isString) { + this.memory = '' + } else if (isArrayBuffer) { + this.memory = new Uint8Array(16) + } else { + this.memory = new Buffer(16) + } + } + + if (this.memsize + len < 16) // fill in tmp buffer + { + // XXH_memcpy(this.memory + this.memsize, input, len) + if (isString) { + this.memory += input + } else if (isArrayBuffer) { + this.memory.set( input.subarray(0, len), this.memsize ) + } else { + input.copy( this.memory, this.memsize, 0, len ) + } + + this.memsize += len + return this + } + + if (this.memsize > 0) // some data left from previous update + { + // XXH_memcpy(this.memory + this.memsize, input, 16-this.memsize); + if (isString) { + this.memory += input.slice(0, 16 - this.memsize) + } else if (isArrayBuffer) { + this.memory.set( input.subarray(0, 16 - this.memsize), this.memsize ) + } else { + input.copy( this.memory, this.memsize, 0, 16 - this.memsize ) + } + + var p32 = 0 + if (isString) { + this.v1.xxh_update( + (this.memory.charCodeAt(p32+1) << 8) | this.memory.charCodeAt(p32) + , (this.memory.charCodeAt(p32+3) << 8) | this.memory.charCodeAt(p32+2) + ) + p32 += 4 + this.v2.xxh_update( + (this.memory.charCodeAt(p32+1) << 8) | this.memory.charCodeAt(p32) + , (this.memory.charCodeAt(p32+3) << 8) | this.memory.charCodeAt(p32+2) + ) + p32 += 4 + this.v3.xxh_update( + (this.memory.charCodeAt(p32+1) << 8) | this.memory.charCodeAt(p32) + , (this.memory.charCodeAt(p32+3) << 8) | this.memory.charCodeAt(p32+2) + ) + p32 += 4 + this.v4.xxh_update( + (this.memory.charCodeAt(p32+1) << 8) | this.memory.charCodeAt(p32) + , (this.memory.charCodeAt(p32+3) << 8) | this.memory.charCodeAt(p32+2) + ) + } else { + this.v1.xxh_update( + (this.memory[p32+1] << 8) | this.memory[p32] + , (this.memory[p32+3] << 8) | this.memory[p32+2] + ) + p32 += 4 + this.v2.xxh_update( + (this.memory[p32+1] << 8) | this.memory[p32] + , (this.memory[p32+3] << 8) | this.memory[p32+2] + ) + p32 += 4 + this.v3.xxh_update( + (this.memory[p32+1] << 8) | this.memory[p32] + , (this.memory[p32+3] << 8) | this.memory[p32+2] + ) + p32 += 4 + this.v4.xxh_update( + (this.memory[p32+1] << 8) | this.memory[p32] + , (this.memory[p32+3] << 8) | this.memory[p32+2] + ) + } + + p += 16 - this.memsize + this.memsize = 0 + if (isString) this.memory = '' + } + + if (p <= bEnd - 16) + { + var limit = bEnd - 16 + + do + { + if (isString) { + this.v1.xxh_update( + (input.charCodeAt(p+1) << 8) | input.charCodeAt(p) + , (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2) + ) + p += 4 + this.v2.xxh_update( + (input.charCodeAt(p+1) << 8) | input.charCodeAt(p) + , (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2) + ) + p += 4 + this.v3.xxh_update( + (input.charCodeAt(p+1) << 8) | input.charCodeAt(p) + , (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2) + ) + p += 4 + this.v4.xxh_update( + (input.charCodeAt(p+1) << 8) | input.charCodeAt(p) + , (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2) + ) + } else { + this.v1.xxh_update( + (input[p+1] << 8) | input[p] + , (input[p+3] << 8) | input[p+2] + ) + p += 4 + this.v2.xxh_update( + (input[p+1] << 8) | input[p] + , (input[p+3] << 8) | input[p+2] + ) + p += 4 + this.v3.xxh_update( + (input[p+1] << 8) | input[p] + , (input[p+3] << 8) | input[p+2] + ) + p += 4 + this.v4.xxh_update( + (input[p+1] << 8) | input[p] + , (input[p+3] << 8) | input[p+2] + ) + } + p += 4 + } while (p <= limit) + } + + if (p < bEnd) + { + // XXH_memcpy(this.memory, p, bEnd-p); + if (isString) { + this.memory += input.slice(p) + } else if (isArrayBuffer) { + this.memory.set( input.subarray(p, bEnd), this.memsize ) + } else { + input.copy( this.memory, this.memsize, p, bEnd ) + } + + this.memsize = bEnd - p + } + + return this + } + + /** + * Finalize the XXH computation. The XXH instance is ready for reuse for the given seed + * @method digest + * @return {UINT32} xxHash + */ + XXH.prototype.digest = function () { + var input = this.memory + var isString = typeof input == 'string' + var p = 0 + var bEnd = this.memsize + var h32, h + var u = new UINT32 + + if (this.total_len >= 16) + { + h32 = this.v1.rotl(1).add( this.v2.rotl(7).add( this.v3.rotl(12).add( this.v4.rotl(18) ) ) ) + } + else + { + h32 = this.seed.add( PRIME32_5 ) + } + + h32.add( u.fromNumber(this.total_len) ) + + while (p <= bEnd - 4) + { + if (isString) { + u.fromBits( + (input.charCodeAt(p+1) << 8) | input.charCodeAt(p) + , (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2) + ) + } else { + u.fromBits( + (input[p+1] << 8) | input[p] + , (input[p+3] << 8) | input[p+2] + ) + } + h32 + .add( u.multiply(PRIME32_3) ) + .rotl(17) + .multiply( PRIME32_4 ) + p += 4 + } + + while (p < bEnd) + { + u.fromBits( isString ? input.charCodeAt(p++) : input[p++], 0 ) + h32 + .add( u.multiply(PRIME32_5) ) + .rotl(11) + .multiply(PRIME32_1) + } + + h = h32.clone().shiftRight(15) + h32.xor(h).multiply(PRIME32_2) + + h = h32.clone().shiftRight(13) + h32.xor(h).multiply(PRIME32_3) + + h = h32.clone().shiftRight(16) + h32.xor(h) + + // Reset the state + this.init( this.seed ) + + return h32 + } + + if (typeof define != 'undefined' && define.amd) { + // AMD / RequireJS + define([], function () { + return XXH + }) + } else if (typeof module != 'undefined' && module.exports) { + // Node.js + module.exports = XXH + } else { + // Browser + root['XXH'] = XXH + } + +})(this) + +}).call(this,require("buffer").Buffer) +},{"buffer":"buffer","cuint":7}],11:[function(require,module,exports){ + +},{}],12:[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)) + +},{}],13:[function(require,module,exports){ +exports.read = function (buffer, offset, isLE, mLen, nBytes) { + var e, m + var eLen = nBytes * 8 - mLen - 1 + var eMax = (1 << eLen) - 1 + var eBias = eMax >> 1 + var nBits = -7 + var i = isLE ? (nBytes - 1) : 0 + var d = isLE ? -1 : 1 + var s = buffer[offset + i] + + i += d + + e = s & ((1 << (-nBits)) - 1) + s >>= (-nBits) + nBits += eLen + 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) {} + + if (e === 0) { + e = 1 - eBias + } else if (e === eMax) { + return m ? NaN : ((s ? -1 : 1) * Infinity) + } else { + m = m + Math.pow(2, mLen) + e = e - eBias + } + return (s ? -1 : 1) * m * Math.pow(2, e - mLen) +} + +exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { + var e, m, c + 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) + var i = isLE ? 0 : (nBytes - 1) + var d = isLE ? 1 : -1 + var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 + + value = Math.abs(value) + + if (isNaN(value) || value === Infinity) { + m = isNaN(value) ? 1 : 0 + e = eMax + } else { + e = Math.floor(Math.log(value) / Math.LN2) + if (value * (c = Math.pow(2, -e)) < 1) { + e-- + c *= 2 + } + if (e + eBias >= 1) { + value += rt / c + } else { + value += rt * Math.pow(2, 1 - eBias) + } + if (value * c >= 2) { + e++ + c /= 2 + } + + if (e + eBias >= eMax) { + m = 0 + e = eMax + } else if (e + eBias >= 1) { + m = (value * c - 1) * Math.pow(2, mLen) + e = e + eBias + } else { + m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) + e = 0 + } + } + + for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} + + e = (e << mLen) | m + eLen += mLen + for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} + + buffer[offset + i - d] |= s * 128 +} + +},{}],14:[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); +}; + +},{}],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. + +function EventEmitter() { + this._events = this._events || {}; + this._maxListeners = this._maxListeners || undefined; +} +module.exports = EventEmitter; + +// Backwards-compat with node 0.10.x +EventEmitter.EventEmitter = EventEmitter; + +EventEmitter.prototype._events = undefined; +EventEmitter.prototype._maxListeners = undefined; + +// By default EventEmitters will print a warning if more than 10 listeners are +// added to it. This is a useful default which helps finding memory leaks. +EventEmitter.defaultMaxListeners = 10; + +// Obviously not all Emitters should be limited to 10. This function allows +// that to be increased. Set to zero for unlimited. +EventEmitter.prototype.setMaxListeners = function(n) { + if (!isNumber(n) || n < 0 || isNaN(n)) + throw TypeError('n must be a positive number'); + this._maxListeners = n; + return this; +}; + +EventEmitter.prototype.emit = function(type) { + var er, handler, len, args, i, listeners; + + if (!this._events) + this._events = {}; + + // If there is no 'error' event listener then throw. + if (type === 'error') { + if (!this._events.error || + (isObject(this._events.error) && !this._events.error.length)) { + er = arguments[1]; + if (er instanceof Error) { + throw er; // Unhandled 'error' event + } + throw TypeError('Uncaught, unspecified "error" event.'); + } + } + + handler = this._events[type]; + + if (isUndefined(handler)) + return false; + + if (isFunction(handler)) { + switch (arguments.length) { + // fast cases + case 1: + handler.call(this); + break; + case 2: + handler.call(this, arguments[1]); + break; + case 3: + handler.call(this, arguments[1], arguments[2]); + break; + // slower + default: + args = Array.prototype.slice.call(arguments, 1); + handler.apply(this, args); + } + } else if (isObject(handler)) { + args = Array.prototype.slice.call(arguments, 1); + listeners = handler.slice(); + len = listeners.length; + for (i = 0; i < len; i++) + listeners[i].apply(this, args); + } + + return true; +}; + +EventEmitter.prototype.addListener = function(type, listener) { + var m; + + if (!isFunction(listener)) + throw TypeError('listener must be a function'); + + if (!this._events) + this._events = {}; + + // To avoid recursion in the case that type === "newListener"! Before + // adding it to the listeners, first emit "newListener". + if (this._events.newListener) + this.emit('newListener', type, + isFunction(listener.listener) ? + listener.listener : listener); + + if (!this._events[type]) + // Optimize the case of one listener. Don't need the extra array object. + this._events[type] = listener; + else if (isObject(this._events[type])) + // If we've already got an array, just append. + this._events[type].push(listener); + else + // Adding the second element, need to change to array. + this._events[type] = [this._events[type], listener]; + + // Check for listener leak + if (isObject(this._events[type]) && !this._events[type].warned) { + if (!isUndefined(this._maxListeners)) { + m = this._maxListeners; + } else { + m = EventEmitter.defaultMaxListeners; + } + + if (m && m > 0 && this._events[type].length > m) { + this._events[type].warned = true; + console.error('(node) warning: possible EventEmitter memory ' + + 'leak detected. %d listeners added. ' + + 'Use emitter.setMaxListeners() to increase limit.', + this._events[type].length); + if (typeof console.trace === 'function') { + // not supported in IE 10 + console.trace(); + } + } + } + + return this; +}; + +EventEmitter.prototype.on = EventEmitter.prototype.addListener; + +EventEmitter.prototype.once = function(type, listener) { + if (!isFunction(listener)) + throw TypeError('listener must be a function'); + + var fired = false; + + function g() { + this.removeListener(type, g); + + if (!fired) { + fired = true; + listener.apply(this, arguments); + } + } + + g.listener = listener; + this.on(type, g); + + return this; +}; + +// emits a 'removeListener' event iff the listener was removed +EventEmitter.prototype.removeListener = function(type, listener) { + var list, position, length, i; + + if (!isFunction(listener)) + throw TypeError('listener must be a function'); + + if (!this._events || !this._events[type]) + return this; + + list = this._events[type]; + length = list.length; + position = -1; + + if (list === listener || + (isFunction(list.listener) && list.listener === listener)) { + delete this._events[type]; + if (this._events.removeListener) + this.emit('removeListener', type, listener); + + } else if (isObject(list)) { + for (i = length; i-- > 0;) { + if (list[i] === listener || + (list[i].listener && list[i].listener === listener)) { + position = i; + break; + } + } + + if (position < 0) + return this; + + if (list.length === 1) { + list.length = 0; + delete this._events[type]; + } else { + list.splice(position, 1); + } + + if (this._events.removeListener) + this.emit('removeListener', type, listener); + } + + return this; +}; + +EventEmitter.prototype.removeAllListeners = function(type) { + var key, listeners; + + if (!this._events) + return this; + + // not listening for removeListener, no need to emit + if (!this._events.removeListener) { + if (arguments.length === 0) + this._events = {}; + else if (this._events[type]) + delete this._events[type]; + return this; + } + + // emit removeListener for all listeners on all events + if (arguments.length === 0) { + for (key in this._events) { + if (key === 'removeListener') continue; + this.removeAllListeners(key); + } + this.removeAllListeners('removeListener'); + this._events = {}; + return this; + } + + listeners = this._events[type]; + + if (isFunction(listeners)) { + this.removeListener(type, listeners); + } else if (listeners) { + // LIFO order + while (listeners.length) + this.removeListener(type, listeners[listeners.length - 1]); + } + delete this._events[type]; + + return this; +}; + +EventEmitter.prototype.listeners = function(type) { + var ret; + if (!this._events || !this._events[type]) + ret = []; + else if (isFunction(this._events[type])) + ret = [this._events[type]]; + else + ret = this._events[type].slice(); + return ret; +}; + +EventEmitter.prototype.listenerCount = function(type) { + if (this._events) { + var evlistener = this._events[type]; + + if (isFunction(evlistener)) + return 1; + else if (evlistener) + return evlistener.length; + } + return 0; +}; + +EventEmitter.listenerCount = function(emitter, type) { + return emitter.listenerCount(type); +}; + +function isFunction(arg) { + return typeof arg === 'function'; +} + +function isNumber(arg) { + return typeof arg === 'number'; +} + +function isObject(arg) { + return typeof arg === 'object' && arg !== null; +} + +function isUndefined(arg) { + return arg === void 0; +} + +},{}],16:[function(require,module,exports){ +if (typeof Object.create === 'function') { + // implementation from standard node.js 'util' module + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false, + writable: true, + configurable: true + } + }); + }; +} else { + // old school shim for old browsers + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + var TempCtor = function () {} + TempCtor.prototype = superCtor.prototype + ctor.prototype = new TempCtor() + ctor.prototype.constructor = ctor + } +} + +},{}],17:[function(require,module,exports){ +/** + * Determine if an object is Buffer + * + * Author: Feross Aboukhadijeh + * License: MIT + * + * `npm install is-buffer` + */ + +module.exports = function (obj) { + return !!(obj != null && + (obj._isBuffer || // For Safari 5-7 (missing Object.prototype.constructor) + (obj.constructor && + typeof obj.constructor.isBuffer === 'function' && + obj.constructor.isBuffer(obj)) + )) +} + +},{}],18:[function(require,module,exports){ +module.exports = Array.isArray || function (arr) { + return Object.prototype.toString.call(arr) == '[object Array]'; +}; + +},{}],19:[function(require,module,exports){ +// shim for using process in browser + +var process = module.exports = {}; +var queue = []; +var draining = false; +var currentQueue; +var queueIndex = -1; + +function cleanUpNextTick() { + draining = false; + if (currentQueue.length) { + queue = currentQueue.concat(queue); + } else { + queueIndex = -1; + } + if (queue.length) { + drainQueue(); + } +} + +function drainQueue() { + if (draining) { + return; + } + var timeout = setTimeout(cleanUpNextTick); + draining = true; + + var len = queue.length; + while(len) { + currentQueue = queue; + queue = []; + while (++queueIndex < len) { + if (currentQueue) { + currentQueue[queueIndex].run(); + } + } + queueIndex = -1; + len = queue.length; + } + currentQueue = null; + draining = false; + clearTimeout(timeout); +} + +process.nextTick = function (fun) { + var args = new Array(arguments.length - 1); + if (arguments.length > 1) { + for (var i = 1; i < arguments.length; i++) { + args[i - 1] = arguments[i]; + } + } + queue.push(new Item(fun, args)); + if (queue.length === 1 && !draining) { + setTimeout(drainQueue, 0); + } +}; + +// v8 likes predictible objects +function Item(fun, array) { + this.fun = fun; + this.array = array; +} +Item.prototype.run = function () { + this.fun.apply(null, this.array); +}; +process.title = 'browser'; +process.browser = true; +process.env = {}; +process.argv = []; +process.version = ''; // empty string to avoid regexp issues +process.versions = {}; + +function noop() {} + +process.on = noop; +process.addListener = noop; +process.once = noop; +process.off = noop; +process.removeListener = noop; +process.removeAllListeners = noop; +process.emit = noop; + +process.binding = function (name) { + throw new Error('process.binding is not supported'); +}; + +process.cwd = function () { return '/' }; +process.chdir = function (dir) { + throw new Error('process.chdir is not supported'); +}; +process.umask = function() { return 0; }; + +},{}],20:[function(require,module,exports){ +module.exports = require("./lib/_stream_duplex.js") + +},{"./lib/_stream_duplex.js":21}],21:[function(require,module,exports){ +// a duplex stream is just a stream that is both readable and writable. +// Since JS doesn't have multiple prototypal inheritance, this class +// prototypally inherits from Readable, and then parasitically from +// Writable. + +'use strict'; + +/**/ +var objectKeys = Object.keys || function (obj) { + var keys = []; + for (var key in obj) keys.push(key); + return keys; +} +/**/ + + +module.exports = Duplex; + +/**/ +var processNextTick = require('process-nextick-args'); +/**/ + + + +/**/ +var util = require('core-util-is'); +util.inherits = require('inherits'); +/**/ + +var Readable = require('./_stream_readable'); +var Writable = require('./_stream_writable'); + +util.inherits(Duplex, Readable); + +var keys = objectKeys(Writable.prototype); +for (var v = 0; v < keys.length; v++) { + var method = keys[v]; + if (!Duplex.prototype[method]) + Duplex.prototype[method] = Writable.prototype[method]; +} + +function Duplex(options) { + if (!(this instanceof Duplex)) + return new Duplex(options); + + Readable.call(this, options); + Writable.call(this, options); + + if (options && options.readable === false) + this.readable = false; + + if (options && options.writable === false) + this.writable = false; + + this.allowHalfOpen = true; + if (options && options.allowHalfOpen === false) + this.allowHalfOpen = false; + + this.once('end', onend); +} + +// the no-half-open enforcer +function onend() { + // if we allow half-open state, or if the writable side ended, + // then we're ok. + if (this.allowHalfOpen || this._writableState.ended) + return; + + // no more data can be written. + // But allow more writes to happen in this tick. + processNextTick(onEndNT, this); +} + +function onEndNT(self) { + self.end(); +} + +function forEach (xs, f) { + for (var i = 0, l = xs.length; i < l; i++) { + f(xs[i], i); + } +} + +},{"./_stream_readable":23,"./_stream_writable":25,"core-util-is":26,"inherits":16,"process-nextick-args":27}],22:[function(require,module,exports){ +// a passthrough stream. +// basically just the most minimal sort of Transform stream. +// Every written chunk gets output as-is. + +'use strict'; + +module.exports = PassThrough; + +var Transform = require('./_stream_transform'); + +/**/ +var util = require('core-util-is'); +util.inherits = require('inherits'); +/**/ + +util.inherits(PassThrough, Transform); + +function PassThrough(options) { + if (!(this instanceof PassThrough)) + return new PassThrough(options); + + Transform.call(this, options); +} + +PassThrough.prototype._transform = function(chunk, encoding, cb) { + cb(null, chunk); +}; + +},{"./_stream_transform":24,"core-util-is":26,"inherits":16}],23:[function(require,module,exports){ +(function (process){ +'use strict'; + +module.exports = Readable; + +/**/ +var processNextTick = require('process-nextick-args'); +/**/ + + +/**/ +var isArray = require('isarray'); +/**/ + + +/**/ +var Buffer = require('buffer').Buffer; +/**/ + +Readable.ReadableState = ReadableState; + +var EE = require('events'); + +/**/ +var EElistenerCount = function(emitter, type) { + return emitter.listeners(type).length; +}; +/**/ + + + +/**/ +var Stream; +(function (){try{ + Stream = require('st' + 'ream'); +}catch(_){}finally{ + if (!Stream) + Stream = require('events').EventEmitter; +}}()) +/**/ + +var Buffer = require('buffer').Buffer; + +/**/ +var util = require('core-util-is'); +util.inherits = require('inherits'); +/**/ + + + +/**/ +var debugUtil = require('util'); +var debug; +if (debugUtil && debugUtil.debuglog) { + debug = debugUtil.debuglog('stream'); +} else { + debug = function () {}; +} +/**/ + +var StringDecoder; + +util.inherits(Readable, Stream); + +function ReadableState(options, stream) { + var Duplex = require('./_stream_duplex'); + + options = options || {}; + + // object stream flag. Used to make read(n) ignore n and to + // make all the buffer merging and length checks go away + this.objectMode = !!options.objectMode; + + if (stream instanceof Duplex) + this.objectMode = this.objectMode || !!options.readableObjectMode; + + // the point at which it stops calling _read() to fill the buffer + // Note: 0 is a valid value, means "don't call _read preemptively ever" + var hwm = options.highWaterMark; + var defaultHwm = this.objectMode ? 16 : 16 * 1024; + this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm; + + // cast to ints. + this.highWaterMark = ~~this.highWaterMark; + + this.buffer = []; + this.length = 0; + this.pipes = null; + this.pipesCount = 0; + this.flowing = null; + this.ended = false; + this.endEmitted = false; + this.reading = false; + + // a flag to be able to tell if the onwrite cb is called immediately, + // or on a later tick. We set this to true at first, because any + // actions that shouldn't happen until "later" should generally also + // not happen before the first write call. + this.sync = true; + + // whenever we return null, then we set a flag to say + // that we're awaiting a 'readable' event emission. + this.needReadable = false; + this.emittedReadable = false; + this.readableListening = false; + + // Crypto is kind of old and crusty. Historically, its default string + // encoding is 'binary' so we have to make this configurable. + // Everything else in the universe uses 'utf8', though. + this.defaultEncoding = options.defaultEncoding || 'utf8'; + + // when piping, we only care about 'readable' events that happen + // after read()ing all the bytes and not getting any pushback. + this.ranOut = false; + + // the number of writers that are awaiting a drain event in .pipe()s + this.awaitDrain = 0; + + // if true, a maybeReadMore has been scheduled + this.readingMore = false; + + this.decoder = null; + this.encoding = null; + if (options.encoding) { + if (!StringDecoder) + StringDecoder = require('string_decoder/').StringDecoder; + this.decoder = new StringDecoder(options.encoding); + this.encoding = options.encoding; + } +} + +function Readable(options) { + var Duplex = require('./_stream_duplex'); + + if (!(this instanceof Readable)) + return new Readable(options); + + this._readableState = new ReadableState(options, this); + + // legacy + this.readable = true; + + if (options && typeof options.read === 'function') + this._read = options.read; + + Stream.call(this); +} + +// Manually shove something into the read() buffer. +// This returns true if the highWaterMark has not been hit yet, +// similar to how Writable.write() returns true if you should +// write() some more. +Readable.prototype.push = function(chunk, encoding) { + var state = this._readableState; + + if (!state.objectMode && typeof chunk === 'string') { + encoding = encoding || state.defaultEncoding; + if (encoding !== state.encoding) { + chunk = new Buffer(chunk, encoding); + encoding = ''; + } + } + + return readableAddChunk(this, state, chunk, encoding, false); +}; + +// Unshift should *always* be something directly out of read() +Readable.prototype.unshift = function(chunk) { + var state = this._readableState; + return readableAddChunk(this, state, chunk, '', true); +}; + +Readable.prototype.isPaused = function() { + return this._readableState.flowing === false; +}; + +function readableAddChunk(stream, state, chunk, encoding, addToFront) { + var er = chunkInvalid(state, chunk); + if (er) { + stream.emit('error', er); + } else if (chunk === null) { + state.reading = false; + onEofChunk(stream, state); + } else if (state.objectMode || chunk && chunk.length > 0) { + if (state.ended && !addToFront) { + var e = new Error('stream.push() after EOF'); + stream.emit('error', e); + } else if (state.endEmitted && addToFront) { + var e = new Error('stream.unshift() after end event'); + stream.emit('error', e); + } else { + if (state.decoder && !addToFront && !encoding) + chunk = state.decoder.write(chunk); + + if (!addToFront) + state.reading = false; + + // if we want the data now, just emit it. + if (state.flowing && state.length === 0 && !state.sync) { + stream.emit('data', chunk); + stream.read(0); + } else { + // update the buffer info. + state.length += state.objectMode ? 1 : chunk.length; + if (addToFront) + state.buffer.unshift(chunk); + else + state.buffer.push(chunk); + + if (state.needReadable) + emitReadable(stream); + } + + maybeReadMore(stream, state); + } + } else if (!addToFront) { + state.reading = false; + } + + return needMoreData(state); +} + + +// if it's past the high water mark, we can push in some more. +// Also, if we have no data yet, we can stand some +// more bytes. This is to work around cases where hwm=0, +// such as the repl. Also, if the push() triggered a +// readable event, and the user called read(largeNumber) such that +// needReadable was set, then we ought to push more, so that another +// 'readable' event will be triggered. +function needMoreData(state) { + return !state.ended && + (state.needReadable || + state.length < state.highWaterMark || + state.length === 0); +} + +// backwards compatibility. +Readable.prototype.setEncoding = function(enc) { + if (!StringDecoder) + StringDecoder = require('string_decoder/').StringDecoder; + this._readableState.decoder = new StringDecoder(enc); + this._readableState.encoding = enc; + return this; +}; + +// Don't raise the hwm > 8MB +var MAX_HWM = 0x800000; +function computeNewHighWaterMark(n) { + if (n >= MAX_HWM) { + n = MAX_HWM; + } else { + // Get the next highest power of 2 + n--; + n |= n >>> 1; + n |= n >>> 2; + n |= n >>> 4; + n |= n >>> 8; + n |= n >>> 16; + n++; + } + return n; +} + +function howMuchToRead(n, state) { + if (state.length === 0 && state.ended) + return 0; + + if (state.objectMode) + return n === 0 ? 0 : 1; + + if (n === null || isNaN(n)) { + // only flow one buffer at a time + if (state.flowing && state.buffer.length) + return state.buffer[0].length; + else + return state.length; + } + + if (n <= 0) + return 0; + + // If we're asking for more than the target buffer level, + // then raise the water mark. Bump up to the next highest + // power of 2, to prevent increasing it excessively in tiny + // amounts. + if (n > state.highWaterMark) + state.highWaterMark = computeNewHighWaterMark(n); + + // don't have that much. return null, unless we've ended. + if (n > state.length) { + if (!state.ended) { + state.needReadable = true; + return 0; + } else { + return state.length; + } + } + + return n; +} + +// you can override either this method, or the async _read(n) below. +Readable.prototype.read = function(n) { + debug('read', n); + var state = this._readableState; + var nOrig = n; + + if (typeof n !== 'number' || n > 0) + state.emittedReadable = false; + + // if we're doing read(0) to trigger a readable event, but we + // already have a bunch of data in the buffer, then just trigger + // the 'readable' event and move on. + if (n === 0 && + state.needReadable && + (state.length >= state.highWaterMark || state.ended)) { + debug('read: emitReadable', state.length, state.ended); + if (state.length === 0 && state.ended) + endReadable(this); + else + emitReadable(this); + return null; + } + + n = howMuchToRead(n, state); + + // if we've ended, and we're now clear, then finish it up. + if (n === 0 && state.ended) { + if (state.length === 0) + endReadable(this); + return null; + } + + // All the actual chunk generation logic needs to be + // *below* the call to _read. The reason is that in certain + // synthetic stream cases, such as passthrough streams, _read + // may be a completely synchronous operation which may change + // the state of the read buffer, providing enough data when + // before there was *not* enough. + // + // So, the steps are: + // 1. Figure out what the state of things will be after we do + // a read from the buffer. + // + // 2. If that resulting state will trigger a _read, then call _read. + // Note that this may be asynchronous, or synchronous. Yes, it is + // deeply ugly to write APIs this way, but that still doesn't mean + // that the Readable class should behave improperly, as streams are + // designed to be sync/async agnostic. + // Take note if the _read call is sync or async (ie, if the read call + // has returned yet), so that we know whether or not it's safe to emit + // 'readable' etc. + // + // 3. Actually pull the requested chunks out of the buffer and return. + + // if we need a readable event, then we need to do some reading. + var doRead = state.needReadable; + debug('need readable', doRead); + + // if we currently have less than the highWaterMark, then also read some + if (state.length === 0 || state.length - n < state.highWaterMark) { + doRead = true; + debug('length less than watermark', doRead); + } + + // however, if we've ended, then there's no point, and if we're already + // reading, then it's unnecessary. + if (state.ended || state.reading) { + doRead = false; + debug('reading or ended', doRead); + } + + if (doRead) { + debug('do read'); + state.reading = true; + state.sync = true; + // if the length is currently zero, then we *need* a readable event. + if (state.length === 0) + state.needReadable = true; + // call internal read method + this._read(state.highWaterMark); + state.sync = false; + } + + // If _read pushed data synchronously, then `reading` will be false, + // and we need to re-evaluate how much data we can return to the user. + if (doRead && !state.reading) + n = howMuchToRead(nOrig, state); + + var ret; + if (n > 0) + ret = fromList(n, state); + else + ret = null; + + if (ret === null) { + state.needReadable = true; + n = 0; + } + + state.length -= n; + + // If we have nothing in the buffer, then we want to know + // as soon as we *do* get something into the buffer. + if (state.length === 0 && !state.ended) + state.needReadable = true; + + // If we tried to read() past the EOF, then emit end on the next tick. + if (nOrig !== n && state.ended && state.length === 0) + endReadable(this); + + if (ret !== null) + this.emit('data', ret); + + return ret; +}; + +function chunkInvalid(state, chunk) { + var er = null; + if (!(Buffer.isBuffer(chunk)) && + typeof chunk !== 'string' && + chunk !== null && + chunk !== undefined && + !state.objectMode) { + er = new TypeError('Invalid non-string/buffer chunk'); + } + return er; +} + + +function onEofChunk(stream, state) { + if (state.ended) return; + if (state.decoder) { + var chunk = state.decoder.end(); + if (chunk && chunk.length) { + state.buffer.push(chunk); + state.length += state.objectMode ? 1 : chunk.length; + } + } + state.ended = true; + + // emit 'readable' now to make sure it gets picked up. + emitReadable(stream); +} + +// Don't emit readable right away in sync mode, because this can trigger +// another read() call => stack overflow. This way, it might trigger +// a nextTick recursion warning, but that's not so bad. +function emitReadable(stream) { + var state = stream._readableState; + state.needReadable = false; + if (!state.emittedReadable) { + debug('emitReadable', state.flowing); + state.emittedReadable = true; + if (state.sync) + processNextTick(emitReadable_, stream); + else + emitReadable_(stream); + } +} + +function emitReadable_(stream) { + debug('emit readable'); + stream.emit('readable'); + flow(stream); +} + + +// at this point, the user has presumably seen the 'readable' event, +// and called read() to consume some data. that may have triggered +// in turn another _read(n) call, in which case reading = true if +// it's in progress. +// However, if we're not ended, or reading, and the length < hwm, +// then go ahead and try to read some more preemptively. +function maybeReadMore(stream, state) { + if (!state.readingMore) { + state.readingMore = true; + processNextTick(maybeReadMore_, stream, state); + } +} + +function maybeReadMore_(stream, state) { + var len = state.length; + while (!state.reading && !state.flowing && !state.ended && + state.length < state.highWaterMark) { + debug('maybeReadMore read 0'); + stream.read(0); + if (len === state.length) + // didn't get any data, stop spinning. + break; + else + len = state.length; + } + state.readingMore = false; +} + +// abstract method. to be overridden in specific implementation classes. +// call cb(er, data) where data is <= n in length. +// for virtual (non-string, non-buffer) streams, "length" is somewhat +// arbitrary, and perhaps not very meaningful. +Readable.prototype._read = function(n) { + this.emit('error', new Error('not implemented')); +}; + +Readable.prototype.pipe = function(dest, pipeOpts) { + var src = this; + var state = this._readableState; + + switch (state.pipesCount) { + case 0: + state.pipes = dest; + break; + case 1: + state.pipes = [state.pipes, dest]; + break; + default: + state.pipes.push(dest); + break; + } + state.pipesCount += 1; + debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts); + + var doEnd = (!pipeOpts || pipeOpts.end !== false) && + dest !== process.stdout && + dest !== process.stderr; + + var endFn = doEnd ? onend : cleanup; + if (state.endEmitted) + processNextTick(endFn); + else + src.once('end', endFn); + + dest.on('unpipe', onunpipe); + function onunpipe(readable) { + debug('onunpipe'); + if (readable === src) { + cleanup(); + } + } + + function onend() { + debug('onend'); + dest.end(); + } + + // when the dest drains, it reduces the awaitDrain counter + // on the source. This would be more elegant with a .once() + // handler in flow(), but adding and removing repeatedly is + // too slow. + var ondrain = pipeOnDrain(src); + dest.on('drain', ondrain); + + var cleanedUp = false; + function cleanup() { + debug('cleanup'); + // cleanup event handlers once the pipe is broken + dest.removeListener('close', onclose); + dest.removeListener('finish', onfinish); + dest.removeListener('drain', ondrain); + dest.removeListener('error', onerror); + dest.removeListener('unpipe', onunpipe); + src.removeListener('end', onend); + src.removeListener('end', cleanup); + src.removeListener('data', ondata); + + cleanedUp = true; + + // if the reader is waiting for a drain event from this + // specific writer, then it would cause it to never start + // flowing again. + // So, if this is awaiting a drain, then we just call it now. + // If we don't know, then assume that we are waiting for one. + if (state.awaitDrain && + (!dest._writableState || dest._writableState.needDrain)) + ondrain(); + } + + src.on('data', ondata); + function ondata(chunk) { + debug('ondata'); + var ret = dest.write(chunk); + if (false === ret) { + // If the user unpiped during `dest.write()`, it is possible + // to get stuck in a permanently paused state if that write + // also returned false. + if (state.pipesCount === 1 && + state.pipes[0] === dest && + src.listenerCount('data') === 1 && + !cleanedUp) { + debug('false write response, pause', src._readableState.awaitDrain); + src._readableState.awaitDrain++; + } + src.pause(); + } + } + + // if the dest has an error, then stop piping into it. + // however, don't suppress the throwing behavior for this. + function onerror(er) { + debug('onerror', er); + unpipe(); + dest.removeListener('error', onerror); + if (EElistenerCount(dest, 'error') === 0) + dest.emit('error', er); + } + // This is a brutally ugly hack to make sure that our error handler + // is attached before any userland ones. NEVER DO THIS. + if (!dest._events || !dest._events.error) + dest.on('error', onerror); + else if (isArray(dest._events.error)) + dest._events.error.unshift(onerror); + else + dest._events.error = [onerror, dest._events.error]; + + + // Both close and finish should trigger unpipe, but only once. + function onclose() { + dest.removeListener('finish', onfinish); + unpipe(); + } + dest.once('close', onclose); + function onfinish() { + debug('onfinish'); + dest.removeListener('close', onclose); + unpipe(); + } + dest.once('finish', onfinish); + + function unpipe() { + debug('unpipe'); + src.unpipe(dest); + } + + // tell the dest that it's being piped to + dest.emit('pipe', src); + + // start the flow if it hasn't been started already. + if (!state.flowing) { + debug('pipe resume'); + src.resume(); + } + + return dest; +}; + +function pipeOnDrain(src) { + return function() { + var state = src._readableState; + debug('pipeOnDrain', state.awaitDrain); + if (state.awaitDrain) + state.awaitDrain--; + if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) { + state.flowing = true; + flow(src); + } + }; +} + + +Readable.prototype.unpipe = function(dest) { + var state = this._readableState; + + // if we're not piping anywhere, then do nothing. + if (state.pipesCount === 0) + return this; + + // just one destination. most common case. + if (state.pipesCount === 1) { + // passed in one, but it's not the right one. + if (dest && dest !== state.pipes) + return this; + + if (!dest) + dest = state.pipes; + + // got a match. + state.pipes = null; + state.pipesCount = 0; + state.flowing = false; + if (dest) + dest.emit('unpipe', this); + return this; + } + + // slow case. multiple pipe destinations. + + if (!dest) { + // remove all. + var dests = state.pipes; + var len = state.pipesCount; + state.pipes = null; + state.pipesCount = 0; + state.flowing = false; + + for (var i = 0; i < len; i++) + dests[i].emit('unpipe', this); + return this; + } + + // try to find the right one. + var i = indexOf(state.pipes, dest); + if (i === -1) + return this; + + state.pipes.splice(i, 1); + state.pipesCount -= 1; + if (state.pipesCount === 1) + state.pipes = state.pipes[0]; + + dest.emit('unpipe', this); + + return this; +}; + +// set up data events if they are asked for +// Ensure readable listeners eventually get something +Readable.prototype.on = function(ev, fn) { + var res = Stream.prototype.on.call(this, ev, fn); + + // If listening to data, and it has not explicitly been paused, + // then call resume to start the flow of data on the next tick. + if (ev === 'data' && false !== this._readableState.flowing) { + this.resume(); + } + + if (ev === 'readable' && this.readable) { + var state = this._readableState; + if (!state.readableListening) { + state.readableListening = true; + state.emittedReadable = false; + state.needReadable = true; + if (!state.reading) { + processNextTick(nReadingNextTick, this); + } else if (state.length) { + emitReadable(this, state); + } + } + } + + return res; +}; +Readable.prototype.addListener = Readable.prototype.on; + +function nReadingNextTick(self) { + debug('readable nexttick read 0'); + self.read(0); +} + +// pause() and resume() are remnants of the legacy readable stream API +// If the user uses them, then switch into old mode. +Readable.prototype.resume = function() { + var state = this._readableState; + if (!state.flowing) { + debug('resume'); + state.flowing = true; + resume(this, state); + } + return this; +}; + +function resume(stream, state) { + if (!state.resumeScheduled) { + state.resumeScheduled = true; + processNextTick(resume_, stream, state); + } +} + +function resume_(stream, state) { + if (!state.reading) { + debug('resume read 0'); + stream.read(0); + } + + state.resumeScheduled = false; + stream.emit('resume'); + flow(stream); + if (state.flowing && !state.reading) + stream.read(0); +} + +Readable.prototype.pause = function() { + debug('call pause flowing=%j', this._readableState.flowing); + if (false !== this._readableState.flowing) { + debug('pause'); + this._readableState.flowing = false; + this.emit('pause'); + } + return this; +}; + +function flow(stream) { + var state = stream._readableState; + debug('flow', state.flowing); + if (state.flowing) { + do { + var chunk = stream.read(); + } while (null !== chunk && state.flowing); + } +} + +// wrap an old-style stream as the async data source. +// This is *not* part of the readable stream interface. +// It is an ugly unfortunate mess of history. +Readable.prototype.wrap = function(stream) { + var state = this._readableState; + var paused = false; + + var self = this; + stream.on('end', function() { + debug('wrapped end'); + if (state.decoder && !state.ended) { + var chunk = state.decoder.end(); + if (chunk && chunk.length) + self.push(chunk); + } + + self.push(null); + }); + + stream.on('data', function(chunk) { + debug('wrapped data'); + if (state.decoder) + chunk = state.decoder.write(chunk); + + // don't skip over falsy values in objectMode + if (state.objectMode && (chunk === null || chunk === undefined)) + return; + else if (!state.objectMode && (!chunk || !chunk.length)) + return; + + var ret = self.push(chunk); + if (!ret) { + paused = true; + stream.pause(); + } + }); + + // proxy all the other methods. + // important when wrapping filters and duplexes. + for (var i in stream) { + if (this[i] === undefined && typeof stream[i] === 'function') { + this[i] = function(method) { return function() { + return stream[method].apply(stream, arguments); + }; }(i); + } + } + + // proxy certain important events. + var events = ['error', 'close', 'destroy', 'pause', 'resume']; + forEach(events, function(ev) { + stream.on(ev, self.emit.bind(self, ev)); + }); + + // when we try to consume some more bytes, simply unpause the + // underlying stream. + self._read = function(n) { + debug('wrapped _read', n); + if (paused) { + paused = false; + stream.resume(); + } + }; + + return self; +}; + + +// exposed for testing purposes only. +Readable._fromList = fromList; + +// Pluck off n bytes from an array of buffers. +// Length is the combined lengths of all the buffers in the list. +function fromList(n, state) { + var list = state.buffer; + var length = state.length; + var stringMode = !!state.decoder; + var objectMode = !!state.objectMode; + var ret; + + // nothing in the list, definitely empty. + if (list.length === 0) + return null; + + if (length === 0) + ret = null; + else if (objectMode) + ret = list.shift(); + else if (!n || n >= length) { + // read it all, truncate the array. + if (stringMode) + ret = list.join(''); + else if (list.length === 1) + ret = list[0]; + else + ret = Buffer.concat(list, length); + list.length = 0; + } else { + // read just some of it. + if (n < list[0].length) { + // just take a part of the first list item. + // slice is the same for buffers and strings. + var buf = list[0]; + ret = buf.slice(0, n); + list[0] = buf.slice(n); + } else if (n === list[0].length) { + // first list is a perfect match + ret = list.shift(); + } else { + // complex case. + // we have enough to cover it, but it spans past the first buffer. + if (stringMode) + ret = ''; + else + ret = new Buffer(n); + + var c = 0; + for (var i = 0, l = list.length; i < l && c < n; i++) { + var buf = list[0]; + var cpy = Math.min(n - c, buf.length); + + if (stringMode) + ret += buf.slice(0, cpy); + else + buf.copy(ret, c, 0, cpy); + + if (cpy < buf.length) + list[0] = buf.slice(cpy); + else + list.shift(); + + c += cpy; + } + } + } + + return ret; +} + +function endReadable(stream) { + var state = stream._readableState; + + // If we get here before consuming all the bytes, then that is a + // bug in node. Should never happen. + if (state.length > 0) + throw new Error('endReadable called on non-empty stream'); + + if (!state.endEmitted) { + state.ended = true; + processNextTick(endReadableNT, state, stream); + } +} + +function endReadableNT(state, stream) { + // Check that we didn't get one last unshift. + if (!state.endEmitted && state.length === 0) { + state.endEmitted = true; + stream.readable = false; + stream.emit('end'); + } +} + +function forEach (xs, f) { + for (var i = 0, l = xs.length; i < l; i++) { + f(xs[i], i); + } +} + +function indexOf (xs, x) { + for (var i = 0, l = xs.length; i < l; i++) { + if (xs[i] === x) return i; + } + return -1; +} + +}).call(this,require('_process')) +},{"./_stream_duplex":21,"_process":19,"buffer":"buffer","core-util-is":26,"events":15,"inherits":16,"isarray":18,"process-nextick-args":27,"string_decoder/":34,"util":11}],24:[function(require,module,exports){ +// a transform stream is a readable/writable stream where you do +// something with the data. Sometimes it's called a "filter", +// but that's not a great name for it, since that implies a thing where +// some bits pass through, and others are simply ignored. (That would +// be a valid example of a transform, of course.) +// +// While the output is causally related to the input, it's not a +// necessarily symmetric or synchronous transformation. For example, +// a zlib stream might take multiple plain-text writes(), and then +// emit a single compressed chunk some time in the future. +// +// Here's how this works: +// +// The Transform stream has all the aspects of the readable and writable +// stream classes. When you write(chunk), that calls _write(chunk,cb) +// internally, and returns false if there's a lot of pending writes +// buffered up. When you call read(), that calls _read(n) until +// there's enough pending readable data buffered up. +// +// In a transform stream, the written data is placed in a buffer. When +// _read(n) is called, it transforms the queued up data, calling the +// buffered _write cb's as it consumes chunks. If consuming a single +// written chunk would result in multiple output chunks, then the first +// outputted bit calls the readcb, and subsequent chunks just go into +// the read buffer, and will cause it to emit 'readable' if necessary. +// +// This way, back-pressure is actually determined by the reading side, +// since _read has to be called to start processing a new chunk. However, +// a pathological inflate type of transform can cause excessive buffering +// here. For example, imagine a stream where every byte of input is +// interpreted as an integer from 0-255, and then results in that many +// bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in +// 1kb of data being output. In this case, you could write a very small +// amount of input, and end up with a very large amount of output. In +// such a pathological inflating mechanism, there'd be no way to tell +// the system to stop doing the transform. A single 4MB write could +// cause the system to run out of memory. +// +// However, even in such a pathological case, only a single written chunk +// would be consumed, and then the rest would wait (un-transformed) until +// the results of the previous transformed chunk were consumed. + +'use strict'; + +module.exports = Transform; + +var Duplex = require('./_stream_duplex'); + +/**/ +var util = require('core-util-is'); +util.inherits = require('inherits'); +/**/ + +util.inherits(Transform, Duplex); + + +function TransformState(stream) { + this.afterTransform = function(er, data) { + return afterTransform(stream, er, data); + }; + + this.needTransform = false; + this.transforming = false; + this.writecb = null; + this.writechunk = null; +} + +function afterTransform(stream, er, data) { + var ts = stream._transformState; + ts.transforming = false; + + var cb = ts.writecb; + + if (!cb) + return stream.emit('error', new Error('no writecb in Transform class')); + + ts.writechunk = null; + ts.writecb = null; + + if (data !== null && data !== undefined) + stream.push(data); + + if (cb) + cb(er); + + var rs = stream._readableState; + rs.reading = false; + if (rs.needReadable || rs.length < rs.highWaterMark) { + stream._read(rs.highWaterMark); + } +} + + +function Transform(options) { + if (!(this instanceof Transform)) + return new Transform(options); + + Duplex.call(this, options); + + this._transformState = new TransformState(this); + + // when the writable side finishes, then flush out anything remaining. + var stream = this; + + // start out asking for a readable event once data is transformed. + this._readableState.needReadable = true; + + // we have implemented the _read method, and done the other things + // that Readable wants before the first _read call, so unset the + // sync guard flag. + this._readableState.sync = false; + + if (options) { + if (typeof options.transform === 'function') + this._transform = options.transform; + + if (typeof options.flush === 'function') + this._flush = options.flush; + } + + this.once('prefinish', function() { + if (typeof this._flush === 'function') + this._flush(function(er) { + done(stream, er); + }); + else + done(stream); + }); +} + +Transform.prototype.push = function(chunk, encoding) { + this._transformState.needTransform = false; + return Duplex.prototype.push.call(this, chunk, encoding); +}; + +// This is the part where you do stuff! +// override this function in implementation classes. +// 'chunk' is an input chunk. +// +// Call `push(newChunk)` to pass along transformed output +// to the readable side. You may call 'push' zero or more times. +// +// Call `cb(err)` when you are done with this chunk. If you pass +// an error, then that'll put the hurt on the whole operation. If you +// never call cb(), then you'll never get another chunk. +Transform.prototype._transform = function(chunk, encoding, cb) { + throw new Error('not implemented'); +}; + +Transform.prototype._write = function(chunk, encoding, cb) { + var ts = this._transformState; + ts.writecb = cb; + ts.writechunk = chunk; + ts.writeencoding = encoding; + if (!ts.transforming) { + var rs = this._readableState; + if (ts.needTransform || + rs.needReadable || + rs.length < rs.highWaterMark) + this._read(rs.highWaterMark); + } +}; + +// Doesn't matter what the args are here. +// _transform does all the work. +// That we got here means that the readable side wants more data. +Transform.prototype._read = function(n) { + var ts = this._transformState; + + if (ts.writechunk !== null && ts.writecb && !ts.transforming) { + ts.transforming = true; + this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform); + } else { + // mark that we need a transform, so that any data that comes in + // will get processed, now that we've asked for it. + ts.needTransform = true; + } +}; + + +function done(stream, er) { + if (er) + return stream.emit('error', er); + + // if there's nothing in the write buffer, then that means + // that nothing more will ever be provided + var ws = stream._writableState; + var ts = stream._transformState; + + if (ws.length) + throw new Error('calling transform done when ws.length != 0'); + + if (ts.transforming) + throw new Error('calling transform done when still transforming'); + + return stream.push(null); +} + +},{"./_stream_duplex":21,"core-util-is":26,"inherits":16}],25:[function(require,module,exports){ +// A bit simpler than readable streams. +// Implement an async ._write(chunk, encoding, cb), and it'll handle all +// the drain event emission and buffering. + +'use strict'; + +module.exports = Writable; + +/**/ +var processNextTick = require('process-nextick-args'); +/**/ + + +/**/ +var Buffer = require('buffer').Buffer; +/**/ + +Writable.WritableState = WritableState; + + +/**/ +var util = require('core-util-is'); +util.inherits = require('inherits'); +/**/ + + +/**/ +var internalUtil = { + deprecate: require('util-deprecate') +}; +/**/ + + + +/**/ +var Stream; +(function (){try{ + Stream = require('st' + 'ream'); +}catch(_){}finally{ + if (!Stream) + Stream = require('events').EventEmitter; +}}()) +/**/ + +var Buffer = require('buffer').Buffer; + +util.inherits(Writable, Stream); + +function nop() {} + +function WriteReq(chunk, encoding, cb) { + this.chunk = chunk; + this.encoding = encoding; + this.callback = cb; + this.next = null; +} + +function WritableState(options, stream) { + var Duplex = require('./_stream_duplex'); + + options = options || {}; + + // object stream flag to indicate whether or not this stream + // contains buffers or objects. + this.objectMode = !!options.objectMode; + + if (stream instanceof Duplex) + this.objectMode = this.objectMode || !!options.writableObjectMode; + + // the point at which write() starts returning false + // Note: 0 is a valid value, means that we always return false if + // the entire buffer is not flushed immediately on write() + var hwm = options.highWaterMark; + var defaultHwm = this.objectMode ? 16 : 16 * 1024; + this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm; + + // cast to ints. + this.highWaterMark = ~~this.highWaterMark; + + this.needDrain = false; + // at the start of calling end() + this.ending = false; + // when end() has been called, and returned + this.ended = false; + // when 'finish' is emitted + this.finished = false; + + // should we decode strings into buffers before passing to _write? + // this is here so that some node-core streams can optimize string + // handling at a lower level. + var noDecode = options.decodeStrings === false; + this.decodeStrings = !noDecode; + + // Crypto is kind of old and crusty. Historically, its default string + // encoding is 'binary' so we have to make this configurable. + // Everything else in the universe uses 'utf8', though. + this.defaultEncoding = options.defaultEncoding || 'utf8'; + + // not an actual buffer we keep track of, but a measurement + // of how much we're waiting to get pushed to some underlying + // socket or file. + this.length = 0; + + // a flag to see when we're in the middle of a write. + this.writing = false; + + // when true all writes will be buffered until .uncork() call + this.corked = 0; + + // a flag to be able to tell if the onwrite cb is called immediately, + // or on a later tick. We set this to true at first, because any + // actions that shouldn't happen until "later" should generally also + // not happen before the first write call. + this.sync = true; + + // a flag to know if we're processing previously buffered items, which + // may call the _write() callback in the same tick, so that we don't + // end up in an overlapped onwrite situation. + this.bufferProcessing = false; + + // the callback that's passed to _write(chunk,cb) + this.onwrite = function(er) { + onwrite(stream, er); + }; + + // the callback that the user supplies to write(chunk,encoding,cb) + this.writecb = null; + + // the amount that is being written when _write is called. + this.writelen = 0; + + this.bufferedRequest = null; + this.lastBufferedRequest = null; + + // number of pending user-supplied write callbacks + // this must be 0 before 'finish' can be emitted + this.pendingcb = 0; + + // emit prefinish if the only thing we're waiting for is _write cbs + // This is relevant for synchronous Transform streams + this.prefinished = false; + + // True if the error was already emitted and should not be thrown again + this.errorEmitted = false; +} + +WritableState.prototype.getBuffer = function writableStateGetBuffer() { + var current = this.bufferedRequest; + var out = []; + while (current) { + out.push(current); + current = current.next; + } + return out; +}; + +(function (){try { +Object.defineProperty(WritableState.prototype, 'buffer', { + get: internalUtil.deprecate(function() { + return this.getBuffer(); + }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + + 'instead.') +}); +}catch(_){}}()); + + +function Writable(options) { + var Duplex = require('./_stream_duplex'); + + // Writable ctor is applied to Duplexes, though they're not + // instanceof Writable, they're instanceof Readable. + if (!(this instanceof Writable) && !(this instanceof Duplex)) + return new Writable(options); + + this._writableState = new WritableState(options, this); + + // legacy. + this.writable = true; + + if (options) { + if (typeof options.write === 'function') + this._write = options.write; + + if (typeof options.writev === 'function') + this._writev = options.writev; + } + + Stream.call(this); +} + +// Otherwise people can pipe Writable streams, which is just wrong. +Writable.prototype.pipe = function() { + this.emit('error', new Error('Cannot pipe. Not readable.')); +}; + + +function writeAfterEnd(stream, cb) { + var er = new Error('write after end'); + // TODO: defer error events consistently everywhere, not just the cb + stream.emit('error', er); + processNextTick(cb, er); +} + +// If we get something that is not a buffer, string, null, or undefined, +// and we're not in objectMode, then that's an error. +// Otherwise stream chunks are all considered to be of length=1, and the +// watermarks determine how many objects to keep in the buffer, rather than +// how many bytes or characters. +function validChunk(stream, state, chunk, cb) { + var valid = true; + + if (!(Buffer.isBuffer(chunk)) && + typeof chunk !== 'string' && + chunk !== null && + chunk !== undefined && + !state.objectMode) { + var er = new TypeError('Invalid non-string/buffer chunk'); + stream.emit('error', er); + processNextTick(cb, er); + valid = false; + } + return valid; +} + +Writable.prototype.write = function(chunk, encoding, cb) { + var state = this._writableState; + var ret = false; + + if (typeof encoding === 'function') { + cb = encoding; + encoding = null; + } + + if (Buffer.isBuffer(chunk)) + encoding = 'buffer'; + else if (!encoding) + encoding = state.defaultEncoding; + + if (typeof cb !== 'function') + cb = nop; + + if (state.ended) + writeAfterEnd(this, cb); + else if (validChunk(this, state, chunk, cb)) { + state.pendingcb++; + ret = writeOrBuffer(this, state, chunk, encoding, cb); + } + + return ret; +}; + +Writable.prototype.cork = function() { + var state = this._writableState; + + state.corked++; +}; + +Writable.prototype.uncork = function() { + var state = this._writableState; + + if (state.corked) { + state.corked--; + + if (!state.writing && + !state.corked && + !state.finished && + !state.bufferProcessing && + state.bufferedRequest) + clearBuffer(this, state); + } +}; + +Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) { + // node::ParseEncoding() requires lower case. + if (typeof encoding === 'string') + encoding = encoding.toLowerCase(); + if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', +'ucs2', 'ucs-2','utf16le', 'utf-16le', 'raw'] +.indexOf((encoding + '').toLowerCase()) > -1)) + throw new TypeError('Unknown encoding: ' + encoding); + this._writableState.defaultEncoding = encoding; +}; + +function decodeChunk(state, chunk, encoding) { + if (!state.objectMode && + state.decodeStrings !== false && + typeof chunk === 'string') { + chunk = new Buffer(chunk, encoding); + } + return chunk; +} + +// if we're already writing something, then just put this +// in the queue, and wait our turn. Otherwise, call _write +// If we return false, then we need a drain event, so set that flag. +function writeOrBuffer(stream, state, chunk, encoding, cb) { + chunk = decodeChunk(state, chunk, encoding); + + if (Buffer.isBuffer(chunk)) + encoding = 'buffer'; + var len = state.objectMode ? 1 : chunk.length; + + state.length += len; + + var ret = state.length < state.highWaterMark; + // we must ensure that previous needDrain will not be reset to false. + if (!ret) + state.needDrain = true; + + if (state.writing || state.corked) { + var last = state.lastBufferedRequest; + state.lastBufferedRequest = new WriteReq(chunk, encoding, cb); + if (last) { + last.next = state.lastBufferedRequest; + } else { + state.bufferedRequest = state.lastBufferedRequest; + } + } else { + doWrite(stream, state, false, len, chunk, encoding, cb); + } + + return ret; +} + +function doWrite(stream, state, writev, len, chunk, encoding, cb) { + state.writelen = len; + state.writecb = cb; + state.writing = true; + state.sync = true; + if (writev) + stream._writev(chunk, state.onwrite); + else + stream._write(chunk, encoding, state.onwrite); + state.sync = false; +} + +function onwriteError(stream, state, sync, er, cb) { + --state.pendingcb; + if (sync) + processNextTick(cb, er); + else + cb(er); + + stream._writableState.errorEmitted = true; + stream.emit('error', er); +} + +function onwriteStateUpdate(state) { + state.writing = false; + state.writecb = null; + state.length -= state.writelen; + state.writelen = 0; +} + +function onwrite(stream, er) { + var state = stream._writableState; + var sync = state.sync; + var cb = state.writecb; + + onwriteStateUpdate(state); + + if (er) + onwriteError(stream, state, sync, er, cb); + else { + // Check if we're actually ready to finish, but don't emit yet + var finished = needFinish(state); + + if (!finished && + !state.corked && + !state.bufferProcessing && + state.bufferedRequest) { + clearBuffer(stream, state); + } + + if (sync) { + processNextTick(afterWrite, stream, state, finished, cb); + } else { + afterWrite(stream, state, finished, cb); + } + } +} + +function afterWrite(stream, state, finished, cb) { + if (!finished) + onwriteDrain(stream, state); + state.pendingcb--; + cb(); + finishMaybe(stream, state); +} + +// Must force callback to be called on nextTick, so that we don't +// emit 'drain' before the write() consumer gets the 'false' return +// value, and has a chance to attach a 'drain' listener. +function onwriteDrain(stream, state) { + if (state.length === 0 && state.needDrain) { + state.needDrain = false; + stream.emit('drain'); + } +} + + +// if there's something in the buffer waiting, then process it +function clearBuffer(stream, state) { + state.bufferProcessing = true; + var entry = state.bufferedRequest; + + if (stream._writev && entry && entry.next) { + // Fast case, write everything using _writev() + var buffer = []; + var cbs = []; + while (entry) { + cbs.push(entry.callback); + buffer.push(entry); + entry = entry.next; + } + + // count the one we are adding, as well. + // TODO(isaacs) clean this up + state.pendingcb++; + state.lastBufferedRequest = null; + doWrite(stream, state, true, state.length, buffer, '', function(err) { + for (var i = 0; i < cbs.length; i++) { + state.pendingcb--; + cbs[i](err); + } + }); + + // Clear buffer + } else { + // Slow case, write chunks one-by-one + while (entry) { + var chunk = entry.chunk; + var encoding = entry.encoding; + var cb = entry.callback; + var len = state.objectMode ? 1 : chunk.length; + + doWrite(stream, state, false, len, chunk, encoding, cb); + entry = entry.next; + // if we didn't call the onwrite immediately, then + // it means that we need to wait until it does. + // also, that means that the chunk and cb are currently + // being processed, so move the buffer counter past them. + if (state.writing) { + break; + } + } + + if (entry === null) + state.lastBufferedRequest = null; + } + state.bufferedRequest = entry; + state.bufferProcessing = false; +} + +Writable.prototype._write = function(chunk, encoding, cb) { + cb(new Error('not implemented')); +}; + +Writable.prototype._writev = null; + +Writable.prototype.end = function(chunk, encoding, cb) { + var state = this._writableState; + + if (typeof chunk === 'function') { + cb = chunk; + chunk = null; + encoding = null; + } else if (typeof encoding === 'function') { + cb = encoding; + encoding = null; + } + + if (chunk !== null && chunk !== undefined) + this.write(chunk, encoding); + + // .end() fully uncorks + if (state.corked) { + state.corked = 1; + this.uncork(); + } + + // ignore unnecessary end() calls. + if (!state.ending && !state.finished) + endWritable(this, state, cb); +}; + + +function needFinish(state) { + return (state.ending && + state.length === 0 && + state.bufferedRequest === null && + !state.finished && + !state.writing); +} + +function prefinish(stream, state) { + if (!state.prefinished) { + state.prefinished = true; + stream.emit('prefinish'); + } +} + +function finishMaybe(stream, state) { + var need = needFinish(state); + if (need) { + if (state.pendingcb === 0) { + prefinish(stream, state); + state.finished = true; + stream.emit('finish'); + } else { + prefinish(stream, state); + } + } + return need; +} + +function endWritable(stream, state, cb) { + state.ending = true; + finishMaybe(stream, state); + if (cb) { + if (state.finished) + processNextTick(cb); + else + stream.once('finish', cb); + } + state.ended = true; +} + +},{"./_stream_duplex":21,"buffer":"buffer","core-util-is":26,"events":15,"inherits":16,"process-nextick-args":27,"util-deprecate":28}],26:[function(require,module,exports){ +(function (Buffer){ +// 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. + +// NOTE: These type checking functions intentionally don't use `instanceof` +// because it is fragile and can be easily faked with `Object.create()`. +function isArray(ar) { + return Array.isArray(ar); +} +exports.isArray = isArray; + +function isBoolean(arg) { + return typeof arg === 'boolean'; +} +exports.isBoolean = isBoolean; + +function isNull(arg) { + return arg === null; +} +exports.isNull = isNull; + +function isNullOrUndefined(arg) { + return arg == null; +} +exports.isNullOrUndefined = isNullOrUndefined; + +function isNumber(arg) { + return typeof arg === 'number'; +} +exports.isNumber = isNumber; + +function isString(arg) { + return typeof arg === 'string'; +} +exports.isString = isString; + +function isSymbol(arg) { + return typeof arg === 'symbol'; +} +exports.isSymbol = isSymbol; + +function isUndefined(arg) { + return arg === void 0; +} +exports.isUndefined = isUndefined; + +function isRegExp(re) { + return isObject(re) && objectToString(re) === '[object RegExp]'; +} +exports.isRegExp = isRegExp; + +function isObject(arg) { + return typeof arg === 'object' && arg !== null; +} +exports.isObject = isObject; + +function isDate(d) { + return isObject(d) && objectToString(d) === '[object Date]'; +} +exports.isDate = isDate; + +function isError(e) { + return isObject(e) && + (objectToString(e) === '[object Error]' || e instanceof Error); +} +exports.isError = isError; + +function isFunction(arg) { + return typeof arg === 'function'; +} +exports.isFunction = isFunction; + +function isPrimitive(arg) { + return arg === null || + typeof arg === 'boolean' || + typeof arg === 'number' || + typeof arg === 'string' || + typeof arg === 'symbol' || // ES6 symbol + typeof arg === 'undefined'; +} +exports.isPrimitive = isPrimitive; + +function isBuffer(arg) { + return Buffer.isBuffer(arg); +} +exports.isBuffer = isBuffer; + +function objectToString(o) { + return Object.prototype.toString.call(o); +} +}).call(this,{"isBuffer":require("../../../../insert-module-globals/node_modules/is-buffer/index.js")}) +},{"../../../../insert-module-globals/node_modules/is-buffer/index.js":17}],27:[function(require,module,exports){ +(function (process){ +'use strict'; +module.exports = nextTick; + +function nextTick(fn) { + var args = new Array(arguments.length - 1); + var i = 0; + while (i < args.length) { + args[i++] = arguments[i]; + } + process.nextTick(function afterTick() { + fn.apply(null, args); + }); +} + +}).call(this,require('_process')) +},{"_process":19}],28:[function(require,module,exports){ +(function (global){ + +/** + * Module exports. + */ + +module.exports = deprecate; + +/** + * Mark that a method should not be used. + * Returns a modified function which warns once by default. + * + * If `localStorage.noDeprecation = true` is set, then it is a no-op. + * + * If `localStorage.throwDeprecation = true` is set, then deprecated functions + * will throw an Error when invoked. + * + * If `localStorage.traceDeprecation = true` is set, then deprecated functions + * will invoke `console.trace()` instead of `console.error()`. + * + * @param {Function} fn - the function to deprecate + * @param {String} msg - the string to print to the console when `fn` is invoked + * @returns {Function} a new "deprecated" version of `fn` + * @api public + */ + +function deprecate (fn, msg) { + if (config('noDeprecation')) { + return fn; + } + + var warned = false; + function deprecated() { + if (!warned) { + if (config('throwDeprecation')) { + throw new Error(msg); + } else if (config('traceDeprecation')) { + console.trace(msg); + } else { + console.warn(msg); + } + warned = true; + } + return fn.apply(this, arguments); + } + + return deprecated; +} + +/** + * Checks `localStorage` for boolean values for the given `name`. + * + * @param {String} name + * @returns {Boolean} + * @api private + */ + +function config (name) { + // accessing global.localStorage can trigger a DOMException in sandboxed iframes + try { + if (!global.localStorage) return false; + } catch (_) { + return false; + } + var val = global.localStorage[name]; + if (null == val) return false; + return String(val).toLowerCase() === 'true'; +} + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],29:[function(require,module,exports){ +module.exports = require("./lib/_stream_passthrough.js") + +},{"./lib/_stream_passthrough.js":22}],30:[function(require,module,exports){ +var Stream = (function (){ + try { + return require('st' + 'ream'); // hack to fix a circular dependency issue when used with browserify + } catch(_){} +}()); +exports = module.exports = require('./lib/_stream_readable.js'); +exports.Stream = Stream || exports; +exports.Readable = exports; +exports.Writable = require('./lib/_stream_writable.js'); +exports.Duplex = require('./lib/_stream_duplex.js'); +exports.Transform = require('./lib/_stream_transform.js'); +exports.PassThrough = require('./lib/_stream_passthrough.js'); + +},{"./lib/_stream_duplex.js":21,"./lib/_stream_passthrough.js":22,"./lib/_stream_readable.js":23,"./lib/_stream_transform.js":24,"./lib/_stream_writable.js":25}],31:[function(require,module,exports){ +module.exports = require("./lib/_stream_transform.js") + +},{"./lib/_stream_transform.js":24}],32:[function(require,module,exports){ +module.exports = require("./lib/_stream_writable.js") + +},{"./lib/_stream_writable.js":25}],33:[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. + +module.exports = Stream; + +var EE = require('events').EventEmitter; +var inherits = require('inherits'); + +inherits(Stream, EE); +Stream.Readable = require('readable-stream/readable.js'); +Stream.Writable = require('readable-stream/writable.js'); +Stream.Duplex = require('readable-stream/duplex.js'); +Stream.Transform = require('readable-stream/transform.js'); +Stream.PassThrough = require('readable-stream/passthrough.js'); + +// Backwards-compat with node 0.4.x +Stream.Stream = Stream; + + + +// old-style streams. Note that the pipe method (the only relevant +// part of this class) is overridden in the Readable class. + +function Stream() { + EE.call(this); +} + +Stream.prototype.pipe = function(dest, options) { + var source = this; + + function ondata(chunk) { + if (dest.writable) { + if (false === dest.write(chunk) && source.pause) { + source.pause(); + } + } + } + + source.on('data', ondata); + + function ondrain() { + if (source.readable && source.resume) { + source.resume(); + } + } + + dest.on('drain', ondrain); + + // If the 'end' option is not supplied, dest.end() will be called when + // source gets the 'end' or 'close' events. Only dest.end() once. + if (!dest._isStdio && (!options || options.end !== false)) { + source.on('end', onend); + source.on('close', onclose); + } + + var didOnEnd = false; + function onend() { + if (didOnEnd) return; + didOnEnd = true; + + dest.end(); + } + + + function onclose() { + if (didOnEnd) return; + didOnEnd = true; + + if (typeof dest.destroy === 'function') dest.destroy(); + } + + // don't leave dangling pipes when there are errors. + function onerror(er) { + cleanup(); + if (EE.listenerCount(this, 'error') === 0) { + throw er; // Unhandled stream error in pipe. + } + } + + source.on('error', onerror); + dest.on('error', onerror); + + // remove all the event listeners that were added. + function cleanup() { + source.removeListener('data', ondata); + dest.removeListener('drain', ondrain); + + source.removeListener('end', onend); + source.removeListener('close', onclose); + + source.removeListener('error', onerror); + dest.removeListener('error', onerror); + + source.removeListener('end', cleanup); + source.removeListener('close', cleanup); + + dest.removeListener('close', cleanup); + } + + source.on('end', cleanup); + source.on('close', cleanup); + + dest.on('close', cleanup); + + dest.emit('pipe', source); + + // Allow for unix-like usage: A.pipe(B).pipe(C) + return dest; +}; + +},{"events":15,"inherits":16,"readable-stream/duplex.js":20,"readable-stream/passthrough.js":29,"readable-stream/readable.js":30,"readable-stream/transform.js":31,"readable-stream/writable.js":32}],34:[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 Buffer = require('buffer').Buffer; + +var isBufferEncoding = Buffer.isEncoding + || function(encoding) { + switch (encoding && encoding.toLowerCase()) { + case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw': return true; + default: return false; + } + } + + +function assertEncoding(encoding) { + if (encoding && !isBufferEncoding(encoding)) { + throw new Error('Unknown encoding: ' + encoding); + } +} + +// StringDecoder provides an interface for efficiently splitting a series of +// buffers into a series of JS strings without breaking apart multi-byte +// characters. CESU-8 is handled as part of the UTF-8 encoding. +// +// @TODO Handling all encodings inside a single object makes it very difficult +// to reason about this code, so it should be split up in the future. +// @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code +// points as used by CESU-8. +var StringDecoder = exports.StringDecoder = function(encoding) { + this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, ''); + assertEncoding(encoding); + switch (this.encoding) { + case 'utf8': + // CESU-8 represents each of Surrogate Pair by 3-bytes + this.surrogateSize = 3; + break; + case 'ucs2': + case 'utf16le': + // UTF-16 represents each of Surrogate Pair by 2-bytes + this.surrogateSize = 2; + this.detectIncompleteChar = utf16DetectIncompleteChar; + break; + case 'base64': + // Base-64 stores 3 bytes in 4 chars, and pads the remainder. + this.surrogateSize = 3; + this.detectIncompleteChar = base64DetectIncompleteChar; + break; + default: + this.write = passThroughWrite; + return; + } + + // Enough space to store all bytes of a single character. UTF-8 needs 4 + // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate). + this.charBuffer = new Buffer(6); + // Number of bytes received for the current incomplete multi-byte character. + this.charReceived = 0; + // Number of bytes expected for the current incomplete multi-byte character. + this.charLength = 0; +}; + + +// write decodes the given buffer and returns it as JS string that is +// guaranteed to not contain any partial multi-byte characters. Any partial +// character found at the end of the buffer is buffered up, and will be +// returned when calling write again with the remaining bytes. +// +// Note: Converting a Buffer containing an orphan surrogate to a String +// currently works, but converting a String to a Buffer (via `new Buffer`, or +// Buffer#write) will replace incomplete surrogates with the unicode +// replacement character. See https://codereview.chromium.org/121173009/ . +StringDecoder.prototype.write = function(buffer) { + var charStr = ''; + // if our last write ended with an incomplete multibyte character + while (this.charLength) { + // determine how many remaining bytes this buffer has to offer for this char + var available = (buffer.length >= this.charLength - this.charReceived) ? + this.charLength - this.charReceived : + buffer.length; + + // add the new bytes to the char buffer + buffer.copy(this.charBuffer, this.charReceived, 0, available); + this.charReceived += available; + + if (this.charReceived < this.charLength) { + // still not enough chars in this buffer? wait for more ... + return ''; + } + + // remove bytes belonging to the current character from the buffer + buffer = buffer.slice(available, buffer.length); + + // get the character that was split + charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding); + + // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character + var charCode = charStr.charCodeAt(charStr.length - 1); + if (charCode >= 0xD800 && charCode <= 0xDBFF) { + this.charLength += this.surrogateSize; + charStr = ''; + continue; + } + this.charReceived = this.charLength = 0; + + // if there are no more bytes in this buffer, just emit our char + if (buffer.length === 0) { + return charStr; + } + break; + } + + // determine and set charLength / charReceived + this.detectIncompleteChar(buffer); + + var end = buffer.length; + if (this.charLength) { + // buffer the incomplete character bytes we got + buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end); + end -= this.charReceived; + } + + charStr += buffer.toString(this.encoding, 0, end); + + var end = charStr.length - 1; + var charCode = charStr.charCodeAt(end); + // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character + if (charCode >= 0xD800 && charCode <= 0xDBFF) { + var size = this.surrogateSize; + this.charLength += size; + this.charReceived += size; + this.charBuffer.copy(this.charBuffer, size, 0, size); + buffer.copy(this.charBuffer, 0, 0, size); + return charStr.substring(0, end); + } + + // or just emit the charStr + return charStr; +}; + +// detectIncompleteChar determines if there is an incomplete UTF-8 character at +// the end of the given buffer. If so, it sets this.charLength to the byte +// length that character, and sets this.charReceived to the number of bytes +// that are available for this character. +StringDecoder.prototype.detectIncompleteChar = function(buffer) { + // determine how many bytes we have to check at the end of this buffer + var i = (buffer.length >= 3) ? 3 : buffer.length; + + // Figure out if one of the last i bytes of our buffer announces an + // incomplete char. + for (; i > 0; i--) { + var c = buffer[buffer.length - i]; + + // See http://en.wikipedia.org/wiki/UTF-8#Description + + // 110XXXXX + if (i == 1 && c >> 5 == 0x06) { + this.charLength = 2; + break; + } + + // 1110XXXX + if (i <= 2 && c >> 4 == 0x0E) { + this.charLength = 3; + break; + } + + // 11110XXX + if (i <= 3 && c >> 3 == 0x1E) { + this.charLength = 4; + break; + } + } + this.charReceived = i; +}; + +StringDecoder.prototype.end = function(buffer) { + var res = ''; + if (buffer && buffer.length) + res = this.write(buffer); + + if (this.charReceived) { + var cr = this.charReceived; + var buf = this.charBuffer; + var enc = this.encoding; + res += buf.slice(0, cr).toString(enc); + } + + return res; +}; + +function passThroughWrite(buffer) { + return buffer.toString(this.encoding); +} + +function utf16DetectIncompleteChar(buffer) { + this.charReceived = buffer.length % 2; + this.charLength = this.charReceived ? 2 : 0; +} + +function base64DetectIncompleteChar(buffer) { + this.charReceived = buffer.length % 3; + this.charLength = this.charReceived ? 3 : 0; +} + +},{"buffer":"buffer"}],35:[function(require,module,exports){ +module.exports = function isBuffer(arg) { + return arg && typeof arg === 'object' + && typeof arg.copy === 'function' + && typeof arg.fill === 'function' + && typeof arg.readUInt8 === 'function'; +} +},{}],36:[function(require,module,exports){ +(function (process,global){ +// 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 formatRegExp = /%[sdj%]/g; +exports.format = function(f) { + if (!isString(f)) { + var objects = []; + for (var i = 0; i < arguments.length; i++) { + objects.push(inspect(arguments[i])); + } + return objects.join(' '); + } + + var i = 1; + var args = arguments; + var len = args.length; + var str = String(f).replace(formatRegExp, function(x) { + if (x === '%%') return '%'; + if (i >= len) return x; + switch (x) { + case '%s': return String(args[i++]); + case '%d': return Number(args[i++]); + case '%j': + try { + return JSON.stringify(args[i++]); + } catch (_) { + return '[Circular]'; + } + default: + return x; + } + }); + for (var x = args[i]; i < len; x = args[++i]) { + if (isNull(x) || !isObject(x)) { + str += ' ' + x; + } else { + str += ' ' + inspect(x); + } + } + return str; +}; + + +// Mark that a method should not be used. +// Returns a modified function which warns once by default. +// If --no-deprecation is set, then it is a no-op. +exports.deprecate = function(fn, msg) { + // Allow for deprecating things in the process of starting up. + if (isUndefined(global.process)) { + return function() { + return exports.deprecate(fn, msg).apply(this, arguments); + }; + } + + if (process.noDeprecation === true) { + return fn; + } + + var warned = false; + function deprecated() { + if (!warned) { + if (process.throwDeprecation) { + throw new Error(msg); + } else if (process.traceDeprecation) { + console.trace(msg); + } else { + console.error(msg); + } + warned = true; + } + return fn.apply(this, arguments); + } + + return deprecated; +}; + + +var debugs = {}; +var debugEnviron; +exports.debuglog = function(set) { + if (isUndefined(debugEnviron)) + debugEnviron = process.env.NODE_DEBUG || ''; + set = set.toUpperCase(); + if (!debugs[set]) { + if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { + var pid = process.pid; + debugs[set] = function() { + var msg = exports.format.apply(exports, arguments); + console.error('%s %d: %s', set, pid, msg); + }; + } else { + debugs[set] = function() {}; + } + } + return debugs[set]; +}; + + +/** + * Echos the value of a value. Trys to print the value out + * in the best way possible given the different types. + * + * @param {Object} obj The object to print out. + * @param {Object} opts Optional options object that alters the output. + */ +/* legacy: obj, showHidden, depth, colors*/ +function inspect(obj, opts) { + // default options + var ctx = { + seen: [], + stylize: stylizeNoColor + }; + // legacy... + if (arguments.length >= 3) ctx.depth = arguments[2]; + if (arguments.length >= 4) ctx.colors = arguments[3]; + if (isBoolean(opts)) { + // legacy... + ctx.showHidden = opts; + } else if (opts) { + // got an "options" object + exports._extend(ctx, opts); + } + // set default options + if (isUndefined(ctx.showHidden)) ctx.showHidden = false; + if (isUndefined(ctx.depth)) ctx.depth = 2; + if (isUndefined(ctx.colors)) ctx.colors = false; + if (isUndefined(ctx.customInspect)) ctx.customInspect = true; + if (ctx.colors) ctx.stylize = stylizeWithColor; + return formatValue(ctx, obj, ctx.depth); +} +exports.inspect = inspect; + + +// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics +inspect.colors = { + 'bold' : [1, 22], + 'italic' : [3, 23], + 'underline' : [4, 24], + 'inverse' : [7, 27], + 'white' : [37, 39], + 'grey' : [90, 39], + 'black' : [30, 39], + 'blue' : [34, 39], + 'cyan' : [36, 39], + 'green' : [32, 39], + 'magenta' : [35, 39], + 'red' : [31, 39], + 'yellow' : [33, 39] +}; + +// Don't use 'blue' not visible on cmd.exe +inspect.styles = { + 'special': 'cyan', + 'number': 'yellow', + 'boolean': 'yellow', + 'undefined': 'grey', + 'null': 'bold', + 'string': 'green', + 'date': 'magenta', + // "name": intentionally not styling + 'regexp': 'red' +}; + + +function stylizeWithColor(str, styleType) { + var style = inspect.styles[styleType]; + + if (style) { + return '\u001b[' + inspect.colors[style][0] + 'm' + str + + '\u001b[' + inspect.colors[style][1] + 'm'; + } else { + return str; + } +} + + +function stylizeNoColor(str, styleType) { + return str; +} + + +function arrayToHash(array) { + var hash = {}; + + array.forEach(function(val, idx) { + hash[val] = true; + }); + + return hash; +} + + +function formatValue(ctx, value, recurseTimes) { + // Provide a hook for user-specified inspect functions. + // Check that value is an object with an inspect function on it + if (ctx.customInspect && + value && + isFunction(value.inspect) && + // Filter out the util module, it's inspect function is special + value.inspect !== exports.inspect && + // Also filter out any prototype objects using the circular check. + !(value.constructor && value.constructor.prototype === value)) { + var ret = value.inspect(recurseTimes, ctx); + if (!isString(ret)) { + ret = formatValue(ctx, ret, recurseTimes); + } + return ret; + } + + // Primitive types cannot have properties + var primitive = formatPrimitive(ctx, value); + if (primitive) { + return primitive; + } + + // Look up the keys of the object. + var keys = Object.keys(value); + var visibleKeys = arrayToHash(keys); + + if (ctx.showHidden) { + keys = Object.getOwnPropertyNames(value); + } + + // IE doesn't make error fields non-enumerable + // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx + if (isError(value) + && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { + return formatError(value); + } + + // Some type of object without properties can be shortcutted. + if (keys.length === 0) { + if (isFunction(value)) { + var name = value.name ? ': ' + value.name : ''; + return ctx.stylize('[Function' + name + ']', 'special'); + } + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + } + if (isDate(value)) { + return ctx.stylize(Date.prototype.toString.call(value), 'date'); + } + if (isError(value)) { + return formatError(value); + } + } + + var base = '', array = false, braces = ['{', '}']; + + // Make Array say that they are Array + if (isArray(value)) { + array = true; + braces = ['[', ']']; + } + + // Make functions say that they are functions + if (isFunction(value)) { + var n = value.name ? ': ' + value.name : ''; + base = ' [Function' + n + ']'; + } + + // Make RegExps say that they are RegExps + if (isRegExp(value)) { + base = ' ' + RegExp.prototype.toString.call(value); + } + + // Make dates with properties first say the date + if (isDate(value)) { + base = ' ' + Date.prototype.toUTCString.call(value); + } + + // Make error with message first say the error + if (isError(value)) { + base = ' ' + formatError(value); + } + + if (keys.length === 0 && (!array || value.length == 0)) { + return braces[0] + base + braces[1]; + } + + if (recurseTimes < 0) { + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + } else { + return ctx.stylize('[Object]', 'special'); + } + } + + ctx.seen.push(value); + + var output; + if (array) { + output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); + } else { + output = keys.map(function(key) { + return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); + }); + } + + ctx.seen.pop(); + + return reduceToSingleString(output, base, braces); +} + + +function formatPrimitive(ctx, value) { + if (isUndefined(value)) + return ctx.stylize('undefined', 'undefined'); + if (isString(value)) { + var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') + .replace(/'/g, "\\'") + .replace(/\\"/g, '"') + '\''; + return ctx.stylize(simple, 'string'); + } + if (isNumber(value)) + return ctx.stylize('' + value, 'number'); + if (isBoolean(value)) + return ctx.stylize('' + value, 'boolean'); + // For some reason typeof null is "object", so special case here. + if (isNull(value)) + return ctx.stylize('null', 'null'); +} + + +function formatError(value) { + return '[' + Error.prototype.toString.call(value) + ']'; +} + + +function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { + var output = []; + for (var i = 0, l = value.length; i < l; ++i) { + if (hasOwnProperty(value, String(i))) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + String(i), true)); + } else { + output.push(''); + } + } + keys.forEach(function(key) { + if (!key.match(/^\d+$/)) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + key, true)); + } + }); + return output; +} + + +function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { + var name, str, desc; + desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; + if (desc.get) { + if (desc.set) { + str = ctx.stylize('[Getter/Setter]', 'special'); + } else { + str = ctx.stylize('[Getter]', 'special'); + } + } else { + if (desc.set) { + str = ctx.stylize('[Setter]', 'special'); + } + } + if (!hasOwnProperty(visibleKeys, key)) { + name = '[' + key + ']'; + } + if (!str) { + if (ctx.seen.indexOf(desc.value) < 0) { + if (isNull(recurseTimes)) { + str = formatValue(ctx, desc.value, null); + } else { + str = formatValue(ctx, desc.value, recurseTimes - 1); + } + if (str.indexOf('\n') > -1) { + if (array) { + str = str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n').substr(2); + } else { + str = '\n' + str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n'); + } + } + } else { + str = ctx.stylize('[Circular]', 'special'); + } + } + if (isUndefined(name)) { + if (array && key.match(/^\d+$/)) { + return str; + } + name = JSON.stringify('' + key); + if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { + name = name.substr(1, name.length - 2); + name = ctx.stylize(name, 'name'); + } else { + name = name.replace(/'/g, "\\'") + .replace(/\\"/g, '"') + .replace(/(^"|"$)/g, "'"); + name = ctx.stylize(name, 'string'); + } + } + + return name + ': ' + str; +} + + +function reduceToSingleString(output, base, braces) { + var numLinesEst = 0; + var length = output.reduce(function(prev, cur) { + numLinesEst++; + if (cur.indexOf('\n') >= 0) numLinesEst++; + return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; + }, 0); + + if (length > 60) { + return braces[0] + + (base === '' ? '' : base + '\n ') + + ' ' + + output.join(',\n ') + + ' ' + + braces[1]; + } + + return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; +} + + +// NOTE: These type checking functions intentionally don't use `instanceof` +// because it is fragile and can be easily faked with `Object.create()`. +function isArray(ar) { + return Array.isArray(ar); +} +exports.isArray = isArray; + +function isBoolean(arg) { + return typeof arg === 'boolean'; +} +exports.isBoolean = isBoolean; + +function isNull(arg) { + return arg === null; +} +exports.isNull = isNull; + +function isNullOrUndefined(arg) { + return arg == null; +} +exports.isNullOrUndefined = isNullOrUndefined; + +function isNumber(arg) { + return typeof arg === 'number'; +} +exports.isNumber = isNumber; + +function isString(arg) { + return typeof arg === 'string'; +} +exports.isString = isString; + +function isSymbol(arg) { + return typeof arg === 'symbol'; +} +exports.isSymbol = isSymbol; + +function isUndefined(arg) { + return arg === void 0; +} +exports.isUndefined = isUndefined; + +function isRegExp(re) { + return isObject(re) && objectToString(re) === '[object RegExp]'; +} +exports.isRegExp = isRegExp; + +function isObject(arg) { + return typeof arg === 'object' && arg !== null; +} +exports.isObject = isObject; + +function isDate(d) { + return isObject(d) && objectToString(d) === '[object Date]'; +} +exports.isDate = isDate; + +function isError(e) { + return isObject(e) && + (objectToString(e) === '[object Error]' || e instanceof Error); +} +exports.isError = isError; + +function isFunction(arg) { + return typeof arg === 'function'; +} +exports.isFunction = isFunction; + +function isPrimitive(arg) { + return arg === null || + typeof arg === 'boolean' || + typeof arg === 'number' || + typeof arg === 'string' || + typeof arg === 'symbol' || // ES6 symbol + typeof arg === 'undefined'; +} +exports.isPrimitive = isPrimitive; + +exports.isBuffer = require('./support/isBuffer'); + +function objectToString(o) { + return Object.prototype.toString.call(o); +} + + +function pad(n) { + return n < 10 ? '0' + n.toString(10) : n.toString(10); +} + + +var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', + 'Oct', 'Nov', 'Dec']; + +// 26 Feb 16:19:34 +function timestamp() { + var d = new Date(); + var time = [pad(d.getHours()), + pad(d.getMinutes()), + pad(d.getSeconds())].join(':'); + return [d.getDate(), months[d.getMonth()], time].join(' '); +} + + +// log is just a thin wrapper to console.log that prepends a timestamp +exports.log = function() { + console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); +}; + + +/** + * Inherit the prototype methods from one constructor into another. + * + * The Function.prototype.inherits from lang.js rewritten as a standalone + * function (not on Function.prototype). NOTE: If this file is to be loaded + * during bootstrapping this function needs to be rewritten using some native + * functions as prototype setup using normal JavaScript does not work as + * expected during bootstrapping (see mirror.js in r114903). + * + * @param {function} ctor Constructor function which needs to inherit the + * prototype. + * @param {function} superCtor Constructor function to inherit prototype from. + */ +exports.inherits = require('inherits'); + +exports._extend = function(origin, add) { + // Don't do anything if add isn't an object + if (!add || !isObject(add)) return origin; + + var keys = Object.keys(add); + var i = keys.length; + while (i--) { + origin[keys[i]] = add[keys[i]]; + } + return origin; +}; + +function hasOwnProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); +} + +}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./support/isBuffer":35,"_process":19,"inherits":16}],"buffer":[function(require,module,exports){ +(function (global){ +/*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijeh + * @license MIT + */ +/* eslint-disable no-proto */ + +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+. + * + * 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) + } + + 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 +} + +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 + +// 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` 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":12,"ieee754":13,"is-array":14}],"lz4":[function(require,module,exports){ +/** + * LZ4 based compression and decompression + * Copyright (c) 2014 Pierre Curto + * MIT Licensed + */ + +module.exports = require('./static') + +module.exports.version = "0.5.1" +module.exports.createDecoderStream = require('./decoder_stream') +module.exports.decode = require('./decoder').LZ4_uncompress + +module.exports.createEncoderStream = require('./encoder_stream') +module.exports.encode = require('./encoder').LZ4_compress + +// Expose block decoder and encoders +var bindings = module.exports.utils.bindings + +module.exports.decodeBlock = bindings.uncompress + +module.exports.encodeBound = bindings.compressBound +module.exports.encodeBlock = bindings.compress +module.exports.encodeBlockHC = bindings.compressHC + +},{"./decoder":2,"./decoder_stream":3,"./encoder":4,"./encoder_stream":5,"./static":6}]},{},["lz4"]); diff --git a/src/html5/js/lib/lz4.min.js b/src/html5/js/lib/lz4.min.js deleted file mode 100644 index eb5639efb0..0000000000 --- a/src/html5/js/lib/lz4.min.js +++ /dev/null @@ -1,3 +0,0 @@ -require=function t(e,r,i){function n(o,a){if(!r[o]){if(!e[o]){var h="function"==typeof require&&require;if(!a&&h)return h(o,!0);if(s)return s(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var f=r[o]={exports:{}};e[o][0].call(f.exports,function(t){var r=e[o][1][t];return n(r?r:t)},f,f.exports,t,e,r,i)}return r[o].exports}for(var s="function"==typeof require&&require,o=0;o>8&255},r.blockChecksum=function(t){return i(t,n).toNumber()},r.streamChecksum=function(t,e){return null===t?e.digest().toNumber():(null===e&&(e=i(n)),e.update(t))},r.readInt32LE=function(t,e){return t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24},r.bindings=t("./binding")},{"./binding":22,xxhashjs:31}],1:[function(t,e,r){var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(t){"use strict";function e(t){var e=t.charCodeAt(0);return e===o?62:e===a?63:h>e?-1:h+10>e?e-h+26+26:f+26>e?e-f:u+26>e?e-u+26:void 0}function r(t){function r(t){u[c++]=t}var i,n,o,a,h,u;if(t.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var f=t.length;h="="===t.charAt(f-2)?2:"="===t.charAt(f-1)?1:0,u=new s(3*t.length/4-h),o=h>0?t.length-4:t.length;var c=0;for(i=0,n=0;o>i;i+=4,n+=3)a=e(t.charAt(i))<<18|e(t.charAt(i+1))<<12|e(t.charAt(i+2))<<6|e(t.charAt(i+3)),r((16711680&a)>>16),r((65280&a)>>8),r(255&a);return 2===h?(a=e(t.charAt(i))<<2|e(t.charAt(i+1))>>4,r(255&a)):1===h&&(a=e(t.charAt(i))<<10|e(t.charAt(i+1))<<4|e(t.charAt(i+2))>>2,r(a>>8&255),r(255&a)),u}function n(t){function e(t){return i.charAt(t)}function r(t){return e(t>>18&63)+e(t>>12&63)+e(t>>6&63)+e(63&t)}var n,s,o,a=t.length%3,h="";for(n=0,o=t.length-a;o>n;n+=3)s=(t[n]<<16)+(t[n+1]<<8)+t[n+2],h+=r(s);switch(a){case 1:s=t[t.length-1],h+=e(s>>2),h+=e(s<<4&63),h+="==";break;case 2:s=(t[t.length-2]<<8)+t[t.length-1],h+=e(s>>10),h+=e(s>>4&63),h+=e(s<<2&63),h+="="}return h}var s="undefined"!=typeof Uint8Array?Uint8Array:Array,o="+".charCodeAt(0),a="/".charCodeAt(0),h="0".charCodeAt(0),u="a".charCodeAt(0),f="A".charCodeAt(0);t.toByteArray=r,t.fromByteArray=n}("undefined"==typeof r?this.base64js={}:r)},{}],2:[function(t,e,r){r.read=function(t,e,r,i,n){var s,o,a=8*n-i-1,h=(1<>1,f=-7,c=r?n-1:0,l=r?-1:1,d=t[e+c];for(c+=l,s=d&(1<<-f)-1,d>>=-f,f+=a;f>0;s=256*s+t[e+c],c+=l,f-=8);for(o=s&(1<<-f)-1,s>>=-f,f+=i;f>0;o=256*o+t[e+c],c+=l,f-=8);if(0===s)s=1-u;else{if(s===h)return o?0/0:1/0*(d?-1:1);o+=Math.pow(2,i),s-=u}return(d?-1:1)*o*Math.pow(2,s-i)},r.write=function(t,e,r,i,n,s){var o,a,h,u=8*s-n-1,f=(1<>1,l=23===n?Math.pow(2,-24)-Math.pow(2,-77):0,d=i?0:s-1,p=i?1:-1,g=0>e||0===e&&0>1/e?1:0;for(e=Math.abs(e),isNaN(e)||1/0===e?(a=isNaN(e)?1:0,o=f):(o=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-o))<1&&(o--,h*=2),e+=o+c>=1?l/h:l*Math.pow(2,1-c),e*h>=2&&(o++,h/=2),o+c>=f?(a=0,o=f):o+c>=1?(a=(e*h-1)*Math.pow(2,n),o+=c):(a=e*Math.pow(2,c-1)*Math.pow(2,n),o=0));n>=8;t[r+d]=255&a,d+=p,a/=256,n-=8);for(o=o<0;t[r+d]=255&o,d+=p,o/=256,u-=8);t[r+d-p]|=128*g}},{}],3:[function(t,e){function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function i(t){return"function"==typeof t}function n(t){return"number"==typeof t}function s(t){return"object"==typeof t&&null!==t}function o(t){return void 0===t}e.exports=r,r.EventEmitter=r,r.prototype._events=void 0,r.prototype._maxListeners=void 0,r.defaultMaxListeners=10,r.prototype.setMaxListeners=function(t){if(!n(t)||0>t||isNaN(t))throw TypeError("n must be a positive number");return this._maxListeners=t,this},r.prototype.emit=function(t){var e,r,n,a,h,u;if(this._events||(this._events={}),"error"===t&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if(e=arguments[1],e instanceof Error)throw e;throw TypeError('Uncaught, unspecified "error" event.')}if(r=this._events[t],o(r))return!1;if(i(r))switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:for(n=arguments.length,a=new Array(n-1),h=1;n>h;h++)a[h-1]=arguments[h];r.apply(this,a)}else if(s(r)){for(n=arguments.length,a=new Array(n-1),h=1;n>h;h++)a[h-1]=arguments[h];for(u=r.slice(),n=u.length,h=0;n>h;h++)u[h].apply(this,a)}return!0},r.prototype.addListener=function(t,e){var n;if(!i(e))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",t,i(e.listener)?e.listener:e),this._events[t]?s(this._events[t])?this._events[t].push(e):this._events[t]=[this._events[t],e]:this._events[t]=e,s(this._events[t])&&!this._events[t].warned){var n;n=o(this._maxListeners)?r.defaultMaxListeners:this._maxListeners,n&&n>0&&this._events[t].length>n&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),"function"==typeof console.trace&&console.trace())}return this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(t,e){function r(){this.removeListener(t,r),n||(n=!0,e.apply(this,arguments))}if(!i(e))throw TypeError("listener must be a function");var n=!1;return r.listener=e,this.on(t,r),this},r.prototype.removeListener=function(t,e){var r,n,o,a;if(!i(e))throw TypeError("listener must be a function");if(!this._events||!this._events[t])return this;if(r=this._events[t],o=r.length,n=-1,r===e||i(r.listener)&&r.listener===e)delete this._events[t],this._events.removeListener&&this.emit("removeListener",t,e);else if(s(r)){for(a=o;a-->0;)if(r[a]===e||r[a].listener&&r[a].listener===e){n=a;break}if(0>n)return this;1===r.length?(r.length=0,delete this._events[t]):r.splice(n,1),this._events.removeListener&&this.emit("removeListener",t,e)}return this},r.prototype.removeAllListeners=function(t){var e,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[t]&&delete this._events[t],this;if(0===arguments.length){for(e in this._events)"removeListener"!==e&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events={},this}if(r=this._events[t],i(r))this.removeListener(t,r);else for(;r.length;)this.removeListener(t,r[r.length-1]);return delete this._events[t],this},r.prototype.listeners=function(t){var e;return e=this._events&&this._events[t]?i(this._events[t])?[this._events[t]]:this._events[t].slice():[]},r.listenerCount=function(t,e){var r;return r=t._events&&t._events[e]?i(t._events[e])?1:t._events[e].length:0}},{}],4:[function(t,e){e.exports="function"==typeof Object.create?function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:function(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}},{}],5:[function(t,e){e.exports=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)}},{}],6:[function(t,e){function r(){}var i=e.exports={};i.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(e){var r=[];return window.addEventListener("message",function(t){var e=t.source;if((e===window||null===e)&&"process-tick"===t.data&&(t.stopPropagation(),r.length>0)){var i=r.shift();i()}},!0),function(t){r.push(t),window.postMessage("process-tick","*")}}return function(t){setTimeout(t,0)}}(),i.title="browser",i.browser=!0,i.env={},i.argv=[],i.on=r,i.addListener=r,i.once=r,i.off=r,i.removeListener=r,i.removeAllListeners=r,i.emit=r,i.binding=function(){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(){throw new Error("process.chdir is not supported")}},{}],7:[function(t,e){e.exports=t("./lib/_stream_duplex.js")},{"./lib/_stream_duplex.js":8}],8:[function(t,e){(function(r){function i(t){return this instanceof i?(h.call(this,t),u.call(this,t),t&&t.readable===!1&&(this.readable=!1),t&&t.writable===!1&&(this.writable=!1),this.allowHalfOpen=!0,t&&t.allowHalfOpen===!1&&(this.allowHalfOpen=!1),void this.once("end",n)):new i(t)}function n(){this.allowHalfOpen||this._writableState.ended||r.nextTick(this.end.bind(this))}function s(t,e){for(var r=0,i=t.length;i>r;r++)e(t[r],r)}e.exports=i;var o=Object.keys||function(t){var e=[];for(var r in t)e.push(r);return e},a=t("core-util-is");a.inherits=t("inherits");var h=t("./_stream_readable"),u=t("./_stream_writable");a.inherits(i,h),s(o(u.prototype),function(t){i.prototype[t]||(i.prototype[t]=u.prototype[t])})}).call(this,t("_process"))},{"./_stream_readable":10,"./_stream_writable":12,_process:6,"core-util-is":13,inherits:4}],9:[function(t,e){function r(t){return this instanceof r?void i.call(this,t):new r(t)}e.exports=r;var i=t("./_stream_transform"),n=t("core-util-is");n.inherits=t("inherits"),n.inherits(r,i),r.prototype._transform=function(t,e,r){r(null,t)}},{"./_stream_transform":11,"core-util-is":13,inherits:4}],10:[function(t,e){(function(r){function i(e){e=e||{};var r=e.highWaterMark;this.highWaterMark=r||0===r?r:16384,this.highWaterMark=~~this.highWaterMark,this.buffer=[],this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=!1,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.calledRead=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.objectMode=!!e.objectMode,this.defaultEncoding=e.defaultEncoding||"utf8",this.ranOut=!1,this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(L||(L=t("string_decoder/").StringDecoder),this.decoder=new L(e.encoding),this.encoding=e.encoding)}function n(t){return this instanceof n?(this._readableState=new i(t,this),this.readable=!0,void A.call(this)):new n(t)}function s(t,e,r,i,n){var s=u(e,r);if(s)t.emit("error",s);else if(null===r||void 0===r)e.reading=!1,e.ended||f(t,e);else if(e.objectMode||r&&r.length>0)if(e.ended&&!n){var a=new Error("stream.push() after EOF");t.emit("error",a)}else if(e.endEmitted&&n){var a=new Error("stream.unshift() after end event");t.emit("error",a)}else!e.decoder||n||i||(r=e.decoder.write(r)),e.length+=e.objectMode?1:r.length,n?e.buffer.unshift(r):(e.reading=!1,e.buffer.push(r)),e.needReadable&&c(t),d(t,e);else n||(e.reading=!1);return o(e)}function o(t){return!t.ended&&(t.needReadable||t.length=B)t=B;else{t--;for(var e=1;32>e;e<<=1)t|=t>>e;t++}return t}function h(t,e){return 0===e.length&&e.ended?0:e.objectMode?0===t?0:1:null===t||isNaN(t)?e.flowing&&e.buffer.length?e.buffer[0].length:e.length:0>=t?0:(t>e.highWaterMark&&(e.highWaterMark=a(t)),t>e.length?e.ended?e.length:(e.needReadable=!0,0):t)}function u(t,e){var r=null;return C.isBuffer(e)||"string"==typeof e||null===e||void 0===e||t.objectMode||(r=new TypeError("Invalid non-string/buffer chunk")),r}function f(t,e){if(e.decoder&&!e.ended){var r=e.decoder.end();r&&r.length&&(e.buffer.push(r),e.length+=e.objectMode?1:r.length)}e.ended=!0,e.length>0?c(t):y(t)}function c(t){var e=t._readableState;e.needReadable=!1,e.emittedReadable||(e.emittedReadable=!0,e.sync?r.nextTick(function(){l(t)}):l(t))}function l(t){t.emit("readable")}function d(t,e){e.readingMore||(e.readingMore=!0,r.nextTick(function(){p(t,e)}))}function p(t,e){for(var r=e.length;!e.reading&&!e.flowing&&!e.ended&&e.length0)return;return 0===i.pipesCount?(i.flowing=!1,void(I.listenerCount(t,"data")>0&&v(t))):void(i.ranOut=!0)}function _(){this._readableState.ranOut&&(this._readableState.ranOut=!1,m(this))}function v(t,e){var i=t._readableState;if(i.flowing)throw new Error("Cannot switch to old mode now.");var n=e||!1,s=!1;t.readable=!0,t.pipe=A.prototype.pipe,t.on=t.addListener=A.prototype.on,t.on("readable",function(){s=!0;for(var e;!n&&null!==(e=t.read());)t.emit("data",e);null===e&&(s=!1,t._readableState.needReadable=!0)}),t.pause=function(){n=!0,this.emit("pause")},t.resume=function(){n=!1,s?r.nextTick(function(){t.emit("readable")}):this.read(0),this.emit("resume")},t.emit("readable")}function b(t,e){var r,i=e.buffer,n=e.length,s=!!e.decoder,o=!!e.objectMode;if(0===i.length)return null;if(0===n)r=null;else if(o)r=i.shift();else if(!t||t>=n)r=s?i.join(""):C.concat(i,n),i.length=0;else if(tu&&t>h;u++){var a=i[0],c=Math.min(t-h,a.length);s?r+=a.slice(0,c):a.copy(r,h,0,c),c0)throw new Error("endReadable called on non-empty stream");!e.endEmitted&&e.calledRead&&(e.ended=!0,r.nextTick(function(){e.endEmitted||0!==e.length||(e.endEmitted=!0,t.readable=!1,t.emit("end"))}))}function w(t,e){for(var r=0,i=t.length;i>r;r++)e(t[r],r)}function E(t,e){for(var r=0,i=t.length;i>r;r++)if(t[r]===e)return r;return-1}e.exports=n;var S=t("isarray"),C=t("buffer").Buffer;n.ReadableState=i;var I=t("events").EventEmitter;I.listenerCount||(I.listenerCount=function(t,e){return t.listeners(e).length});var A=t("stream"),k=t("core-util-is");k.inherits=t("inherits");var L;k.inherits(n,A),n.prototype.push=function(t,e){var r=this._readableState;return"string"!=typeof t||r.objectMode||(e=e||r.defaultEncoding,e!==r.encoding&&(t=new C(t,e),e="")),s(this,r,t,e,!1)},n.prototype.unshift=function(t){var e=this._readableState;return s(this,e,t,"",!0)},n.prototype.setEncoding=function(e){L||(L=t("string_decoder/").StringDecoder),this._readableState.decoder=new L(e),this._readableState.encoding=e};var B=8388608;n.prototype.read=function(t){var e=this._readableState;e.calledRead=!0;var r,i=t;if(("number"!=typeof t||t>0)&&(e.emittedReadable=!1),0===t&&e.needReadable&&(e.length>=e.highWaterMark||e.ended))return c(this),null;if(t=h(t,e),0===t&&e.ended)return r=null,e.length>0&&e.decoder&&(r=b(t,e),e.length-=r.length),0===e.length&&y(this),r;var n=e.needReadable;return e.length-t<=e.highWaterMark&&(n=!0),(e.ended||e.reading)&&(n=!1),n&&(e.reading=!0,e.sync=!0,0===e.length&&(e.needReadable=!0),this._read(e.highWaterMark),e.sync=!1),n&&!e.reading&&(t=h(i,e)),r=t>0?b(t,e):null,null===r&&(e.needReadable=!0,t=0),e.length-=t,0!==e.length||e.ended||(e.needReadable=!0),e.ended&&!e.endEmitted&&0===e.length&&y(this),r},n.prototype._read=function(){this.emit("error",new Error("not implemented"))},n.prototype.pipe=function(t,e){function i(t){t===f&&s()}function n(){t.end()}function s(){t.removeListener("close",a),t.removeListener("finish",h),t.removeListener("drain",p),t.removeListener("error",o),t.removeListener("unpipe",i),f.removeListener("end",n),f.removeListener("end",s),(!t._writableState||t._writableState.needDrain)&&p()}function o(e){u(),t.removeListener("error",o),0===I.listenerCount(t,"error")&&t.emit("error",e)}function a(){t.removeListener("finish",h),u()}function h(){t.removeListener("close",a),u()}function u(){f.unpipe(t)}var f=this,c=this._readableState;switch(c.pipesCount){case 0:c.pipes=t;break;case 1:c.pipes=[c.pipes,t];break;default:c.pipes.push(t)}c.pipesCount+=1;var l=(!e||e.end!==!1)&&t!==r.stdout&&t!==r.stderr,d=l?n:s;c.endEmitted?r.nextTick(d):f.once("end",d),t.on("unpipe",i);var p=g(f);return t.on("drain",p),t._events&&t._events.error?S(t._events.error)?t._events.error.unshift(o):t._events.error=[o,t._events.error]:t.on("error",o),t.once("close",a),t.once("finish",h),t.emit("pipe",f),c.flowing||(this.on("readable",_),c.flowing=!0,r.nextTick(function(){m(f)})),t},n.prototype.unpipe=function(t){var e=this._readableState;if(0===e.pipesCount)return this;if(1===e.pipesCount)return t&&t!==e.pipes?this:(t||(t=e.pipes),e.pipes=null,e.pipesCount=0,this.removeListener("readable",_),e.flowing=!1,t&&t.emit("unpipe",this),this);if(!t){var r=e.pipes,i=e.pipesCount;e.pipes=null,e.pipesCount=0,this.removeListener("readable",_),e.flowing=!1;for(var n=0;i>n;n++)r[n].emit("unpipe",this);return this}var n=E(e.pipes,t);return-1===n?this:(e.pipes.splice(n,1),e.pipesCount-=1,1===e.pipesCount&&(e.pipes=e.pipes[0]),t.emit("unpipe",this),this)},n.prototype.on=function(t,e){var r=A.prototype.on.call(this,t,e);if("data"!==t||this._readableState.flowing||v(this),"readable"===t&&this.readable){var i=this._readableState;i.readableListening||(i.readableListening=!0,i.emittedReadable=!1,i.needReadable=!0,i.reading?i.length&&c(this,i):this.read(0))}return r},n.prototype.addListener=n.prototype.on,n.prototype.resume=function(){v(this),this.read(0),this.emit("resume")},n.prototype.pause=function(){v(this,!0),this.emit("pause")},n.prototype.wrap=function(t){var e=this._readableState,r=!1,i=this;t.on("end",function(){if(e.decoder&&!e.ended){var t=e.decoder.end();t&&t.length&&i.push(t)}i.push(null)}),t.on("data",function(n){if(e.decoder&&(n=e.decoder.write(n)),(!e.objectMode||null!==n&&void 0!==n)&&(e.objectMode||n&&n.length)){var s=i.push(n);s||(r=!0,t.pause())}});for(var n in t)"function"==typeof t[n]&&"undefined"==typeof this[n]&&(this[n]=function(e){return function(){return t[e].apply(t,arguments)}}(n));var s=["error","close","destroy","pause","resume"];return w(s,function(e){t.on(e,i.emit.bind(i,e))}),i._read=function(){r&&(r=!1,t.resume())},i},n._fromList=b}).call(this,t("_process"))},{_process:6,buffer:void 0,"core-util-is":13,events:3,inherits:4,isarray:5,stream:19,"string_decoder/":14}],11:[function(t,e){function r(t,e){this.afterTransform=function(t,r){return i(e,t,r)},this.needTransform=!1,this.transforming=!1,this.writecb=null,this.writechunk=null}function i(t,e,r){var i=t._transformState;i.transforming=!1;var n=i.writecb;if(!n)return t.emit("error",new Error("no writecb in Transform class"));i.writechunk=null,i.writecb=null,null!==r&&void 0!==r&&t.push(r),n&&n(e);var s=t._readableState;s.reading=!1,(s.needReadable||s.length=this.charLength-this.charReceived?this.charLength-this.charReceived:t.length;if(t.copy(this.charBuffer,this.charReceived,0,r),this.charReceived+=r,this.charReceived=55296&&56319>=i)){if(this.charReceived=this.charLength=0,0===t.length)return e;break}this.charLength+=this.surrogateSize,e=""}this.detectIncompleteChar(t);var n=t.length;this.charLength&&(t.copy(this.charBuffer,0,t.length-this.charReceived,n),n-=this.charReceived),e+=t.toString(this.encoding,0,n);var n=e.length-1,i=e.charCodeAt(n);if(i>=55296&&56319>=i){var s=this.surrogateSize;return this.charLength+=s,this.charReceived+=s,this.charBuffer.copy(this.charBuffer,s,0,s),t.copy(this.charBuffer,0,0,s),e.substring(0,n)}return e},u.prototype.detectIncompleteChar=function(t){for(var e=t.length>=3?3:t.length;e>0;e--){var r=t[t.length-e];if(1==e&&r>>5==6){this.charLength=2;break}if(2>=e&&r>>4==14){this.charLength=3;break}if(3>=e&&r>>3==30){this.charLength=4;break}}this.charReceived=e},u.prototype.end=function(t){var e="";if(t&&t.length&&(e=this.write(t)),this.charReceived){var r=this.charReceived,i=this.charBuffer,n=this.encoding;e+=i.slice(0,r).toString(n)}return e}},{buffer:void 0}],15:[function(t,e){e.exports=t("./lib/_stream_passthrough.js")},{"./lib/_stream_passthrough.js":9}],16:[function(t,e,r){r=e.exports=t("./lib/_stream_readable.js"),r.Readable=r,r.Writable=t("./lib/_stream_writable.js"),r.Duplex=t("./lib/_stream_duplex.js"),r.Transform=t("./lib/_stream_transform.js"),r.PassThrough=t("./lib/_stream_passthrough.js")},{"./lib/_stream_duplex.js":8,"./lib/_stream_passthrough.js":9,"./lib/_stream_readable.js":10,"./lib/_stream_transform.js":11,"./lib/_stream_writable.js":12}],17:[function(t,e){e.exports=t("./lib/_stream_transform.js")},{"./lib/_stream_transform.js":11}],18:[function(t,e){e.exports=t("./lib/_stream_writable.js")},{"./lib/_stream_writable.js":12}],19:[function(t,e){function r(){i.call(this)}e.exports=r;var i=t("events").EventEmitter,n=t("inherits");n(r,i),r.Readable=t("readable-stream/readable.js"),r.Writable=t("readable-stream/writable.js"),r.Duplex=t("readable-stream/duplex.js"),r.Transform=t("readable-stream/transform.js"),r.PassThrough=t("readable-stream/passthrough.js"),r.Stream=r,r.prototype.pipe=function(t,e){function r(e){t.writable&&!1===t.write(e)&&u.pause&&u.pause()}function n(){u.readable&&u.resume&&u.resume()}function s(){f||(f=!0,t.end())}function o(){f||(f=!0,"function"==typeof t.destroy&&t.destroy())}function a(t){if(h(),0===i.listenerCount(this,"error"))throw t}function h(){u.removeListener("data",r),t.removeListener("drain",n),u.removeListener("end",s),u.removeListener("close",o),u.removeListener("error",a),t.removeListener("error",a),u.removeListener("end",h),u.removeListener("close",h),t.removeListener("close",h)}var u=this;u.on("data",r),t.on("drain",n),t._isStdio||e&&e.end===!1||(u.on("end",s),u.on("close",o));var f=!1;return u.on("error",a),t.on("error",a),u.on("end",h),u.on("close",h),t.on("close",h),t.emit("pipe",u),t}},{events:3,inherits:4,"readable-stream/duplex.js":7,"readable-stream/passthrough.js":15,"readable-stream/readable.js":16,"readable-stream/transform.js":17,"readable-stream/writable.js":18}],20:[function(t,e){e.exports=function(t){return t&&"object"==typeof t&&"function"==typeof t.copy&&"function"==typeof t.fill&&"function"==typeof t.readUInt8}},{}],21:[function(t,e,r){(function(e,i){function n(t,e){var i={seen:[],stylize:o};return arguments.length>=3&&(i.depth=arguments[2]),arguments.length>=4&&(i.colors=arguments[3]),g(e)?i.showHidden=e:e&&r._extend(i,e),w(i.showHidden)&&(i.showHidden=!1),w(i.depth)&&(i.depth=2),w(i.colors)&&(i.colors=!1),w(i.customInspect)&&(i.customInspect=!0),i.colors&&(i.stylize=s),h(i,t,i.depth)}function s(t,e){var r=n.styles[e];return r?"["+n.colors[r][0]+"m"+t+"["+n.colors[r][1]+"m":t}function o(t){return t}function a(t){var e={};return t.forEach(function(t){e[t]=!0}),e}function h(t,e,i){if(t.customInspect&&e&&A(e.inspect)&&e.inspect!==r.inspect&&(!e.constructor||e.constructor.prototype!==e)){var n=e.inspect(i,t);return b(n)||(n=h(t,n,i)),n}var s=u(t,e);if(s)return s;var o=Object.keys(e),g=a(o);if(t.showHidden&&(o=Object.getOwnPropertyNames(e)),I(e)&&(o.indexOf("message")>=0||o.indexOf("description")>=0))return f(e);if(0===o.length){if(A(e)){var m=e.name?": "+e.name:"";return t.stylize("[Function"+m+"]","special")}if(E(e))return t.stylize(RegExp.prototype.toString.call(e),"regexp");if(C(e))return t.stylize(Date.prototype.toString.call(e),"date");if(I(e))return f(e)}var _="",v=!1,y=["{","}"];if(p(e)&&(v=!0,y=["[","]"]),A(e)){var w=e.name?": "+e.name:"";_=" [Function"+w+"]"}if(E(e)&&(_=" "+RegExp.prototype.toString.call(e)),C(e)&&(_=" "+Date.prototype.toUTCString.call(e)),I(e)&&(_=" "+f(e)),0===o.length&&(!v||0==e.length))return y[0]+_+y[1];if(0>i)return E(e)?t.stylize(RegExp.prototype.toString.call(e),"regexp"):t.stylize("[Object]","special");t.seen.push(e);var S;return S=v?c(t,e,i,g,o):o.map(function(r){return l(t,e,i,g,r,v)}),t.seen.pop(),d(S,_,y)}function u(t,e){if(w(e))return t.stylize("undefined","undefined");if(b(e)){var r="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(r,"string")}return v(e)?t.stylize(""+e,"number"):g(e)?t.stylize(""+e,"boolean"):m(e)?t.stylize("null","null"):void 0}function f(t){return"["+Error.prototype.toString.call(t)+"]"}function c(t,e,r,i,n){for(var s=[],o=0,a=e.length;a>o;++o)s.push(M(e,String(o))?l(t,e,r,i,String(o),!0):"");return n.forEach(function(n){n.match(/^\d+$/)||s.push(l(t,e,r,i,n,!0))}),s}function l(t,e,r,i,n,s){var o,a,u;if(u=Object.getOwnPropertyDescriptor(e,n)||{value:e[n]},u.get?a=u.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):u.set&&(a=t.stylize("[Setter]","special")),M(i,n)||(o="["+n+"]"),a||(t.seen.indexOf(u.value)<0?(a=m(r)?h(t,u.value,null):h(t,u.value,r-1),a.indexOf("\n")>-1&&(a=s?a.split("\n").map(function(t){return" "+t}).join("\n").substr(2):"\n"+a.split("\n").map(function(t){return" "+t}).join("\n"))):a=t.stylize("[Circular]","special")),w(o)){if(s&&n.match(/^\d+$/))return a;o=JSON.stringify(""+n),o.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(o=o.substr(1,o.length-2),o=t.stylize(o,"name")):(o=o.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),o=t.stylize(o,"string"))}return o+": "+a}function d(t,e,r){var i=0,n=t.reduce(function(t,e){return i++,e.indexOf("\n")>=0&&i++,t+e.replace(/\u001b\[\d\d?m/g,"").length+1},0);return n>60?r[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+r[1]:r[0]+e+" "+t.join(", ")+" "+r[1]}function p(t){return Array.isArray(t)}function g(t){return"boolean"==typeof t}function m(t){return null===t -}function _(t){return null==t}function v(t){return"number"==typeof t}function b(t){return"string"==typeof t}function y(t){return"symbol"==typeof t}function w(t){return void 0===t}function E(t){return S(t)&&"[object RegExp]"===L(t)}function S(t){return"object"==typeof t&&null!==t}function C(t){return S(t)&&"[object Date]"===L(t)}function I(t){return S(t)&&("[object Error]"===L(t)||t instanceof Error)}function A(t){return"function"==typeof t}function k(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||"undefined"==typeof t}function L(t){return Object.prototype.toString.call(t)}function B(t){return 10>t?"0"+t.toString(10):t.toString(10)}function x(){var t=new Date,e=[B(t.getHours()),B(t.getMinutes()),B(t.getSeconds())].join(":");return[t.getDate(),U[t.getMonth()],e].join(" ")}function M(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var D=/%[sdj%]/g;r.format=function(t){if(!b(t)){for(var e=[],r=0;r=s)return t;switch(t){case"%s":return String(i[r++]);case"%d":return Number(i[r++]);case"%j":try{return JSON.stringify(i[r++])}catch(e){return"[Circular]"}default:return t}}),a=i[r];s>r;a=i[++r])o+=m(a)||!S(a)?" "+a:" "+n(a);return o},r.deprecate=function(t,n){function s(){if(!o){if(e.throwDeprecation)throw new Error(n);e.traceDeprecation?console.trace(n):console.error(n),o=!0}return t.apply(this,arguments)}if(w(i.process))return function(){return r.deprecate(t,n).apply(this,arguments)};if(e.noDeprecation===!0)return t;var o=!1;return s};var T,O={};r.debuglog=function(t){if(w(T)&&(T=e.env.NODE_DEBUG||""),t=t.toUpperCase(),!O[t])if(new RegExp("\\b"+t+"\\b","i").test(T)){var i=e.pid;O[t]=function(){var e=r.format.apply(r,arguments);console.error("%s %d: %s",t,i,e)}}else O[t]=function(){};return O[t]},r.inspect=n,n.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},n.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},r.isArray=p,r.isBoolean=g,r.isNull=m,r.isNullOrUndefined=_,r.isNumber=v,r.isString=b,r.isSymbol=y,r.isUndefined=w,r.isRegExp=E,r.isObject=S,r.isDate=C,r.isError=I,r.isFunction=A,r.isPrimitive=k,r.isBuffer=t("./support/isBuffer");var U=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];r.log=function(){console.log("%s - %s",x(),r.format.apply(r,arguments))},r.inherits=t("inherits"),r._extend=function(t,e){if(!e||!S(e))return t;for(var r=Object.keys(e),i=r.length;i--;)t[r[i]]=e[r[i]];return t}}).call(this,t("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./support/isBuffer":20,_process:6,inherits:4}],22:[function(t,e,r){function i(t,e,i,a,u,f){var g=n(),v=u,b=f-u,y=0;if(t.length>=s)throw new Error("input too large");if(t.length>c){var w=r.compressBound(t.length);if(w>b)throw Error("output too small: "+b+" < "+w);for(var E=1,S=(1<i+o;){var I=t[i+1]<<8|t[i],A=t[i+3]<<8|t[i+2],k=g.fromBits(I,A).multiply(_).shiftr(h).toNumber(),L=a[k]-1;if(a[k]=i+1,0>L||i-L>>>16>0||(t[L+3]<<8|t[L+2])!=A&&(t[L+1]<<8|t[L])!=I)E=S++>>l,i+=E;else{S=(1<i&&t[i]==t[L];)i++,L++;M=i-M;var D=p>M?M:p;if(B>=m){e[v++]=(m<254;T-=255)e[v++]=255;e[v++]=T}else e[v++]=(B<O;O++)e[v++]=t[y+O];if(e[v++]=x,e[v++]=x>>8,M>=p){for(M-=p;M>=255;)M-=255,e[v++]=255;e[v++]=M}y=i}}}if(0==y)return 0;if(B=t.length-y,B>=m){e[v++]=m<254;U-=255)e[v++]=255;e[v++]=U}else e[v++]=B<n;){var a=t[n++],h=a>>4;if(h>0){for(var u=h+240;255===u;)u=t[n++],h+=u;for(var f=n+h;f>n;)e[o++]=t[n++];if(n===s)return o}var c=t[n++]|t[n++]<<8;if(0===c||c>o)return-(n-2);for(var l=15&a,u=l+240;255===u;)u=t[n++],l+=u;for(var d=o-c,f=o+l+4;f>o;)e[o++]=e[d++]}return o};var s=2113929216,o=4,a=16,h=8*o-a,u=1<s?0:t+t/255+16|0},r.compressHC=r.compress,r.compress=function(t,e,r,n){for(var s=new Array(u),o=0;u>o;o++)s[o]=0;return i(t,e,0,s,r||0,n||e.length)},r.compressDependent=i},{cuint:28}],23:[function(t,e,r){(function(e){function i(t,r){var i=[],s=new n(r);return s.on("data",function(t){i.push(t)}),s.end(t),e.concat(i)}var n=t("./decoder_stream");r.LZ4_uncompress=i}).call(this,t("buffer").Buffer)},{"./decoder_stream":24,buffer:void 0}],24:[function(t,e){(function(r){function i(t){return this instanceof i?(n.call(this,t),this.options=t||{},this.binding=this.options.useJS?u:h,this.buffer=null,this.pos=0,this.descriptor=null,this.state=f.MAGIC,this.notEnoughData=!1,this.descriptorStart=0,this.streamSize=null,this.dictId=null,this.currentStreamChecksum=null,this.dataBlockSize=0,void(this.skippableSize=0)):new i(t)}var n=t("stream").Transform,s=t("util").inherits,o=t("./static"),a=o.utils,h=a.bindings,u=t("./binding"),f=o.STATES,c=o.SIZES;s(i,n),i.prototype._transform=function(t,e,i){if(this.skippableSize>0){if(this.skippableSize-=t.length,this.skippableSize>0)return void i();t=t.slice(-this.skippableSize),this.skippableSize=0,this.state=f.MAGIC}this.buffer=this.buffer?r.concat([this.buffer,t],this.buffer.length+t.length):t,this._main(i)},i.prototype.emit_Error=function(t){this.emit("error",new Error(t+" @"+this.pos))},i.prototype.check_Size=function(t){var e=this.buffer.length-this.pos;return 0>=e||t>e?(this.notEnoughData&&this.emit_Error("Unexpected end of LZ4 stream"),!0):(this.pos+=t,!1)},i.prototype.read_MagicNumber=function(){var t=this.pos;if(this.check_Size(c.MAGIC))return!0;var e=a.readInt32LE(this.buffer,t);return(4294967280&e)===o.MAGICNUMBER_SKIPPABLE?void(this.state=f.SKIP_SIZE):e!==o.MAGICNUMBER?(this.pos=t,this.emit_Error("Invalid magic number: "+e.toString(16).toUpperCase()),!0):void(this.state=f.DESCRIPTOR)},i.prototype.read_SkippableSize=function(){var t=this.pos;return this.check_Size(c.SKIP_SIZE)?!0:(this.state=f.SKIP_DATA,void(this.skippableSize=a.readInt32LE(this.buffer,t)))},i.prototype.read_Descriptor=function(){var t=this.pos;if(this.check_Size(c.DESCRIPTOR))return!0;this.descriptorStart=t;var e=this.buffer[t],r=e>>6;if(r!==o.VERSION)return this.pos=t,this.emit_Error("Invalid version: "+r+" != "+o.VERSION),!0;if(e>>1&1)return this.pos=t,this.emit_Error("Reserved bit set"),!0;var i=this.buffer[t+1]>>4&7,n=o.blockMaxSizes[i];return null===n?(this.pos=t,this.emit_Error("Invalid block max size: "+i),!0):(this.descriptor={blockIndependence:Boolean(e>>5&1),blockChecksum:Boolean(e>>4&1),blockMaxSize:n,streamSize:Boolean(e>>3&1),streamChecksum:Boolean(e>>2&1),dict:Boolean(1&e),dictId:0},void(this.state=f.SIZE))},i.prototype.read_Size=function(){if(this.descriptor.streamSize){var t=this.pos;if(this.check_Size(c.SIZE))return!0;this.streamSize=this.buffer.slice(t,t+8)}this.state=f.DICTID},i.prototype.read_DictId=function(){if(this.descriptor.dictId){var t=this.pos;if(this.check_Size(c.DICTID))return!0;this.dictId=a.readInt32LE(this.buffer,t)}this.state=f.DESCRIPTOR_CHECKSUM},i.prototype.read_DescriptorChecksum=function(){var t=this.pos;if(this.check_Size(c.DESCRIPTOR_CHECKSUM))return!0;var e=this.buffer[t],r=a.descriptorChecksum(this.buffer.slice(this.descriptorStart,t));return r!==e?(this.pos=t,this.emit_Error("Invalid stream descriptor checksum"),!0):void(this.state=f.DATABLOCK_SIZE)},i.prototype.read_DataBlockSize=function(){var t=this.pos;if(this.check_Size(c.DATABLOCK_SIZE))return!0;var e=a.readInt32LE(this.buffer,t);return e===o.EOS?void(this.state=f.EOS):(this.dataBlockSize=e,void(this.state=f.DATABLOCK_DATA))},i.prototype.read_DataBlockData=function(){var t=this.pos,e=this.dataBlockSize;return 2147483648&e&&(e=2147483647&e),this.check_Size(e)?!0:(this.dataBlock=this.buffer.slice(t,t+e),void(this.state=f.DATABLOCK_CHECKSUM))},i.prototype.read_DataBlockChecksum=function(){var t=this.pos;if(this.descriptor.blockChecksum){if(this.check_Size(c.DATABLOCK_CHECKSUM))return!0;var e=a.readInt32LE(this.buffer,this.pos-4),r=a.blockChecksum(this.dataBlock);if(r!==e)return this.pos=t,this.emit_Error("Invalid block checksum"),!0}this.state=f.DATABLOCK_UNCOMPRESS},i.prototype.uncompress_DataBlock=function(){var t;if(2147483648&this.dataBlockSize)t=this.dataBlock;else{t=new r(this.descriptor.blockMaxSize);var e=this.binding.uncompress(this.dataBlock,t);if(0>e)return this.emit_Error("Invalid data block: "+-e),!0;er&&(this.buffer=this.buffer.slice(this.pos),this.pos=0),t()},e.exports=i}).call(this,t("buffer").Buffer)},{"./binding":22,"./static":27,buffer:void 0,stream:19,util:21}],25:[function(t,e,r){(function(e){function i(t,r){var i=[],s=new n(r);return s.on("data",function(t){i.push(t)}),s.end(t),e.concat(i)}var n=t("./encoder_stream");r.LZ4_compress=i}).call(this,t("buffer").Buffer)},{"./encoder_stream":26,buffer:void 0}],26:[function(t,e){(function(r){function i(t){if(!(this instanceof i))return new i(t);n.call(this,t);var e=t||l;e!==l&&Object.keys(l).forEach(function(t){e.hasOwnProperty(t)||(e[t]=l[t])}),this.options=e,this.binding=this.options.useJS?u:h,this.compress=e.highCompression?this.binding.compressHC:this.binding.compress;var r=0;r|=o.VERSION<<6,r|=(1&e.blockIndependence)<<5,r|=(1&e.blockChecksum)<<4,r|=(1&e.streamSize)<<3,r|=(1&e.streamChecksum)<<2,r|=1&e.dict;var s=o.blockMaxSizes.indexOf(e.blockMaxSize);if(0>s)throw new Error("Invalid blockMaxSize: "+e.blockMaxSize);this.descriptor={flg:r,bd:(7&s)<<4},this.buffer=[],this.length=0,this.first=!0,this.checksum=null}var n=t("stream").Transform,s=t("util").inherits,o=t("./static"),a=o.utils,h=a.bindings,u=t("./binding"),f=o.STATES,c=o.SIZES,l={blockIndependence:!0,blockChecksum:!1,blockMaxSize:4<<20,streamSize:!1,streamChecksum:!0,dict:!1,dictId:0,highCompression:!1};s(i,n),i.prototype.headerSize=function(){var t=this.options.streamSize?c.DESCRIPTOR:0,e=this.options.dict?c.DICTID:0;return c.MAGIC+1+1+t+e+1},i.prototype.header=function(){var t=this.headerSize(),e=new r(t);this.state=f.MAGIC,e.writeInt32LE(o.MAGICNUMBER,0,!0),this.state=f.DESCRIPTOR;var i=e.slice(c.MAGIC,e.length-1);i.writeUInt8(this.descriptor.flg,0,!0),i.writeUInt8(this.descriptor.bd,1,!0);var n=2;return this.state=f.SIZE,this.options.streamSize&&(i.writeInt32LE(0,n,!0),i.writeInt32LE(this.size,n+4,!0),n+=c.SIZE),this.state=f.DICTID,this.options.dict&&(i.writeInt32LE(this.dictId,n,!0),n+=c.DICTID),this.state=f.DESCRIPTOR_CHECKSUM,e.writeUInt8(a.descriptorChecksum(i),c.MAGIC+n,!1),e},i.prototype.update_Checksum=function(t){this.state=f.CHECKSUM_UPDATE,this.options.streamChecksum&&(this.checksum=a.streamChecksum(t,this.checksum))},i.prototype.compress_DataBlock=function(t){this.state=f.DATABLOCK_COMPRESS;var e=this.options.blockChecksum?c.DATABLOCK_CHECKSUM:0,i=this.binding.compressBound(t.length),n=new r(c.DATABLOCK_SIZE+i+e),s=n.slice(c.DATABLOCK_SIZE,c.DATABLOCK_SIZE+i),o=this.compress(t,s);if(this.state=f.DATABLOCK_SIZE,o>0&&o<=this.options.blockMaxSize?(n.writeUInt32LE(o,0,!0),n=n.slice(0,c.DATABLOCK_SIZE+o+e)):(n.writeInt32LE(2147483648|t.length,0,!0),n=n.slice(0,c.DATABLOCK_SIZE+t.length+e),t.copy(n,c.DATABLOCK_SIZE)),this.state=f.DATABLOCK_CHECKSUM,this.options.blockChecksum){var h=n.slice(-e);h.writeInt32LE(a.blockChecksum(s),0,!0)}return this.update_Checksum(t),this.size+=t.length,n},i.prototype._transform=function(t,e,i){t&&(this.buffer.push(t),this.length+=t.length),this.first&&(this.push(this.header()),this.first=!1);var n=this.options.blockMaxSize;if(this.length=n;a-=n,o+=n)this.push(this.compress_DataBlock(s.slice(o,o+n)));a>0?(this.buffer=[s.slice(o)],this.length=this.buffer[0].length):(this.buffer=[],this.length=0),i()},i.prototype._flush=function(t){if(this.length>0){var e=r.concat(this.buffer,this.length);this.buffer=[],this.length=0;var i=this.compress_DataBlock(e);this.push(i)}if(this.options.streamChecksum){this.state=f.CHECKSUM;var n=new r(c.EOS+c.CHECKSUM);n.writeInt32LE(a.streamChecksum(null,this.checksum),c.EOS,!0)}else var n=new r(c.EOS);this.state=f.EOS,n.writeInt32LE(o.EOS,0,!0),this.push(n),t()},e.exports=i}).call(this,t("buffer").Buffer)},{"./binding":22,"./static":27,buffer:void 0,stream:19,util:21}],27:[function(t,e,r){(function(e){r.MAGICNUMBER=407708164,r.MAGICNUMBER_BUFFER=new e(4),r.MAGICNUMBER_BUFFER.writeUInt32LE(r.MAGICNUMBER,0,!1),r.EOS=0,r.EOS_BUFFER=new e(4),r.EOS_BUFFER.writeUInt32LE(r.EOS,0,!1),r.VERSION=1,r.MAGICNUMBER_SKIPPABLE=407710288,r.blockMaxSizes=[null,null,null,null,65536,262144,1<<20,4<<20],r.extension=".lz4",r.STATES={MAGIC:0,DESCRIPTOR:1,SIZE:2,DICTID:3,DESCRIPTOR_CHECKSUM:4,DATABLOCK_SIZE:5,DATABLOCK_DATA:6,DATABLOCK_CHECKSUM:7,DATABLOCK_UNCOMPRESS:8,DATABLOCK_COMPRESS:9,CHECKSUM:10,CHECKSUM_UPDATE:11,EOS:90,SKIP_SIZE:101,SKIP_DATA:102},r.SIZES={MAGIC:4,DESCRIPTOR:2,SIZE:8,DICTID:4,DESCRIPTOR_CHECKSUM:1,DATABLOCK_SIZE:4,DATABLOCK_CHECKSUM:4,CHECKSUM:4,EOS:4,SKIP_SIZE:4},r.utils=t("./utils")}).call(this,t("buffer").Buffer)},{"./utils":void 0,buffer:void 0}],28:[function(t,e,r){r.UINT32=t("./lib/uint32"),r.UINT64=t("./lib/uint64")},{"./lib/uint32":29,"./lib/uint64":30}],29:[function(t,e){!function(t){function r(t,e){return this instanceof r?(this._low=0,this._high=0,this.remainder=null,"undefined"==typeof e?n.call(this,t):"string"==typeof t?s.call(this,t,e):void i.call(this,t,e)):new r(t,e)}function i(t,e){return this._low=0|t,this._high=0|e,this}function n(t){return this._low=65535&t,this._high=t>>>16,this}function s(t,e){var r=parseInt(t,e||10);return this._low=65535&r,this._high=r>>>16,this}var o=({36:r(Math.pow(36,5)),16:r(Math.pow(16,7)),10:r(Math.pow(10,9)),2:r(Math.pow(2,30))},{36:r(36),16:r(16),10:r(10),2:r(2)});r.prototype.fromBits=i,r.prototype.fromNumber=n,r.prototype.fromString=s,r.prototype.toNumber=function(){return this._high<<16|this._low},r.prototype.toString=function(t){t=t||10;var e=o[t]||new r(t);if(!this.gt(e))return this.toNumber().toString(t);for(var i=this.clone(),n=new Array(32),s=31;s>=0&&(i.div(e),n[s]=i.remainder.toNumber().toString(t),i.gt(e));s--);return n[s-1]=i.toNumber().toString(t),n.join("")},r.prototype.add=function(t){var e=this._low+t._low,r=e>>>16;return r+=this._high+t._high,this._low=65535&e,this._high=65535&r,this},r.prototype.subtract=function(t){return this.add(t.clone().negate())},r.prototype.multiply=function(t){var e,r,i=this._high,n=this._low,s=t._high,o=t._low;return r=n*o,e=r>>>16,e+=i*o,e&=65535,e+=n*s,this._low=65535&r,this._high=65535&e,this},r.prototype.div=function(t){if(0==t._low&&0==t._high)throw Error("division by zero");if(0==t._high&&1==t._low)return this.remainder=new r(0),this;if(t.gt(this))return this.remainder=new r(0),this._low=0,this._high=0,this;if(this.eq(t))return this.remainder=new r(0),this._low=1,this._high=0,this;for(var e=t.clone(),i=-1;!this.lt(e);)e.shiftLeft(1,!0),i++;for(this.remainder=this.clone(),this._low=0,this._high=0;i>=0;i--)e.shiftRight(1),this.remainder.lt(e)||(this.remainder.subtract(e),i>=16?this._high|=1<>>16)&65535,this},r.prototype.equals=r.prototype.eq=function(t){return this._low==t._low&&this._high==t._high},r.prototype.greaterThan=r.prototype.gt=function(t){return this._high>t._high?!0:this._hight._low},r.prototype.lessThan=r.prototype.lt=function(t){return this._hight._high?!1:this._low16?(this._low=this._high>>t-16,this._high=0):16==t?(this._low=this._high,this._high=0):(this._low=this._low>>t|this._high<<16-t&65535,this._high>>=t),this},r.prototype.shiftLeft=r.prototype.shiftl=function(t,e){return t>16?(this._high=this._low<>16-t,this._low=this._low<>>32-t,this._low=65535&e,this._high=e>>>16,this},r.prototype.rotateRight=r.prototype.rotr=function(t){var e=this._high<<16|this._low;return e=e>>>t|e<<32-t,this._low=65535&e,this._high=e>>>16,this},r.prototype.clone=function(){return new r(this._low,this._high)},"undefined"!=typeof define&&define.amd?define([],function(){return r}):"undefined"!=typeof e&&e.exports?e.exports=r:t.UINT32=r}(this)},{}],30:[function(t,e){!function(t){function r(t,e,o,a){return this instanceof r?(this.remainder=null,"string"==typeof t?s.call(this,t,e):"undefined"==typeof e?n.call(this,t):void i.apply(this,arguments)):new r(t,e,o,a)}function i(t,e,r,i){return"undefined"==typeof r?(this._a00=65535&t,this._a16=t>>>16,this._a32=65535&e,this._a48=e>>>16,this):(this._a00=0|t,this._a16=0|e,this._a32=0|r,this._a48=0|i,this)}function n(t){return this._a00=65535&t,this._a16=t>>>16,this._a32=0,this._a48=0,this}function s(t,e){e=e||10,this._a00=0,this._a16=0,this._a32=0,this._a48=0;for(var i=o[e]||new r(Math.pow(e,5)),n=0,s=t.length;s>n;n+=5){var a=Math.min(5,s-n),h=parseInt(t.slice(n,n+a),e);this.multiply(5>a?new r(Math.pow(e,a)):i).add(new r(h))}return this}var o={16:r(Math.pow(16,5)),10:r(Math.pow(10,5)),2:r(Math.pow(2,5))},a={16:r(16),10:r(10),2:r(2)};r.prototype.fromBits=i,r.prototype.fromNumber=n,r.prototype.fromString=s,r.prototype.toNumber=function(){return this._a16<<16|this._a00},r.prototype.toString=function(t){t=t||10;var e=a[t]||new r(t);if(!this.gt(e))return this.toNumber().toString(t);for(var i=this.clone(),n=new Array(64),s=63;s>=0&&(i.div(e),n[s]=i.remainder.toNumber().toString(t),i.gt(e));s--);return n[s-1]=i.toNumber().toString(t),n.join("")},r.prototype.add=function(t){var e=this._a00+t._a00,r=e>>>16;r+=this._a16+t._a16;var i=r>>>16;i+=this._a32+t._a32;var n=i>>>16;return n+=this._a48+t._a48,this._a00=65535&e,this._a16=65535&r,this._a32=65535&i,this._a48=65535&n,this},r.prototype.subtract=function(t){return this.add(t.clone().negate())},r.prototype.multiply=function(t){var e=this._a00,r=this._a16,i=this._a32,n=this._a48,s=t._a00,o=t._a16,a=t._a32,h=t._a48,u=e*s,f=u>>>16;f+=e*o;var c=f>>>16;f&=65535,f+=r*s,c+=f>>>16,c+=e*a;var l=c>>>16;return c&=65535,c+=r*o,l+=c>>>16,c&=65535,c+=i*s,l+=c>>>16,l+=e*h,l&=65535,l+=r*a,l&=65535,l+=i*o,l&=65535,l+=n*s,this._a00=65535&u,this._a16=65535&f,this._a32=65535&c,this._a48=65535&l,this},r.prototype.div=function(t){if(0==t._a16&&0==t._a32&&0==t._a48){if(0==t._a00)throw Error("division by zero");if(1==t._a00)return this.remainder=new r(0),this}if(t.gt(this))return this.remainder=new r(0),this._a00=0,this._a16=0,this._a32=0,this._a48=0,this;if(this.eq(t))return this.remainder=new r(0),this._a00=1,this._a16=0,this._a32=0,this._a48=0,this;for(var e=t.clone(),i=-1;!this.lt(e);)e.shiftLeft(1,!0),i++;for(this.remainder=this.clone(),this._a00=0,this._a16=0,this._a32=0,this._a48=0;i>=0;i--)e.shiftRight(1),this.remainder.lt(e)||(this.remainder.subtract(e),i>=48?this._a48|=1<=32?this._a32|=1<=16?this._a16|=1<>>16),this._a16=65535&t,t=(65535&~this._a32)+(t>>>16),this._a32=65535&t,this._a48=~this._a48+(t>>>16)&65535,this},r.prototype.equals=r.prototype.eq=function(t){return this._a48==t._a48&&this._a00==t._a00&&this._a32==t._a32&&this._a16==t._a16},r.prototype.greaterThan=r.prototype.gt=function(t){return this._a48>t._a48?!0:this._a48t._a32?!0:this._a32t._a16?!0:this._a16t._a00},r.prototype.lessThan=r.prototype.lt=function(t){return this._a48t._a48?!1:this._a32t._a32?!1:this._a16t._a16?!1:this._a00=48?(this._a00=this._a48>>t-48,this._a16=0,this._a32=0,this._a48=0):t>=32?(t-=32,this._a00=65535&(this._a32>>t|this._a48<<16-t),this._a16=this._a48>>t&65535,this._a32=0,this._a48=0):t>=16?(t-=16,this._a00=65535&(this._a16>>t|this._a32<<16-t),this._a16=65535&(this._a32>>t|this._a48<<16-t),this._a32=this._a48>>t&65535,this._a48=0):(this._a00=65535&(this._a00>>t|this._a16<<16-t),this._a16=65535&(this._a16>>t|this._a32<<16-t),this._a32=65535&(this._a32>>t|this._a48<<16-t),this._a48=this._a48>>t&65535),this},r.prototype.shiftLeft=r.prototype.shiftl=function(t,e){return t%=64,t>=48?(this._a48=this._a00<=32?(t-=32,this._a48=this._a16<>16-t,this._a32=this._a00<=16?(t-=16,this._a48=this._a32<>16-t,this._a32=65535&(this._a16<>16-t),this._a16=this._a00<>16-t,this._a32=65535&(this._a32<>16-t),this._a16=65535&(this._a16<>16-t),this._a00=this._a00<=32){var e=this._a00;if(this._a00=this._a32,this._a32=e,e=this._a48,this._a48=this._a16,this._a16=e,32==t)return this;t-=32}var r=this._a48<<16|this._a32,i=this._a16<<16|this._a00,n=r<>>32-t,s=i<>>32-t;return this._a00=65535&s,this._a16=s>>>16,this._a32=65535&n,this._a48=n>>>16,this},r.prototype.rotateRight=r.prototype.rotr=function(t){if(t%=64,0==t)return this;if(t>=32){var e=this._a00;if(this._a00=this._a32,this._a32=e,e=this._a48,this._a48=this._a16,this._a16=e,32==t)return this;t-=32}var r=this._a48<<16|this._a32,i=this._a16<<16|this._a00,n=r>>>t|i<<32-t,s=i>>>t|r<<32-t;return this._a00=65535&s,this._a16=s>>>16,this._a32=65535&n,this._a48=n>>>16,this},r.prototype.clone=function(){return new r(this._a00,this._a16,this._a32,this._a48)},"undefined"!=typeof define&&define.amd?define([],function(){return r}):"undefined"!=typeof e&&e.exports?e.exports=r:t.UINT64=r}(this)},{}],31:[function(t,e){(function(r){!function(i){function n(t){for(var e=[],r=0,i=t.length;i>r;r++){var n=t.charCodeAt(r);128>n?e.push(n):2048>n?e.push(192|n>>6,128|63&n):55296>n||n>=57344?e.push(224|n>>12,128|n>>6&63,128|63&n):(r++,n=65536+((1023&n)<<10|1023&t.charCodeAt(r)),e.push(240|n>>18,128|n>>12&63,128|n>>6&63,128|63&n))}return new Uint8Array(e)}function s(){return 2==arguments.length?new s(arguments[1]).update(arguments[0]).digest():this instanceof s?void o.call(this,arguments[0]):new s(arguments[0])}function o(t){return this.seed=t instanceof a?t.clone():a(t),this.v1=this.seed.clone().add(d),this.v2=this.seed.clone().add(u),this.v3=this.seed.clone(),this.v4=this.seed.clone().subtract(h),this.total_len=0,this.memsize=0,this.memory=null,this}var a=t("cuint").UINT32;a.prototype.xxh_update=function(t,e){var r,i,n=u._low,s=u._high;i=t*n,r=i>>>16,r+=e*n,r&=65535,r+=t*s;var o=this._low+(65535&i),a=o>>>16;a+=this._high+(65535&r);var f=a<<16|65535&o;f=f<<13|f>>>19,o=65535&f,a=f>>>16,n=h._low,s=h._high,i=o*n,r=i>>>16,r+=a*n,r&=65535,r+=o*s,this._low=65535&i,this._high=65535&r};var h=a("2654435761"),u=a("2246822519"),f=a("3266489917"),c=a("668265263"),l=a("374761393"),d=h.clone().add(u);s.prototype.init=o,s.prototype.update=function(t){var e,i="string"==typeof t;i&&(t=n(t),i=!1,e=!0),"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer&&(e=!0,t=new Uint8Array(t));var s=0,o=t.length,a=s+o;if(0==o)return this;if(this.total_len+=o,0==this.memsize&&(this.memory=i?"":e?new Uint8Array(16):new r(16)),this.memsize+o<16)return i?this.memory+=t:e?this.memory.set(t.subarray(0,o),this.memsize):t.copy(this.memory,this.memsize,0,o),this.memsize+=o,this;if(this.memsize>0){i?this.memory+=t.slice(0,16-this.memsize):e?this.memory.set(t.subarray(0,16-this.memsize),this.memsize):t.copy(this.memory,this.memsize,0,16-this.memsize);var h=0;i?(this.v1.xxh_update(this.memory.charCodeAt(h+1)<<8|this.memory.charCodeAt(h),this.memory.charCodeAt(h+3)<<8|this.memory.charCodeAt(h+2)),h+=4,this.v2.xxh_update(this.memory.charCodeAt(h+1)<<8|this.memory.charCodeAt(h),this.memory.charCodeAt(h+3)<<8|this.memory.charCodeAt(h+2)),h+=4,this.v3.xxh_update(this.memory.charCodeAt(h+1)<<8|this.memory.charCodeAt(h),this.memory.charCodeAt(h+3)<<8|this.memory.charCodeAt(h+2)),h+=4,this.v4.xxh_update(this.memory.charCodeAt(h+1)<<8|this.memory.charCodeAt(h),this.memory.charCodeAt(h+3)<<8|this.memory.charCodeAt(h+2))):(this.v1.xxh_update(this.memory[h+1]<<8|this.memory[h],this.memory[h+3]<<8|this.memory[h+2]),h+=4,this.v2.xxh_update(this.memory[h+1]<<8|this.memory[h],this.memory[h+3]<<8|this.memory[h+2]),h+=4,this.v3.xxh_update(this.memory[h+1]<<8|this.memory[h],this.memory[h+3]<<8|this.memory[h+2]),h+=4,this.v4.xxh_update(this.memory[h+1]<<8|this.memory[h],this.memory[h+3]<<8|this.memory[h+2])),s+=16-this.memsize,this.memsize=0,i&&(this.memory="")}if(a-16>=s){var u=a-16;do i?(this.v1.xxh_update(t.charCodeAt(s+1)<<8|t.charCodeAt(s),t.charCodeAt(s+3)<<8|t.charCodeAt(s+2)),s+=4,this.v2.xxh_update(t.charCodeAt(s+1)<<8|t.charCodeAt(s),t.charCodeAt(s+3)<<8|t.charCodeAt(s+2)),s+=4,this.v3.xxh_update(t.charCodeAt(s+1)<<8|t.charCodeAt(s),t.charCodeAt(s+3)<<8|t.charCodeAt(s+2)),s+=4,this.v4.xxh_update(t.charCodeAt(s+1)<<8|t.charCodeAt(s),t.charCodeAt(s+3)<<8|t.charCodeAt(s+2))):(this.v1.xxh_update(t[s+1]<<8|t[s],t[s+3]<<8|t[s+2]),s+=4,this.v2.xxh_update(t[s+1]<<8|t[s],t[s+3]<<8|t[s+2]),s+=4,this.v3.xxh_update(t[s+1]<<8|t[s],t[s+3]<<8|t[s+2]),s+=4,this.v4.xxh_update(t[s+1]<<8|t[s],t[s+3]<<8|t[s+2])),s+=4;while(u>=s)}return a>s&&(i?this.memory+=t.slice(s):e?this.memory.set(t.subarray(s,a),this.memsize):t.copy(this.memory,this.memsize,s,a),this.memsize=a-s),this},s.prototype.digest=function(){var t,e,r=this.memory,i="string"==typeof r,n=0,s=this.memsize,o=new a;for(t=this.total_len>=16?this.v1.rotl(1).add(this.v2.rotl(7).add(this.v3.rotl(12).add(this.v4.rotl(18)))):this.seed.add(l),t.add(o.fromNumber(this.total_len));s-4>=n;)i?o.fromBits(r.charCodeAt(n+1)<<8|r.charCodeAt(n),r.charCodeAt(n+3)<<8|r.charCodeAt(n+2)):o.fromBits(r[n+1]<<8|r[n],r[n+3]<<8|r[n+2]),t.add(o.multiply(f)).rotl(17).multiply(c),n+=4;for(;s>n;)o.fromBits(i?r.charCodeAt(n++):r[n++],0),t.add(o.multiply(l)).rotl(11).multiply(h);return e=t.clone().shiftRight(15),t.xor(e).multiply(u),e=t.clone().shiftRight(13),t.xor(e).multiply(f),e=t.clone().shiftRight(16),t.xor(e),this.init(this.seed),t},"undefined"!=typeof define&&define.amd?define([],function(){return s}):"undefined"!=typeof e&&e.exports?e.exports=s:i.XXH=s}(this)}).call(this,t("buffer").Buffer)},{buffer:void 0,cuint:28}],buffer:[function(t,e,r){function i(t,e,r){if(!(this instanceof i))return new i(t,e,r);var n,s=typeof t;if("number"===s)n=t>0?t>>>0:0;else if("string"===s)"base64"===e&&(t=L(t)),n=i.byteLength(t,e);else{if("object"!==s||null===t)throw new Error("First argument needs to be a number, array or string.");"Buffer"===t.type&&x(t.data)&&(t=t.data),n=+t.length>0?Math.floor(+t.length):0}var o;W?o=i._augment(new Uint8Array(n)):(o=this,o.length=n,o._isBuffer=!0);var a;if(W&&"number"==typeof t.byteLength)o._set(t);else if(M(t))if(i.isBuffer(t))for(a=0;n>a;a++)o[a]=t.readUInt8(a);else for(a=0;n>a;a++)o[a]=(t[a]%256+256)%256;else if("string"===s)o.write(t,0,e);else if("number"===s&&!W&&!r)for(a=0;n>a;a++)o[a]=0;return o}function n(t,e,r,i){r=Number(r)||0;var n=t.length-r;i?(i=Number(i),i>n&&(i=n)):i=n;var s=e.length;Z(s%2===0,"Invalid hex string"),i>s/2&&(i=s/2);for(var o=0;i>o;o++){var a=parseInt(e.substr(2*o,2),16);Z(!isNaN(a),"Invalid hex string"),t[r+o]=a}return o}function s(t,e,r,i){var n=z(T(e),t,r,i);return n}function o(t,e,r,i){var n=z(O(e),t,r,i);return n}function a(t,e,r,i){return o(t,e,r,i)}function h(t,e,r,i){var n=z(R(e),t,r,i);return n}function u(t,e,r,i){var n=z(U(e),t,r,i);return n}function f(t,e,r){return H.fromByteArray(0===e&&r===t.length?t:t.slice(e,r))}function c(t,e,r){var i="",n="";r=Math.min(t.length,r);for(var s=e;r>s;s++)t[s]<=127?(i+=j(n)+String.fromCharCode(t[s]),n=""):n+="%"+t[s].toString(16);return i+j(n)}function l(t,e,r){var i="";r=Math.min(t.length,r);for(var n=e;r>n;n++)i+=String.fromCharCode(t[n]);return i}function d(t,e,r){return l(t,e,r)}function p(t,e,r){var i=t.length;(!e||0>e)&&(e=0),(!r||0>r||r>i)&&(r=i);for(var n="",s=e;r>s;s++)n+=D(t[s]);return n}function g(t,e,r){for(var i=t.slice(e,r),n="",s=0;s=n)){var s;return r?(s=t[e],n>e+1&&(s|=t[e+1]<<8)):(s=t[e]<<8,n>e+1&&(s|=t[e+1])),s}}function _(t,e,r,i){i||(Z("boolean"==typeof r,"missing or invalid endian"),Z(void 0!==e&&null!==e,"missing offset"),Z(e+3=n)){var s;return r?(n>e+2&&(s=t[e+2]<<16),n>e+1&&(s|=t[e+1]<<8),s|=t[e],n>e+3&&(s+=t[e+3]<<24>>>0)):(n>e+1&&(s=t[e+1]<<16),n>e+2&&(s|=t[e+2]<<8),n>e+3&&(s|=t[e+3]),s+=t[e]<<24>>>0),s}}function v(t,e,r,i){i||(Z("boolean"==typeof r,"missing or invalid endian"),Z(void 0!==e&&null!==e,"missing offset"),Z(e+1=n)){var s=m(t,e,r,!0),o=32768&s;return o?-1*(65535-s+1):s}}function b(t,e,r,i){i||(Z("boolean"==typeof r,"missing or invalid endian"),Z(void 0!==e&&null!==e,"missing offset"),Z(e+3=n)){var s=_(t,e,r,!0),o=2147483648&s;return o?-1*(4294967295-s+1):s -}}function y(t,e,r,i){return i||(Z("boolean"==typeof r,"missing or invalid endian"),Z(e+3=s)){for(var o=0,a=Math.min(s-r,2);a>o;o++)t[r+o]=(e&255<<8*(i?o:1-o))>>>8*(i?o:1-o);return r+2}}function S(t,e,r,i,n){n||(Z(void 0!==e&&null!==e,"missing value"),Z("boolean"==typeof i,"missing or invalid endian"),Z(void 0!==r&&null!==r,"missing offset"),Z(r+3=s)){for(var o=0,a=Math.min(s-r,4);a>o;o++)t[r+o]=e>>>8*(i?o:3-o)&255;return r+4}}function C(t,e,r,i,n){n||(Z(void 0!==e&&null!==e,"missing value"),Z("boolean"==typeof i,"missing or invalid endian"),Z(void 0!==r&&null!==r,"missing offset"),Z(r+1=s))return e>=0?E(t,e,r,i,n):E(t,65535+e+1,r,i,n),r+2}function I(t,e,r,i,n){n||(Z(void 0!==e&&null!==e,"missing value"),Z("boolean"==typeof i,"missing or invalid endian"),Z(void 0!==r&&null!==r,"missing offset"),Z(r+3=s))return e>=0?S(t,e,r,i,n):S(t,4294967295+e+1,r,i,n),r+4}function A(t,e,r,i,n){n||(Z(void 0!==e&&null!==e,"missing value"),Z("boolean"==typeof i,"missing or invalid endian"),Z(void 0!==r&&null!==r,"missing offset"),Z(r+3=s))return F.write(t,e,r,i,23,4),r+4}function k(t,e,r,i,n){n||(Z(void 0!==e&&null!==e,"missing value"),Z("boolean"==typeof i,"missing or invalid endian"),Z(void 0!==r&&null!==r,"missing offset"),Z(r+7=s))return F.write(t,e,r,i,52,8),r+8}function L(t){for(t=B(t).replace(q,"");t.length%4!==0;)t+="=";return t}function B(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function x(t){return(Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)})(t)}function M(t){return x(t)||i.isBuffer(t)||t&&"object"==typeof t&&"number"==typeof t.length}function D(t){return 16>t?"0"+t.toString(16):t.toString(16)}function T(t){for(var e=[],r=0;r=i)e.push(i);else{var n=r;i>=55296&&57343>=i&&r++;for(var s=encodeURIComponent(t.slice(n,r+1)).substr(1).split("%"),o=0;o>8,i=e%256,n.push(i),n.push(r);return n}function R(t){return H.toByteArray(t)}function z(t,e,r,i){for(var n=0;i>n&&!(n+r>=e.length||n>=t.length);n++)e[n+r]=t[n];return n}function j(t){try{return decodeURIComponent(t)}catch(e){return String.fromCharCode(65533)}}function N(t,e){Z("number"==typeof t,"cannot write a non-number as a number"),Z(t>=0,"specified a negative value for writing an unsigned value"),Z(e>=t,"value is larger than maximum value for type"),Z(Math.floor(t)===t,"value has a fractional component")}function K(t,e,r){Z("number"==typeof t,"cannot write a non-number as a number"),Z(e>=t,"value larger than maximum allowed value"),Z(t>=r,"value smaller than minimum allowed value"),Z(Math.floor(t)===t,"value has a fractional component")}function P(t,e,r){Z("number"==typeof t,"cannot write a non-number as a number"),Z(e>=t,"value larger than maximum allowed value"),Z(t>=r,"value smaller than minimum allowed value")}function Z(t,e){if(!t)throw new Error(e||"Failed assertion")}var H=t("base64-js"),F=t("ieee754");r.Buffer=i,r.SlowBuffer=i,r.INSPECT_MAX_BYTES=50,i.poolSize=8192;var W=function(){try{var t=new ArrayBuffer(0),e=new Uint8Array(t);return e.foo=function(){return 42},42===e.foo()&&"function"==typeof e.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(r){return!1}}();i.isEncoding=function(t){switch(String(t).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}},i.isBuffer=function(t){return!(null==t||!t._isBuffer)},i.byteLength=function(t,e){var r;switch(t=t.toString(),e||"utf8"){case"hex":r=t.length/2;break;case"utf8":case"utf-8":r=T(t).length;break;case"ascii":case"binary":case"raw":r=t.length;break;case"base64":r=R(t).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":r=2*t.length;break;default:throw new Error("Unknown encoding")}return r},i.concat=function(t,e){if(Z(x(t),"Usage: Buffer.concat(list[, length])"),0===t.length)return new i(0);if(1===t.length)return t[0];var r;if(void 0===e)for(e=0,r=0;rs&&t[s]===e[s];s++);return s!==o&&(r=t[s],n=e[s]),n>r?-1:r>n?1:0},i.prototype.write=function(t,e,r,i){if(isFinite(e))isFinite(r)||(i=r,r=void 0);else{var f=i;i=e,e=r,r=f}e=Number(e)||0;var c=this.length-e;r?(r=Number(r),r>c&&(r=c)):r=c,i=String(i||"utf8").toLowerCase();var l;switch(i){case"hex":l=n(this,t,e,r);break;case"utf8":case"utf-8":l=s(this,t,e,r);break;case"ascii":l=o(this,t,e,r);break;case"binary":l=a(this,t,e,r);break;case"base64":l=h(this,t,e,r);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":l=u(this,t,e,r);break;default:throw new Error("Unknown encoding")}return l},i.prototype.toString=function(t,e,r){var i=this;if(t=String(t||"utf8").toLowerCase(),e=Number(e)||0,r=void 0===r?i.length:Number(r),r===e)return"";var n;switch(t){case"hex":n=p(i,e,r);break;case"utf8":case"utf-8":n=c(i,e,r);break;case"ascii":n=l(i,e,r);break;case"binary":n=d(i,e,r);break;case"base64":n=f(i,e,r);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":n=g(i,e,r);break;default:throw new Error("Unknown encoding")}return n},i.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},i.prototype.equals=function(t){return Z(i.isBuffer(t),"Argument must be a Buffer"),0===i.compare(this,t)},i.prototype.compare=function(t){return Z(i.isBuffer(t),"Argument must be a Buffer"),i.compare(this,t)},i.prototype.copy=function(t,e,r,i){var n=this;if(r||(r=0),i||0===i||(i=this.length),e||(e=0),i!==r&&0!==t.length&&0!==n.length){Z(i>=r,"sourceEnd < sourceStart"),Z(e>=0&&e=0&&r=0&&i<=n.length,"sourceEnd out of bounds"),i>this.length&&(i=this.length),t.length-es||!W)for(var o=0;s>o;o++)t[o+e]=this[o+r];else t._set(this.subarray(r,r+s),e)}},i.prototype.slice=function(t,e){var r=this.length;if(t=~~t,e=void 0===e?r:~~e,0>t?(t+=r,0>t&&(t=0)):t>r&&(t=r),0>e?(e+=r,0>e&&(e=0)):e>r&&(e=r),t>e&&(e=t),W)return i._augment(this.subarray(t,e));for(var n=e-t,s=new i(n,void 0,!0),o=0;n>o;o++)s[o]=this[o+t];return s},i.prototype.get=function(t){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(t)},i.prototype.set=function(t,e){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(t,e)},i.prototype.readUInt8=function(t,e){return e||(Z(void 0!==t&&null!==t,"missing offset"),Z(t=this.length?void 0:this[t]},i.prototype.readUInt16LE=function(t,e){return m(this,t,!0,e)},i.prototype.readUInt16BE=function(t,e){return m(this,t,!1,e)},i.prototype.readUInt32LE=function(t,e){return _(this,t,!0,e)},i.prototype.readUInt32BE=function(t,e){return _(this,t,!1,e)},i.prototype.readInt8=function(t,e){if(e||(Z(void 0!==t&&null!==t,"missing offset"),Z(t=this.length)){var r=128&this[t];return r?-1*(255-this[t]+1):this[t]}},i.prototype.readInt16LE=function(t,e){return v(this,t,!0,e)},i.prototype.readInt16BE=function(t,e){return v(this,t,!1,e)},i.prototype.readInt32LE=function(t,e){return b(this,t,!0,e)},i.prototype.readInt32BE=function(t,e){return b(this,t,!1,e)},i.prototype.readFloatLE=function(t,e){return y(this,t,!0,e)},i.prototype.readFloatBE=function(t,e){return y(this,t,!1,e)},i.prototype.readDoubleLE=function(t,e){return w(this,t,!0,e)},i.prototype.readDoubleBE=function(t,e){return w(this,t,!1,e)},i.prototype.writeUInt8=function(t,e,r){return r||(Z(void 0!==t&&null!==t,"missing value"),Z(void 0!==e&&null!==e,"missing offset"),Z(e=this.length?void 0:(this[e]=t,e+1)},i.prototype.writeUInt16LE=function(t,e,r){return E(this,t,e,!0,r)},i.prototype.writeUInt16BE=function(t,e,r){return E(this,t,e,!1,r)},i.prototype.writeUInt32LE=function(t,e,r){return S(this,t,e,!0,r)},i.prototype.writeUInt32BE=function(t,e,r){return S(this,t,e,!1,r)},i.prototype.writeInt8=function(t,e,r){return r||(Z(void 0!==t&&null!==t,"missing value"),Z(void 0!==e&&null!==e,"missing offset"),Z(e=this.length?void 0:(t>=0?this.writeUInt8(t,e,r):this.writeUInt8(255+t+1,e,r),e+1)},i.prototype.writeInt16LE=function(t,e,r){return C(this,t,e,!0,r)},i.prototype.writeInt16BE=function(t,e,r){return C(this,t,e,!1,r)},i.prototype.writeInt32LE=function(t,e,r){return I(this,t,e,!0,r)},i.prototype.writeInt32BE=function(t,e,r){return I(this,t,e,!1,r)},i.prototype.writeFloatLE=function(t,e,r){return A(this,t,e,!0,r)},i.prototype.writeFloatBE=function(t,e,r){return A(this,t,e,!1,r)},i.prototype.writeDoubleLE=function(t,e,r){return k(this,t,e,!0,r)},i.prototype.writeDoubleBE=function(t,e,r){return k(this,t,e,!1,r)},i.prototype.fill=function(t,e,r){if(t||(t=0),e||(e=0),r||(r=this.length),Z(r>=e,"end < start"),r!==e&&0!==this.length){Z(e>=0&&e=0&&r<=this.length,"end out of bounds");var i;if("number"==typeof t)for(i=e;r>i;i++)this[i]=t;else{var n=T(t.toString()),s=n.length;for(i=e;r>i;i++)this[i]=n[i%s]}return this}},i.prototype.inspect=function(){for(var t=[],e=this.length,i=0;e>i;i++)if(t[i]=D(this[i]),i===r.INSPECT_MAX_BYTES){t[i+1]="...";break}return""},i.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(W)return new i(this).buffer;for(var t=new Uint8Array(this.length),e=0,r=t.length;r>e;e+=1)t[e]=this[e];return t.buffer}throw new Error("Buffer.toArrayBuffer not supported in this browser")};var G=i.prototype;i._augment=function(t){return t._isBuffer=!0,t._get=t.get,t._set=t.set,t.get=G.get,t.set=G.set,t.write=G.write,t.toString=G.toString,t.toLocaleString=G.toString,t.toJSON=G.toJSON,t.equals=G.equals,t.compare=G.compare,t.copy=G.copy,t.slice=G.slice,t.readUInt8=G.readUInt8,t.readUInt16LE=G.readUInt16LE,t.readUInt16BE=G.readUInt16BE,t.readUInt32LE=G.readUInt32LE,t.readUInt32BE=G.readUInt32BE,t.readInt8=G.readInt8,t.readInt16LE=G.readInt16LE,t.readInt16BE=G.readInt16BE,t.readInt32LE=G.readInt32LE,t.readInt32BE=G.readInt32BE,t.readFloatLE=G.readFloatLE,t.readFloatBE=G.readFloatBE,t.readDoubleLE=G.readDoubleLE,t.readDoubleBE=G.readDoubleBE,t.writeUInt8=G.writeUInt8,t.writeUInt16LE=G.writeUInt16LE,t.writeUInt16BE=G.writeUInt16BE,t.writeUInt32LE=G.writeUInt32LE,t.writeUInt32BE=G.writeUInt32BE,t.writeInt8=G.writeInt8,t.writeInt16LE=G.writeInt16LE,t.writeInt16BE=G.writeInt16BE,t.writeInt32LE=G.writeInt32LE,t.writeInt32BE=G.writeInt32BE,t.writeFloatLE=G.writeFloatLE,t.writeFloatBE=G.writeFloatBE,t.writeDoubleLE=G.writeDoubleLE,t.writeDoubleBE=G.writeDoubleBE,t.fill=G.fill,t.inspect=G.inspect,t.toArrayBuffer=G.toArrayBuffer,t};var q=/[^+\/0-9A-z]/g},{"base64-js":1,ieee754:2}],lz4:[function(t,e){e.exports=t("./static"),e.exports.createDecoderStream=t("./decoder_stream"),e.exports.decode=t("./decoder").LZ4_uncompress,e.exports.createEncoderStream=t("./encoder_stream"),e.exports.encode=t("./encoder").LZ4_compress;var r=e.exports.utils.bindings;e.exports.decodeBlock=r.uncompress,e.exports.encodeBound=r.compressBound,e.exports.encodeBlock=r.compress,e.exports.encodeBlockHC=r.compressHC},{"./decoder":23,"./decoder_stream":24,"./encoder":25,"./encoder_stream":26,"./static":27}]},{},["lz4"]); diff --git a/src/html5/js/xpra_client.js b/src/html5/js/xpra_client.js index b9aa7a0eda..7a5b59901d 100644 --- a/src/html5/js/xpra_client.js +++ b/src/html5/js/xpra_client.js @@ -610,7 +610,6 @@ XpraClient.prototype._make_hello_base = function() { "digest" : ["hmac", "xor"], //compression bits: "zlib" : true, - "lz4" : true, "lzo" : false, "compression_level" : 1, // packet encoders @@ -618,6 +617,13 @@ XpraClient.prototype._make_hello_base = function() { "bencode" : true, "yaml" : false, }); + var LZ4 = require('lz4'); + if(LZ4) { + this._update_capabilities({ + "lz4" : true, + "lz4.js.version" : LZ4.version, + }); + } if(this.encryption) { this.cipher_in_caps = { diff --git a/src/html5/js/xpra_protocol.js b/src/html5/js/xpra_protocol.js index c0abcce760..6cefdc215b 100644 --- a/src/html5/js/xpra_protocol.js +++ b/src/html5/js/xpra_protocol.js @@ -334,7 +334,7 @@ if (!(typeof window == "object" && typeof document == "object" && window.documen importScripts('lib/websock.js', 'lib/bencode.js', 'lib/inflate.min.js', - 'lib/lz4.min.js', + 'lib/lz4.js', 'lib/forge.min.js'); // make protocol instance var protocol = new XpraProtocol();