Created
May 2, 2013 00:10
-
-
Save No9/5499324 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){ | |
var leveldowngap = require('leveldown-gap') | |
, levelup = require('levelup') | |
, factory = function (location) { return new leveldowngap(location) } | |
, db = levelup('/does/not/matter', { db: factory }) | |
db.put('name', 'Yuri Irsenovich Kim') | |
db.put('dob', '16 February 1941') | |
db.put('spouse', 'Kim Young-sook') | |
db.put('occupation', 'Clown') | |
db.readStream() | |
.on('data', console.log) | |
.on('close', function () { console.log('Show\'s over folks!') }) | |
},{"leveldown-gap":2,"levelup":3}],4:[function(require,module,exports){ | |
var events = require('events'); | |
exports.isArray = isArray; | |
exports.isDate = function(obj){return Object.prototype.toString.call(obj) === '[object Date]'}; | |
exports.isRegExp = function(obj){return Object.prototype.toString.call(obj) === '[object RegExp]'}; | |
exports.print = function () {}; | |
exports.puts = function () {}; | |
exports.debug = function() {}; | |
exports.inspect = function(obj, showHidden, depth, colors) { | |
var seen = []; | |
var stylize = function(str, styleType) { | |
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics | |
var styles = | |
{ '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] }; | |
var style = | |
{ 'special': 'cyan', | |
'number': 'blue', | |
'boolean': 'yellow', | |
'undefined': 'grey', | |
'null': 'bold', | |
'string': 'green', | |
'date': 'magenta', | |
// "name": intentionally not styling | |
'regexp': 'red' }[styleType]; | |
if (style) { | |
return '\033[' + styles[style][0] + 'm' + str + | |
'\033[' + styles[style][1] + 'm'; | |
} else { | |
return str; | |
} | |
}; | |
if (! colors) { | |
stylize = function(str, styleType) { return str; }; | |
} | |
function format(value, recurseTimes) { | |
// Provide a hook for user-specified inspect functions. | |
// Check that value is an object with an inspect function on it | |
if (value && typeof value.inspect === 'function' && | |
// Filter out the util module, it's inspect function is special | |
value !== exports && | |
// Also filter out any prototype objects using the circular check. | |
!(value.constructor && value.constructor.prototype === value)) { | |
return value.inspect(recurseTimes); | |
} | |
// Primitive types cannot have properties | |
switch (typeof value) { | |
case 'undefined': | |
return stylize('undefined', 'undefined'); | |
case 'string': | |
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') | |
.replace(/'/g, "\\'") | |
.replace(/\\"/g, '"') + '\''; | |
return stylize(simple, 'string'); | |
case 'number': | |
return stylize('' + value, 'number'); | |
case 'boolean': | |
return stylize('' + value, 'boolean'); | |
} | |
// For some reason typeof null is "object", so special case here. | |
if (value === null) { | |
return stylize('null', 'null'); | |
} | |
// Look up the keys of the object. | |
var visible_keys = Object_keys(value); | |
var keys = showHidden ? Object_getOwnPropertyNames(value) : visible_keys; | |
// Functions without properties can be shortcutted. | |
if (typeof value === 'function' && keys.length === 0) { | |
if (isRegExp(value)) { | |
return stylize('' + value, 'regexp'); | |
} else { | |
var name = value.name ? ': ' + value.name : ''; | |
return stylize('[Function' + name + ']', 'special'); | |
} | |
} | |
// Dates without properties can be shortcutted | |
if (isDate(value) && keys.length === 0) { | |
return stylize(value.toUTCString(), 'date'); | |
} | |
var base, type, braces; | |
// Determine the object type | |
if (isArray(value)) { | |
type = 'Array'; | |
braces = ['[', ']']; | |
} else { | |
type = 'Object'; | |
braces = ['{', '}']; | |
} | |
// Make functions say that they are functions | |
if (typeof value === 'function') { | |
var n = value.name ? ': ' + value.name : ''; | |
base = (isRegExp(value)) ? ' ' + value : ' [Function' + n + ']'; | |
} else { | |
base = ''; | |
} | |
// Make dates with properties first say the date | |
if (isDate(value)) { | |
base = ' ' + value.toUTCString(); | |
} | |
if (keys.length === 0) { | |
return braces[0] + base + braces[1]; | |
} | |
if (recurseTimes < 0) { | |
if (isRegExp(value)) { | |
return stylize('' + value, 'regexp'); | |
} else { | |
return stylize('[Object]', 'special'); | |
} | |
} | |
seen.push(value); | |
var output = keys.map(function(key) { | |
var name, str; | |
if (value.__lookupGetter__) { | |
if (value.__lookupGetter__(key)) { | |
if (value.__lookupSetter__(key)) { | |
str = stylize('[Getter/Setter]', 'special'); | |
} else { | |
str = stylize('[Getter]', 'special'); | |
} | |
} else { | |
if (value.__lookupSetter__(key)) { | |
str = stylize('[Setter]', 'special'); | |
} | |
} | |
} | |
if (visible_keys.indexOf(key) < 0) { | |
name = '[' + key + ']'; | |
} | |
if (!str) { | |
if (seen.indexOf(value[key]) < 0) { | |
if (recurseTimes === null) { | |
str = format(value[key]); | |
} else { | |
str = format(value[key], recurseTimes - 1); | |
} | |
if (str.indexOf('\n') > -1) { | |
if (isArray(value)) { | |
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 = stylize('[Circular]', 'special'); | |
} | |
} | |
if (typeof name === 'undefined') { | |
if (type === '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 = stylize(name, 'name'); | |
} else { | |
name = name.replace(/'/g, "\\'") | |
.replace(/\\"/g, '"') | |
.replace(/(^"|"$)/g, "'"); | |
name = stylize(name, 'string'); | |
} | |
} | |
return name + ': ' + str; | |
}); | |
seen.pop(); | |
var numLinesEst = 0; | |
var length = output.reduce(function(prev, cur) { | |
numLinesEst++; | |
if (cur.indexOf('\n') >= 0) numLinesEst++; | |
return prev + cur.length + 1; | |
}, 0); | |
if (length > 50) { | |
output = braces[0] + | |
(base === '' ? '' : base + '\n ') + | |
' ' + | |
output.join(',\n ') + | |
' ' + | |
braces[1]; | |
} else { | |
output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; | |
} | |
return output; | |
} | |
return format(obj, (typeof depth === 'undefined' ? 2 : depth)); | |
}; | |
function isArray(ar) { | |
return ar instanceof Array || | |
Array.isArray(ar) || | |
(ar && ar !== Object.prototype && isArray(ar.__proto__)); | |
} | |
function isRegExp(re) { | |
return re instanceof RegExp || | |
(typeof re === 'object' && Object.prototype.toString.call(re) === '[object RegExp]'); | |
} | |
function isDate(d) { | |
if (d instanceof Date) return true; | |
if (typeof d !== 'object') return false; | |
var properties = Date.prototype && Object_getOwnPropertyNames(Date.prototype); | |
var proto = d.__proto__ && Object_getOwnPropertyNames(d.__proto__); | |
return JSON.stringify(proto) === JSON.stringify(properties); | |
} | |
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(' '); | |
} | |
exports.log = function (msg) {}; | |
exports.pump = null; | |
var Object_keys = Object.keys || function (obj) { | |
var res = []; | |
for (var key in obj) res.push(key); | |
return res; | |
}; | |
var Object_getOwnPropertyNames = Object.getOwnPropertyNames || function (obj) { | |
var res = []; | |
for (var key in obj) { | |
if (Object.hasOwnProperty.call(obj, key)) res.push(key); | |
} | |
return res; | |
}; | |
var Object_create = Object.create || function (prototype, properties) { | |
// from es5-shim | |
var object; | |
if (prototype === null) { | |
object = { '__proto__' : null }; | |
} | |
else { | |
if (typeof prototype !== 'object') { | |
throw new TypeError( | |
'typeof prototype[' + (typeof prototype) + '] != \'object\'' | |
); | |
} | |
var Type = function () {}; | |
Type.prototype = prototype; | |
object = new Type(); | |
object.__proto__ = prototype; | |
} | |
if (typeof properties !== 'undefined' && Object.defineProperties) { | |
Object.defineProperties(object, properties); | |
} | |
return object; | |
}; | |
exports.inherits = function(ctor, superCtor) { | |
ctor.super_ = superCtor; | |
ctor.prototype = Object_create(superCtor.prototype, { | |
constructor: { | |
value: ctor, | |
enumerable: false, | |
writable: true, | |
configurable: true | |
} | |
}); | |
}; | |
var formatRegExp = /%[sdj%]/g; | |
exports.format = function(f) { | |
if (typeof f !== 'string') { | |
var objects = []; | |
for (var i = 0; i < arguments.length; i++) { | |
objects.push(exports.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': return JSON.stringify(args[i++]); | |
default: | |
return x; | |
} | |
}); | |
for(var x = args[i]; i < len; x = args[++i]){ | |
if (x === null || typeof x !== 'object') { | |
str += ' ' + x; | |
} else { | |
str += ' ' + exports.inspect(x); | |
} | |
} | |
return str; | |
}; | |
},{"events":5}],6:[function(require,module,exports){ | |
// shim for using process in browser | |
var process = module.exports = {}; | |
process.nextTick = (function () { | |
var canSetImmediate = typeof window !== 'undefined' | |
&& window.setImmediate; | |
var canPost = typeof window !== 'undefined' | |
&& window.postMessage && window.addEventListener | |
; | |
if (canSetImmediate) { | |
return function (f) { return window.setImmediate(f) }; | |
} | |
if (canPost) { | |
var queue = []; | |
window.addEventListener('message', function (ev) { | |
if (ev.source === window && ev.data === 'process-tick') { | |
ev.stopPropagation(); | |
if (queue.length > 0) { | |
var fn = queue.shift(); | |
fn(); | |
} | |
} | |
}, true); | |
return function nextTick(fn) { | |
queue.push(fn); | |
window.postMessage('process-tick', '*'); | |
}; | |
} | |
return function nextTick(fn) { | |
setTimeout(fn, 0); | |
}; | |
})(); | |
process.title = 'browser'; | |
process.browser = true; | |
process.env = {}; | |
process.argv = []; | |
process.binding = function (name) { | |
throw new Error('process.binding is not supported'); | |
} | |
// TODO(shtylman) | |
process.cwd = function () { return '/' }; | |
process.chdir = function (dir) { | |
throw new Error('process.chdir is not supported'); | |
}; | |
},{}],5:[function(require,module,exports){ | |
(function(process){if (!process.EventEmitter) process.EventEmitter = function () {}; | |
var EventEmitter = exports.EventEmitter = process.EventEmitter; | |
var isArray = typeof Array.isArray === 'function' | |
? Array.isArray | |
: function (xs) { | |
return Object.prototype.toString.call(xs) === '[object Array]' | |
} | |
; | |
function indexOf (xs, x) { | |
if (xs.indexOf) return xs.indexOf(x); | |
for (var i = 0; i < xs.length; i++) { | |
if (x === xs[i]) return i; | |
} | |
return -1; | |
} | |
// 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. | |
// | |
// Obviously not all Emitters should be limited to 10. This function allows | |
// that to be increased. Set to zero for unlimited. | |
var defaultMaxListeners = 10; | |
EventEmitter.prototype.setMaxListeners = function(n) { | |
if (!this._events) this._events = {}; | |
this._events.maxListeners = n; | |
}; | |
EventEmitter.prototype.emit = function(type) { | |
// If there is no 'error' event listener then throw. | |
if (type === 'error') { | |
if (!this._events || !this._events.error || | |
(isArray(this._events.error) && !this._events.error.length)) | |
{ | |
if (arguments[1] instanceof Error) { | |
throw arguments[1]; // Unhandled 'error' event | |
} else { | |
throw new Error("Uncaught, unspecified 'error' event."); | |
} | |
return false; | |
} | |
} | |
if (!this._events) return false; | |
var handler = this._events[type]; | |
if (!handler) return false; | |
if (typeof handler == 'function') { | |
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: | |
var args = Array.prototype.slice.call(arguments, 1); | |
handler.apply(this, args); | |
} | |
return true; | |
} else if (isArray(handler)) { | |
var args = Array.prototype.slice.call(arguments, 1); | |
var listeners = handler.slice(); | |
for (var i = 0, l = listeners.length; i < l; i++) { | |
listeners[i].apply(this, args); | |
} | |
return true; | |
} else { | |
return false; | |
} | |
}; | |
// EventEmitter is defined in src/node_events.cc | |
// EventEmitter.prototype.emit() is also defined there. | |
EventEmitter.prototype.addListener = function(type, listener) { | |
if ('function' !== typeof listener) { | |
throw new Error('addListener only takes instances of Function'); | |
} | |
if (!this._events) this._events = {}; | |
// To avoid recursion in the case that type == "newListeners"! Before | |
// adding it to the listeners, first emit "newListeners". | |
this.emit('newListener', type, listener); | |
if (!this._events[type]) { | |
// Optimize the case of one listener. Don't need the extra array object. | |
this._events[type] = listener; | |
} else if (isArray(this._events[type])) { | |
// Check for listener leak | |
if (!this._events[type].warned) { | |
var m; | |
if (this._events.maxListeners !== undefined) { | |
m = this._events.maxListeners; | |
} else { | |
m = 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); | |
console.trace(); | |
} | |
} | |
// 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]; | |
} | |
return this; | |
}; | |
EventEmitter.prototype.on = EventEmitter.prototype.addListener; | |
EventEmitter.prototype.once = function(type, listener) { | |
var self = this; | |
self.on(type, function g() { | |
self.removeListener(type, g); | |
listener.apply(this, arguments); | |
}); | |
return this; | |
}; | |
EventEmitter.prototype.removeListener = function(type, listener) { | |
if ('function' !== typeof listener) { | |
throw new Error('removeListener only takes instances of Function'); | |
} | |
// does not use listeners(), so no side effect of creating _events[type] | |
if (!this._events || !this._events[type]) return this; | |
var list = this._events[type]; | |
if (isArray(list)) { | |
var i = indexOf(list, listener); | |
if (i < 0) return this; | |
list.splice(i, 1); | |
if (list.length == 0) | |
delete this._events[type]; | |
} else if (this._events[type] === listener) { | |
delete this._events[type]; | |
} | |
return this; | |
}; | |
EventEmitter.prototype.removeAllListeners = function(type) { | |
if (arguments.length === 0) { | |
this._events = {}; | |
return this; | |
} | |
// does not use listeners(), so no side effect of creating _events[type] | |
if (type && this._events && this._events[type]) this._events[type] = null; | |
return this; | |
}; | |
EventEmitter.prototype.listeners = function(type) { | |
if (!this._events) this._events = {}; | |
if (!this._events[type]) this._events[type] = []; | |
if (!isArray(this._events[type])) { | |
this._events[type] = [this._events[type]]; | |
} | |
return this._events[type]; | |
}; | |
})(require("__browserify_process")) | |
},{"__browserify_process":6}],7:[function(require,module,exports){ | |
function localStorage(){ | |
this._keys = []; | |
for (var i = 0; i < window.localStorage.length; i++){ | |
this._keys.push('$' + window.localStorage.key(i)) | |
} | |
this._keys.sort(); | |
} | |
//key: Returns the name of the key at the position specified. | |
localStorage.prototype.key = function (keyindex){ | |
return this._keys[keyindex]; | |
} | |
//setItem: Saves and item at the key provided. | |
localStorage.prototype.setItem = function (key, value){ | |
this._keys.push(key) | |
this._keys.sort() | |
key = '$' + key; // safety, to avoid key='__proto__'-type skullduggery | |
window.localStorage.setItem(key, value) | |
} | |
//getItem: Returns the item identified by it's key. | |
localStorage.prototype.getItem = function (key){ | |
var retval = window.localStorage.getItem('$' + key) | |
if(retval == null){ | |
retval = undefined; | |
} | |
return retval; | |
} | |
//removeItem: Removes the item identified by it's key. | |
localStorage.prototype.removeItem = function (key){ | |
window.localStorage.removeItem('$' + key) | |
} | |
//clear: Removes all of the key value pairs. | |
localStorage.prototype.clear = function (){ | |
window.localStorage.clear() | |
} | |
localStorage.prototype.length = function(){ | |
return window.localStorage.length | |
} | |
exports.localStorage = localStorage; | |
},{}],8:[function(require,module,exports){ | |
function memStorage(){ | |
this._store = {} | |
this._keys = [] | |
} | |
//key: Returns the name of the key at the position specified. | |
localStorage.prototype.key = function (keyindex){ | |
return this._keys[keyindex]; | |
} | |
//setItem: Saves and item at the key provided. | |
localStorage.prototype.setItem = function (key, value){ | |
this._keys.push(key) | |
this._keys.sort() | |
key = '$' + key // safety, to avoid key='__proto__'-type skullduggery | |
this._store[key] = value | |
} | |
//getItem: Returns the item identified by it's key. | |
localStorage.prototype.getItem = function (key){ | |
return this._store['$' + key] | |
} | |
//removeItem: Removes the item identified by it's key. | |
localStorage.prototype.removeItem = function (key){ | |
delete this._store['$' + key] | |
} | |
//clear: Removes all of the key value pairs. | |
localStorage.prototype.clear = function (){ | |
this._store = {}; | |
this._keys = []; | |
} | |
localStorage.prototype.length = function(){ | |
return this._keys.length; | |
} | |
exports.localStorage = memStorage; | |
},{}],9:[function(require,module,exports){ | |
require=(function(e,t,n,r){function i(r){if(!n[r]){if(!t[r]){if(e)return e(r);throw new Error("Cannot find module '"+r+"'")}var s=n[r]={exports:{}};t[r][0](function(e){var n=t[r][1][e];return i(n?n:e)},s,s.exports)}return n[r].exports}for(var s=0;s<r.length;s++)i(r[s]);return i})(typeof require!=="undefined"&&require,{1:[function(require,module,exports){ | |
exports.readIEEE754 = function(buffer, offset, isBE, mLen, nBytes) { | |
var e, m, | |
eLen = nBytes * 8 - mLen - 1, | |
eMax = (1 << eLen) - 1, | |
eBias = eMax >> 1, | |
nBits = -7, | |
i = isBE ? 0 : (nBytes - 1), | |
d = isBE ? 1 : -1, | |
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.writeIEEE754 = function(buffer, value, offset, isBE, mLen, nBytes) { | |
var e, m, c, | |
eLen = nBytes * 8 - mLen - 1, | |
eMax = (1 << eLen) - 1, | |
eBias = eMax >> 1, | |
rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0), | |
i = isBE ? (nBytes - 1) : 0, | |
d = isBE ? -1 : 1, | |
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; | |
}; | |
},{}],2:[function(require,module,exports){ | |
(function(){// UTILITY | |
var util = require('util'); | |
var Buffer = require("buffer").Buffer; | |
var pSlice = Array.prototype.slice; | |
function objectKeys(object) { | |
if (Object.keys) return Object.keys(object); | |
var result = []; | |
for (var name in object) { | |
if (Object.prototype.hasOwnProperty.call(object, name)) { | |
result.push(name); | |
} | |
} | |
return result; | |
} | |
// 1. The assert module provides functions that throw | |
// AssertionError's when particular conditions are not met. The | |
// assert module must conform to the following interface. | |
var assert = module.exports = ok; | |
// 2. The AssertionError is defined in assert. | |
// new assert.AssertionError({ message: message, | |
// actual: actual, | |
// expected: expected }) | |
assert.AssertionError = function AssertionError(options) { | |
this.name = 'AssertionError'; | |
this.message = options.message; | |
this.actual = options.actual; | |
this.expected = options.expected; | |
this.operator = options.operator; | |
var stackStartFunction = options.stackStartFunction || fail; | |
if (Error.captureStackTrace) { | |
Error.captureStackTrace(this, stackStartFunction); | |
} | |
}; | |
util.inherits(assert.AssertionError, Error); | |
function replacer(key, value) { | |
if (value === undefined) { | |
return '' + value; | |
} | |
if (typeof value === 'number' && (isNaN(value) || !isFinite(value))) { | |
return value.toString(); | |
} | |
if (typeof value === 'function' || value instanceof RegExp) { | |
return value.toString(); | |
} | |
return value; | |
} | |
function truncate(s, n) { | |
if (typeof s == 'string') { | |
return s.length < n ? s : s.slice(0, n); | |
} else { | |
return s; | |
} | |
} | |
assert.AssertionError.prototype.toString = function() { | |
if (this.message) { | |
return [this.name + ':', this.message].join(' '); | |
} else { | |
return [ | |
this.name + ':', | |
truncate(JSON.stringify(this.actual, replacer), 128), | |
this.operator, | |
truncate(JSON.stringify(this.expected, replacer), 128) | |
].join(' '); | |
} | |
}; | |
// assert.AssertionError instanceof Error | |
assert.AssertionError.__proto__ = Error.prototype; | |
// At present only the three keys mentioned above are used and | |
// understood by the spec. Implementations or sub modules can pass | |
// other keys to the AssertionError's constructor - they will be | |
// ignored. | |
// 3. All of the following functions must throw an AssertionError | |
// when a corresponding condition is not met, with a message that | |
// may be undefined if not provided. All assertion methods provide | |
// both the actual and expected values to the assertion error for | |
// display purposes. | |
function fail(actual, expected, message, operator, stackStartFunction) { | |
throw new assert.AssertionError({ | |
message: message, | |
actual: actual, | |
expected: expected, | |
operator: operator, | |
stackStartFunction: stackStartFunction | |
}); | |
} | |
// EXTENSION! allows for well behaved errors defined elsewhere. | |
assert.fail = fail; | |
// 4. Pure assertion tests whether a value is truthy, as determined | |
// by !!guard. | |
// assert.ok(guard, message_opt); | |
// This statement is equivalent to assert.equal(true, guard, | |
// message_opt);. To test strictly for the value true, use | |
// assert.strictEqual(true, guard, message_opt);. | |
function ok(value, message) { | |
if (!!!value) fail(value, true, message, '==', assert.ok); | |
} | |
assert.ok = ok; | |
// 5. The equality assertion tests shallow, coercive equality with | |
// ==. | |
// assert.equal(actual, expected, message_opt); | |
assert.equal = function equal(actual, expected, message) { | |
if (actual != expected) fail(actual, expected, message, '==', assert.equal); | |
}; | |
// 6. The non-equality assertion tests for whether two objects are not equal | |
// with != assert.notEqual(actual, expected, message_opt); | |
assert.notEqual = function notEqual(actual, expected, message) { | |
if (actual == expected) { | |
fail(actual, expected, message, '!=', assert.notEqual); | |
} | |
}; | |
// 7. The equivalence assertion tests a deep equality relation. | |
// assert.deepEqual(actual, expected, message_opt); | |
assert.deepEqual = function deepEqual(actual, expected, message) { | |
if (!_deepEqual(actual, expected)) { | |
fail(actual, expected, message, 'deepEqual', assert.deepEqual); | |
} | |
}; | |
function _deepEqual(actual, expected) { | |
// 7.1. All identical values are equivalent, as determined by ===. | |
if (actual === expected) { | |
return true; | |
} else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) { | |
if (actual.length != expected.length) return false; | |
for (var i = 0; i < actual.length; i++) { | |
if (actual[i] !== expected[i]) return false; | |
} | |
return true; | |
// 7.2. If the expected value is a Date object, the actual value is | |
// equivalent if it is also a Date object that refers to the same time. | |
} else if (actual instanceof Date && expected instanceof Date) { | |
return actual.getTime() === expected.getTime(); | |
// 7.3. Other pairs that do not both pass typeof value == 'object', | |
// equivalence is determined by ==. | |
} else if (typeof actual != 'object' && typeof expected != 'object') { | |
return actual == expected; | |
// 7.4. For all other Object pairs, including Array objects, equivalence is | |
// determined by having the same number of owned properties (as verified | |
// with Object.prototype.hasOwnProperty.call), the same set of keys | |
// (although not necessarily the same order), equivalent values for every | |
// corresponding key, and an identical 'prototype' property. Note: this | |
// accounts for both named and indexed properties on Arrays. | |
} else { | |
return objEquiv(actual, expected); | |
} | |
} | |
function isUndefinedOrNull(value) { | |
return value === null || value === undefined; | |
} | |
function isArguments(object) { | |
return Object.prototype.toString.call(object) == '[object Arguments]'; | |
} | |
function objEquiv(a, b) { | |
if (isUndefinedOrNull(a) || isUndefinedOrNull(b)) | |
return false; | |
// an identical 'prototype' property. | |
if (a.prototype !== b.prototype) return false; | |
//~~~I've managed to break Object.keys through screwy arguments passing. | |
// Converting to array solves the problem. | |
if (isArguments(a)) { | |
if (!isArguments(b)) { | |
return false; | |
} | |
a = pSlice.call(a); | |
b = pSlice.call(b); | |
return _deepEqual(a, b); | |
} | |
try { | |
var ka = objectKeys(a), | |
kb = objectKeys(b), | |
key, i; | |
} catch (e) {//happens when one is a string literal and the other isn't | |
return false; | |
} | |
// having the same number of owned properties (keys incorporates | |
// hasOwnProperty) | |
if (ka.length != kb.length) | |
return false; | |
//the same set of keys (although not necessarily the same order), | |
ka.sort(); | |
kb.sort(); | |
//~~~cheap key test | |
for (i = ka.length - 1; i >= 0; i--) { | |
if (ka[i] != kb[i]) | |
return false; | |
} | |
//equivalent values for every corresponding key, and | |
//~~~possibly expensive deep test | |
for (i = ka.length - 1; i >= 0; i--) { | |
key = ka[i]; | |
if (!_deepEqual(a[key], b[key])) return false; | |
} | |
return true; | |
} | |
// 8. The non-equivalence assertion tests for any deep inequality. | |
// assert.notDeepEqual(actual, expected, message_opt); | |
assert.notDeepEqual = function notDeepEqual(actual, expected, message) { | |
if (_deepEqual(actual, expected)) { | |
fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual); | |
} | |
}; | |
// 9. The strict equality assertion tests strict equality, as determined by ===. | |
// assert.strictEqual(actual, expected, message_opt); | |
assert.strictEqual = function strictEqual(actual, expected, message) { | |
if (actual !== expected) { | |
fail(actual, expected, message, '===', assert.strictEqual); | |
} | |
}; | |
// 10. The strict non-equality assertion tests for strict inequality, as | |
// determined by !==. assert.notStrictEqual(actual, expected, message_opt); | |
assert.notStrictEqual = function notStrictEqual(actual, expected, message) { | |
if (actual === expected) { | |
fail(actual, expected, message, '!==', assert.notStrictEqual); | |
} | |
}; | |
function expectedException(actual, expected) { | |
if (!actual || !expected) { | |
return false; | |
} | |
if (expected instanceof RegExp) { | |
return expected.test(actual); | |
} else if (actual instanceof expected) { | |
return true; | |
} else if (expected.call({}, actual) === true) { | |
return true; | |
} | |
return false; | |
} | |
function _throws(shouldThrow, block, expected, message) { | |
var actual; | |
if (typeof expected === 'string') { | |
message = expected; | |
expected = null; | |
} | |
try { | |
block(); | |
} catch (e) { | |
actual = e; | |
} | |
message = (expected && expected.name ? ' (' + expected.name + ').' : '.') + | |
(message ? ' ' + message : '.'); | |
if (shouldThrow && !actual) { | |
fail('Missing expected exception' + message); | |
} | |
if (!shouldThrow && expectedException(actual, expected)) { | |
fail('Got unwanted exception' + message); | |
} | |
if ((shouldThrow && actual && expected && | |
!expectedException(actual, expected)) || (!shouldThrow && actual)) { | |
throw actual; | |
} | |
} | |
// 11. Expected to throw an error: | |
// assert.throws(block, Error_opt, message_opt); | |
assert.throws = function(block, /*optional*/error, /*optional*/message) { | |
_throws.apply(this, [true].concat(pSlice.call(arguments))); | |
}; | |
// EXTENSION! This is annoying to write outside this module. | |
assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) { | |
_throws.apply(this, [false].concat(pSlice.call(arguments))); | |
}; | |
assert.ifError = function(err) { if (err) {throw err;}}; | |
})() | |
},{"util":3,"buffer":4}],"buffer-browserify":[function(require,module,exports){ | |
module.exports=require('q9TxCC'); | |
},{}],"q9TxCC":[function(require,module,exports){ | |
(function(){function SlowBuffer (size) { | |
this.length = size; | |
}; | |
var assert = require('assert'); | |
exports.INSPECT_MAX_BYTES = 50; | |
function toHex(n) { | |
if (n < 16) return '0' + n.toString(16); | |
return n.toString(16); | |
} | |
function utf8ToBytes(str) { | |
var byteArray = []; | |
for (var i = 0; i < str.length; i++) | |
if (str.charCodeAt(i) <= 0x7F) | |
byteArray.push(str.charCodeAt(i)); | |
else { | |
var h = encodeURIComponent(str.charAt(i)).substr(1).split('%'); | |
for (var j = 0; j < h.length; j++) | |
byteArray.push(parseInt(h[j], 16)); | |
} | |
return byteArray; | |
} | |
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 base64ToBytes(str) { | |
return require("base64-js").toByteArray(str); | |
} | |
SlowBuffer.byteLength = function (str, encoding) { | |
switch (encoding || "utf8") { | |
case 'hex': | |
return str.length / 2; | |
case 'utf8': | |
case 'utf-8': | |
return utf8ToBytes(str).length; | |
case 'ascii': | |
case 'binary': | |
return str.length; | |
case 'base64': | |
return base64ToBytes(str).length; | |
default: | |
throw new Error('Unknown encoding'); | |
} | |
}; | |
function blitBuffer(src, dst, offset, length) { | |
var pos, i = 0; | |
while (i < length) { | |
if ((i+offset >= dst.length) || (i >= src.length)) | |
break; | |
dst[i + offset] = src[i]; | |
i++; | |
} | |
return i; | |
} | |
SlowBuffer.prototype.utf8Write = function (string, offset, length) { | |
var bytes, pos; | |
return SlowBuffer._charsWritten = blitBuffer(utf8ToBytes(string), this, offset, length); | |
}; | |
SlowBuffer.prototype.asciiWrite = function (string, offset, length) { | |
var bytes, pos; | |
return SlowBuffer._charsWritten = blitBuffer(asciiToBytes(string), this, offset, length); | |
}; | |
SlowBuffer.prototype.binaryWrite = SlowBuffer.prototype.asciiWrite; | |
SlowBuffer.prototype.base64Write = function (string, offset, length) { | |
var bytes, pos; | |
return SlowBuffer._charsWritten = blitBuffer(base64ToBytes(string), this, offset, length); | |
}; | |
SlowBuffer.prototype.base64Slice = function (start, end) { | |
var bytes = Array.prototype.slice.apply(this, arguments) | |
return require("base64-js").fromByteArray(bytes); | |
} | |
function decodeUtf8Char(str) { | |
try { | |
return decodeURIComponent(str); | |
} catch (err) { | |
return String.fromCharCode(0xFFFD); // UTF 8 invalid char | |
} | |
} | |
SlowBuffer.prototype.utf8Slice = function () { | |
var bytes = Array.prototype.slice.apply(this, arguments); | |
var res = ""; | |
var tmp = ""; | |
var i = 0; | |
while (i < bytes.length) { | |
if (bytes[i] <= 0x7F) { | |
res += decodeUtf8Char(tmp) + String.fromCharCode(bytes[i]); | |
tmp = ""; | |
} else | |
tmp += "%" + bytes[i].toString(16); | |
i++; | |
} | |
return res + decodeUtf8Char(tmp); | |
} | |
SlowBuffer.prototype.asciiSlice = function () { | |
var bytes = Array.prototype.slice.apply(this, arguments); | |
var ret = ""; | |
for (var i = 0; i < bytes.length; i++) | |
ret += String.fromCharCode(bytes[i]); | |
return ret; | |
} | |
SlowBuffer.prototype.binarySlice = SlowBuffer.prototype.asciiSlice; | |
SlowBuffer.prototype.inspect = function() { | |
var out = [], | |
len = this.length; | |
for (var i = 0; i < len; i++) { | |
out[i] = toHex(this[i]); | |
if (i == exports.INSPECT_MAX_BYTES) { | |
out[i + 1] = '...'; | |
break; | |
} | |
} | |
return '<SlowBuffer ' + out.join(' ') + '>'; | |
}; | |
SlowBuffer.prototype.hexSlice = function(start, end) { | |
var len = this.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(this[i]); | |
} | |
return out; | |
}; | |
SlowBuffer.prototype.toString = function(encoding, start, end) { | |
encoding = String(encoding || 'utf8').toLowerCase(); | |
start = +start || 0; | |
if (typeof end == 'undefined') end = this.length; | |
// Fastpath empty strings | |
if (+end == start) { | |
return ''; | |
} | |
switch (encoding) { | |
case 'hex': | |
return this.hexSlice(start, end); | |
case 'utf8': | |
case 'utf-8': | |
return this.utf8Slice(start, end); | |
case 'ascii': | |
return this.asciiSlice(start, end); | |
case 'binary': | |
return this.binarySlice(start, end); | |
case 'base64': | |
return this.base64Slice(start, end); | |
case 'ucs2': | |
case 'ucs-2': | |
return this.ucs2Slice(start, end); | |
default: | |
throw new Error('Unknown encoding'); | |
} | |
}; | |
SlowBuffer.prototype.hexWrite = function(string, offset, length) { | |
offset = +offset || 0; | |
var remaining = this.length - offset; | |
if (!length) { | |
length = remaining; | |
} else { | |
length = +length; | |
if (length > remaining) { | |
length = remaining; | |
} | |
} | |
// must be an even number of digits | |
var strLen = string.length; | |
if (strLen % 2) { | |
throw new Error('Invalid hex string'); | |
} | |
if (length > strLen / 2) { | |
length = strLen / 2; | |
} | |
for (var i = 0; i < length; i++) { | |
var byte = parseInt(string.substr(i * 2, 2), 16); | |
if (isNaN(byte)) throw new Error('Invalid hex string'); | |
this[offset + i] = byte; | |
} | |
SlowBuffer._charsWritten = i * 2; | |
return i; | |
}; | |
SlowBuffer.prototype.write = function(string, offset, length, encoding) { | |
// Support both (string, offset, length, encoding) | |
// and the legacy (string, encoding, offset, length) | |
if (isFinite(offset)) { | |
if (!isFinite(length)) { | |
encoding = length; | |
length = undefined; | |
} | |
} else { // legacy | |
var swap = encoding; | |
encoding = offset; | |
offset = length; | |
length = swap; | |
} | |
offset = +offset || 0; | |
var remaining = this.length - offset; | |
if (!length) { | |
length = remaining; | |
} else { | |
length = +length; | |
if (length > remaining) { | |
length = remaining; | |
} | |
} | |
encoding = String(encoding || 'utf8').toLowerCase(); | |
switch (encoding) { | |
case 'hex': | |
return this.hexWrite(string, offset, length); | |
case 'utf8': | |
case 'utf-8': | |
return this.utf8Write(string, offset, length); | |
case 'ascii': | |
return this.asciiWrite(string, offset, length); | |
case 'binary': | |
return this.binaryWrite(string, offset, length); | |
case 'base64': | |
return this.base64Write(string, offset, length); | |
case 'ucs2': | |
case 'ucs-2': | |
return this.ucs2Write(string, offset, length); | |
default: | |
throw new Error('Unknown encoding'); | |
} | |
}; | |
// slice(start, end) | |
SlowBuffer.prototype.slice = function(start, end) { | |
if (end === undefined) end = this.length; | |
if (end > this.length) { | |
throw new Error('oob'); | |
} | |
if (start > end) { | |
throw new Error('oob'); | |
} | |
return new Buffer(this, end - start, +start); | |
}; | |
SlowBuffer.prototype.copy = function(target, targetstart, sourcestart, sourceend) { | |
var temp = []; | |
for (var i=sourcestart; i<sourceend; i++) { | |
assert.ok(typeof this[i] !== 'undefined', "copying undefined buffer bytes!"); | |
temp.push(this[i]); | |
} | |
for (var i=targetstart; i<targetstart+temp.length; i++) { | |
target[i] = temp[i-targetstart]; | |
} | |
}; | |
SlowBuffer.prototype.fill = function(value, start, end) { | |
if (end > this.length) { | |
throw new Error('oob'); | |
} | |
if (start > end) { | |
throw new Error('oob'); | |
} | |
for (var i = start; i < end; i++) { | |
this[i] = value; | |
} | |
} | |
function coerce(length) { | |
// Coerce length to a number (possibly NaN), round up | |
// in case it's fractional (e.g. 123.456) then do a | |
// double negate to coerce a NaN to 0. Easy, right? | |
length = ~~Math.ceil(+length); | |
return length < 0 ? 0 : length; | |
} | |
// Buffer | |
function Buffer(subject, encoding, offset) { | |
if (!(this instanceof Buffer)) { | |
return new Buffer(subject, encoding, offset); | |
} | |
var type; | |
// Are we slicing? | |
if (typeof offset === 'number') { | |
this.length = coerce(encoding); | |
this.parent = subject; | |
this.offset = offset; | |
} else { | |
// Find the length | |
switch (type = typeof subject) { | |
case 'number': | |
this.length = coerce(subject); | |
break; | |
case 'string': | |
this.length = Buffer.byteLength(subject, encoding); | |
break; | |
case 'object': // Assume object is an array | |
this.length = coerce(subject.length); | |
break; | |
default: | |
throw new Error('First argument needs to be a number, ' + | |
'array or string.'); | |
} | |
if (this.length > Buffer.poolSize) { | |
// Big buffer, just alloc one. | |
this.parent = new SlowBuffer(this.length); | |
this.offset = 0; | |
} else { | |
// Small buffer. | |
if (!pool || pool.length - pool.used < this.length) allocPool(); | |
this.parent = pool; | |
this.offset = pool.used; | |
pool.used += this.length; | |
} | |
// Treat array-ish objects as a byte array. | |
if (isArrayIsh(subject)) { | |
for (var i = 0; i < this.length; i++) { | |
if (subject instanceof Buffer) { | |
this.parent[i + this.offset] = subject.readUInt8(i); | |
} | |
else { | |
this.parent[i + this.offset] = subject[i]; | |
} | |
} | |
} else if (type == 'string') { | |
// We are a string | |
this.length = this.write(subject, 0, encoding); | |
} | |
} | |
} | |
function isArrayIsh(subject) { | |
return Array.isArray(subject) || Buffer.isBuffer(subject) || | |
subject && typeof subject === 'object' && | |
typeof subject.length === 'number'; | |
} | |
exports.SlowBuffer = SlowBuffer; | |
exports.Buffer = Buffer; | |
Buffer.poolSize = 8 * 1024; | |
var pool; | |
function allocPool() { | |
pool = new SlowBuffer(Buffer.poolSize); | |
pool.used = 0; | |
} | |
// Static methods | |
Buffer.isBuffer = function isBuffer(b) { | |
return b instanceof Buffer || b instanceof SlowBuffer; | |
}; | |
Buffer.concat = function (list, totalLength) { | |
if (!Array.isArray(list)) { | |
throw new Error("Usage: Buffer.concat(list, [totalLength])\n \ | |
list should be an Array."); | |
} | |
if (list.length === 0) { | |
return new Buffer(0); | |
} else if (list.length === 1) { | |
return list[0]; | |
} | |
if (typeof totalLength !== 'number') { | |
totalLength = 0; | |
for (var i = 0; i < list.length; i++) { | |
var buf = list[i]; | |
totalLength += buf.length; | |
} | |
} | |
var buffer = new Buffer(totalLength); | |
var pos = 0; | |
for (var i = 0; i < list.length; i++) { | |
var buf = list[i]; | |
buf.copy(buffer, pos); | |
pos += buf.length; | |
} | |
return buffer; | |
}; | |
// Inspect | |
Buffer.prototype.inspect = function inspect() { | |
var out = [], | |
len = this.length; | |
for (var i = 0; i < len; i++) { | |
out[i] = toHex(this.parent[i + this.offset]); | |
if (i == exports.INSPECT_MAX_BYTES) { | |
out[i + 1] = '...'; | |
break; | |
} | |
} | |
return '<Buffer ' + out.join(' ') + '>'; | |
}; | |
Buffer.prototype.get = function get(i) { | |
if (i < 0 || i >= this.length) throw new Error('oob'); | |
return this.parent[this.offset + i]; | |
}; | |
Buffer.prototype.set = function set(i, v) { | |
if (i < 0 || i >= this.length) throw new Error('oob'); | |
return this.parent[this.offset + i] = v; | |
}; | |
// write(string, offset = 0, length = buffer.length-offset, encoding = 'utf8') | |
Buffer.prototype.write = function(string, offset, length, encoding) { | |
// Support both (string, offset, length, encoding) | |
// and the legacy (string, encoding, offset, length) | |
if (isFinite(offset)) { | |
if (!isFinite(length)) { | |
encoding = length; | |
length = undefined; | |
} | |
} else { // legacy | |
var swap = encoding; | |
encoding = offset; | |
offset = length; | |
length = swap; | |
} | |
offset = +offset || 0; | |
var remaining = this.length - offset; | |
if (!length) { | |
length = remaining; | |
} else { | |
length = +length; | |
if (length > remaining) { | |
length = remaining; | |
} | |
} | |
encoding = String(encoding || 'utf8').toLowerCase(); | |
var ret; | |
switch (encoding) { | |
case 'hex': | |
ret = this.parent.hexWrite(string, this.offset + offset, length); | |
break; | |
case 'utf8': | |
case 'utf-8': | |
ret = this.parent.utf8Write(string, this.offset + offset, length); | |
break; | |
case 'ascii': | |
ret = this.parent.asciiWrite(string, this.offset + offset, length); | |
break; | |
case 'binary': | |
ret = this.parent.binaryWrite(string, this.offset + offset, length); | |
break; | |
case 'base64': | |
// Warning: maxLength not taken into account in base64Write | |
ret = this.parent.base64Write(string, this.offset + offset, length); | |
break; | |
case 'ucs2': | |
case 'ucs-2': | |
ret = this.parent.ucs2Write(string, this.offset + offset, length); | |
break; | |
default: | |
throw new Error('Unknown encoding'); | |
} | |
Buffer._charsWritten = SlowBuffer._charsWritten; | |
return ret; | |
}; | |
// toString(encoding, start=0, end=buffer.length) | |
Buffer.prototype.toString = function(encoding, start, end) { | |
encoding = String(encoding || 'utf8').toLowerCase(); | |
if (typeof start == 'undefined' || start < 0) { | |
start = 0; | |
} else if (start > this.length) { | |
start = this.length; | |
} | |
if (typeof end == 'undefined' || end > this.length) { | |
end = this.length; | |
} else if (end < 0) { | |
end = 0; | |
} | |
start = start + this.offset; | |
end = end + this.offset; | |
switch (encoding) { | |
case 'hex': | |
return this.parent.hexSlice(start, end); | |
case 'utf8': | |
case 'utf-8': | |
return this.parent.utf8Slice(start, end); | |
case 'ascii': | |
return this.parent.asciiSlice(start, end); | |
case 'binary': | |
return this.parent.binarySlice(start, end); | |
case 'base64': | |
return this.parent.base64Slice(start, end); | |
case 'ucs2': | |
case 'ucs-2': | |
return this.parent.ucs2Slice(start, end); | |
default: | |
throw new Error('Unknown encoding'); | |
} | |
}; | |
// byteLength | |
Buffer.byteLength = SlowBuffer.byteLength; | |
// fill(value, start=0, end=buffer.length) | |
Buffer.prototype.fill = function fill(value, start, end) { | |
value || (value = 0); | |
start || (start = 0); | |
end || (end = this.length); | |
if (typeof value === 'string') { | |
value = value.charCodeAt(0); | |
} | |
if (!(typeof value === 'number') || isNaN(value)) { | |
throw new Error('value is not a number'); | |
} | |
if (end < start) throw new Error('end < start'); | |
// Fill 0 bytes; we're done | |
if (end === start) return 0; | |
if (this.length == 0) return 0; | |
if (start < 0 || start >= this.length) { | |
throw new Error('start out of bounds'); | |
} | |
if (end < 0 || end > this.length) { | |
throw new Error('end out of bounds'); | |
} | |
return this.parent.fill(value, | |
start + this.offset, | |
end + this.offset); | |
}; | |
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) | |
Buffer.prototype.copy = function(target, target_start, start, end) { | |
var source = this; | |
start || (start = 0); | |
end || (end = this.length); | |
target_start || (target_start = 0); | |
if (end < start) throw new Error('sourceEnd < sourceStart'); | |
// Copy 0 bytes; we're done | |
if (end === start) return 0; | |
if (target.length == 0 || source.length == 0) return 0; | |
if (target_start < 0 || target_start >= target.length) { | |
throw new Error('targetStart out of bounds'); | |
} | |
if (start < 0 || start >= source.length) { | |
throw new Error('sourceStart out of bounds'); | |
} | |
if (end < 0 || end > source.length) { | |
throw new Error('sourceEnd out of bounds'); | |
} | |
// Are we oob? | |
if (end > this.length) { | |
end = this.length; | |
} | |
if (target.length - target_start < end - start) { | |
end = target.length - target_start + start; | |
} | |
return this.parent.copy(target.parent, | |
target_start + target.offset, | |
start + this.offset, | |
end + this.offset); | |
}; | |
// slice(start, end) | |
Buffer.prototype.slice = function(start, end) { | |
if (end === undefined) end = this.length; | |
if (end > this.length) throw new Error('oob'); | |
if (start > end) throw new Error('oob'); | |
return new Buffer(this.parent, end - start, +start + this.offset); | |
}; | |
// Legacy methods for backwards compatibility. | |
Buffer.prototype.utf8Slice = function(start, end) { | |
return this.toString('utf8', start, end); | |
}; | |
Buffer.prototype.binarySlice = function(start, end) { | |
return this.toString('binary', start, end); | |
}; | |
Buffer.prototype.asciiSlice = function(start, end) { | |
return this.toString('ascii', start, end); | |
}; | |
Buffer.prototype.utf8Write = function(string, offset) { | |
return this.write(string, offset, 'utf8'); | |
}; | |
Buffer.prototype.binaryWrite = function(string, offset) { | |
return this.write(string, offset, 'binary'); | |
}; | |
Buffer.prototype.asciiWrite = function(string, offset) { | |
return this.write(string, offset, 'ascii'); | |
}; | |
Buffer.prototype.readUInt8 = function(offset, noAssert) { | |
var buffer = this; | |
if (!noAssert) { | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset < buffer.length, | |
'Trying to read beyond buffer length'); | |
} | |
if (offset >= buffer.length) return; | |
return buffer.parent[buffer.offset + offset]; | |
}; | |
function readUInt16(buffer, offset, isBigEndian, noAssert) { | |
var val = 0; | |
if (!noAssert) { | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 1 < buffer.length, | |
'Trying to read beyond buffer length'); | |
} | |
if (offset >= buffer.length) return 0; | |
if (isBigEndian) { | |
val = buffer.parent[buffer.offset + offset] << 8; | |
if (offset + 1 < buffer.length) { | |
val |= buffer.parent[buffer.offset + offset + 1]; | |
} | |
} else { | |
val = buffer.parent[buffer.offset + offset]; | |
if (offset + 1 < buffer.length) { | |
val |= buffer.parent[buffer.offset + offset + 1] << 8; | |
} | |
} | |
return val; | |
} | |
Buffer.prototype.readUInt16LE = function(offset, noAssert) { | |
return readUInt16(this, offset, false, noAssert); | |
}; | |
Buffer.prototype.readUInt16BE = function(offset, noAssert) { | |
return readUInt16(this, offset, true, noAssert); | |
}; | |
function readUInt32(buffer, offset, isBigEndian, noAssert) { | |
var val = 0; | |
if (!noAssert) { | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 3 < buffer.length, | |
'Trying to read beyond buffer length'); | |
} | |
if (offset >= buffer.length) return 0; | |
if (isBigEndian) { | |
if (offset + 1 < buffer.length) | |
val = buffer.parent[buffer.offset + offset + 1] << 16; | |
if (offset + 2 < buffer.length) | |
val |= buffer.parent[buffer.offset + offset + 2] << 8; | |
if (offset + 3 < buffer.length) | |
val |= buffer.parent[buffer.offset + offset + 3]; | |
val = val + (buffer.parent[buffer.offset + offset] << 24 >>> 0); | |
} else { | |
if (offset + 2 < buffer.length) | |
val = buffer.parent[buffer.offset + offset + 2] << 16; | |
if (offset + 1 < buffer.length) | |
val |= buffer.parent[buffer.offset + offset + 1] << 8; | |
val |= buffer.parent[buffer.offset + offset]; | |
if (offset + 3 < buffer.length) | |
val = val + (buffer.parent[buffer.offset + offset + 3] << 24 >>> 0); | |
} | |
return val; | |
} | |
Buffer.prototype.readUInt32LE = function(offset, noAssert) { | |
return readUInt32(this, offset, false, noAssert); | |
}; | |
Buffer.prototype.readUInt32BE = function(offset, noAssert) { | |
return readUInt32(this, offset, true, noAssert); | |
}; | |
/* | |
* Signed integer types, yay team! A reminder on how two's complement actually | |
* works. The first bit is the signed bit, i.e. tells us whether or not the | |
* number should be positive or negative. If the two's complement value is | |
* positive, then we're done, as it's equivalent to the unsigned representation. | |
* | |
* Now if the number is positive, you're pretty much done, you can just leverage | |
* the unsigned translations and return those. Unfortunately, negative numbers | |
* aren't quite that straightforward. | |
* | |
* At first glance, one might be inclined to use the traditional formula to | |
* translate binary numbers between the positive and negative values in two's | |
* complement. (Though it doesn't quite work for the most negative value) | |
* Mainly: | |
* - invert all the bits | |
* - add one to the result | |
* | |
* Of course, this doesn't quite work in Javascript. Take for example the value | |
* of -128. This could be represented in 16 bits (big-endian) as 0xff80. But of | |
* course, Javascript will do the following: | |
* | |
* > ~0xff80 | |
* -65409 | |
* | |
* Whoh there, Javascript, that's not quite right. But wait, according to | |
* Javascript that's perfectly correct. When Javascript ends up seeing the | |
* constant 0xff80, it has no notion that it is actually a signed number. It | |
* assumes that we've input the unsigned value 0xff80. Thus, when it does the | |
* binary negation, it casts it into a signed value, (positive 0xff80). Then | |
* when you perform binary negation on that, it turns it into a negative number. | |
* | |
* Instead, we're going to have to use the following general formula, that works | |
* in a rather Javascript friendly way. I'm glad we don't support this kind of | |
* weird numbering scheme in the kernel. | |
* | |
* (BIT-MAX - (unsigned)val + 1) * -1 | |
* | |
* The astute observer, may think that this doesn't make sense for 8-bit numbers | |
* (really it isn't necessary for them). However, when you get 16-bit numbers, | |
* you do. Let's go back to our prior example and see how this will look: | |
* | |
* (0xffff - 0xff80 + 1) * -1 | |
* (0x007f + 1) * -1 | |
* (0x0080) * -1 | |
*/ | |
Buffer.prototype.readInt8 = function(offset, noAssert) { | |
var buffer = this; | |
var neg; | |
if (!noAssert) { | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset < buffer.length, | |
'Trying to read beyond buffer length'); | |
} | |
if (offset >= buffer.length) return; | |
neg = buffer.parent[buffer.offset + offset] & 0x80; | |
if (!neg) { | |
return (buffer.parent[buffer.offset + offset]); | |
} | |
return ((0xff - buffer.parent[buffer.offset + offset] + 1) * -1); | |
}; | |
function readInt16(buffer, offset, isBigEndian, noAssert) { | |
var neg, val; | |
if (!noAssert) { | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 1 < buffer.length, | |
'Trying to read beyond buffer length'); | |
} | |
val = readUInt16(buffer, offset, isBigEndian, noAssert); | |
neg = val & 0x8000; | |
if (!neg) { | |
return val; | |
} | |
return (0xffff - val + 1) * -1; | |
} | |
Buffer.prototype.readInt16LE = function(offset, noAssert) { | |
return readInt16(this, offset, false, noAssert); | |
}; | |
Buffer.prototype.readInt16BE = function(offset, noAssert) { | |
return readInt16(this, offset, true, noAssert); | |
}; | |
function readInt32(buffer, offset, isBigEndian, noAssert) { | |
var neg, val; | |
if (!noAssert) { | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 3 < buffer.length, | |
'Trying to read beyond buffer length'); | |
} | |
val = readUInt32(buffer, offset, isBigEndian, noAssert); | |
neg = val & 0x80000000; | |
if (!neg) { | |
return (val); | |
} | |
return (0xffffffff - val + 1) * -1; | |
} | |
Buffer.prototype.readInt32LE = function(offset, noAssert) { | |
return readInt32(this, offset, false, noAssert); | |
}; | |
Buffer.prototype.readInt32BE = function(offset, noAssert) { | |
return readInt32(this, offset, true, noAssert); | |
}; | |
function readFloat(buffer, offset, isBigEndian, noAssert) { | |
if (!noAssert) { | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset + 3 < buffer.length, | |
'Trying to read beyond buffer length'); | |
} | |
return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian, | |
23, 4); | |
} | |
Buffer.prototype.readFloatLE = function(offset, noAssert) { | |
return readFloat(this, offset, false, noAssert); | |
}; | |
Buffer.prototype.readFloatBE = function(offset, noAssert) { | |
return readFloat(this, offset, true, noAssert); | |
}; | |
function readDouble(buffer, offset, isBigEndian, noAssert) { | |
if (!noAssert) { | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset + 7 < buffer.length, | |
'Trying to read beyond buffer length'); | |
} | |
return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian, | |
52, 8); | |
} | |
Buffer.prototype.readDoubleLE = function(offset, noAssert) { | |
return readDouble(this, offset, false, noAssert); | |
}; | |
Buffer.prototype.readDoubleBE = function(offset, noAssert) { | |
return readDouble(this, offset, true, noAssert); | |
}; | |
/* | |
* We have to make sure that the value is a valid integer. This means that it is | |
* non-negative. It has no fractional component and that it does not exceed the | |
* maximum allowed value. | |
* | |
* value The number to check for validity | |
* | |
* max The maximum value | |
*/ | |
function verifuint(value, max) { | |
assert.ok(typeof (value) == 'number', | |
'cannot write a non-number as a number'); | |
assert.ok(value >= 0, | |
'specified a negative value for writing an unsigned value'); | |
assert.ok(value <= max, 'value is larger than maximum value for type'); | |
assert.ok(Math.floor(value) === value, 'value has a fractional component'); | |
} | |
Buffer.prototype.writeUInt8 = function(value, offset, noAssert) { | |
var buffer = this; | |
if (!noAssert) { | |
assert.ok(value !== undefined && value !== null, | |
'missing value'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset < buffer.length, | |
'trying to write beyond buffer length'); | |
verifuint(value, 0xff); | |
} | |
if (offset < buffer.length) { | |
buffer.parent[buffer.offset + offset] = value; | |
} | |
}; | |
function writeUInt16(buffer, value, offset, isBigEndian, noAssert) { | |
if (!noAssert) { | |
assert.ok(value !== undefined && value !== null, | |
'missing value'); | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 1 < buffer.length, | |
'trying to write beyond buffer length'); | |
verifuint(value, 0xffff); | |
} | |
for (var i = 0; i < Math.min(buffer.length - offset, 2); i++) { | |
buffer.parent[buffer.offset + offset + i] = | |
(value & (0xff << (8 * (isBigEndian ? 1 - i : i)))) >>> | |
(isBigEndian ? 1 - i : i) * 8; | |
} | |
} | |
Buffer.prototype.writeUInt16LE = function(value, offset, noAssert) { | |
writeUInt16(this, value, offset, false, noAssert); | |
}; | |
Buffer.prototype.writeUInt16BE = function(value, offset, noAssert) { | |
writeUInt16(this, value, offset, true, noAssert); | |
}; | |
function writeUInt32(buffer, value, offset, isBigEndian, noAssert) { | |
if (!noAssert) { | |
assert.ok(value !== undefined && value !== null, | |
'missing value'); | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 3 < buffer.length, | |
'trying to write beyond buffer length'); | |
verifuint(value, 0xffffffff); | |
} | |
for (var i = 0; i < Math.min(buffer.length - offset, 4); i++) { | |
buffer.parent[buffer.offset + offset + i] = | |
(value >>> (isBigEndian ? 3 - i : i) * 8) & 0xff; | |
} | |
} | |
Buffer.prototype.writeUInt32LE = function(value, offset, noAssert) { | |
writeUInt32(this, value, offset, false, noAssert); | |
}; | |
Buffer.prototype.writeUInt32BE = function(value, offset, noAssert) { | |
writeUInt32(this, value, offset, true, noAssert); | |
}; | |
/* | |
* We now move onto our friends in the signed number category. Unlike unsigned | |
* numbers, we're going to have to worry a bit more about how we put values into | |
* arrays. Since we are only worrying about signed 32-bit values, we're in | |
* slightly better shape. Unfortunately, we really can't do our favorite binary | |
* & in this system. It really seems to do the wrong thing. For example: | |
* | |
* > -32 & 0xff | |
* 224 | |
* | |
* What's happening above is really: 0xe0 & 0xff = 0xe0. However, the results of | |
* this aren't treated as a signed number. Ultimately a bad thing. | |
* | |
* What we're going to want to do is basically create the unsigned equivalent of | |
* our representation and pass that off to the wuint* functions. To do that | |
* we're going to do the following: | |
* | |
* - if the value is positive | |
* we can pass it directly off to the equivalent wuint | |
* - if the value is negative | |
* we do the following computation: | |
* mb + val + 1, where | |
* mb is the maximum unsigned value in that byte size | |
* val is the Javascript negative integer | |
* | |
* | |
* As a concrete value, take -128. In signed 16 bits this would be 0xff80. If | |
* you do out the computations: | |
* | |
* 0xffff - 128 + 1 | |
* 0xffff - 127 | |
* 0xff80 | |
* | |
* You can then encode this value as the signed version. This is really rather | |
* hacky, but it should work and get the job done which is our goal here. | |
*/ | |
/* | |
* A series of checks to make sure we actually have a signed 32-bit number | |
*/ | |
function verifsint(value, max, min) { | |
assert.ok(typeof (value) == 'number', | |
'cannot write a non-number as a number'); | |
assert.ok(value <= max, 'value larger than maximum allowed value'); | |
assert.ok(value >= min, 'value smaller than minimum allowed value'); | |
assert.ok(Math.floor(value) === value, 'value has a fractional component'); | |
} | |
function verifIEEE754(value, max, min) { | |
assert.ok(typeof (value) == 'number', | |
'cannot write a non-number as a number'); | |
assert.ok(value <= max, 'value larger than maximum allowed value'); | |
assert.ok(value >= min, 'value smaller than minimum allowed value'); | |
} | |
Buffer.prototype.writeInt8 = function(value, offset, noAssert) { | |
var buffer = this; | |
if (!noAssert) { | |
assert.ok(value !== undefined && value !== null, | |
'missing value'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset < buffer.length, | |
'Trying to write beyond buffer length'); | |
verifsint(value, 0x7f, -0x80); | |
} | |
if (value >= 0) { | |
buffer.writeUInt8(value, offset, noAssert); | |
} else { | |
buffer.writeUInt8(0xff + value + 1, offset, noAssert); | |
} | |
}; | |
function writeInt16(buffer, value, offset, isBigEndian, noAssert) { | |
if (!noAssert) { | |
assert.ok(value !== undefined && value !== null, | |
'missing value'); | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 1 < buffer.length, | |
'Trying to write beyond buffer length'); | |
verifsint(value, 0x7fff, -0x8000); | |
} | |
if (value >= 0) { | |
writeUInt16(buffer, value, offset, isBigEndian, noAssert); | |
} else { | |
writeUInt16(buffer, 0xffff + value + 1, offset, isBigEndian, noAssert); | |
} | |
} | |
Buffer.prototype.writeInt16LE = function(value, offset, noAssert) { | |
writeInt16(this, value, offset, false, noAssert); | |
}; | |
Buffer.prototype.writeInt16BE = function(value, offset, noAssert) { | |
writeInt16(this, value, offset, true, noAssert); | |
}; | |
function writeInt32(buffer, value, offset, isBigEndian, noAssert) { | |
if (!noAssert) { | |
assert.ok(value !== undefined && value !== null, | |
'missing value'); | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 3 < buffer.length, | |
'Trying to write beyond buffer length'); | |
verifsint(value, 0x7fffffff, -0x80000000); | |
} | |
if (value >= 0) { | |
writeUInt32(buffer, value, offset, isBigEndian, noAssert); | |
} else { | |
writeUInt32(buffer, 0xffffffff + value + 1, offset, isBigEndian, noAssert); | |
} | |
} | |
Buffer.prototype.writeInt32LE = function(value, offset, noAssert) { | |
writeInt32(this, value, offset, false, noAssert); | |
}; | |
Buffer.prototype.writeInt32BE = function(value, offset, noAssert) { | |
writeInt32(this, value, offset, true, noAssert); | |
}; | |
function writeFloat(buffer, value, offset, isBigEndian, noAssert) { | |
if (!noAssert) { | |
assert.ok(value !== undefined && value !== null, | |
'missing value'); | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 3 < buffer.length, | |
'Trying to write beyond buffer length'); | |
verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38); | |
} | |
require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian, | |
23, 4); | |
} | |
Buffer.prototype.writeFloatLE = function(value, offset, noAssert) { | |
writeFloat(this, value, offset, false, noAssert); | |
}; | |
Buffer.prototype.writeFloatBE = function(value, offset, noAssert) { | |
writeFloat(this, value, offset, true, noAssert); | |
}; | |
function writeDouble(buffer, value, offset, isBigEndian, noAssert) { | |
if (!noAssert) { | |
assert.ok(value !== undefined && value !== null, | |
'missing value'); | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 7 < buffer.length, | |
'Trying to write beyond buffer length'); | |
verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308); | |
} | |
require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian, | |
52, 8); | |
} | |
Buffer.prototype.writeDoubleLE = function(value, offset, noAssert) { | |
writeDouble(this, value, offset, false, noAssert); | |
}; | |
Buffer.prototype.writeDoubleBE = function(value, offset, noAssert) { | |
writeDouble(this, value, offset, true, noAssert); | |
}; | |
SlowBuffer.prototype.readUInt8 = Buffer.prototype.readUInt8; | |
SlowBuffer.prototype.readUInt16LE = Buffer.prototype.readUInt16LE; | |
SlowBuffer.prototype.readUInt16BE = Buffer.prototype.readUInt16BE; | |
SlowBuffer.prototype.readUInt32LE = Buffer.prototype.readUInt32LE; | |
SlowBuffer.prototype.readUInt32BE = Buffer.prototype.readUInt32BE; | |
SlowBuffer.prototype.readInt8 = Buffer.prototype.readInt8; | |
SlowBuffer.prototype.readInt16LE = Buffer.prototype.readInt16LE; | |
SlowBuffer.prototype.readInt16BE = Buffer.prototype.readInt16BE; | |
SlowBuffer.prototype.readInt32LE = Buffer.prototype.readInt32LE; | |
SlowBuffer.prototype.readInt32BE = Buffer.prototype.readInt32BE; | |
SlowBuffer.prototype.readFloatLE = Buffer.prototype.readFloatLE; | |
SlowBuffer.prototype.readFloatBE = Buffer.prototype.readFloatBE; | |
SlowBuffer.prototype.readDoubleLE = Buffer.prototype.readDoubleLE; | |
SlowBuffer.prototype.readDoubleBE = Buffer.prototype.readDoubleBE; | |
SlowBuffer.prototype.writeUInt8 = Buffer.prototype.writeUInt8; | |
SlowBuffer.prototype.writeUInt16LE = Buffer.prototype.writeUInt16LE; | |
SlowBuffer.prototype.writeUInt16BE = Buffer.prototype.writeUInt16BE; | |
SlowBuffer.prototype.writeUInt32LE = Buffer.prototype.writeUInt32LE; | |
SlowBuffer.prototype.writeUInt32BE = Buffer.prototype.writeUInt32BE; | |
SlowBuffer.prototype.writeInt8 = Buffer.prototype.writeInt8; | |
SlowBuffer.prototype.writeInt16LE = Buffer.prototype.writeInt16LE; | |
SlowBuffer.prototype.writeInt16BE = Buffer.prototype.writeInt16BE; | |
SlowBuffer.prototype.writeInt32LE = Buffer.prototype.writeInt32LE; | |
SlowBuffer.prototype.writeInt32BE = Buffer.prototype.writeInt32BE; | |
SlowBuffer.prototype.writeFloatLE = Buffer.prototype.writeFloatLE; | |
SlowBuffer.prototype.writeFloatBE = Buffer.prototype.writeFloatBE; | |
SlowBuffer.prototype.writeDoubleLE = Buffer.prototype.writeDoubleLE; | |
SlowBuffer.prototype.writeDoubleBE = Buffer.prototype.writeDoubleBE; | |
})() | |
},{"assert":2,"./buffer_ieee754":1,"base64-js":5}],3:[function(require,module,exports){ | |
var events = require('events'); | |
exports.isArray = isArray; | |
exports.isDate = function(obj){return Object.prototype.toString.call(obj) === '[object Date]'}; | |
exports.isRegExp = function(obj){return Object.prototype.toString.call(obj) === '[object RegExp]'}; | |
exports.print = function () {}; | |
exports.puts = function () {}; | |
exports.debug = function() {}; | |
exports.inspect = function(obj, showHidden, depth, colors) { | |
var seen = []; | |
var stylize = function(str, styleType) { | |
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics | |
var styles = | |
{ '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] }; | |
var style = | |
{ 'special': 'cyan', | |
'number': 'blue', | |
'boolean': 'yellow', | |
'undefined': 'grey', | |
'null': 'bold', | |
'string': 'green', | |
'date': 'magenta', | |
// "name": intentionally not styling | |
'regexp': 'red' }[styleType]; | |
if (style) { | |
return '\033[' + styles[style][0] + 'm' + str + | |
'\033[' + styles[style][1] + 'm'; | |
} else { | |
return str; | |
} | |
}; | |
if (! colors) { | |
stylize = function(str, styleType) { return str; }; | |
} | |
function format(value, recurseTimes) { | |
// Provide a hook for user-specified inspect functions. | |
// Check that value is an object with an inspect function on it | |
if (value && typeof value.inspect === 'function' && | |
// Filter out the util module, it's inspect function is special | |
value !== exports && | |
// Also filter out any prototype objects using the circular check. | |
!(value.constructor && value.constructor.prototype === value)) { | |
return value.inspect(recurseTimes); | |
} | |
// Primitive types cannot have properties | |
switch (typeof value) { | |
case 'undefined': | |
return stylize('undefined', 'undefined'); | |
case 'string': | |
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') | |
.replace(/'/g, "\\'") | |
.replace(/\\"/g, '"') + '\''; | |
return stylize(simple, 'string'); | |
case 'number': | |
return stylize('' + value, 'number'); | |
case 'boolean': | |
return stylize('' + value, 'boolean'); | |
} | |
// For some reason typeof null is "object", so special case here. | |
if (value === null) { | |
return stylize('null', 'null'); | |
} | |
// Look up the keys of the object. | |
var visible_keys = Object_keys(value); | |
var keys = showHidden ? Object_getOwnPropertyNames(value) : visible_keys; | |
// Functions without properties can be shortcutted. | |
if (typeof value === 'function' && keys.length === 0) { | |
if (isRegExp(value)) { | |
return stylize('' + value, 'regexp'); | |
} else { | |
var name = value.name ? ': ' + value.name : ''; | |
return stylize('[Function' + name + ']', 'special'); | |
} | |
} | |
// Dates without properties can be shortcutted | |
if (isDate(value) && keys.length === 0) { | |
return stylize(value.toUTCString(), 'date'); | |
} | |
var base, type, braces; | |
// Determine the object type | |
if (isArray(value)) { | |
type = 'Array'; | |
braces = ['[', ']']; | |
} else { | |
type = 'Object'; | |
braces = ['{', '}']; | |
} | |
// Make functions say that they are functions | |
if (typeof value === 'function') { | |
var n = value.name ? ': ' + value.name : ''; | |
base = (isRegExp(value)) ? ' ' + value : ' [Function' + n + ']'; | |
} else { | |
base = ''; | |
} | |
// Make dates with properties first say the date | |
if (isDate(value)) { | |
base = ' ' + value.toUTCString(); | |
} | |
if (keys.length === 0) { | |
return braces[0] + base + braces[1]; | |
} | |
if (recurseTimes < 0) { | |
if (isRegExp(value)) { | |
return stylize('' + value, 'regexp'); | |
} else { | |
return stylize('[Object]', 'special'); | |
} | |
} | |
seen.push(value); | |
var output = keys.map(function(key) { | |
var name, str; | |
if (value.__lookupGetter__) { | |
if (value.__lookupGetter__(key)) { | |
if (value.__lookupSetter__(key)) { | |
str = stylize('[Getter/Setter]', 'special'); | |
} else { | |
str = stylize('[Getter]', 'special'); | |
} | |
} else { | |
if (value.__lookupSetter__(key)) { | |
str = stylize('[Setter]', 'special'); | |
} | |
} | |
} | |
if (visible_keys.indexOf(key) < 0) { | |
name = '[' + key + ']'; | |
} | |
if (!str) { | |
if (seen.indexOf(value[key]) < 0) { | |
if (recurseTimes === null) { | |
str = format(value[key]); | |
} else { | |
str = format(value[key], recurseTimes - 1); | |
} | |
if (str.indexOf('\n') > -1) { | |
if (isArray(value)) { | |
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 = stylize('[Circular]', 'special'); | |
} | |
} | |
if (typeof name === 'undefined') { | |
if (type === '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 = stylize(name, 'name'); | |
} else { | |
name = name.replace(/'/g, "\\'") | |
.replace(/\\"/g, '"') | |
.replace(/(^"|"$)/g, "'"); | |
name = stylize(name, 'string'); | |
} | |
} | |
return name + ': ' + str; | |
}); | |
seen.pop(); | |
var numLinesEst = 0; | |
var length = output.reduce(function(prev, cur) { | |
numLinesEst++; | |
if (cur.indexOf('\n') >= 0) numLinesEst++; | |
return prev + cur.length + 1; | |
}, 0); | |
if (length > 50) { | |
output = braces[0] + | |
(base === '' ? '' : base + '\n ') + | |
' ' + | |
output.join(',\n ') + | |
' ' + | |
braces[1]; | |
} else { | |
output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; | |
} | |
return output; | |
} | |
return format(obj, (typeof depth === 'undefined' ? 2 : depth)); | |
}; | |
function isArray(ar) { | |
return ar instanceof Array || | |
Array.isArray(ar) || | |
(ar && ar !== Object.prototype && isArray(ar.__proto__)); | |
} | |
function isRegExp(re) { | |
return re instanceof RegExp || | |
(typeof re === 'object' && Object.prototype.toString.call(re) === '[object RegExp]'); | |
} | |
function isDate(d) { | |
if (d instanceof Date) return true; | |
if (typeof d !== 'object') return false; | |
var properties = Date.prototype && Object_getOwnPropertyNames(Date.prototype); | |
var proto = d.__proto__ && Object_getOwnPropertyNames(d.__proto__); | |
return JSON.stringify(proto) === JSON.stringify(properties); | |
} | |
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(' '); | |
} | |
exports.log = function (msg) {}; | |
exports.pump = null; | |
var Object_keys = Object.keys || function (obj) { | |
var res = []; | |
for (var key in obj) res.push(key); | |
return res; | |
}; | |
var Object_getOwnPropertyNames = Object.getOwnPropertyNames || function (obj) { | |
var res = []; | |
for (var key in obj) { | |
if (Object.hasOwnProperty.call(obj, key)) res.push(key); | |
} | |
return res; | |
}; | |
var Object_create = Object.create || function (prototype, properties) { | |
// from es5-shim | |
var object; | |
if (prototype === null) { | |
object = { '__proto__' : null }; | |
} | |
else { | |
if (typeof prototype !== 'object') { | |
throw new TypeError( | |
'typeof prototype[' + (typeof prototype) + '] != \'object\'' | |
); | |
} | |
var Type = function () {}; | |
Type.prototype = prototype; | |
object = new Type(); | |
object.__proto__ = prototype; | |
} | |
if (typeof properties !== 'undefined' && Object.defineProperties) { | |
Object.defineProperties(object, properties); | |
} | |
return object; | |
}; | |
exports.inherits = function(ctor, superCtor) { | |
ctor.super_ = superCtor; | |
ctor.prototype = Object_create(superCtor.prototype, { | |
constructor: { | |
value: ctor, | |
enumerable: false, | |
writable: true, | |
configurable: true | |
} | |
}); | |
}; | |
var formatRegExp = /%[sdj%]/g; | |
exports.format = function(f) { | |
if (typeof f !== 'string') { | |
var objects = []; | |
for (var i = 0; i < arguments.length; i++) { | |
objects.push(exports.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': return JSON.stringify(args[i++]); | |
default: | |
return x; | |
} | |
}); | |
for(var x = args[i]; i < len; x = args[++i]){ | |
if (x === null || typeof x !== 'object') { | |
str += ' ' + x; | |
} else { | |
str += ' ' + exports.inspect(x); | |
} | |
} | |
return str; | |
}; | |
},{"events":6}],5:[function(require,module,exports){ | |
(function (exports) { | |
'use strict'; | |
var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; | |
function b64ToByteArray(b64) { | |
var i, j, l, tmp, placeHolders, arr; | |
if (b64.length % 4 > 0) { | |
throw '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 | |
placeHolders = b64.indexOf('='); | |
placeHolders = placeHolders > 0 ? b64.length - placeHolders : 0; | |
// base64 is 4/3 + up to two characters of the original data | |
arr = [];//new Uint8Array(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; | |
for (i = 0, j = 0; i < l; i += 4, j += 3) { | |
tmp = (lookup.indexOf(b64[i]) << 18) | (lookup.indexOf(b64[i + 1]) << 12) | (lookup.indexOf(b64[i + 2]) << 6) | lookup.indexOf(b64[i + 3]); | |
arr.push((tmp & 0xFF0000) >> 16); | |
arr.push((tmp & 0xFF00) >> 8); | |
arr.push(tmp & 0xFF); | |
} | |
if (placeHolders === 2) { | |
tmp = (lookup.indexOf(b64[i]) << 2) | (lookup.indexOf(b64[i + 1]) >> 4); | |
arr.push(tmp & 0xFF); | |
} else if (placeHolders === 1) { | |
tmp = (lookup.indexOf(b64[i]) << 10) | (lookup.indexOf(b64[i + 1]) << 4) | (lookup.indexOf(b64[i + 2]) >> 2); | |
arr.push((tmp >> 8) & 0xFF); | |
arr.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 tripletToBase64 (num) { | |
return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[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 += lookup[temp >> 2]; | |
output += lookup[(temp << 4) & 0x3F]; | |
output += '=='; | |
break; | |
case 2: | |
temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]); | |
output += lookup[temp >> 10]; | |
output += lookup[(temp >> 4) & 0x3F]; | |
output += lookup[(temp << 2) & 0x3F]; | |
output += '='; | |
break; | |
} | |
return output; | |
} | |
module.exports.toByteArray = b64ToByteArray; | |
module.exports.fromByteArray = uint8ToBase64; | |
}()); | |
},{}],7:[function(require,module,exports){ | |
exports.readIEEE754 = function(buffer, offset, isBE, mLen, nBytes) { | |
var e, m, | |
eLen = nBytes * 8 - mLen - 1, | |
eMax = (1 << eLen) - 1, | |
eBias = eMax >> 1, | |
nBits = -7, | |
i = isBE ? 0 : (nBytes - 1), | |
d = isBE ? 1 : -1, | |
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.writeIEEE754 = function(buffer, value, offset, isBE, mLen, nBytes) { | |
var e, m, c, | |
eLen = nBytes * 8 - mLen - 1, | |
eMax = (1 << eLen) - 1, | |
eBias = eMax >> 1, | |
rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0), | |
i = isBE ? (nBytes - 1) : 0, | |
d = isBE ? -1 : 1, | |
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; | |
}; | |
},{}],8:[function(require,module,exports){ | |
// shim for using process in browser | |
var process = module.exports = {}; | |
process.nextTick = (function () { | |
var canSetImmediate = typeof window !== 'undefined' | |
&& window.setImmediate; | |
var canPost = typeof window !== 'undefined' | |
&& window.postMessage && window.addEventListener | |
; | |
if (canSetImmediate) { | |
return function (f) { return window.setImmediate(f) }; | |
} | |
if (canPost) { | |
var queue = []; | |
window.addEventListener('message', function (ev) { | |
if (ev.source === window && ev.data === 'process-tick') { | |
ev.stopPropagation(); | |
if (queue.length > 0) { | |
var fn = queue.shift(); | |
fn(); | |
} | |
} | |
}, true); | |
return function nextTick(fn) { | |
queue.push(fn); | |
window.postMessage('process-tick', '*'); | |
}; | |
} | |
return function nextTick(fn) { | |
setTimeout(fn, 0); | |
}; | |
})(); | |
process.title = 'browser'; | |
process.browser = true; | |
process.env = {}; | |
process.argv = []; | |
process.binding = function (name) { | |
throw new Error('process.binding is not supported'); | |
} | |
// TODO(shtylman) | |
process.cwd = function () { return '/' }; | |
process.chdir = function (dir) { | |
throw new Error('process.chdir is not supported'); | |
}; | |
},{}],6:[function(require,module,exports){ | |
(function(process){if (!process.EventEmitter) process.EventEmitter = function () {}; | |
var EventEmitter = exports.EventEmitter = process.EventEmitter; | |
var isArray = typeof Array.isArray === 'function' | |
? Array.isArray | |
: function (xs) { | |
return Object.prototype.toString.call(xs) === '[object Array]' | |
} | |
; | |
function indexOf (xs, x) { | |
if (xs.indexOf) return xs.indexOf(x); | |
for (var i = 0; i < xs.length; i++) { | |
if (x === xs[i]) return i; | |
} | |
return -1; | |
} | |
// 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. | |
// | |
// Obviously not all Emitters should be limited to 10. This function allows | |
// that to be increased. Set to zero for unlimited. | |
var defaultMaxListeners = 10; | |
EventEmitter.prototype.setMaxListeners = function(n) { | |
if (!this._events) this._events = {}; | |
this._events.maxListeners = n; | |
}; | |
EventEmitter.prototype.emit = function(type) { | |
// If there is no 'error' event listener then throw. | |
if (type === 'error') { | |
if (!this._events || !this._events.error || | |
(isArray(this._events.error) && !this._events.error.length)) | |
{ | |
if (arguments[1] instanceof Error) { | |
throw arguments[1]; // Unhandled 'error' event | |
} else { | |
throw new Error("Uncaught, unspecified 'error' event."); | |
} | |
return false; | |
} | |
} | |
if (!this._events) return false; | |
var handler = this._events[type]; | |
if (!handler) return false; | |
if (typeof handler == 'function') { | |
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: | |
var args = Array.prototype.slice.call(arguments, 1); | |
handler.apply(this, args); | |
} | |
return true; | |
} else if (isArray(handler)) { | |
var args = Array.prototype.slice.call(arguments, 1); | |
var listeners = handler.slice(); | |
for (var i = 0, l = listeners.length; i < l; i++) { | |
listeners[i].apply(this, args); | |
} | |
return true; | |
} else { | |
return false; | |
} | |
}; | |
// EventEmitter is defined in src/node_events.cc | |
// EventEmitter.prototype.emit() is also defined there. | |
EventEmitter.prototype.addListener = function(type, listener) { | |
if ('function' !== typeof listener) { | |
throw new Error('addListener only takes instances of Function'); | |
} | |
if (!this._events) this._events = {}; | |
// To avoid recursion in the case that type == "newListeners"! Before | |
// adding it to the listeners, first emit "newListeners". | |
this.emit('newListener', type, listener); | |
if (!this._events[type]) { | |
// Optimize the case of one listener. Don't need the extra array object. | |
this._events[type] = listener; | |
} else if (isArray(this._events[type])) { | |
// Check for listener leak | |
if (!this._events[type].warned) { | |
var m; | |
if (this._events.maxListeners !== undefined) { | |
m = this._events.maxListeners; | |
} else { | |
m = 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); | |
console.trace(); | |
} | |
} | |
// 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]; | |
} | |
return this; | |
}; | |
EventEmitter.prototype.on = EventEmitter.prototype.addListener; | |
EventEmitter.prototype.once = function(type, listener) { | |
var self = this; | |
self.on(type, function g() { | |
self.removeListener(type, g); | |
listener.apply(this, arguments); | |
}); | |
return this; | |
}; | |
EventEmitter.prototype.removeListener = function(type, listener) { | |
if ('function' !== typeof listener) { | |
throw new Error('removeListener only takes instances of Function'); | |
} | |
// does not use listeners(), so no side effect of creating _events[type] | |
if (!this._events || !this._events[type]) return this; | |
var list = this._events[type]; | |
if (isArray(list)) { | |
var i = indexOf(list, listener); | |
if (i < 0) return this; | |
list.splice(i, 1); | |
if (list.length == 0) | |
delete this._events[type]; | |
} else if (this._events[type] === listener) { | |
delete this._events[type]; | |
} | |
return this; | |
}; | |
EventEmitter.prototype.removeAllListeners = function(type) { | |
if (arguments.length === 0) { | |
this._events = {}; | |
return this; | |
} | |
// does not use listeners(), so no side effect of creating _events[type] | |
if (type && this._events && this._events[type]) this._events[type] = null; | |
return this; | |
}; | |
EventEmitter.prototype.listeners = function(type) { | |
if (!this._events) this._events = {}; | |
if (!this._events[type]) this._events[type] = []; | |
if (!isArray(this._events[type])) { | |
this._events[type] = [this._events[type]]; | |
} | |
return this._events[type]; | |
}; | |
})(require("__browserify_process")) | |
},{"__browserify_process":8}],4:[function(require,module,exports){ | |
(function(){function SlowBuffer (size) { | |
this.length = size; | |
}; | |
var assert = require('assert'); | |
exports.INSPECT_MAX_BYTES = 50; | |
function toHex(n) { | |
if (n < 16) return '0' + n.toString(16); | |
return n.toString(16); | |
} | |
function utf8ToBytes(str) { | |
var byteArray = []; | |
for (var i = 0; i < str.length; i++) | |
if (str.charCodeAt(i) <= 0x7F) | |
byteArray.push(str.charCodeAt(i)); | |
else { | |
var h = encodeURIComponent(str.charAt(i)).substr(1).split('%'); | |
for (var j = 0; j < h.length; j++) | |
byteArray.push(parseInt(h[j], 16)); | |
} | |
return byteArray; | |
} | |
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 base64ToBytes(str) { | |
return require("base64-js").toByteArray(str); | |
} | |
SlowBuffer.byteLength = function (str, encoding) { | |
switch (encoding || "utf8") { | |
case 'hex': | |
return str.length / 2; | |
case 'utf8': | |
case 'utf-8': | |
return utf8ToBytes(str).length; | |
case 'ascii': | |
return str.length; | |
case 'base64': | |
return base64ToBytes(str).length; | |
default: | |
throw new Error('Unknown encoding'); | |
} | |
}; | |
function blitBuffer(src, dst, offset, length) { | |
var pos, i = 0; | |
while (i < length) { | |
if ((i+offset >= dst.length) || (i >= src.length)) | |
break; | |
dst[i + offset] = src[i]; | |
i++; | |
} | |
return i; | |
} | |
SlowBuffer.prototype.utf8Write = function (string, offset, length) { | |
var bytes, pos; | |
return SlowBuffer._charsWritten = blitBuffer(utf8ToBytes(string), this, offset, length); | |
}; | |
SlowBuffer.prototype.asciiWrite = function (string, offset, length) { | |
var bytes, pos; | |
return SlowBuffer._charsWritten = blitBuffer(asciiToBytes(string), this, offset, length); | |
}; | |
SlowBuffer.prototype.base64Write = function (string, offset, length) { | |
var bytes, pos; | |
return SlowBuffer._charsWritten = blitBuffer(base64ToBytes(string), this, offset, length); | |
}; | |
SlowBuffer.prototype.base64Slice = function (start, end) { | |
var bytes = Array.prototype.slice.apply(this, arguments) | |
return require("base64-js").fromByteArray(bytes); | |
} | |
function decodeUtf8Char(str) { | |
try { | |
return decodeURIComponent(str); | |
} catch (err) { | |
return String.fromCharCode(0xFFFD); // UTF 8 invalid char | |
} | |
} | |
SlowBuffer.prototype.utf8Slice = function () { | |
var bytes = Array.prototype.slice.apply(this, arguments); | |
var res = ""; | |
var tmp = ""; | |
var i = 0; | |
while (i < bytes.length) { | |
if (bytes[i] <= 0x7F) { | |
res += decodeUtf8Char(tmp) + String.fromCharCode(bytes[i]); | |
tmp = ""; | |
} else | |
tmp += "%" + bytes[i].toString(16); | |
i++; | |
} | |
return res + decodeUtf8Char(tmp); | |
} | |
SlowBuffer.prototype.asciiSlice = function () { | |
var bytes = Array.prototype.slice.apply(this, arguments); | |
var ret = ""; | |
for (var i = 0; i < bytes.length; i++) | |
ret += String.fromCharCode(bytes[i]); | |
return ret; | |
} | |
SlowBuffer.prototype.inspect = function() { | |
var out = [], | |
len = this.length; | |
for (var i = 0; i < len; i++) { | |
out[i] = toHex(this[i]); | |
if (i == exports.INSPECT_MAX_BYTES) { | |
out[i + 1] = '...'; | |
break; | |
} | |
} | |
return '<SlowBuffer ' + out.join(' ') + '>'; | |
}; | |
SlowBuffer.prototype.hexSlice = function(start, end) { | |
var len = this.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(this[i]); | |
} | |
return out; | |
}; | |
SlowBuffer.prototype.toString = function(encoding, start, end) { | |
encoding = String(encoding || 'utf8').toLowerCase(); | |
start = +start || 0; | |
if (typeof end == 'undefined') end = this.length; | |
// Fastpath empty strings | |
if (+end == start) { | |
return ''; | |
} | |
switch (encoding) { | |
case 'hex': | |
return this.hexSlice(start, end); | |
case 'utf8': | |
case 'utf-8': | |
return this.utf8Slice(start, end); | |
case 'ascii': | |
return this.asciiSlice(start, end); | |
case 'binary': | |
return this.binarySlice(start, end); | |
case 'base64': | |
return this.base64Slice(start, end); | |
case 'ucs2': | |
case 'ucs-2': | |
return this.ucs2Slice(start, end); | |
default: | |
throw new Error('Unknown encoding'); | |
} | |
}; | |
SlowBuffer.prototype.hexWrite = function(string, offset, length) { | |
offset = +offset || 0; | |
var remaining = this.length - offset; | |
if (!length) { | |
length = remaining; | |
} else { | |
length = +length; | |
if (length > remaining) { | |
length = remaining; | |
} | |
} | |
// must be an even number of digits | |
var strLen = string.length; | |
if (strLen % 2) { | |
throw new Error('Invalid hex string'); | |
} | |
if (length > strLen / 2) { | |
length = strLen / 2; | |
} | |
for (var i = 0; i < length; i++) { | |
var byte = parseInt(string.substr(i * 2, 2), 16); | |
if (isNaN(byte)) throw new Error('Invalid hex string'); | |
this[offset + i] = byte; | |
} | |
SlowBuffer._charsWritten = i * 2; | |
return i; | |
}; | |
SlowBuffer.prototype.write = function(string, offset, length, encoding) { | |
// Support both (string, offset, length, encoding) | |
// and the legacy (string, encoding, offset, length) | |
if (isFinite(offset)) { | |
if (!isFinite(length)) { | |
encoding = length; | |
length = undefined; | |
} | |
} else { // legacy | |
var swap = encoding; | |
encoding = offset; | |
offset = length; | |
length = swap; | |
} | |
offset = +offset || 0; | |
var remaining = this.length - offset; | |
if (!length) { | |
length = remaining; | |
} else { | |
length = +length; | |
if (length > remaining) { | |
length = remaining; | |
} | |
} | |
encoding = String(encoding || 'utf8').toLowerCase(); | |
switch (encoding) { | |
case 'hex': | |
return this.hexWrite(string, offset, length); | |
case 'utf8': | |
case 'utf-8': | |
return this.utf8Write(string, offset, length); | |
case 'ascii': | |
return this.asciiWrite(string, offset, length); | |
case 'binary': | |
return this.binaryWrite(string, offset, length); | |
case 'base64': | |
return this.base64Write(string, offset, length); | |
case 'ucs2': | |
case 'ucs-2': | |
return this.ucs2Write(string, offset, length); | |
default: | |
throw new Error('Unknown encoding'); | |
} | |
}; | |
// slice(start, end) | |
SlowBuffer.prototype.slice = function(start, end) { | |
if (end === undefined) end = this.length; | |
if (end > this.length) { | |
throw new Error('oob'); | |
} | |
if (start > end) { | |
throw new Error('oob'); | |
} | |
return new Buffer(this, end - start, +start); | |
}; | |
SlowBuffer.prototype.copy = function(target, targetstart, sourcestart, sourceend) { | |
var temp = []; | |
for (var i=sourcestart; i<sourceend; i++) { | |
assert.ok(typeof this[i] !== 'undefined', "copying undefined buffer bytes!"); | |
temp.push(this[i]); | |
} | |
for (var i=targetstart; i<targetstart+temp.length; i++) { | |
target[i] = temp[i-targetstart]; | |
} | |
}; | |
function coerce(length) { | |
// Coerce length to a number (possibly NaN), round up | |
// in case it's fractional (e.g. 123.456) then do a | |
// double negate to coerce a NaN to 0. Easy, right? | |
length = ~~Math.ceil(+length); | |
return length < 0 ? 0 : length; | |
} | |
// Buffer | |
function Buffer(subject, encoding, offset) { | |
if (!(this instanceof Buffer)) { | |
return new Buffer(subject, encoding, offset); | |
} | |
var type; | |
// Are we slicing? | |
if (typeof offset === 'number') { | |
this.length = coerce(encoding); | |
this.parent = subject; | |
this.offset = offset; | |
} else { | |
// Find the length | |
switch (type = typeof subject) { | |
case 'number': | |
this.length = coerce(subject); | |
break; | |
case 'string': | |
this.length = Buffer.byteLength(subject, encoding); | |
break; | |
case 'object': // Assume object is an array | |
this.length = coerce(subject.length); | |
break; | |
default: | |
throw new Error('First argument needs to be a number, ' + | |
'array or string.'); | |
} | |
if (this.length > Buffer.poolSize) { | |
// Big buffer, just alloc one. | |
this.parent = new SlowBuffer(this.length); | |
this.offset = 0; | |
} else { | |
// Small buffer. | |
if (!pool || pool.length - pool.used < this.length) allocPool(); | |
this.parent = pool; | |
this.offset = pool.used; | |
pool.used += this.length; | |
} | |
// Treat array-ish objects as a byte array. | |
if (isArrayIsh(subject)) { | |
for (var i = 0; i < this.length; i++) { | |
this.parent[i + this.offset] = subject[i]; | |
} | |
} else if (type == 'string') { | |
// We are a string | |
this.length = this.write(subject, 0, encoding); | |
} | |
} | |
} | |
function isArrayIsh(subject) { | |
return Array.isArray(subject) || Buffer.isBuffer(subject) || | |
subject && typeof subject === 'object' && | |
typeof subject.length === 'number'; | |
} | |
exports.SlowBuffer = SlowBuffer; | |
exports.Buffer = Buffer; | |
Buffer.poolSize = 8 * 1024; | |
var pool; | |
function allocPool() { | |
pool = new SlowBuffer(Buffer.poolSize); | |
pool.used = 0; | |
} | |
// Static methods | |
Buffer.isBuffer = function isBuffer(b) { | |
return b instanceof Buffer || b instanceof SlowBuffer; | |
}; | |
Buffer.concat = function (list, totalLength) { | |
if (!Array.isArray(list)) { | |
throw new Error("Usage: Buffer.concat(list, [totalLength])\n \ | |
list should be an Array."); | |
} | |
if (list.length === 0) { | |
return new Buffer(0); | |
} else if (list.length === 1) { | |
return list[0]; | |
} | |
if (typeof totalLength !== 'number') { | |
totalLength = 0; | |
for (var i = 0; i < list.length; i++) { | |
var buf = list[i]; | |
totalLength += buf.length; | |
} | |
} | |
var buffer = new Buffer(totalLength); | |
var pos = 0; | |
for (var i = 0; i < list.length; i++) { | |
var buf = list[i]; | |
buf.copy(buffer, pos); | |
pos += buf.length; | |
} | |
return buffer; | |
}; | |
// Inspect | |
Buffer.prototype.inspect = function inspect() { | |
var out = [], | |
len = this.length; | |
for (var i = 0; i < len; i++) { | |
out[i] = toHex(this.parent[i + this.offset]); | |
if (i == exports.INSPECT_MAX_BYTES) { | |
out[i + 1] = '...'; | |
break; | |
} | |
} | |
return '<Buffer ' + out.join(' ') + '>'; | |
}; | |
Buffer.prototype.get = function get(i) { | |
if (i < 0 || i >= this.length) throw new Error('oob'); | |
return this.parent[this.offset + i]; | |
}; | |
Buffer.prototype.set = function set(i, v) { | |
if (i < 0 || i >= this.length) throw new Error('oob'); | |
return this.parent[this.offset + i] = v; | |
}; | |
// write(string, offset = 0, length = buffer.length-offset, encoding = 'utf8') | |
Buffer.prototype.write = function(string, offset, length, encoding) { | |
// Support both (string, offset, length, encoding) | |
// and the legacy (string, encoding, offset, length) | |
if (isFinite(offset)) { | |
if (!isFinite(length)) { | |
encoding = length; | |
length = undefined; | |
} | |
} else { // legacy | |
var swap = encoding; | |
encoding = offset; | |
offset = length; | |
length = swap; | |
} | |
offset = +offset || 0; | |
var remaining = this.length - offset; | |
if (!length) { | |
length = remaining; | |
} else { | |
length = +length; | |
if (length > remaining) { | |
length = remaining; | |
} | |
} | |
encoding = String(encoding || 'utf8').toLowerCase(); | |
var ret; | |
switch (encoding) { | |
case 'hex': | |
ret = this.parent.hexWrite(string, this.offset + offset, length); | |
break; | |
case 'utf8': | |
case 'utf-8': | |
ret = this.parent.utf8Write(string, this.offset + offset, length); | |
break; | |
case 'ascii': | |
ret = this.parent.asciiWrite(string, this.offset + offset, length); | |
break; | |
case 'binary': | |
ret = this.parent.binaryWrite(string, this.offset + offset, length); | |
break; | |
case 'base64': | |
// Warning: maxLength not taken into account in base64Write | |
ret = this.parent.base64Write(string, this.offset + offset, length); | |
break; | |
case 'ucs2': | |
case 'ucs-2': | |
ret = this.parent.ucs2Write(string, this.offset + offset, length); | |
break; | |
default: | |
throw new Error('Unknown encoding'); | |
} | |
Buffer._charsWritten = SlowBuffer._charsWritten; | |
return ret; | |
}; | |
// toString(encoding, start=0, end=buffer.length) | |
Buffer.prototype.toString = function(encoding, start, end) { | |
encoding = String(encoding || 'utf8').toLowerCase(); | |
if (typeof start == 'undefined' || start < 0) { | |
start = 0; | |
} else if (start > this.length) { | |
start = this.length; | |
} | |
if (typeof end == 'undefined' || end > this.length) { | |
end = this.length; | |
} else if (end < 0) { | |
end = 0; | |
} | |
start = start + this.offset; | |
end = end + this.offset; | |
switch (encoding) { | |
case 'hex': | |
return this.parent.hexSlice(start, end); | |
case 'utf8': | |
case 'utf-8': | |
return this.parent.utf8Slice(start, end); | |
case 'ascii': | |
return this.parent.asciiSlice(start, end); | |
case 'binary': | |
return this.parent.binarySlice(start, end); | |
case 'base64': | |
return this.parent.base64Slice(start, end); | |
case 'ucs2': | |
case 'ucs-2': | |
return this.parent.ucs2Slice(start, end); | |
default: | |
throw new Error('Unknown encoding'); | |
} | |
}; | |
// byteLength | |
Buffer.byteLength = SlowBuffer.byteLength; | |
// fill(value, start=0, end=buffer.length) | |
Buffer.prototype.fill = function fill(value, start, end) { | |
value || (value = 0); | |
start || (start = 0); | |
end || (end = this.length); | |
if (typeof value === 'string') { | |
value = value.charCodeAt(0); | |
} | |
if (!(typeof value === 'number') || isNaN(value)) { | |
throw new Error('value is not a number'); | |
} | |
if (end < start) throw new Error('end < start'); | |
// Fill 0 bytes; we're done | |
if (end === start) return 0; | |
if (this.length == 0) return 0; | |
if (start < 0 || start >= this.length) { | |
throw new Error('start out of bounds'); | |
} | |
if (end < 0 || end > this.length) { | |
throw new Error('end out of bounds'); | |
} | |
return this.parent.fill(value, | |
start + this.offset, | |
end + this.offset); | |
}; | |
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) | |
Buffer.prototype.copy = function(target, target_start, start, end) { | |
var source = this; | |
start || (start = 0); | |
end || (end = this.length); | |
target_start || (target_start = 0); | |
if (end < start) throw new Error('sourceEnd < sourceStart'); | |
// Copy 0 bytes; we're done | |
if (end === start) return 0; | |
if (target.length == 0 || source.length == 0) return 0; | |
if (target_start < 0 || target_start >= target.length) { | |
throw new Error('targetStart out of bounds'); | |
} | |
if (start < 0 || start >= source.length) { | |
throw new Error('sourceStart out of bounds'); | |
} | |
if (end < 0 || end > source.length) { | |
throw new Error('sourceEnd out of bounds'); | |
} | |
// Are we oob? | |
if (end > this.length) { | |
end = this.length; | |
} | |
if (target.length - target_start < end - start) { | |
end = target.length - target_start + start; | |
} | |
return this.parent.copy(target.parent, | |
target_start + target.offset, | |
start + this.offset, | |
end + this.offset); | |
}; | |
// slice(start, end) | |
Buffer.prototype.slice = function(start, end) { | |
if (end === undefined) end = this.length; | |
if (end > this.length) throw new Error('oob'); | |
if (start > end) throw new Error('oob'); | |
return new Buffer(this.parent, end - start, +start + this.offset); | |
}; | |
// Legacy methods for backwards compatibility. | |
Buffer.prototype.utf8Slice = function(start, end) { | |
return this.toString('utf8', start, end); | |
}; | |
Buffer.prototype.binarySlice = function(start, end) { | |
return this.toString('binary', start, end); | |
}; | |
Buffer.prototype.asciiSlice = function(start, end) { | |
return this.toString('ascii', start, end); | |
}; | |
Buffer.prototype.utf8Write = function(string, offset) { | |
return this.write(string, offset, 'utf8'); | |
}; | |
Buffer.prototype.binaryWrite = function(string, offset) { | |
return this.write(string, offset, 'binary'); | |
}; | |
Buffer.prototype.asciiWrite = function(string, offset) { | |
return this.write(string, offset, 'ascii'); | |
}; | |
Buffer.prototype.readUInt8 = function(offset, noAssert) { | |
var buffer = this; | |
if (!noAssert) { | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset < buffer.length, | |
'Trying to read beyond buffer length'); | |
} | |
return buffer.parent[buffer.offset + offset]; | |
}; | |
function readUInt16(buffer, offset, isBigEndian, noAssert) { | |
var val = 0; | |
if (!noAssert) { | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 1 < buffer.length, | |
'Trying to read beyond buffer length'); | |
} | |
if (isBigEndian) { | |
val = buffer.parent[buffer.offset + offset] << 8; | |
val |= buffer.parent[buffer.offset + offset + 1]; | |
} else { | |
val = buffer.parent[buffer.offset + offset]; | |
val |= buffer.parent[buffer.offset + offset + 1] << 8; | |
} | |
return val; | |
} | |
Buffer.prototype.readUInt16LE = function(offset, noAssert) { | |
return readUInt16(this, offset, false, noAssert); | |
}; | |
Buffer.prototype.readUInt16BE = function(offset, noAssert) { | |
return readUInt16(this, offset, true, noAssert); | |
}; | |
function readUInt32(buffer, offset, isBigEndian, noAssert) { | |
var val = 0; | |
if (!noAssert) { | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 3 < buffer.length, | |
'Trying to read beyond buffer length'); | |
} | |
if (isBigEndian) { | |
val = buffer.parent[buffer.offset + offset + 1] << 16; | |
val |= buffer.parent[buffer.offset + offset + 2] << 8; | |
val |= buffer.parent[buffer.offset + offset + 3]; | |
val = val + (buffer.parent[buffer.offset + offset] << 24 >>> 0); | |
} else { | |
val = buffer.parent[buffer.offset + offset + 2] << 16; | |
val |= buffer.parent[buffer.offset + offset + 1] << 8; | |
val |= buffer.parent[buffer.offset + offset]; | |
val = val + (buffer.parent[buffer.offset + offset + 3] << 24 >>> 0); | |
} | |
return val; | |
} | |
Buffer.prototype.readUInt32LE = function(offset, noAssert) { | |
return readUInt32(this, offset, false, noAssert); | |
}; | |
Buffer.prototype.readUInt32BE = function(offset, noAssert) { | |
return readUInt32(this, offset, true, noAssert); | |
}; | |
/* | |
* Signed integer types, yay team! A reminder on how two's complement actually | |
* works. The first bit is the signed bit, i.e. tells us whether or not the | |
* number should be positive or negative. If the two's complement value is | |
* positive, then we're done, as it's equivalent to the unsigned representation. | |
* | |
* Now if the number is positive, you're pretty much done, you can just leverage | |
* the unsigned translations and return those. Unfortunately, negative numbers | |
* aren't quite that straightforward. | |
* | |
* At first glance, one might be inclined to use the traditional formula to | |
* translate binary numbers between the positive and negative values in two's | |
* complement. (Though it doesn't quite work for the most negative value) | |
* Mainly: | |
* - invert all the bits | |
* - add one to the result | |
* | |
* Of course, this doesn't quite work in Javascript. Take for example the value | |
* of -128. This could be represented in 16 bits (big-endian) as 0xff80. But of | |
* course, Javascript will do the following: | |
* | |
* > ~0xff80 | |
* -65409 | |
* | |
* Whoh there, Javascript, that's not quite right. But wait, according to | |
* Javascript that's perfectly correct. When Javascript ends up seeing the | |
* constant 0xff80, it has no notion that it is actually a signed number. It | |
* assumes that we've input the unsigned value 0xff80. Thus, when it does the | |
* binary negation, it casts it into a signed value, (positive 0xff80). Then | |
* when you perform binary negation on that, it turns it into a negative number. | |
* | |
* Instead, we're going to have to use the following general formula, that works | |
* in a rather Javascript friendly way. I'm glad we don't support this kind of | |
* weird numbering scheme in the kernel. | |
* | |
* (BIT-MAX - (unsigned)val + 1) * -1 | |
* | |
* The astute observer, may think that this doesn't make sense for 8-bit numbers | |
* (really it isn't necessary for them). However, when you get 16-bit numbers, | |
* you do. Let's go back to our prior example and see how this will look: | |
* | |
* (0xffff - 0xff80 + 1) * -1 | |
* (0x007f + 1) * -1 | |
* (0x0080) * -1 | |
*/ | |
Buffer.prototype.readInt8 = function(offset, noAssert) { | |
var buffer = this; | |
var neg; | |
if (!noAssert) { | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset < buffer.length, | |
'Trying to read beyond buffer length'); | |
} | |
neg = buffer.parent[buffer.offset + offset] & 0x80; | |
if (!neg) { | |
return (buffer.parent[buffer.offset + offset]); | |
} | |
return ((0xff - buffer.parent[buffer.offset + offset] + 1) * -1); | |
}; | |
function readInt16(buffer, offset, isBigEndian, noAssert) { | |
var neg, val; | |
if (!noAssert) { | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 1 < buffer.length, | |
'Trying to read beyond buffer length'); | |
} | |
val = readUInt16(buffer, offset, isBigEndian, noAssert); | |
neg = val & 0x8000; | |
if (!neg) { | |
return val; | |
} | |
return (0xffff - val + 1) * -1; | |
} | |
Buffer.prototype.readInt16LE = function(offset, noAssert) { | |
return readInt16(this, offset, false, noAssert); | |
}; | |
Buffer.prototype.readInt16BE = function(offset, noAssert) { | |
return readInt16(this, offset, true, noAssert); | |
}; | |
function readInt32(buffer, offset, isBigEndian, noAssert) { | |
var neg, val; | |
if (!noAssert) { | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 3 < buffer.length, | |
'Trying to read beyond buffer length'); | |
} | |
val = readUInt32(buffer, offset, isBigEndian, noAssert); | |
neg = val & 0x80000000; | |
if (!neg) { | |
return (val); | |
} | |
return (0xffffffff - val + 1) * -1; | |
} | |
Buffer.prototype.readInt32LE = function(offset, noAssert) { | |
return readInt32(this, offset, false, noAssert); | |
}; | |
Buffer.prototype.readInt32BE = function(offset, noAssert) { | |
return readInt32(this, offset, true, noAssert); | |
}; | |
function readFloat(buffer, offset, isBigEndian, noAssert) { | |
if (!noAssert) { | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset + 3 < buffer.length, | |
'Trying to read beyond buffer length'); | |
} | |
return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian, | |
23, 4); | |
} | |
Buffer.prototype.readFloatLE = function(offset, noAssert) { | |
return readFloat(this, offset, false, noAssert); | |
}; | |
Buffer.prototype.readFloatBE = function(offset, noAssert) { | |
return readFloat(this, offset, true, noAssert); | |
}; | |
function readDouble(buffer, offset, isBigEndian, noAssert) { | |
if (!noAssert) { | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset + 7 < buffer.length, | |
'Trying to read beyond buffer length'); | |
} | |
return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian, | |
52, 8); | |
} | |
Buffer.prototype.readDoubleLE = function(offset, noAssert) { | |
return readDouble(this, offset, false, noAssert); | |
}; | |
Buffer.prototype.readDoubleBE = function(offset, noAssert) { | |
return readDouble(this, offset, true, noAssert); | |
}; | |
/* | |
* We have to make sure that the value is a valid integer. This means that it is | |
* non-negative. It has no fractional component and that it does not exceed the | |
* maximum allowed value. | |
* | |
* value The number to check for validity | |
* | |
* max The maximum value | |
*/ | |
function verifuint(value, max) { | |
assert.ok(typeof (value) == 'number', | |
'cannot write a non-number as a number'); | |
assert.ok(value >= 0, | |
'specified a negative value for writing an unsigned value'); | |
assert.ok(value <= max, 'value is larger than maximum value for type'); | |
assert.ok(Math.floor(value) === value, 'value has a fractional component'); | |
} | |
Buffer.prototype.writeUInt8 = function(value, offset, noAssert) { | |
var buffer = this; | |
if (!noAssert) { | |
assert.ok(value !== undefined && value !== null, | |
'missing value'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset < buffer.length, | |
'trying to write beyond buffer length'); | |
verifuint(value, 0xff); | |
} | |
buffer.parent[buffer.offset + offset] = value; | |
}; | |
function writeUInt16(buffer, value, offset, isBigEndian, noAssert) { | |
if (!noAssert) { | |
assert.ok(value !== undefined && value !== null, | |
'missing value'); | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 1 < buffer.length, | |
'trying to write beyond buffer length'); | |
verifuint(value, 0xffff); | |
} | |
if (isBigEndian) { | |
buffer.parent[buffer.offset + offset] = (value & 0xff00) >>> 8; | |
buffer.parent[buffer.offset + offset + 1] = value & 0x00ff; | |
} else { | |
buffer.parent[buffer.offset + offset + 1] = (value & 0xff00) >>> 8; | |
buffer.parent[buffer.offset + offset] = value & 0x00ff; | |
} | |
} | |
Buffer.prototype.writeUInt16LE = function(value, offset, noAssert) { | |
writeUInt16(this, value, offset, false, noAssert); | |
}; | |
Buffer.prototype.writeUInt16BE = function(value, offset, noAssert) { | |
writeUInt16(this, value, offset, true, noAssert); | |
}; | |
function writeUInt32(buffer, value, offset, isBigEndian, noAssert) { | |
if (!noAssert) { | |
assert.ok(value !== undefined && value !== null, | |
'missing value'); | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 3 < buffer.length, | |
'trying to write beyond buffer length'); | |
verifuint(value, 0xffffffff); | |
} | |
if (isBigEndian) { | |
buffer.parent[buffer.offset + offset] = (value >>> 24) & 0xff; | |
buffer.parent[buffer.offset + offset + 1] = (value >>> 16) & 0xff; | |
buffer.parent[buffer.offset + offset + 2] = (value >>> 8) & 0xff; | |
buffer.parent[buffer.offset + offset + 3] = value & 0xff; | |
} else { | |
buffer.parent[buffer.offset + offset + 3] = (value >>> 24) & 0xff; | |
buffer.parent[buffer.offset + offset + 2] = (value >>> 16) & 0xff; | |
buffer.parent[buffer.offset + offset + 1] = (value >>> 8) & 0xff; | |
buffer.parent[buffer.offset + offset] = value & 0xff; | |
} | |
} | |
Buffer.prototype.writeUInt32LE = function(value, offset, noAssert) { | |
writeUInt32(this, value, offset, false, noAssert); | |
}; | |
Buffer.prototype.writeUInt32BE = function(value, offset, noAssert) { | |
writeUInt32(this, value, offset, true, noAssert); | |
}; | |
/* | |
* We now move onto our friends in the signed number category. Unlike unsigned | |
* numbers, we're going to have to worry a bit more about how we put values into | |
* arrays. Since we are only worrying about signed 32-bit values, we're in | |
* slightly better shape. Unfortunately, we really can't do our favorite binary | |
* & in this system. It really seems to do the wrong thing. For example: | |
* | |
* > -32 & 0xff | |
* 224 | |
* | |
* What's happening above is really: 0xe0 & 0xff = 0xe0. However, the results of | |
* this aren't treated as a signed number. Ultimately a bad thing. | |
* | |
* What we're going to want to do is basically create the unsigned equivalent of | |
* our representation and pass that off to the wuint* functions. To do that | |
* we're going to do the following: | |
* | |
* - if the value is positive | |
* we can pass it directly off to the equivalent wuint | |
* - if the value is negative | |
* we do the following computation: | |
* mb + val + 1, where | |
* mb is the maximum unsigned value in that byte size | |
* val is the Javascript negative integer | |
* | |
* | |
* As a concrete value, take -128. In signed 16 bits this would be 0xff80. If | |
* you do out the computations: | |
* | |
* 0xffff - 128 + 1 | |
* 0xffff - 127 | |
* 0xff80 | |
* | |
* You can then encode this value as the signed version. This is really rather | |
* hacky, but it should work and get the job done which is our goal here. | |
*/ | |
/* | |
* A series of checks to make sure we actually have a signed 32-bit number | |
*/ | |
function verifsint(value, max, min) { | |
assert.ok(typeof (value) == 'number', | |
'cannot write a non-number as a number'); | |
assert.ok(value <= max, 'value larger than maximum allowed value'); | |
assert.ok(value >= min, 'value smaller than minimum allowed value'); | |
assert.ok(Math.floor(value) === value, 'value has a fractional component'); | |
} | |
function verifIEEE754(value, max, min) { | |
assert.ok(typeof (value) == 'number', | |
'cannot write a non-number as a number'); | |
assert.ok(value <= max, 'value larger than maximum allowed value'); | |
assert.ok(value >= min, 'value smaller than minimum allowed value'); | |
} | |
Buffer.prototype.writeInt8 = function(value, offset, noAssert) { | |
var buffer = this; | |
if (!noAssert) { | |
assert.ok(value !== undefined && value !== null, | |
'missing value'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset < buffer.length, | |
'Trying to write beyond buffer length'); | |
verifsint(value, 0x7f, -0x80); | |
} | |
if (value >= 0) { | |
buffer.writeUInt8(value, offset, noAssert); | |
} else { | |
buffer.writeUInt8(0xff + value + 1, offset, noAssert); | |
} | |
}; | |
function writeInt16(buffer, value, offset, isBigEndian, noAssert) { | |
if (!noAssert) { | |
assert.ok(value !== undefined && value !== null, | |
'missing value'); | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 1 < buffer.length, | |
'Trying to write beyond buffer length'); | |
verifsint(value, 0x7fff, -0x8000); | |
} | |
if (value >= 0) { | |
writeUInt16(buffer, value, offset, isBigEndian, noAssert); | |
} else { | |
writeUInt16(buffer, 0xffff + value + 1, offset, isBigEndian, noAssert); | |
} | |
} | |
Buffer.prototype.writeInt16LE = function(value, offset, noAssert) { | |
writeInt16(this, value, offset, false, noAssert); | |
}; | |
Buffer.prototype.writeInt16BE = function(value, offset, noAssert) { | |
writeInt16(this, value, offset, true, noAssert); | |
}; | |
function writeInt32(buffer, value, offset, isBigEndian, noAssert) { | |
if (!noAssert) { | |
assert.ok(value !== undefined && value !== null, | |
'missing value'); | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 3 < buffer.length, | |
'Trying to write beyond buffer length'); | |
verifsint(value, 0x7fffffff, -0x80000000); | |
} | |
if (value >= 0) { | |
writeUInt32(buffer, value, offset, isBigEndian, noAssert); | |
} else { | |
writeUInt32(buffer, 0xffffffff + value + 1, offset, isBigEndian, noAssert); | |
} | |
} | |
Buffer.prototype.writeInt32LE = function(value, offset, noAssert) { | |
writeInt32(this, value, offset, false, noAssert); | |
}; | |
Buffer.prototype.writeInt32BE = function(value, offset, noAssert) { | |
writeInt32(this, value, offset, true, noAssert); | |
}; | |
function writeFloat(buffer, value, offset, isBigEndian, noAssert) { | |
if (!noAssert) { | |
assert.ok(value !== undefined && value !== null, | |
'missing value'); | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 3 < buffer.length, | |
'Trying to write beyond buffer length'); | |
verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38); | |
} | |
require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian, | |
23, 4); | |
} | |
Buffer.prototype.writeFloatLE = function(value, offset, noAssert) { | |
writeFloat(this, value, offset, false, noAssert); | |
}; | |
Buffer.prototype.writeFloatBE = function(value, offset, noAssert) { | |
writeFloat(this, value, offset, true, noAssert); | |
}; | |
function writeDouble(buffer, value, offset, isBigEndian, noAssert) { | |
if (!noAssert) { | |
assert.ok(value !== undefined && value !== null, | |
'missing value'); | |
assert.ok(typeof (isBigEndian) === 'boolean', | |
'missing or invalid endian'); | |
assert.ok(offset !== undefined && offset !== null, | |
'missing offset'); | |
assert.ok(offset + 7 < buffer.length, | |
'Trying to write beyond buffer length'); | |
verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308); | |
} | |
require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian, | |
52, 8); | |
} | |
Buffer.prototype.writeDoubleLE = function(value, offset, noAssert) { | |
writeDouble(this, value, offset, false, noAssert); | |
}; | |
Buffer.prototype.writeDoubleBE = function(value, offset, noAssert) { | |
writeDouble(this, value, offset, true, noAssert); | |
}; | |
SlowBuffer.prototype.readUInt8 = Buffer.prototype.readUInt8; | |
SlowBuffer.prototype.readUInt16LE = Buffer.prototype.readUInt16LE; | |
SlowBuffer.prototype.readUInt16BE = Buffer.prototype.readUInt16BE; | |
SlowBuffer.prototype.readUInt32LE = Buffer.prototype.readUInt32LE; | |
SlowBuffer.prototype.readUInt32BE = Buffer.prototype.readUInt32BE; | |
SlowBuffer.prototype.readInt8 = Buffer.prototype.readInt8; | |
SlowBuffer.prototype.readInt16LE = Buffer.prototype.readInt16LE; | |
SlowBuffer.prototype.readInt16BE = Buffer.prototype.readInt16BE; | |
SlowBuffer.prototype.readInt32LE = Buffer.prototype.readInt32LE; | |
SlowBuffer.prototype.readInt32BE = Buffer.prototype.readInt32BE; | |
SlowBuffer.prototype.readFloatLE = Buffer.prototype.readFloatLE; | |
SlowBuffer.prototype.readFloatBE = Buffer.prototype.readFloatBE; | |
SlowBuffer.prototype.readDoubleLE = Buffer.prototype.readDoubleLE; | |
SlowBuffer.prototype.readDoubleBE = Buffer.prototype.readDoubleBE; | |
SlowBuffer.prototype.writeUInt8 = Buffer.prototype.writeUInt8; | |
SlowBuffer.prototype.writeUInt16LE = Buffer.prototype.writeUInt16LE; | |
SlowBuffer.prototype.writeUInt16BE = Buffer.prototype.writeUInt16BE; | |
SlowBuffer.prototype.writeUInt32LE = Buffer.prototype.writeUInt32LE; | |
SlowBuffer.prototype.writeUInt32BE = Buffer.prototype.writeUInt32BE; | |
SlowBuffer.prototype.writeInt8 = Buffer.prototype.writeInt8; | |
SlowBuffer.prototype.writeInt16LE = Buffer.prototype.writeInt16LE; | |
SlowBuffer.prototype.writeInt16BE = Buffer.prototype.writeInt16BE; | |
SlowBuffer.prototype.writeInt32LE = Buffer.prototype.writeInt32LE; | |
SlowBuffer.prototype.writeInt32BE = Buffer.prototype.writeInt32BE; | |
SlowBuffer.prototype.writeFloatLE = Buffer.prototype.writeFloatLE; | |
SlowBuffer.prototype.writeFloatBE = Buffer.prototype.writeFloatBE; | |
SlowBuffer.prototype.writeDoubleLE = Buffer.prototype.writeDoubleLE; | |
SlowBuffer.prototype.writeDoubleBE = Buffer.prototype.writeDoubleBE; | |
})() | |
},{"assert":2,"./buffer_ieee754":7,"base64-js":9}],9:[function(require,module,exports){ | |
(function (exports) { | |
'use strict'; | |
var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; | |
function b64ToByteArray(b64) { | |
var i, j, l, tmp, placeHolders, arr; | |
if (b64.length % 4 > 0) { | |
throw '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 | |
placeHolders = b64.indexOf('='); | |
placeHolders = placeHolders > 0 ? b64.length - placeHolders : 0; | |
// base64 is 4/3 + up to two characters of the original data | |
arr = [];//new Uint8Array(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; | |
for (i = 0, j = 0; i < l; i += 4, j += 3) { | |
tmp = (lookup.indexOf(b64[i]) << 18) | (lookup.indexOf(b64[i + 1]) << 12) | (lookup.indexOf(b64[i + 2]) << 6) | lookup.indexOf(b64[i + 3]); | |
arr.push((tmp & 0xFF0000) >> 16); | |
arr.push((tmp & 0xFF00) >> 8); | |
arr.push(tmp & 0xFF); | |
} | |
if (placeHolders === 2) { | |
tmp = (lookup.indexOf(b64[i]) << 2) | (lookup.indexOf(b64[i + 1]) >> 4); | |
arr.push(tmp & 0xFF); | |
} else if (placeHolders === 1) { | |
tmp = (lookup.indexOf(b64[i]) << 10) | (lookup.indexOf(b64[i + 1]) << 4) | (lookup.indexOf(b64[i + 2]) >> 2); | |
arr.push((tmp >> 8) & 0xFF); | |
arr.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 tripletToBase64 (num) { | |
return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[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 += lookup[temp >> 2]; | |
output += lookup[(temp << 4) & 0x3F]; | |
output += '=='; | |
break; | |
case 2: | |
temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]); | |
output += lookup[temp >> 10]; | |
output += lookup[(temp >> 4) & 0x3F]; | |
output += lookup[(temp << 2) & 0x3F]; | |
output += '='; | |
break; | |
} | |
return output; | |
} | |
module.exports.toByteArray = b64ToByteArray; | |
module.exports.fromByteArray = uint8ToBase64; | |
}()); | |
},{}]},{},[]) | |
;;module.exports=require("buffer-browserify") | |
},{}],10:[function(require,module,exports){ | |
(function(process,Buffer,global){/* Copyright (c) 2012-2013 LevelUP contributors | |
* See list at <https://github.com/rvagg/node-levelup#contributing> | |
* MIT +no-false-attribs License | |
* <https://github.com/rvagg/node-levelup/blob/master/LICENSE> | |
*/ | |
var encodings = [ | |
'hex' | |
, 'utf8' | |
, 'utf-8' | |
, 'ascii' | |
, 'binary' | |
, 'base64' | |
, 'ucs2' | |
, 'ucs-2' | |
, 'utf16le' | |
, 'utf-16le' | |
] | |
, toSlice = (function () { | |
var slicers = {} | |
, isBuffer = function (data) { | |
return data === undefined || data === null || Buffer.isBuffer(data) | |
} | |
slicers.json = JSON.stringify.bind(JSON) | |
slicers.utf8 = function (data) { | |
return isBuffer(data) ? data : String(data) | |
} | |
encodings.forEach(function (enc) { | |
if (slicers[enc]) return | |
slicers[enc] = function (data) { | |
return isBuffer(data) ? data : new Buffer(data, enc) | |
} | |
}) | |
return slicers | |
}()) | |
, toEncoding = (function () { | |
var encoders = {} | |
encoders.json = function (str) { return JSON.parse(str) } | |
encoders.utf8 = function (str) { return str } | |
encoders.binary = function (buffer) { return buffer } | |
encodings.forEach(function (enc) { | |
if (encoders[enc]) return | |
encoders[enc] = function (buffer) { return buffer.toString(enc) } | |
}) | |
return encoders | |
}()) | |
, copy = function (srcdb, dstdb, callback) { | |
srcdb.readStream() | |
.pipe(dstdb.writeStream()) | |
.on('close', callback ? callback : function () {}) | |
.on('error', callback ? callback : function (err) { throw err }) | |
} | |
, setImmediate = global.setImmediate || process.nextTick | |
, encodingOpts = (function () { | |
var eo = {} | |
encodings.forEach(function (e) { | |
eo[e] = { valueEncoding : e } | |
}) | |
return eo | |
}()) | |
module.exports = { | |
toSlice : toSlice | |
, toEncoding : toEncoding | |
, copy : copy | |
, setImmediate : setImmediate | |
, encodingOpts : encodingOpts | |
} | |
})(require("__browserify_process"),require("__browserify_buffer").Buffer,window) | |
},{"__browserify_process":6,"__browserify_buffer":9}],2:[function(require,module,exports){ | |
(function(process,Buffer,global){var util = require('util') | |
, AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN | |
, AbstractIterator = require('abstract-leveldown').AbstractIterator | |
, checkKeyValue = require('abstract-leveldown').checkKeyValue | |
, noop = function () {} | |
, setImmediate = global.setImmediate || process.nextTick | |
function ldgapIterator (db, options) { | |
AbstractIterator.call(this, db) | |
var emptybuffer = new Buffer(0) | |
this._dbsize = this.db.container.length(); | |
this._reverse = !!options.reverse | |
// Test for empty buffer in end | |
if(options.end instanceof Buffer){ | |
if(options.end.length = 0) | |
this._end = this.db.container.key(this._dbsize - 1) | |
}else{ | |
this._end = options.end | |
} | |
this._limit = options.limit | |
this._count = 0 | |
if (options.start) { | |
// if pos is more than the size of the database then set pos to the end | |
var found = false; | |
for (var i = 0; i < this._dbsize; i++) { | |
if (this.db.container.key(i) >= options.start) { | |
this._pos = i | |
//Make sure we step back for mid values e.g 49.5 test | |
if(this._reverse){ | |
if(this.db.container.key(i) > options.start){ | |
this._pos = i -1 | |
}else{ | |
this._pos = i | |
} | |
} | |
found = true; | |
break | |
} | |
} | |
if(!found){ | |
this._pos = this._reverse ? this._dbsize - 1 : 0 | |
} | |
} else { | |
this._pos = this._reverse ? this._dbsize - 1 : 0 | |
} | |
} | |
util.inherits(ldgapIterator, AbstractIterator) | |
ldgapIterator.prototype._next = function (callback) { | |
if (this._pos >= this.db.container.length || this._pos < 0) | |
return setImmediate(callback) | |
var key = this.db.container.key(this._pos) | |
, value | |
if (!!this._end && (this._reverse ? key < this._end : key > this._end)) | |
return setImmediate(callback) | |
if (!!this._limit && this._limit > 0 && this._count++ >= this._limit) | |
return setImmediate(callback) | |
value = this.db.container.getItem(key) | |
this._pos += this._reverse ? -1 : 1 | |
setImmediate(callback.bind(null, null, key, value)) | |
} | |
function ldgap (location) { | |
AbstractLevelDOWN.call(this, location) | |
if(window.localStorage){ | |
console.dir("Using browser localStorage") | |
var wstore = require('./localstorage').localStorage; | |
this.container = new wstore(); | |
}else{ | |
// Default to in memory | |
console.dir("Using inmemory localStorage") | |
var store = require('./inmemory').localStorage; | |
this.container = new store(); | |
} | |
/*console.dir("Using inmemory localStorage") | |
var store = require('./inmemory').localStorage; | |
this.container = new store();*/ | |
} | |
util.inherits(ldgap, AbstractLevelDOWN) | |
ldgap.prototype._open = function (options, callback) { | |
setImmediate(function () { callback(null, this) }.bind(this)) | |
} | |
ldgap.prototype._put = function (key, value, options, callback) { | |
this.container.setItem(key, value); | |
setImmediate(callback) | |
} | |
ldgap.prototype._get = function (key, options, callback) { | |
var value = this.container.getItem(key); | |
if (value === undefined) { | |
// 'NotFound' error, consistent with LevelDOWN API | |
return setImmediate(function () { callback(new Error('NotFound')) }) | |
} | |
if (options.asBuffer !== false && !Buffer.isBuffer(value)) | |
value = new Buffer(String(value)) | |
setImmediate(function () { | |
callback(null, value) | |
}) | |
} | |
ldgap.prototype._del = function (key, options, callback) { | |
for (var i = 0; i < this.container.length; i++) { | |
if (this.container.key(i) == key) { | |
this.container.removeItem(i); | |
break; | |
} | |
} | |
this.container.removeItem(key); | |
setImmediate(callback) | |
} | |
ldgap.prototype._batch = function (array, options, callback) { | |
var err | |
, i = 0 | |
if (Array.isArray(array)) { | |
for (; i < array.length; i++) { | |
if (array[i]) { | |
key = Buffer.isBuffer(array[i].key) ? array[i].key : String(array[i].key) | |
err = checkKeyValue(key, 'key') | |
if (err) return setImmediate(callback.bind(null, err)) | |
if (array[i].type === 'del') { | |
this._del(array[i].key, options, noop) | |
} else if (array[i].type === 'put') { | |
value = Buffer.isBuffer(array[i].value) ? array[i].value : String(array[i].value) | |
err = checkKeyValue(value, 'value') | |
if (err) return setImmediate(callback.bind(null, err)) | |
this._put(key, value, options, noop) | |
} | |
} | |
} | |
} | |
setImmediate(callback) | |
} | |
ldgap.prototype._iterator = function (options) { | |
return new ldgapIterator(this, options) | |
} | |
function subarray(start, end) { | |
return this.slice(start, end) | |
} | |
function set_(array, offset) { | |
if (arguments.length < 2) offset = 0 | |
for (var i = 0, n = array.length; i < n; ++i, ++offset) | |
this[offset] = array[i] & 0xFF | |
} | |
// we need typed arrays | |
function TypedArray(arg1) { | |
var result; | |
if (typeof arg1 === "number") { | |
result = new Array(arg1); | |
for (var i = 0; i < arg1; ++i) | |
result[i] = 0; | |
} else | |
result = arg1.slice(0) | |
result.subarray = subarray | |
result.buffer = result | |
result.byteLength = result.length | |
result.set = set_ | |
if (typeof arg1 === "object" && arg1.buffer) | |
result.buffer = arg1.buffer | |
return result | |
} | |
if(!window.Uint8Array){ | |
window.Uint8Array = TypedArray; | |
window.Uint32Array = TypedArray; | |
window.Int32Array = TypedArray; | |
} | |
module.exports = ldgap | |
})(require("__browserify_process"),require("__browserify_buffer").Buffer,window) | |
},{"util":4,"./localstorage":7,"./inmemory":8,"abstract-leveldown":11,"__browserify_process":6,"__browserify_buffer":9}],12:[function(require,module,exports){ | |
var events = require('events'); | |
var util = require('util'); | |
function Stream() { | |
events.EventEmitter.call(this); | |
} | |
util.inherits(Stream, events.EventEmitter); | |
module.exports = Stream; | |
// Backwards-compat with node 0.4.x | |
Stream.Stream = Stream; | |
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, and | |
// only when all sources have ended. | |
if (!dest._isStdio && (!options || options.end !== false)) { | |
dest._pipeCount = dest._pipeCount || 0; | |
dest._pipeCount++; | |
source.on('end', onend); | |
source.on('close', onclose); | |
} | |
var didOnEnd = false; | |
function onend() { | |
if (didOnEnd) return; | |
didOnEnd = true; | |
dest._pipeCount--; | |
// remove the listeners | |
cleanup(); | |
if (dest._pipeCount > 0) { | |
// waiting for other incoming streams to end. | |
return; | |
} | |
dest.end(); | |
} | |
function onclose() { | |
if (didOnEnd) return; | |
didOnEnd = true; | |
dest._pipeCount--; | |
// remove the listeners | |
cleanup(); | |
if (dest._pipeCount > 0) { | |
// waiting for other incoming streams to end. | |
return; | |
} | |
dest.destroy(); | |
} | |
// don't leave dangling pipes when there are errors. | |
function onerror(er) { | |
cleanup(); | |
if (this.listeners('error').length === 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('end', cleanup); | |
dest.removeListener('close', cleanup); | |
} | |
source.on('end', cleanup); | |
source.on('close', cleanup); | |
dest.on('end', cleanup); | |
dest.on('close', cleanup); | |
dest.emit('pipe', source); | |
// Allow for unix-like usage: A.pipe(B).pipe(C) | |
return dest; | |
}; | |
},{"events":5,"util":4}],11:[function(require,module,exports){ | |
(function(process,Buffer){/* Copyright (c) 2013 Rod Vagg, MIT License */ | |
function checkKeyValue (obj, type) { | |
if (obj === null || obj === undefined) | |
return new Error(type + ' cannot be `null` or `undefined`') | |
if (obj === null || obj === undefined) | |
return new Error(type + ' cannot be `null` or `undefined`') | |
if (isBuffer(obj) && obj.byteLength === 0) | |
return new Error(type + ' cannot be an empty ArrayBuffer') | |
if (String(obj) === '') | |
return new Error(type + ' cannot be an empty String') | |
if (obj.length === 0) | |
return new Error(type + ' cannot be an empty Array') | |
} | |
function isBuffer(buf) { | |
return buf instanceof ArrayBuffer | |
} | |
function ArrayBufferToString(buf) { | |
return String.fromCharCode.apply(null, new Uint16Array(buf)) | |
} | |
function StringToArrayBuffer(str) { | |
var buf = new ArrayBuffer(str.length * 2) // 2 bytes for each char | |
var bufView = new Uint16Array(buf) | |
for (var i = 0, strLen = str.length; i < strLen; i++) { | |
bufView[i] = str.charCodeAt(i) | |
} | |
return buf | |
} | |
function AbstractIterator (db) { | |
this.db = db | |
this._ended = false | |
this._nexting = false | |
} | |
AbstractIterator.prototype.next = function (callback) { | |
if (typeof callback != 'function') | |
throw new Error('next() requires a callback argument') | |
if (this._ended) | |
throw new Error('cannot call next() after end()') | |
if (this._nexting) | |
throw new Error('cannot call next() before previous next() has completed') | |
this._nexting = true | |
if (typeof this._next == 'function') { | |
return this._next(function () { | |
this._nexting = false | |
callback.apply(null, arguments) | |
}.bind(this)) | |
} | |
process.nextTick(function () { | |
this._nexting = false | |
callback() | |
}.bind(this)) | |
} | |
AbstractIterator.prototype.end = function (callback) { | |
if (typeof callback != 'function') | |
throw new Error('end() requires a callback argument') | |
if (this._ended) | |
throw new Error('end() already called on iterator') | |
this._ended = true | |
if (typeof this._end == 'function') | |
return this._end(callback) | |
process.nextTick(callback) | |
} | |
function AbstractLevelDOWN (location) { | |
if (!arguments.length || location === undefined) | |
throw new Error('constructor requires at least a location argument') | |
if (typeof location != 'string') | |
throw new Error('constructor requires a location string argument') | |
this.location = location | |
} | |
AbstractLevelDOWN.prototype.open = function (options, callback) { | |
if (typeof options == 'function') | |
callback = options | |
if (typeof callback != 'function') | |
throw new Error('open() requires a callback argument') | |
if (typeof options != 'object') | |
options = {} | |
if (typeof this._open == 'function') | |
return this._open(options, callback) | |
process.nextTick(callback) | |
} | |
AbstractLevelDOWN.prototype.close = function (callback) { | |
if (typeof callback != 'function') | |
throw new Error('close() requires a callback argument') | |
if (typeof this._close == 'function') | |
return this._close(callback) | |
process.nextTick(callback) | |
} | |
AbstractLevelDOWN.prototype.get = function (key, options, callback) { | |
if (typeof options == 'function') | |
callback = options | |
if (typeof callback != 'function') | |
throw new Error('get() requires a callback argument') | |
var err = checkKeyValue(key, 'key') | |
if (err) return callback(err) | |
if (!Buffer.isBuffer(key)) key = String(key) | |
if (typeof options != 'object') | |
options = {} | |
if (typeof this._get == 'function') | |
return this._get(key, options, callback) | |
process.nextTick(callback.bind(null, new Error('NotFound'))) | |
} | |
AbstractLevelDOWN.prototype.put = function (key, value, options, callback) { | |
if (typeof options == 'function') | |
callback = options | |
if (typeof callback != 'function') | |
throw new Error('put() requires a callback argument') | |
var err = checkKeyValue(value, 'value') | |
if (err) return callback(err) | |
err = checkKeyValue(key, 'key') | |
if (err) return callback(err) | |
if (!Buffer.isBuffer(key)) key = String(key) | |
if (!Buffer.isBuffer(value)) value = String(value) | |
if (typeof options != 'object') | |
options = {} | |
if (typeof this._put == 'function') | |
return this._put(key, value, options, callback) | |
process.nextTick(callback) | |
} | |
AbstractLevelDOWN.prototype.del = function (key, options, callback) { | |
if (typeof options == 'function') | |
callback = options | |
if (typeof callback != 'function') | |
throw new Error('del() requires a callback argument') | |
var err = checkKeyValue(key, 'key') | |
if (err) return callback(err) | |
if (!Buffer.isBuffer(key)) key = String(key) | |
if (typeof options != 'object') | |
options = {} | |
if (typeof this._del == 'function') | |
return this._del(key, options, callback) | |
process.nextTick(callback) | |
} | |
AbstractLevelDOWN.prototype.batch = function (array, options, callback) { | |
if (typeof options == 'function') | |
callback = options | |
if (!Array.isArray(array) && typeof array == 'object') { | |
options = array | |
array = undefined | |
} | |
if (typeof options != 'object') | |
options = {} | |
// TODO: if array == undefined && callback == function, derp | |
if (typeof this._batch == 'function') | |
return this._batch(array, options, callback) | |
process.nextTick(callback) | |
} | |
AbstractLevelDOWN.prototype.approximateSize = function (start, end, callback) { | |
if (start == null || end == null || typeof start == 'function' || typeof end == 'function') | |
throw new Error('approximateSize() requires valid `start`, `end` and `callback` arguments') | |
if (typeof callback != 'function') | |
throw new Error('approximateSize() requires a callback argument') | |
if (!Buffer.isBuffer(start)) start = String(start) | |
if (!Buffer.isBuffer(end)) end = String(end) | |
if (typeof this._approximateSize == 'function') | |
return this._approximateSize(start, end, callback) | |
process.nextTick(callback.bind(null, null, 0)) | |
} | |
AbstractLevelDOWN.prototype.iterator = function (options) { | |
if (typeof options != 'object') | |
options = {} | |
if (typeof this._iterator == 'function') | |
return this._iterator(options) | |
return new AbstractIterator(this) | |
} | |
module.exports.AbstractLevelDOWN = AbstractLevelDOWN | |
module.exports.AbstractIterator = AbstractIterator | |
module.exports.checkKeyValue = checkKeyValue | |
})(require("__browserify_process"),require("__browserify_buffer").Buffer) | |
},{"__browserify_process":6,"__browserify_buffer":9}],3:[function(require,module,exports){ | |
(function(process){/* Copyright (c) 2012-2013 LevelUP contributors | |
* See list at <https://github.com/rvagg/node-levelup#contributing> | |
* MIT +no-false-attribs License | |
* <https://github.com/rvagg/node-levelup/blob/master/LICENSE> | |
*/ | |
var leveldown = require('leveldown') | |
, EventEmitter = require('events').EventEmitter | |
, inherits = require('util').inherits | |
, extend = require('xtend') | |
, prr = require('prr') | |
, errors = require('./errors') | |
, readStream = require('./read-stream') | |
, writeStream = require('./write-stream') | |
, util = require('./util') | |
, toEncoding = util.toEncoding | |
, toSlice = util.toSlice | |
, encodingOpts = util.encodingOpts | |
, defaultOptions = { | |
createIfMissing : true | |
, errorIfExists : false | |
, keyEncoding : 'utf8' | |
, valueEncoding : 'utf8' | |
, compression : true | |
, db : leveldown | |
} | |
, createLevelUP = function (location, options, callback) { | |
// Possible status values: | |
// - 'new' - newly created, not opened or closed | |
// - 'opening' - waiting for the database to be opened, post open() | |
// - 'open' - successfully opened the database, available for use | |
// - 'closing' - waiting for the database to be closed, post close() | |
// - 'closed' - database has been successfully closed, should not be | |
// used except for another open() operation | |
var status = 'new' | |
, error | |
, levelup | |
, isOpen = function () { return status == 'open' } | |
, isOpening = function () { return status == 'opening' } | |
, dispatchError = function (error, callback) { | |
return typeof callback == 'function' | |
? callback(error) | |
: levelup.emit('error', error) | |
} | |
, getCallback = function (options, callback) { | |
return typeof options == 'function' ? options : callback | |
} | |
, getOptions = function (options) { | |
var s = typeof options == 'string' // just an encoding | |
if (!s && options && options.encoding && !options.valueEncoding) | |
options.valueEncoding = options.encoding | |
return extend( | |
(levelup && levelup.options) || {} | |
, s ? encodingOpts[options] || encodingOpts[defaultOptions.valueEncoding] | |
: options | |
) | |
} | |
if (typeof options == 'function') { | |
callback = options | |
options = {} | |
} | |
options = getOptions(options) | |
if (typeof location != 'string') { | |
error = new errors.InitializationError( | |
'Must provide a location for the database') | |
if (callback) | |
return callback(error) | |
throw error | |
} | |
function LevelUP (location, options) { | |
EventEmitter.call(this) | |
this.setMaxListeners(Infinity) | |
this.options = extend(defaultOptions, options) | |
// set this.location as enumerable but not configurable or writable | |
prr(this, 'location', location, 'e') | |
} | |
inherits(LevelUP, EventEmitter) | |
LevelUP.prototype.open = function (callback) { | |
if (isOpen()) { | |
if (callback) | |
process.nextTick(callback.bind(null, null, this)) | |
return this | |
} | |
if (isOpening()) | |
return callback && levelup.once( | |
'open' | |
, callback.bind(null, null, this) | |
) | |
status = 'opening' | |
var execute = function () { | |
var db = levelup.options.db(levelup.location) | |
db.open(levelup.options, function (err) { | |
if (err) { | |
err = new errors.OpenError(err) | |
return dispatchError(err, callback) | |
} else { | |
levelup._db = db | |
status = 'open' | |
if (callback) | |
callback(null, levelup) | |
levelup.emit('open') | |
levelup.emit('ready') | |
} | |
}) | |
} | |
, deferred = {} | |
;['get', 'put', 'batch', 'del', 'approximateSize'] | |
.forEach(function (name) { | |
deferred[name] = function () { | |
var args = Array.prototype.slice.call(arguments) | |
levelup.once('ready', function () { | |
levelup._db[name].apply(levelup._db, args) | |
}) | |
} | |
}) | |
this._db = deferred | |
execute() | |
levelup.emit('opening') | |
} | |
LevelUP.prototype.close = function (callback) { | |
if (isOpen()) { | |
status = 'closing' | |
this._db.close(function () { | |
status = 'closed' | |
levelup.emit('closed') | |
if (callback) | |
callback.apply(null, arguments) | |
}) | |
levelup.emit('closing') | |
this._db = null | |
} else if (status == 'closed' && callback) { | |
callback() | |
} else if (status == 'closing' && callback) { | |
levelup.once('closed', callback) | |
} else if (isOpening()) { | |
levelup.once('open', function () { | |
levelup.close(callback) | |
}) | |
} | |
} | |
LevelUP.prototype.isOpen = function () { return isOpen() } | |
LevelUP.prototype.isClosed = function () { return (/^clos/).test(status) } | |
LevelUP.prototype.get = function (key_, options, callback) { | |
var key | |
, valueEnc | |
, err | |
callback = getCallback(options, callback) | |
if (typeof callback != 'function') { | |
err = new errors.ReadError('get() requires key and callback arguments') | |
return dispatchError(err) | |
} | |
if (!isOpening() && !isOpen()) { | |
err = new errors.ReadError('Database is not open') | |
return dispatchError(err, callback) | |
} | |
options = getOptions(options) | |
key = toSlice[options.keyEncoding](key_) | |
valueEnc = options.valueEncoding | |
options.asBuffer = valueEnc != 'utf8' && valueEnc != 'json' | |
this._db.get(key, options, function (err, value) { | |
if (err) { | |
if ((/notfound/i).test(err)) { | |
err = new errors.NotFoundError( | |
'Key not found in database [' + key_ + ']', err) | |
} else { | |
err = new errors.ReadError(err) | |
} | |
return dispatchError(err, callback) | |
} | |
if (callback) { | |
try { | |
value = toEncoding[valueEnc](value) | |
} catch (e) { | |
return callback(new errors.EncodingError(e)) | |
} | |
callback(null, value) | |
} | |
}) | |
} | |
LevelUP.prototype.put = function (key_, value_, options, callback) { | |
var err | |
, key | |
, value | |
callback = getCallback(options, callback) | |
if (key_ === null || key_ === undefined | |
|| value_ === null || value_ === undefined) { | |
err = new errors.WriteError('put() requires key and value arguments') | |
return dispatchError(err, callback) | |
} | |
if (!isOpening() && !isOpen()) { | |
err = new errors.WriteError('Database is not open') | |
return dispatchError(err, callback) | |
} | |
options = getOptions(options) | |
key = toSlice[options.keyEncoding](key_) | |
value = toSlice[options.valueEncoding](value_) | |
this._db.put(key, value, options, function (err) { | |
if (err) { | |
err = new errors.WriteError(err) | |
return dispatchError(err, callback) | |
} else { | |
levelup.emit('put', key_, value_) | |
if (callback) | |
callback() | |
} | |
}) | |
} | |
LevelUP.prototype.del = function (key_, options, callback) { | |
var err | |
, key | |
callback = getCallback(options, callback) | |
if (key_ === null || key_ === undefined) { | |
err = new errors.WriteError('del() requires a key argument') | |
return dispatchError(err, callback) | |
} | |
if (!isOpening() && !isOpen()) { | |
err = new errors.WriteError('Database is not open') | |
return dispatchError(err, callback) | |
} | |
options = getOptions(options) | |
key = toSlice[options.keyEncoding](key_) | |
this._db.del(key, options, function (err) { | |
if (err) { | |
err = new errors.WriteError(err) | |
return dispatchError(err, callback) | |
} else { | |
levelup.emit('del', key_) | |
if (callback) | |
callback() | |
} | |
}) | |
} | |
LevelUP.prototype.batch = function (arr_, options, callback) { | |
var keyEnc | |
, valueEnc | |
, err | |
, arr | |
callback = getCallback(options, callback) | |
if (!Array.isArray(arr_)) { | |
err = new errors.WriteError('batch() requires an array argument') | |
return dispatchError(err, callback) | |
} | |
if (!isOpening() && !isOpen()) { | |
err = new errors.WriteError('Database is not open') | |
return dispatchError(err, callback) | |
} | |
options = getOptions(options) | |
keyEnc = options.keyEncoding | |
valueEnc = options.valueEncoding | |
// If we're not dealing with plain utf8 strings or plain | |
// Buffers then we have to do some work on the array to | |
// encode the keys and/or values. This includes JSON types. | |
if ((keyEnc != 'utf8' && keyEnc != 'binary') | |
|| (valueEnc != 'utf8' && valueEnc != 'binary')) { | |
arr = arr_.map(function (e) { | |
if (e.type !== undefined && e.key !== undefined) { | |
var o = { type: e.type, key: toSlice[keyEnc](e.key) } | |
if (e.value !== undefined) | |
o.value = toSlice[valueEnc](e.value) | |
return o | |
} | |
return {} | |
}) | |
} else { | |
arr = arr_ | |
} | |
this._db.batch(arr, options, function (err) { | |
if (err) { | |
err = new errors.WriteError(err) | |
return dispatchError(err, callback) | |
} else { | |
levelup.emit('batch', arr_) | |
if (callback) | |
callback() | |
} | |
}) | |
} | |
LevelUP.prototype.approximateSize = function(start, end, callback) { | |
var err | |
if (start === null || start === undefined | |
|| end === null || end === undefined | |
|| typeof callback != 'function') { | |
err = new errors.ReadError('approximateSize() requires start, end and callback arguments') | |
return dispatchError(err, callback) | |
} | |
if (!isOpening() && !isOpen()) { | |
err = new errors.WriteError('Database is not open') | |
return dispatchError(err, callback) | |
} | |
this._db.approximateSize(start, end, function(err, size) { | |
if (err) { | |
err = new errors.OpenError(err) | |
return dispatchError(err, callback) | |
} else if (callback) | |
callback(null, size) | |
}) | |
} | |
LevelUP.prototype.readStream = | |
LevelUP.prototype.createReadStream = function (options) { | |
options = extend(this.options, options) | |
return readStream.create( | |
options | |
, this | |
, function (options) { | |
return levelup._db.iterator(options) | |
} | |
) | |
} | |
LevelUP.prototype.keyStream = | |
LevelUP.prototype.createKeyStream = function (options) { | |
return this.readStream(extend(options, { keys: true, values: false })) | |
} | |
LevelUP.prototype.valueStream = | |
LevelUP.prototype.createValueStream = function (options) { | |
return this.readStream(extend(options, { keys: false, values: true })) | |
} | |
LevelUP.prototype.writeStream = | |
LevelUP.prototype.createWriteStream = function (options) { | |
return writeStream.create(extend(options), this) | |
} | |
LevelUP.prototype.toString = function () { | |
return 'LevelUP' | |
} | |
levelup = new LevelUP(location, options) | |
levelup.open(callback) | |
return levelup | |
} | |
, destroy = function (location, callback) { | |
leveldown.destroy(location, callback || function () {}) | |
} | |
, repair = function (location, callback) { | |
leveldown.repair(location, callback || function () {}) | |
} | |
module.exports = createLevelUP | |
module.exports.copy = util.copy | |
module.exports.destroy = destroy | |
module.exports.repair = repair | |
})(require("__browserify_process")) | |
},{"events":5,"util":4,"./errors":13,"./read-stream":14,"./write-stream":15,"./util":10,"leveldown":16,"prr":17,"xtend":18,"__browserify_process":6}],17:[function(require,module,exports){ | |
/*! | |
* prr | |
* (c) 2013 Rod Vagg <[email protected]> | |
* https://github.com/rvagg/prr | |
* License: MIT | |
*/ | |
(function (name, context, definition) { | |
if (typeof module != 'undefined' && module.exports) | |
module.exports = definition() | |
else | |
context[name] = definition() | |
})('prr', this, function() { | |
var setProperty = typeof Object.defineProperty == 'function' | |
? function (obj, key, options) { | |
Object.defineProperty(obj, key, options) | |
return obj | |
} | |
: function (obj, key, options) { // < es5 | |
obj[key] = options.value | |
return obj | |
} | |
, makeOptions = function (value, options) { | |
var oo = typeof options == 'object' | |
, os = !oo && typeof options == 'string' | |
, op = function (p) { | |
return oo | |
? !!options[p] | |
: os | |
? options.indexOf(p[0]) > -1 | |
: false | |
} | |
return { | |
enumerable : op('enumerable') | |
, configurable : op('configurable') | |
, writable : op('writable') | |
, value : value | |
} | |
} | |
, prr = function (obj, key, value, options) { | |
var k | |
options = makeOptions(value, options) | |
if (typeof key == 'object') { | |
for (k in key) { | |
if (Object.hasOwnProperty.call(key, k)) { | |
options.value = key[k] | |
setProperty(obj, k, options) | |
} | |
} | |
return obj | |
} | |
return setProperty(obj, key, options) | |
} | |
return prr | |
}) | |
},{}],19:[function(require,module,exports){ | |
function State () { | |
this.ended = this._ready = this._reading = this._destroyed = this._paused = false | |
} | |
State.prototype.end = function() { | |
this.ended = true | |
this._destroyed = false | |
} | |
State.prototype.ready = function() { | |
this._ready = true | |
} | |
State.prototype.destroy = function() { | |
this._destroyed = true | |
} | |
State.prototype.pause = function() { | |
this._paused = true | |
} | |
State.prototype.resume = function() { | |
this._paused = false | |
} | |
State.prototype.read = function() { | |
this._reading = true | |
} | |
State.prototype.endRead = function() { | |
this._reading = false | |
} | |
State.prototype.canPause = function() { | |
return !this.ended && !this._paused | |
} | |
State.prototype.canResume = function() { | |
return !this.ended && this._paused | |
} | |
State.prototype.canRead = function() { | |
return !this.ended && !this._reading && !this._paused | |
} | |
State.prototype.canCleanup = function() { | |
return !this.ended && !this._reading | |
} | |
State.prototype.canEmitData = function() { | |
return !this.ended && !this._destroyed | |
} | |
State.prototype.canEnd = function() { | |
return !this.ended | |
} | |
module.exports = function () { return new State() } | |
},{}],18:[function(require,module,exports){ | |
var Keys = Object.keys || objectKeys | |
module.exports = extend | |
function extend() { | |
var target = {} | |
for (var i = 0; i < arguments.length; i++) { | |
var source = arguments[i] | |
if (!isObject(source)) { | |
continue | |
} | |
var keys = Keys(source) | |
for (var j = 0; j < keys.length; j++) { | |
var name = keys[j] | |
target[name] = source[name] | |
} | |
} | |
return target | |
} | |
function objectKeys(obj) { | |
var keys = [] | |
for (var k in obj) { | |
keys.push(k) | |
} | |
return keys | |
} | |
function isObject(obj) { | |
return obj !== null && typeof obj === "object" | |
} | |
},{}],13:[function(require,module,exports){ | |
/* Copyright (c) 2012-2013 LevelUP contributors | |
* See list at <https://github.com/rvagg/node-levelup#contributing> | |
* MIT +no-false-attribs License | |
* <https://github.com/rvagg/node-levelup/blob/master/LICENSE> | |
*/ | |
var createError = require('errno').custom.createError | |
, LevelUPError = createError('LevelUPError') | |
module.exports = { | |
LevelUPError : LevelUPError | |
, InitializationError : createError('InitializationError', LevelUPError) | |
, OpenError : createError('OpenError', LevelUPError) | |
, ReadError : createError('ReadError', LevelUPError) | |
, WriteError : createError('WriteError', LevelUPError) | |
, NotFoundError : createError('NotFoundError', LevelUPError) | |
, EncodingError : createError('EncodingError', LevelUPError) | |
} | |
},{"errno":20}],14:[function(require,module,exports){ | |
(function(Buffer){/* Copyright (c) 2012-2013 LevelUP contributors | |
* See list at <https://github.com/rvagg/node-levelup#contributing> | |
* MIT +no-false-attribs License <https://github.com/rvagg/node-levelup/blob/master/LICENSE> | |
*/ | |
var Stream = require('stream').Stream | |
, bufferStream = require('simple-bufferstream') | |
, inherits = require('util').inherits | |
, extend = require('xtend') | |
, errors = require('./errors') | |
, State = require('./read-stream-state') | |
, toEncoding = require('./util').toEncoding | |
, toSlice = require('./util').toSlice | |
, setImmediate = require('./util').setImmediate | |
, defaultOptions = { keys: true, values: true } | |
, makeKeyValueData = function (key, value) { | |
return { | |
key: toEncoding[this._keyEncoding](key) | |
, value: toEncoding[this._valueEncoding](value) | |
} | |
} | |
, makeKeyData = function (key) { | |
return toEncoding[this._keyEncoding](key) | |
} | |
, makeValueData = function (key, value) { | |
return toEncoding[this._valueEncoding](value) | |
} | |
, makeNoData = function () { return null } | |
function ReadStream (options, db, iteratorFactory) { | |
Stream.call(this) | |
this._state = State() | |
this._dataEvent = 'data' | |
this.readable = true | |
this.writable = false | |
// purely to keep `db` around until we're done so it's not GCed if the user doesn't keep a ref | |
this._db = db | |
options = this._options = extend(defaultOptions, options) | |
this._keyEncoding = options.keyEncoding || options.encoding | |
this._valueEncoding = options.valueEncoding || options.encoding | |
if (typeof this._options.start != 'undefined') | |
this._options.start = toSlice[this._keyEncoding](this._options.start) | |
if (typeof this._options.end != 'undefined') | |
this._options.end = toSlice[this._keyEncoding](this._options.end) | |
if (typeof this._options.limit != 'number') | |
this._options.limit = -1 | |
this._options.keyAsBuffer = this._keyEncoding != 'utf8' && this._keyEncoding != 'json' | |
this._options.valueAsBuffer = this._valueEncoding != 'utf8' && this._valueEncoding != 'json' | |
this._makeData = this._options.keys && this._options.values | |
? makeKeyValueData.bind(this) : this._options.keys | |
? makeKeyData.bind(this) : this._options.values | |
? makeValueData.bind(this) : makeNoData | |
var ready = function () { | |
if (!this._state.canEmitData()) | |
return | |
this._state.ready() | |
this._iterator = iteratorFactory(this._options) | |
this.emit('ready') | |
this._read() | |
}.bind(this) | |
if (db.isOpen()) | |
setImmediate(ready) | |
else | |
db.once('ready', ready) | |
} | |
inherits(ReadStream, Stream) | |
ReadStream.prototype.destroy = function () { | |
this._state.destroy() | |
if (this._state.canCleanup()) | |
this._cleanup() | |
} | |
ReadStream.prototype.pause = function () { | |
if (this._state.canPause()) { | |
this._state.pause() | |
this.emit('pause') | |
} | |
} | |
ReadStream.prototype.resume = function () { | |
if (this._state.canResume()) { | |
this.emit('resume') | |
this._state.resume() | |
this._read() | |
} | |
} | |
ReadStream.prototype.pipe = function (dest) { | |
if (typeof dest.add == 'function' && this._options.type == 'fstream') { | |
this._dataEvent = 'entry' | |
this.on('entry', function (data) { | |
var entry = bufferStream(new Buffer(data.value)) | |
entry.path = data.key.toString() | |
entry.type = 'File' | |
entry.props = { | |
type: 'File' | |
, path: data.key.toString() | |
} | |
entry.pause() | |
if (dest.add(entry) === false) | |
this.pause() | |
}.bind(this)) | |
} | |
return Stream.prototype.pipe.apply(this, arguments) | |
} | |
ReadStream.prototype._read = function () { | |
if (this._state.canRead()) { | |
this._state.read() | |
this._iterator.next(this._onData.bind(this)) | |
} | |
} | |
ReadStream.prototype._onData = function (err, key, value) { | |
this._state.endRead() | |
if (err || !arguments.length /* end */ || !this._state.canEmitData()) | |
return this._cleanup(err) | |
this._read() // queue another read even tho we may not need it | |
try { | |
value = this._makeData(key, value) | |
} catch (e) { | |
return this.emit('error', new errors.EncodingError(e)) | |
} | |
this.emit(this._dataEvent, value) | |
} | |
ReadStream.prototype._cleanup = function (err) { | |
if (err) | |
this.emit('error', err) | |
if (!this._state.canEnd()) | |
return | |
this._state.end() | |
this.readable = false | |
if (this._iterator) { | |
this._iterator.end(function () { | |
this._iterator = null | |
this.emit('close') | |
}.bind(this)) | |
} else | |
this.emit('close') | |
this.emit('end') | |
} | |
ReadStream.prototype.toString = function () { | |
return 'LevelUP.ReadStream' | |
} | |
module.exports.create = function (options, db, iteratorFactory) { | |
return new ReadStream(options, db, iteratorFactory) | |
} | |
})(require("__browserify_buffer").Buffer) | |
},{"stream":12,"util":4,"./errors":13,"./read-stream-state":19,"./util":10,"simple-bufferstream":21,"xtend":18,"__browserify_buffer":9}],15:[function(require,module,exports){ | |
/* Copyright (c) 2012-2013 LevelUP contributors | |
* See list at <https://github.com/rvagg/node-levelup#contributing> | |
* MIT +no-false-attribs License | |
* <https://github.com/rvagg/node-levelup/blob/master/LICENSE> | |
*/ | |
var Stream = require('stream').Stream | |
, inherits = require('util').inherits | |
, extend = require('xtend') | |
, concatStream = require('concat-stream') | |
, setImmediate = require('./util').setImmediate | |
, defaultOptions = {} | |
function WriteStream (options, db) { | |
Stream.call(this) | |
this._options = extend(defaultOptions, options) | |
this._db = db | |
this._buffer = [] | |
this._status = 'init' | |
this._end = false | |
this.writable = true | |
this.readable = false | |
var ready = function () { | |
if (!this.writable) | |
return | |
this._status = 'ready' | |
this.emit('ready') | |
this._process() | |
}.bind(this) | |
if (db.isOpen()) | |
setImmediate(ready) | |
else | |
db.once('ready', ready) | |
} | |
inherits(WriteStream, Stream) | |
WriteStream.prototype.write = function (data) { | |
if (!this.writable) | |
return false | |
this._buffer.push(data) | |
if (this._status != 'init') | |
this._processDelayed() | |
if (this._options.maxBufferLength && | |
this._buffer.length > this._options.maxBufferLength) { | |
this._writeBlock = true | |
return false | |
} | |
return true | |
} | |
WriteStream.prototype.end = function() { | |
setImmediate(function () { | |
this._end = true | |
this._process() | |
}.bind(this)) | |
} | |
WriteStream.prototype.destroy = function() { | |
this.writable = false | |
this.end() | |
} | |
WriteStream.prototype.destroySoon = function() { | |
this.end() | |
} | |
WriteStream.prototype.add = function(entry) { | |
if (!entry.props) | |
return | |
if (entry.props.Directory) | |
entry.pipe(this._db.writeStream(this._options)) | |
else if (entry.props.File || entry.File || entry.type == 'File') | |
this._write(entry) | |
return true | |
} | |
WriteStream.prototype._processDelayed = function() { | |
setImmediate(this._process.bind(this)) | |
} | |
WriteStream.prototype._process = function() { | |
var buffer | |
, entry | |
, cb = function (err) { | |
if (!this.writable) | |
return | |
if (this._status != 'closed') | |
this._status = 'ready' | |
if (err) { | |
this.writable = false | |
return this.emit('error', err) | |
} | |
this._process() | |
}.bind(this) | |
if (this._status != 'ready' && this.writable) { | |
if (this._buffer.length && this._status != 'closed') | |
this._processDelayed() | |
return | |
} | |
if (this._buffer.length && this.writable) { | |
this._status = 'writing' | |
buffer = this._buffer | |
this._buffer = [] | |
if (buffer.length == 1) { | |
entry = buffer.pop() | |
if (entry.key !== undefined && entry.value !== undefined) | |
this._db.put(entry.key, entry.value, cb) | |
} else { | |
this._db.batch(buffer.map(function (d) { | |
return { type: 'put', key: d.key, value: d.value } | |
}), cb) | |
} | |
if (this._writeBlock) { | |
this._writeBlock = false | |
this.emit('drain') | |
} | |
// don't allow close until callback has returned | |
return | |
} | |
if (this._end && this._status != 'closed') { | |
this._status = 'closed' | |
this.writable = false | |
this.emit('close') | |
} | |
} | |
WriteStream.prototype._write = function (entry) { | |
var key = entry.path || entry.props.path | |
if (!key) | |
return | |
entry.pipe(concatStream(function (err, data) { | |
if (err) { | |
this.writable = false | |
return this.emit('error', err) | |
} | |
if (this._options.fstreamRoot && | |
key.indexOf(this._options.fstreamRoot) > -1) | |
key = key.substr(this._options.fstreamRoot.length + 1) | |
this.write({ key: key, value: data }) | |
}.bind(this))) | |
} | |
WriteStream.prototype.toString = function () { | |
return 'LevelUP.WriteStream' | |
} | |
module.exports.create = function (options, db) { | |
return new WriteStream(options, db) | |
} | |
},{"stream":12,"util":4,"./util":10,"xtend":18,"concat-stream":22}],21:[function(require,module,exports){ | |
(function(process){const stream = require('stream') | |
, util = require('util') | |
var SimpleBufferStream = function (buffer) { | |
stream.Stream.call(this) | |
this._state = 'ready' | |
this._buffer = buffer | |
process.nextTick(this._dump.bind(this)) | |
} | |
util.inherits(SimpleBufferStream, stream.Stream) | |
SimpleBufferStream.prototype._dump = function() { | |
if (this._state != 'ready') | |
return | |
this._state = 'done' | |
this.emit('data', this._buffer) | |
this.emit('end') | |
this.emit('close') | |
} | |
SimpleBufferStream.prototype.pause = function() { | |
if (this._state != 'done') | |
this._state = 'paused' | |
} | |
SimpleBufferStream.prototype.resume = function() { | |
if (this._state == 'done') | |
return | |
this._state = 'ready' | |
this._dump() | |
} | |
SimpleBufferStream.prototype.destroy = function() {} | |
module.exports = function (buffer) { | |
return new SimpleBufferStream(buffer) | |
} | |
})(require("__browserify_process")) | |
},{"stream":12,"util":4,"__browserify_process":6}],16:[function(require,module,exports){ | |
module.exports = require('bindings')('leveldown.node').leveldown | |
},{"bindings":23}],22:[function(require,module,exports){ | |
(function(Buffer){var stream = require('stream') | |
var util = require('util') | |
function ConcatStream(cb) { | |
stream.Stream.call(this) | |
this.writable = true | |
if (cb) this.cb = cb | |
this.body = [] | |
this.on('error', function(err) { | |
if (this.cb) this.cb(err) | |
}) | |
} | |
util.inherits(ConcatStream, stream.Stream) | |
ConcatStream.prototype.write = function(chunk) { | |
this.body.push(chunk) | |
} | |
ConcatStream.prototype.destroy = function() {} | |
ConcatStream.prototype.arrayConcat = function(arrs) { | |
if (arrs.length === 0) return [] | |
if (arrs.length === 1) return arrs[0] | |
return arrs.reduce(function (a, b) { return a.concat(b) }) | |
} | |
ConcatStream.prototype.isArray = function(arr) { | |
return Array.isArray(arr) | |
} | |
ConcatStream.prototype.getBody = function () { | |
if (this.body.length === 0) return | |
if (typeof(this.body[0]) === "string") return this.body.join('') | |
if (this.isArray(this.body[0])) return this.arrayConcat(this.body) | |
if (typeof(Buffer) !== "undefined" && Buffer.isBuffer(this.body[0])) { | |
return Buffer.concat(this.body) | |
} | |
return this.body | |
} | |
ConcatStream.prototype.end = function() { | |
if (this.cb) this.cb(false, this.getBody()) | |
} | |
module.exports = function(cb) { | |
return new ConcatStream(cb) | |
} | |
module.exports.ConcatStream = ConcatStream | |
})(require("__browserify_buffer").Buffer) | |
},{"stream":12,"util":4,"__browserify_buffer":9}],23:[function(require,module,exports){ | |
(function(process,__filename){ | |
/** | |
* Module dependencies. | |
*/ | |
var fs = require('fs') | |
, path = require('path') | |
, join = path.join | |
, dirname = path.dirname | |
, exists = fs.existsSync || path.existsSync | |
, defaults = { | |
arrow: process.env.NODE_BINDINGS_ARROW || ' → ' | |
, compiled: process.env.NODE_BINDINGS_COMPILED_DIR || 'compiled' | |
, platform: process.platform | |
, arch: process.arch | |
, version: process.versions.node | |
Uncaught TypeError: Cannot read property 'node' of undefined | |
, bindings: 'bindings.node' | |
, try: [ | |
// node-gyp's linked version in the "build" dir | |
[ 'module_root', 'build', 'bindings' ] | |
// node-waf and gyp_addon (a.k.a node-gyp) | |
, [ 'module_root', 'build', 'Debug', 'bindings' ] | |
, [ 'module_root', 'build', 'Release', 'bindings' ] | |
// Debug files, for development (legacy behavior, remove for node v0.9) | |
, [ 'module_root', 'out', 'Debug', 'bindings' ] | |
, [ 'module_root', 'Debug', 'bindings' ] | |
// Release files, but manually compiled (legacy behavior, remove for node v0.9) | |
, [ 'module_root', 'out', 'Release', 'bindings' ] | |
, [ 'module_root', 'Release', 'bindings' ] | |
// Legacy from node-waf, node <= 0.4.x | |
, [ 'module_root', 'build', 'default', 'bindings' ] | |
// Production "Release" buildtype binary (meh...) | |
, [ 'module_root', 'compiled', 'version', 'platform', 'arch', 'bindings' ] | |
] | |
} | |
/** | |
* The main `bindings()` function loads the compiled bindings for a given module. | |
* It uses V8's Error API to determine the parent filename that this function is | |
* being invoked from, which is then used to find the root directory. | |
*/ | |
function bindings (opts) { | |
// Argument surgery | |
if (typeof opts == 'string') { | |
opts = { bindings: opts } | |
} else if (!opts) { | |
opts = {} | |
} | |
opts.__proto__ = defaults | |
// Get the module root | |
if (!opts.module_root) { | |
opts.module_root = exports.getRoot(exports.getFileName()) | |
} | |
// Ensure the given bindings name ends with .node | |
if (path.extname(opts.bindings) != '.node') { | |
opts.bindings += '.node' | |
} | |
var tries = [] | |
, i = 0 | |
, l = opts.try.length | |
, n | |
, b | |
, err | |
for (; i<l; i++) { | |
n = join.apply(null, opts.try[i].map(function (p) { | |
return opts[p] || p | |
})) | |
tries.push(n) | |
try { | |
b = opts.path ? require.resolve(n) : require(n) | |
if (!opts.path) { | |
b.path = n | |
} | |
return b | |
} catch (e) { | |
if (!/not find/i.test(e.message)) { | |
throw e | |
} | |
} | |
} | |
err = new Error('Could not locate the bindings file. Tried:\n' | |
+ tries.map(function (a) { return opts.arrow + a }).join('\n')) | |
err.tries = tries | |
throw err | |
} | |
module.exports = exports = bindings | |
/** | |
* Gets the filename of the JavaScript file that invokes this function. | |
* Used to help find the root directory of a module. | |
*/ | |
exports.getFileName = function getFileName () { | |
var origPST = Error.prepareStackTrace | |
, dummy = {} | |
, fileName | |
Error.prepareStackTrace = function (e, st) { | |
for (var i=0, l=st.length; i<l; i++) { | |
fileName = st[i].getFileName() | |
if (fileName !== __filename) { | |
return | |
} | |
} | |
} | |
// run the 'prepareStackTrace' function above | |
Error.captureStackTrace(dummy) | |
dummy.stack | |
// cleanup | |
Error.prepareStackTrace = origPST | |
return fileName | |
} | |
/** | |
* Gets the root directory of a module, given an arbitrary filename | |
* somewhere in the module tree. The "root directory" is the directory | |
* containing the `package.json` file. | |
* | |
* In: /home/nate/node-native-module/lib/index.js | |
* Out: /home/nate/node-native-module | |
*/ | |
exports.getRoot = function getRoot (file) { | |
var dir = dirname(file) | |
, prev | |
while (true) { | |
if (dir === '.') { | |
// Avoids an infinite loop in rare cases, like the REPL | |
dir = process.cwd() | |
} | |
if (exists(join(dir, 'package.json')) || exists(join(dir, 'node_modules'))) { | |
// Found the 'package.json' file or 'node_modules' dir; we're done | |
return dir | |
} | |
if (prev === dir) { | |
// Got to the top | |
throw new Error('Could not find module root given file: "' + file | |
+ '". Do you have a `package.json` file? ') | |
} | |
// Try the parent dir next | |
prev = dir | |
dir = join(dir, '..') | |
} | |
} | |
})(require("__browserify_process"),"/node_modules/levelup/node_modules/leveldown/node_modules/bindings/bindings.js") | |
},{"fs":24,"path":25,"__browserify_process":6}],20:[function(require,module,exports){ | |
(function(){var all = module.exports.all = [ | |
{ | |
"errno": -1, | |
"code": "UNKNOWN", | |
"description": "unknown error" | |
}, | |
{ | |
"errno": 0, | |
"code": "OK", | |
"description": "success" | |
}, | |
{ | |
"errno": 1, | |
"code": "EOF", | |
"description": "end of file" | |
}, | |
{ | |
"errno": 2, | |
"code": "EADDRINFO", | |
"description": "getaddrinfo error" | |
}, | |
{ | |
"errno": 3, | |
"code": "EACCES", | |
"description": "permission denied" | |
}, | |
{ | |
"errno": 4, | |
"code": "EAGAIN", | |
"description": "no more processes" | |
}, | |
{ | |
"errno": 5, | |
"code": "EADDRINUSE", | |
"description": "address already in use" | |
}, | |
{ | |
"errno": 6, | |
"code": "EADDRNOTAVAIL", | |
"description": "" | |
}, | |
{ | |
"errno": 7, | |
"code": "EAFNOSUPPORT", | |
"description": "" | |
}, | |
{ | |
"errno": 8, | |
"code": "EALREADY", | |
"description": "" | |
}, | |
{ | |
"errno": 9, | |
"code": "EBADF", | |
"description": "bad file descriptor" | |
}, | |
{ | |
"errno": 10, | |
"code": "EBUSY", | |
"description": "resource busy or locked" | |
}, | |
{ | |
"errno": 11, | |
"code": "ECONNABORTED", | |
"description": "software caused connection abort" | |
}, | |
{ | |
"errno": 12, | |
"code": "ECONNREFUSED", | |
"description": "connection refused" | |
}, | |
{ | |
"errno": 13, | |
"code": "ECONNRESET", | |
"description": "connection reset by peer" | |
}, | |
{ | |
"errno": 14, | |
"code": "EDESTADDRREQ", | |
"description": "destination address required" | |
}, | |
{ | |
"errno": 15, | |
"code": "EFAULT", | |
"description": "bad address in system call argument" | |
}, | |
{ | |
"errno": 16, | |
"code": "EHOSTUNREACH", | |
"description": "host is unreachable" | |
}, | |
{ | |
"errno": 17, | |
"code": "EINTR", | |
"description": "interrupted system call" | |
}, | |
{ | |
"errno": 18, | |
"code": "EINVAL", | |
"description": "invalid argument" | |
}, | |
{ | |
"errno": 19, | |
"code": "EISCONN", | |
"description": "socket is already connected" | |
}, | |
{ | |
"errno": 20, | |
"code": "EMFILE", | |
"description": "too many open files" | |
}, | |
{ | |
"errno": 21, | |
"code": "EMSGSIZE", | |
"description": "message too long" | |
}, | |
{ | |
"errno": 22, | |
"code": "ENETDOWN", | |
"description": "network is down" | |
}, | |
{ | |
"errno": 23, | |
"code": "ENETUNREACH", | |
"description": "network is unreachable" | |
}, | |
{ | |
"errno": 24, | |
"code": "ENFILE", | |
"description": "file table overflow" | |
}, | |
{ | |
"errno": 25, | |
"code": "ENOBUFS", | |
"description": "no buffer space available" | |
}, | |
{ | |
"errno": 26, | |
"code": "ENOMEM", | |
"description": "not enough memory" | |
}, | |
{ | |
"errno": 27, | |
"code": "ENOTDIR", | |
"description": "not a directory" | |
}, | |
{ | |
"errno": 28, | |
"code": "EISDIR", | |
"description": "illegal operation on a directory" | |
}, | |
{ | |
"errno": 29, | |
"code": "ENONET", | |
"description": "machine is not on the network" | |
}, | |
{ | |
"errno": 31, | |
"code": "ENOTCONN", | |
"description": "socket is not connected" | |
}, | |
{ | |
"errno": 32, | |
"code": "ENOTSOCK", | |
"description": "socket operation on non-socket" | |
}, | |
{ | |
"errno": 33, | |
"code": "ENOTSUP", | |
"description": "operation not supported on socket" | |
}, | |
{ | |
"errno": 34, | |
"code": "ENOENT", | |
"description": "no such file or directory" | |
}, | |
{ | |
"errno": 35, | |
"code": "ENOSYS", | |
"description": "function not implemented" | |
}, | |
{ | |
"errno": 36, | |
"code": "EPIPE", | |
"description": "broken pipe" | |
}, | |
{ | |
"errno": 37, | |
"code": "EPROTO", | |
"description": "protocol error" | |
}, | |
{ | |
"errno": 38, | |
"code": "EPROTONOSUPPORT", | |
"description": "protocol not supported" | |
}, | |
{ | |
"errno": 39, | |
"code": "EPROTOTYPE", | |
"description": "protocol wrong type for socket" | |
}, | |
{ | |
"errno": 40, | |
"code": "ETIMEDOUT", | |
"description": "connection timed out" | |
}, | |
{ | |
"errno": 41, | |
"code": "ECHARSET", | |
"description": "" | |
}, | |
{ | |
"errno": 42, | |
"code": "EAIFAMNOSUPPORT", | |
"description": "" | |
}, | |
{ | |
"errno": 44, | |
"code": "EAISERVICE", | |
"description": "" | |
}, | |
{ | |
"errno": 45, | |
"code": "EAISOCKTYPE", | |
"description": "" | |
}, | |
{ | |
"errno": 46, | |
"code": "ESHUTDOWN", | |
"description": "" | |
}, | |
{ | |
"errno": 47, | |
"code": "EEXIST", | |
"description": "file already exists" | |
}, | |
{ | |
"errno": 48, | |
"code": "ESRCH", | |
"description": "no such process" | |
}, | |
{ | |
"errno": 49, | |
"code": "ENAMETOOLONG", | |
"description": "name too long" | |
}, | |
{ | |
"errno": 50, | |
"code": "EPERM", | |
"description": "operation not permitted" | |
}, | |
{ | |
"errno": 51, | |
"code": "ELOOP", | |
"description": "too many symbolic links encountered" | |
}, | |
{ | |
"errno": 52, | |
"code": "EXDEV", | |
"description": "cross-device link not permitted" | |
}, | |
{ | |
"errno": 53, | |
"code": "ENOTEMPTY", | |
"description": "directory not empty" | |
}, | |
{ | |
"errno": 54, | |
"code": "ENOSPC", | |
"description": "no space left on device" | |
}, | |
{ | |
"errno": 55, | |
"code": "EIO", | |
"description": "i/o error" | |
}, | |
{ | |
"errno": 56, | |
"code": "EROFS", | |
"description": "read-only file system" | |
}, | |
{ | |
"errno": 57, | |
"code": "ENODEV", | |
"description": "no such device" | |
}, | |
{ | |
"errno": 58, | |
"code": "ESPIPE", | |
"description": "invalid seek" | |
}, | |
{ | |
"errno": 59, | |
"code": "ECANCELED", | |
"description": "operation canceled" | |
} | |
] | |
module.exports.errno = { | |
'-1': all[0] | |
, '0': all[1] | |
, '1': all[2] | |
, '2': all[3] | |
, '3': all[4] | |
, '4': all[5] | |
, '5': all[6] | |
, '6': all[7] | |
, '7': all[8] | |
, '8': all[9] | |
, '9': all[10] | |
, '10': all[11] | |
, '11': all[12] | |
, '12': all[13] | |
, '13': all[14] | |
, '14': all[15] | |
, '15': all[16] | |
, '16': all[17] | |
, '17': all[18] | |
, '18': all[19] | |
, '19': all[20] | |
, '20': all[21] | |
, '21': all[22] | |
, '22': all[23] | |
, '23': all[24] | |
, '24': all[25] | |
, '25': all[26] | |
, '26': all[27] | |
, '27': all[28] | |
, '28': all[29] | |
, '29': all[30] | |
, '31': all[31] | |
, '32': all[32] | |
, '33': all[33] | |
, '34': all[34] | |
, '35': all[35] | |
, '36': all[36] | |
, '37': all[37] | |
, '38': all[38] | |
, '39': all[39] | |
, '40': all[40] | |
, '41': all[41] | |
, '42': all[42] | |
, '44': all[43] | |
, '45': all[44] | |
, '46': all[45] | |
, '47': all[46] | |
, '48': all[47] | |
, '49': all[48] | |
, '50': all[49] | |
, '51': all[50] | |
, '52': all[51] | |
, '53': all[52] | |
, '54': all[53] | |
, '55': all[54] | |
, '56': all[55] | |
, '57': all[56] | |
, '58': all[57] | |
, '59': all[58] | |
} | |
module.exports.code = { | |
'UNKNOWN': all[0] | |
, 'OK': all[1] | |
, 'EOF': all[2] | |
, 'EADDRINFO': all[3] | |
, 'EACCES': all[4] | |
, 'EAGAIN': all[5] | |
, 'EADDRINUSE': all[6] | |
, 'EADDRNOTAVAIL': all[7] | |
, 'EAFNOSUPPORT': all[8] | |
, 'EALREADY': all[9] | |
, 'EBADF': all[10] | |
, 'EBUSY': all[11] | |
, 'ECONNABORTED': all[12] | |
, 'ECONNREFUSED': all[13] | |
, 'ECONNRESET': all[14] | |
, 'EDESTADDRREQ': all[15] | |
, 'EFAULT': all[16] | |
, 'EHOSTUNREACH': all[17] | |
, 'EINTR': all[18] | |
, 'EINVAL': all[19] | |
, 'EISCONN': all[20] | |
, 'EMFILE': all[21] | |
, 'EMSGSIZE': all[22] | |
, 'ENETDOWN': all[23] | |
, 'ENETUNREACH': all[24] | |
, 'ENFILE': all[25] | |
, 'ENOBUFS': all[26] | |
, 'ENOMEM': all[27] | |
, 'ENOTDIR': all[28] | |
, 'EISDIR': all[29] | |
, 'ENONET': all[30] | |
, 'ENOTCONN': all[31] | |
, 'ENOTSOCK': all[32] | |
, 'ENOTSUP': all[33] | |
, 'ENOENT': all[34] | |
, 'ENOSYS': all[35] | |
, 'EPIPE': all[36] | |
, 'EPROTO': all[37] | |
, 'EPROTONOSUPPORT': all[38] | |
, 'EPROTOTYPE': all[39] | |
, 'ETIMEDOUT': all[40] | |
, 'ECHARSET': all[41] | |
, 'EAIFAMNOSUPPORT': all[42] | |
, 'EAISERVICE': all[43] | |
, 'EAISOCKTYPE': all[44] | |
, 'ESHUTDOWN': all[45] | |
, 'EEXIST': all[46] | |
, 'ESRCH': all[47] | |
, 'ENAMETOOLONG': all[48] | |
, 'EPERM': all[49] | |
, 'ELOOP': all[50] | |
, 'EXDEV': all[51] | |
, 'ENOTEMPTY': all[52] | |
, 'ENOSPC': all[53] | |
, 'EIO': all[54] | |
, 'EROFS': all[55] | |
, 'ENODEV': all[56] | |
, 'ESPIPE': all[57] | |
, 'ECANCELED': all[58] | |
} | |
module.exports.custom = require("./custom")(module.exports) | |
})() | |
},{"./custom":26}],26:[function(require,module,exports){ | |
function init (name, message, cause) { | |
this.name = name | |
// can be passed just a 'cause' | |
this.cause = typeof message != 'string' ? message : cause | |
this.message = !!message && typeof message != 'string' ? message.message : message | |
} | |
// generic prototype, not intended to be actually used - helpful for `instanceof` | |
function CustomError (message, cause) { | |
Error.call(this) | |
Error.captureStackTrace(this, arguments.callee) | |
init.call(this, 'CustomError', message, cause) | |
} | |
CustomError.prototype = new Error() | |
function createError (errno, name, proto) { | |
var err = function (message, cause) { | |
init.call(this, name, message, cause) | |
//TODO: the specificity here is stupid, errno should be available everywhere | |
if (name == 'FilesystemError') { | |
this.code = this.cause.code | |
this.path = this.cause.path | |
this.errno = this.cause.errno | |
this.message = | |
(errno.errno[this.cause.errno] | |
? errno.errno[this.cause.errno].description | |
: this.cause.message) | |
+ (this.cause.path ? ' [' + this.cause.path + ']' : '') | |
} | |
Error.call(this) | |
Error.captureStackTrace(this, arguments.callee) | |
} | |
err.prototype = !!proto ? new proto() : new CustomError() | |
return err | |
} | |
module.exports = function (errno) { | |
var ce = createError.bind(null, errno) | |
return { | |
CustomError : CustomError | |
, FilesystemError : ce('FilesystemError') | |
, createError : ce | |
} | |
} | |
},{}],24:[function(require,module,exports){ | |
// nothing to see here... no file methods for the browser | |
},{}],25:[function(require,module,exports){ | |
(function(process){function filter (xs, fn) { | |
var res = []; | |
for (var i = 0; i < xs.length; i++) { | |
if (fn(xs[i], i, xs)) res.push(xs[i]); | |
} | |
return res; | |
} | |
// resolves . and .. elements in a path array with directory names there | |
// must be no slashes, empty elements, or device names (c:\) in the array | |
// (so also no leading and trailing slashes - it does not distinguish | |
// relative and absolute paths) | |
function normalizeArray(parts, allowAboveRoot) { | |
// if the path tries to go above the root, `up` ends up > 0 | |
var up = 0; | |
for (var i = parts.length; i >= 0; i--) { | |
var last = parts[i]; | |
if (last == '.') { | |
parts.splice(i, 1); | |
} else if (last === '..') { | |
parts.splice(i, 1); | |
up++; | |
} else if (up) { | |
parts.splice(i, 1); | |
up--; | |
} | |
} | |
// if the path is allowed to go above the root, restore leading ..s | |
if (allowAboveRoot) { | |
for (; up--; up) { | |
parts.unshift('..'); | |
} | |
} | |
return parts; | |
} | |
// Regex to split a filename into [*, dir, basename, ext] | |
// posix version | |
var splitPathRe = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/; | |
// path.resolve([from ...], to) | |
// posix version | |
exports.resolve = function() { | |
var resolvedPath = '', | |
resolvedAbsolute = false; | |
for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) { | |
var path = (i >= 0) | |
? arguments[i] | |
: process.cwd(); | |
// Skip empty and invalid entries | |
if (typeof path !== 'string' || !path) { | |
continue; | |
} | |
resolvedPath = path + '/' + resolvedPath; | |
resolvedAbsolute = path.charAt(0) === '/'; | |
} | |
// At this point the path should be resolved to a full absolute path, but | |
// handle relative paths to be safe (might happen when process.cwd() fails) | |
// Normalize the path | |
resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) { | |
return !!p; | |
}), !resolvedAbsolute).join('/'); | |
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; | |
}; | |
// path.normalize(path) | |
// posix version | |
exports.normalize = function(path) { | |
var isAbsolute = path.charAt(0) === '/', | |
trailingSlash = path.slice(-1) === '/'; | |
// Normalize the path | |
path = normalizeArray(filter(path.split('/'), function(p) { | |
return !!p; | |
}), !isAbsolute).join('/'); | |
if (!path && !isAbsolute) { | |
path = '.'; | |
} | |
if (path && trailingSlash) { | |
path += '/'; | |
} | |
return (isAbsolute ? '/' : '') + path; | |
}; | |
// posix version | |
exports.join = function() { | |
var paths = Array.prototype.slice.call(arguments, 0); | |
return exports.normalize(filter(paths, function(p, index) { | |
return p && typeof p === 'string'; | |
}).join('/')); | |
}; | |
exports.dirname = function(path) { | |
var dir = splitPathRe.exec(path)[1] || ''; | |
var isWindows = false; | |
if (!dir) { | |
// No dirname | |
return '.'; | |
} else if (dir.length === 1 || | |
(isWindows && dir.length <= 3 && dir.charAt(1) === ':')) { | |
// It is just a slash or a drive letter with a slash | |
return dir; | |
} else { | |
// It is a full dirname, strip trailing slash | |
return dir.substring(0, dir.length - 1); | |
} | |
}; | |
exports.basename = function(path, ext) { | |
var f = splitPathRe.exec(path)[2] || ''; | |
// TODO: make this comparison case-insensitive on windows? | |
if (ext && f.substr(-1 * ext.length) === ext) { | |
f = f.substr(0, f.length - ext.length); | |
} | |
return f; | |
}; | |
exports.extname = function(path) { | |
return splitPathRe.exec(path)[3] || ''; | |
}; | |
exports.relative = function(from, to) { | |
from = exports.resolve(from).substr(1); | |
to = exports.resolve(to).substr(1); | |
function trim(arr) { | |
var start = 0; | |
for (; start < arr.length; start++) { | |
if (arr[start] !== '') break; | |
} | |
var end = arr.length - 1; | |
for (; end >= 0; end--) { | |
if (arr[end] !== '') break; | |
} | |
if (start > end) return []; | |
return arr.slice(start, end - start + 1); | |
} | |
var fromParts = trim(from.split('/')); | |
var toParts = trim(to.split('/')); | |
var length = Math.min(fromParts.length, toParts.length); | |
var samePartsLength = length; | |
for (var i = 0; i < length; i++) { | |
if (fromParts[i] !== toParts[i]) { | |
samePartsLength = i; | |
break; | |
} | |
} | |
var outputParts = []; | |
for (var i = samePartsLength; i < fromParts.length; i++) { | |
outputParts.push('..'); | |
} | |
outputParts = outputParts.concat(toParts.slice(samePartsLength)); | |
return outputParts.join('/'); | |
}; | |
})(require("__browserify_process")) | |
},{"__browserify_process":6}]},{},[1]) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment