nyc-bookstores/node_modules/filesystem-browserify/bundle.js

236 lines
56 KiB
JavaScript
Raw Normal View History

2013-05-27 20:45:59 +00:00
(function(){var require = function (file, cwd) {
var resolved = require.resolve(file, cwd || '/');
var mod = require.modules[resolved];
if (!mod) throw new Error(
'Failed to resolve module ' + file + ', tried ' + resolved
);
var cached = require.cache[resolved];
var res = cached? cached.exports : mod();
return res;
};
require.paths = [];
require.modules = {};
require.cache = {};
require.extensions = [".js",".coffee",".json"];
require._core = {
'assert': true,
'events': true,
'fs': true,
'path': true,
'vm': true
};
require.resolve = (function () {
return function (x, cwd) {
if (!cwd) cwd = '/';
if (require._core[x]) return x;
var path = require.modules.path();
cwd = path.resolve('/', cwd);
var y = cwd || '/';
if (x.match(/^(?:\.\.?\/|\/)/)) {
var m = loadAsFileSync(path.resolve(y, x))
|| loadAsDirectorySync(path.resolve(y, x));
if (m) return m;
}
var n = loadNodeModulesSync(x, y);
if (n) return n;
throw new Error("Cannot find module '" + x + "'");
function loadAsFileSync (x) {
x = path.normalize(x);
if (require.modules[x]) {
return x;
}
for (var i = 0; i < require.extensions.length; i++) {
var ext = require.extensions[i];
if (require.modules[x + ext]) return x + ext;
}
}
function loadAsDirectorySync (x) {
x = x.replace(/\/+$/, '');
var pkgfile = path.normalize(x + '/package.json');
if (require.modules[pkgfile]) {
var pkg = require.modules[pkgfile]();
var b = pkg.browserify;
if (typeof b === 'object' && b.main) {
var m = loadAsFileSync(path.resolve(x, b.main));
if (m) return m;
}
else if (typeof b === 'string') {
var m = loadAsFileSync(path.resolve(x, b));
if (m) return m;
}
else if (pkg.main) {
var m = loadAsFileSync(path.resolve(x, pkg.main));
if (m) return m;
}
}
return loadAsFileSync(x + '/index');
}
function loadNodeModulesSync (x, start) {
var dirs = nodeModulesPathsSync(start);
for (var i = 0; i < dirs.length; i++) {
var dir = dirs[i];
var m = loadAsFileSync(dir + '/' + x);
if (m) return m;
var n = loadAsDirectorySync(dir + '/' + x);
if (n) return n;
}
var m = loadAsFileSync(x);
if (m) return m;
}
function nodeModulesPathsSync (start) {
var parts;
if (start === '/') parts = [ '' ];
else parts = path.normalize(start).split('/');
var dirs = [];
for (var i = parts.length - 1; i >= 0; i--) {
if (parts[i] === 'node_modules') continue;
var dir = parts.slice(0, i + 1).join('/') + '/node_modules';
dirs.push(dir);
}
return dirs;
}
};
})();
require.alias = function (from, to) {
var path = require.modules.path();
var res = null;
try {
res = require.resolve(from + '/package.json', '/');
}
catch (err) {
res = require.resolve(from, '/');
}
var basedir = path.dirname(res);
var keys = (Object.keys || function (obj) {
var res = [];
for (var key in obj) res.push(key);
return res;
})(require.modules);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (key.slice(0, basedir.length + 1) === basedir + '/') {
var f = key.slice(basedir.length);
require.modules[to + f] = require.modules[basedir + f];
}
else if (key === basedir) {
require.modules[to] = require.modules[basedir];
}
}
};
(function () {
var process = {};
var global = typeof window !== 'undefined' ? window : {};
var definedProcess = false;
require.define = function (filename, fn) {
if (!definedProcess && require.modules.__browserify_process) {
process = require.modules.__browserify_process();
definedProcess = true;
}
var dirname = require._core[filename]
? ''
: require.modules.path().dirname(filename)
;
var require_ = function (file) {
var requiredModule = require(file, dirname);
var cached = require.cache[require.resolve(file, dirname)];
if (cached && cached.parent === null) {
cached.parent = module_;
}
return requiredModule;
};
require_.resolve = function (name) {
return require.resolve(name, dirname);
};
require_.modules = require.modules;
require_.define = require.define;
require_.cache = require.cache;
var module_ = {
id : filename,
filename: filename,
exports : {},
loaded : false,
parent: null
};
require.modules[filename] = function () {
require.cache[filename] = module_;
fn.call(
module_.exports,
require_,
module_,
module_.exports,
dirname,
filename,
process,
global
);
module_.loaded = true;
return module_.exports;
};
};
})();
require.define("path",Function(['require','module','exports','__dirname','__filename','process','global'],"function filter (xs, fn) {\n var res = [];\n for (var i = 0; i < xs.length; i++) {\n if (fn(xs[i], i, xs)) res.push(xs[i]);\n }\n return res;\n}\n\n// resolves . and .. elements in a path array with directory names there\n// must be no slashes, empty elements, or device names (c:\\) in the array\n// (so also no leading and trailing slashes - it does not distinguish\n// relative and absolute paths)\nfunction normalizeArray(parts, allowAboveRoot) {\n // if the path tries to go above the root, `up` ends up > 0\n var up = 0;\n for (var i = parts.length; i >= 0; i--) {\n var last = parts[i];\n if (last == '.') {\n parts.splice(i, 1);\n } else if (last === '..') {\n parts.splice(i, 1);\n up++;\n } else if (up) {\n parts.splice(i, 1);\n up--;\n }\n }\n\n // if the path is allowed to go above the root, restore leading ..s\n if (allowAboveRoot) {\n for (; up--; up) {\n parts.unshift('..');\n }\n }\n\n return parts;\n}\n\n// Regex to split a filename into [*, dir, basename, ext]\n// posix version\nvar splitPathRe = /^(.+\\/(?!$)|\\/)?((?:.+?)?(\\.[^.]*)?)$/;\n\n// path.resolve([from ...], to)\n// posix version\nexports.resolve = function() {\nvar resolvedPath = '',\n resolvedAbsolute = false;\n\nfor (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) {\n var path = (i >= 0)\n ? arguments[i]\n : process.cwd();\n\n // Skip empty and invalid entries\n if (typeof path !== 'string' || !path) {\n continue;\n }\n\n resolvedPath = path + '/' + resolvedPath;\n resolvedAbsolute = path.charAt(0) === '/';\n}\n\n// At this point the path should be resolved to a full absolute path, but\n// handle relative paths to be safe (might happen when process.cwd() fails)\n\n// Normalize the path\nresolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {\n return !!p;\n }), !resolvedAbsolute).join('/');\n\n return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';\n};\n\n// path.normalize(path)\n// posix version\nexports.normalize = function(path) {\nvar isAbsolute = path.charAt(0) === '/',\n trailingSlash = path.slice(-1) === '/';\n\n// Normalize the path\npath = normalizeArray(filter(path.split('/'), function(p) {\n return !!p;\n }), !isAbsolute).join('/');\n\n if (!path && !isAbsolute) {\n path = '.';\n }\n if (path && trailingSlash) {\n path += '/';\n }\n \n return (isAbsolute ? '/' : '') + path;\n};\n\n\n// posix version\nexports.join = function() {\n var paths = Array.prototype.slice.call(arguments, 0);\n return exports.normalize(filter(paths, function(p, index) {\n return p && typeof p === 'string';\n }).join('/'));\n};\n\n\nexports.dirname = function(path) {\n var dir = splitPathRe.exec(path)[1] || '';\n var isWindows = false;\n if (!dir) {\n // No dirname\n return '.';\n } else if (dir.length === 1 ||\n (isWindows && dir.length <= 3 && dir.charAt(1) === ':')) {\n // It is just a slash or a drive letter with a slash\n return dir;\n } else {\n // It is a full dirname, strip trailing slash\n return dir.substring(0, dir.length - 1);\n }\n};\n\n\nexports.basename = function(path, ext) {\n var f = splitPathRe.exec(path)[2] || '';\n // TODO: make this comparison case-insensitive on windows?\n if (ext && f.substr(-1 * ext.length) === ext) {\n f = f.substr(0, f.length - ext.length);\n }\n return f;\n};\n\n\nexports.extname = function(path) {\n return splitPathRe.exec(path)[3] || '';\n};\n\nexports.relative = function(from, to) {\n from = exports.resolve(from).substr(1);\n to = exports.resolve(to).substr(1);\n\n function trim(arr) {\n var start = 0;\n for (; start < arr.length; start++) {\n if (arr[start] !== '') break;\n }\n\n var end = arr.length - 1;\n for (; end >= 0; end--) {\n if (arr[end] !== '') break;\n }\n\n if (start > end) return [];\n return arr.slice(start, end - start + 1);\n }\n\n var fromParts = tri
));
require.define("__browserify_process",Function(['require','module','exports','__dirname','__filename','process','global'],"var process = module.exports = {};\n\nprocess.nextTick = (function () {\n var canSetImmediate = typeof window !== 'undefined'\n && window.setImmediate;\n var canPost = typeof window !== 'undefined'\n && window.postMessage && window.addEventListener\n ;\n\n if (canSetImmediate) {\n return function (f) { return window.setImmediate(f) };\n }\n\n if (canPost) {\n var queue = [];\n window.addEventListener('message', function (ev) {\n if (ev.source === window && ev.data === 'browserify-tick') {\n ev.stopPropagation();\n if (queue.length > 0) {\n var fn = queue.shift();\n fn();\n }\n }\n }, true);\n\n return function nextTick(fn) {\n queue.push(fn);\n window.postMessage('browserify-tick', '*');\n };\n }\n\n return function nextTick(fn) {\n setTimeout(fn, 0);\n };\n})();\n\nprocess.title = 'browser';\nprocess.browser = true;\nprocess.env = {};\nprocess.argv = [];\n\nprocess.binding = function (name) {\n if (name === 'evals') return (require)('vm')\n else throw new Error('No such module. (Possibly not yet loaded)')\n};\n\n(function () {\n var cwd = '/';\n var path;\n process.cwd = function () { return cwd };\n process.chdir = function (dir) {\n if (!path) path = require('path');\n cwd = path.resolve(dir, cwd);\n };\n})();\n\n//@ sourceURL=__browserify_process"
));
require.define("/index.js",Function(['require','module','exports','__dirname','__filename','process','global'],"const util = require('util');\nconst Stream = require('stream');\nconst DataStore = require('./datastore');\nconst fs = {};\nconst FILESYSTEM = new DataStore();\n\nfs.createWriteStream = function createWriteStream(path) {\n return new WriteStream(path);\n};\n\nfs.createReadStream = function createReadStream(path) {\n return new ReadStream(path);\n};\n\nfs.rename = FILESYSTEM.rename.bind(FILESYSTEM);\nfs.writeFile = FILESYSTEM.writeFile.bind(FILESYSTEM);\nfs.readFile = FILESYSTEM.writeFile.bind(FILESYSTEM);\nfs.readdir = FILESYSTEM.readdir.bind(FILESYSTEM);\nfs.unlink = FILESYSTEM.unlink.bind(FILESYSTEM);\n\nfunction WriteStream(path) {\n this._buffer = '';\n this.path = path;\n this.writable = true;\n this.bytesWritten = 0;\n};\nutil.inherits(WriteStream, Stream);\n\nWriteStream.prototype.write = function write(data) {\n this._buffer += data;\n this.bytesWritten += data.length;\n};\n\nWriteStream.prototype.end = function end() {\n FILESYSTEM.writeFile(this.path, this._buffer, function (err) {\n this.emit('close');\n }.bind(this));\n};\n\nfunction ReadStream(path) {\n this.readable = true;\n this.path = path;\n};\nutil.inherits(ReadStream, Stream);\n\nReadStream.prototype.pipe = function pipe(dest) {\n console.log('path', this.path);\n FILESYSTEM.readFile(this.path, function (err, dataObj) {\n dest.write(dataObj.data);\n });\n return dest;\n};\n\nmodule.exports = fs;\n//@ sourceURL=/index.js"
));
require.define("util",Function(['require','module','exports','__dirname','__filename','process','global'],"var events = require('events');\n\nexports.isArray = isArray;\nexports.isDate = function(obj){return Object.prototype.toString.call(obj) === '[object Date]'};\nexports.isRegExp = function(obj){return Object.prototype.toString.call(obj) === '[object RegExp]'};\n\n\nexports.print = function () {};\nexports.puts = function () {};\nexports.debug = function() {};\n\nexports.inspect = function(obj, showHidden, depth, colors) {\n var seen = [];\n\n var stylize = function(str, styleType) {\n // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics\n var styles =\n { 'bold' : [1, 22],\n 'italic' : [3, 23],\n 'underline' : [4, 24],\n 'inverse' : [7, 27],\n 'white' : [37, 39],\n 'grey' : [90, 39],\n 'black' : [30, 39],\n 'blue' : [34, 39],\n 'cyan' : [36, 39],\n 'green' : [32, 39],\n 'magenta' : [35, 39],\n 'red' : [31, 39],\n 'yellow' : [33, 39] };\n\n var style =\n { 'special': 'cyan',\n 'number': 'blue',\n 'boolean': 'yellow',\n 'undefined': 'grey',\n 'null': 'bold',\n 'string': 'green',\n 'date': 'magenta',\n // \"name\": intentionally not styling\n 'regexp': 'red' }[styleType];\n\n if (style) {\n return '\\033[' + styles[style][0] + 'm' + str +\n '\\033[' + styles[style][1] + 'm';\n } else {\n return str;\n }\n };\n if (! colors) {\n stylize = function(str, styleType) { return str; };\n }\n\n function format(value, recurseTimes) {\n // Provide a hook for user-specified inspect functions.\n // Check that value is an object with an inspect function on it\n if (value && typeof value.inspect === 'function' &&\n // Filter out the util module, it's inspect function is special\n value !== exports &&\n // Also filter out any prototype objects using the circular check.\n !(value.constructor && value.constructor.prototype === value)) {\n return value.inspect(recurseTimes);\n }\n\n // Primitive types cannot have properties\n switch (typeof value) {\n case 'undefined':\n return stylize('undefined', 'undefined');\n\n case 'string':\n var simple = '\\'' + JSON.stringify(value).replace(/^\"|\"$/g, '')\n .replace(/'/g, \"\\\\'\")\n .replace(/\\\\\"/g, '\"') + '\\'';\n return stylize(simple, 'string');\n\n case 'number':\n return stylize('' + value, 'number');\n\n case 'boolean':\n return stylize('' + value, 'boolean');\n }\n // For some reason typeof null is \"object\", so special case here.\n if (value === null) {\n return stylize('null', 'null');\n }\n\n // Look up the keys of the object.\n var visible_keys = Object_keys(value);\n var keys = showHidden ? Object_getOwnPropertyNames(value) : visible_keys;\n\n // Functions without properties can be shortcutted.\n if (typeof value === 'function' && keys.length === 0) {\n if (isRegExp(value)) {\n return stylize('' + value, 'regexp');\n } else {\n var name = value.name ? ': ' + value.name : '';\n return stylize('[Function' + name + ']', 'special');\n }\n }\n\n // Dates without properties can be shortcutted\n if (isDate(value) && keys.length === 0) {\n return stylize(value.toUTCString(), 'date');\n }\n\n var base, type, braces;\n // Determine the object type\n if (isArray(value)) {\n type = 'Array';\n braces = ['[', ']'];\n } else {\n type = 'Object';\n braces = ['{', '}'];\n }\n\n // Make functions say that they are functions\n if (typeof value === 'function') {\n var n = value.name ? ': ' + value.name : '';\n base = (isRegExp(value)) ? ' ' + value : ' [Function' + n + ']';\n } else {\n base = '';\n }\n\n
));
require.define("events",Function(['require','module','exports','__dirname','__filename','process','global'],"if (!process.EventEmitter) process.EventEmitter = function () {};\n\nvar EventEmitter = exports.EventEmitter = process.EventEmitter;\nvar isArray = typeof Array.isArray === 'function'\n ? Array.isArray\n : function (xs) {\n return Object.prototype.toString.call(xs) === '[object Array]'\n }\n;\nfunction indexOf (xs, x) {\n if (xs.indexOf) return xs.indexOf(x);\n for (var i = 0; i < xs.length; i++) {\n if (x === xs[i]) return i;\n }\n return -1;\n}\n\n// By default EventEmitters will print a warning if more than\n// 10 listeners are added to it. This is a useful default which\n// helps finding memory leaks.\n//\n// Obviously not all Emitters should be limited to 10. This function allows\n// that to be increased. Set to zero for unlimited.\nvar defaultMaxListeners = 10;\nEventEmitter.prototype.setMaxListeners = function(n) {\n if (!this._events) this._events = {};\n this._events.maxListeners = n;\n};\n\n\nEventEmitter.prototype.emit = function(type) {\n // If there is no 'error' event listener then throw.\n if (type === 'error') {\n if (!this._events || !this._events.error ||\n (isArray(this._events.error) && !this._events.error.length))\n {\n if (arguments[1] instanceof Error) {\n throw arguments[1]; // Unhandled 'error' event\n } else {\n throw new Error(\"Uncaught, unspecified 'error' event.\");\n }\n return false;\n }\n }\n\n if (!this._events) return false;\n var handler = this._events[type];\n if (!handler) return false;\n\n if (typeof handler == 'function') {\n switch (arguments.length) {\n // fast cases\n case 1:\n handler.call(this);\n break;\n case 2:\n handler.call(this, arguments[1]);\n break;\n case 3:\n handler.call(this, arguments[1], arguments[2]);\n break;\n // slower\n default:\n var args = Array.prototype.slice.call(arguments, 1);\n handler.apply(this, args);\n }\n return true;\n\n } else if (isArray(handler)) {\n var args = Array.prototype.slice.call(arguments, 1);\n\n var listeners = handler.slice();\n for (var i = 0, l = listeners.length; i < l; i++) {\n listeners[i].apply(this, args);\n }\n return true;\n\n } else {\n return false;\n }\n};\n\n// EventEmitter is defined in src/node_events.cc\n// EventEmitter.prototype.emit() is also defined there.\nEventEmitter.prototype.addListener = function(type, listener) {\n if ('function' !== typeof listener) {\n throw new Error('addListener only takes instances of Function');\n }\n\n if (!this._events) this._events = {};\n\n // To avoid recursion in the case that type == \"newListeners\"! Before\n // adding it to the listeners, first emit \"newListeners\".\n this.emit('newListener', type, listener);\n\n if (!this._events[type]) {\n // Optimize the case of one listener. Don't need the extra array object.\n this._events[type] = listener;\n } else if (isArray(this._events[type])) {\n\n // Check for listener leak\n if (!this._events[type].warned) {\n var m;\n if (this._events.maxListeners !== undefined) {\n m = this._events.maxListeners;\n } else {\n m = defaultMaxListeners;\n }\n\n if (m && m > 0 && this._events[type].length > m) {\n this._events[type].warned = true;\n console.error('(node) warning: possible EventEmitter memory ' +\n 'leak detected. %d listeners added. ' +\n 'Use emitter.setMaxListeners() to increase limit.',\n this._events[type].length);\n console.trace();\n }\n }\n\n // If we've already got an array, just append.\n this._events[type].push(listener);\n } else {\n // Adding the second element, need to change to array.\n this._events[type] = [this._events[type], listener];\n }\n\n return this;\n};\n\nEventEmitter.prototype.on = EventEmitter.prototype.addListener;\n
));
require.define("stream",Function(['require','module','exports','__dirname','__filename','process','global'],"var events = require('events');\nvar util = require('util');\n\nfunction Stream() {\n events.EventEmitter.call(this);\n}\nutil.inherits(Stream, events.EventEmitter);\nmodule.exports = Stream;\n// Backwards-compat with node 0.4.x\nStream.Stream = Stream;\n\nStream.prototype.pipe = function(dest, options) {\n var source = this;\n\n function ondata(chunk) {\n if (dest.writable) {\n if (false === dest.write(chunk) && source.pause) {\n source.pause();\n }\n }\n }\n\n source.on('data', ondata);\n\n function ondrain() {\n if (source.readable && source.resume) {\n source.resume();\n }\n }\n\n dest.on('drain', ondrain);\n\n // If the 'end' option is not supplied, dest.end() will be called when\n // source gets the 'end' or 'close' events. Only dest.end() once, and\n // only when all sources have ended.\n if (!dest._isStdio && (!options || options.end !== false)) {\n dest._pipeCount = dest._pipeCount || 0;\n dest._pipeCount++;\n\n source.on('end', onend);\n source.on('close', onclose);\n }\n\n var didOnEnd = false;\n function onend() {\n if (didOnEnd) return;\n didOnEnd = true;\n\n dest._pipeCount--;\n\n // remove the listeners\n cleanup();\n\n if (dest._pipeCount > 0) {\n // waiting for other incoming streams to end.\n return;\n }\n\n dest.end();\n }\n\n\n function onclose() {\n if (didOnEnd) return;\n didOnEnd = true;\n\n dest._pipeCount--;\n\n // remove the listeners\n cleanup();\n\n if (dest._pipeCount > 0) {\n // waiting for other incoming streams to end.\n return;\n }\n\n dest.destroy();\n }\n\n // don't leave dangling pipes when there are errors.\n function onerror(er) {\n cleanup();\n if (this.listeners('error').length === 0) {\n throw er; // Unhandled stream error in pipe.\n }\n }\n\n source.on('error', onerror);\n dest.on('error', onerror);\n\n // remove all the event listeners that were added.\n function cleanup() {\n source.removeListener('data', ondata);\n dest.removeListener('drain', ondrain);\n\n source.removeListener('end', onend);\n source.removeListener('close', onclose);\n\n source.removeListener('error', onerror);\n dest.removeListener('error', onerror);\n\n source.removeListener('end', cleanup);\n source.removeListener('close', cleanup);\n\n dest.removeListener('end', cleanup);\n dest.removeListener('close', cleanup);\n }\n\n source.on('end', cleanup);\n source.on('close', cleanup);\n\n dest.on('end', cleanup);\n dest.on('close', cleanup);\n\n dest.emit('pipe', source);\n\n // Allow for unix-like usage: A.pipe(B).pipe(C)\n return dest;\n};\n\n//@ sourceURL=stream"
));
require.define("/datastore.js",Function(['require','module','exports','__dirname','__filename','process','global'],"const util = require('util');\nconst IDBStore = require('idb-wrapper');\nconst EventEmitter = require('events').EventEmitter;\n\nfunction nothing() {}\n\nfunction DataStore(name) {\n this.ready = false;\n this.store = new IDBStore({\n storeName: 'PseudoFS',\n onStoreReady: function () {\n this.ready = true;\n this.emit('ready')\n this._flush();\n }.bind(this)\n });\n this.queue = [];\n};\nutil.inherits(DataStore, EventEmitter);\n\nDataStore.prototype.writeFile = function writeFile(path, data, callback) {\n callback = callback || nothing;\n if (!this.ready)\n return this._enqueue({\n type: 'write',\n args: [path, data, callback],\n });\n return this.__write(path, data, callback);\n};\n\nDataStore.prototype.readFile = function readFile(path, callback) {\n callback = callback || nothing;\n if (!this.ready)\n return this._enqueue({\n type: 'read',\n args: [path, callback],\n });\n return this.__read(path, callback);\n};\n\nDataStore.prototype.readdir = function readdir(path, callback) {\n if (!this.ready)\n return this._enqueue({\n type: 'readdir',\n args: [path, callback],\n });\n return this.__readdir(path, callback);\n};\n\nDataStore.prototype.unlink = function unlink(path, callback) {\n callback = callback || nothing;\n if (!this.ready)\n return this._enqueue({\n type: 'unlink',\n args: [path, callback],\n });\n return this.__unlink(path, callback);\n};\n\nDataStore.prototype.rename = function rename(path, newPath, callback) {\n callback = callback || nothing;\n if (!this.ready)\n return this._enqueue({\n type: 'rename',\n args: [path, newPath, callback],\n });\n return this.__rename(path, newPath, callback);\n};\n\nDataStore.prototype._enqueue = function enqueue(actionPlan) {\n console.log('queuing', actionPlan.type);\n this.queue.push(actionPlan);\n if (this.ready)\n this._flush();\n};\n\nDataStore.prototype._flush = function flush() {\n var action;\n while ((action = this.queue.shift())) {\n var method = this['__' + action.type];\n method.apply(this, action.args);\n }\n};\n\nDataStore.prototype.__write = function write(path, data, callback) {\n const dataObj = {\n id: path,\n data: data,\n lastModified: Date.now(),\n };\n this.store.put(dataObj, function success() {\n callback(null);\n }, function error(err) {\n callback(err);\n });\n};\n\nDataStore.prototype.__read = function read(path, callback) {\n this.store.get(path, function success(data) {\n callback(null, data);\n }, function error(err) {\n callback(err);\n });\n};\n\nDataStore.prototype.__readdir = function read(path, callback) {\n this.store.getAll(function success(data) {\n callback(null, data.map(extract('id')));\n }, function error(err) {\n callback(err);\n });\n};\n\nDataStore.prototype.__unlink = function unlink(path, callback) {\n this.store.remove(path, function success() {\n callback();\n }, function error(err) {\n callback(err);\n });\n};\n\nDataStore.prototype.__rename = function rename(path, newPath, callback) {\n console.log('renmaing');\n this.readFile(path, function (err, data) {\n if (err) return callback(err);\n this.writeFile(newPath, data, function (err) {\n if (err) return callback(err);\n this.unlink(path, function (err) {\n return callback(err);\n }.bind(this));\n }.bind(this));\n }.bind(this));\n};\n\nfunction extract(field) {\n return function (doc) {\n return doc[field];\n }\n}\n\nmodule.exports = DataStore;\n\n//@ sourceURL=/datastore.js"
));
require.define("/node_modules/idb-wrapper/package.json",Function(['require','module','exports','__dirname','__filename','process','global'],"module.exports = {\"main\":\"idbstore\"}\n//@ sourceURL=/node_modules/idb-wrapper/package.json"
));
require.define("/node_modules/idb-wrapper/idbstore.js",Function(['require','module','exports','__dirname','__filename','process','global'],"/*\n * IDBWrapper - A cross-browser wrapper for IndexedDB\n * Copyright (c) 2011 - 2013 Jens Arps\n * http://jensarps.de/\n *\n * Licensed under the MIT (X11) license\n */\n\n\"use strict\";\n\n(function (name, definition, global) {\n if (typeof define === 'function') {\n define(definition);\n } else if (typeof module !== 'undefined' && module.exports) {\n module.exports = definition();\n } else {\n global[name] = definition();\n }\n})('IDBStore', function () {\n\n var IDBStore;\n\n var defaults = {\n storeName: 'Store',\n dbVersion: 1,\n keyPath: 'id',\n autoIncrement: true,\n onStoreReady: function () {\n },\n onError: function(error){\n throw error;\n },\n indexes: []\n };\n\n IDBStore = function (kwArgs, onStoreReady) {\n\n for(var key in defaults){\n this[key] = typeof kwArgs[key] != 'undefined' ? kwArgs[key] : defaults[key];\n }\n\n this.dbName = 'IDBWrapper-' + this.storeName;\n this.dbVersion = parseInt(this.dbVersion, 10);\n\n onStoreReady && (this.onStoreReady = onStoreReady);\n\n this.idb = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;\n this.keyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.mozIDBKeyRange;\n\n this.consts = {\n 'READ_ONLY': 'readonly',\n 'READ_WRITE': 'readwrite',\n 'VERSION_CHANGE': 'versionchange',\n 'NEXT': 'next',\n 'NEXT_NO_DUPLICATE': 'nextunique',\n 'PREV': 'prev',\n 'PREV_NO_DUPLICATE': 'prevunique'\n };\n\n this.openDB();\n };\n\n IDBStore.prototype = {\n\n version: '0.3.1',\n\n db: null,\n\n dbName: null,\n\n dbVersion: null,\n\n store: null,\n\n storeName: null,\n\n keyPath: null,\n\n autoIncrement: null,\n\n indexes: null,\n\n features: null,\n\n onStoreReady: null,\n\n onError: null,\n\n _insertIdCount: 0,\n\n openDB: function () {\n\n var features = this.features = {};\n features.hasAutoIncrement = !window.mozIndexedDB; // TODO: Still, really?\n\n var openRequest = this.idb.open(this.dbName, this.dbVersion);\n var preventSuccessCallback = false;\n\n openRequest.onerror = function (error) {\n\n var gotVersionErr = false;\n if ('error' in error.target) {\n gotVersionErr = error.target.error.name == \"VersionError\";\n } else if ('errorCode' in error.target) {\n gotVersionErr = error.target.errorCode == 12; // TODO: Use const\n }\n\n if (gotVersionErr) {\n this.onError(new Error('The version number provided is lower than the existing one.'));\n } else {\n this.onError(error);\n }\n }.bind(this);\n\n openRequest.onsuccess = function (event) {\n\n if (preventSuccessCallback) {\n return;\n }\n\n if(this.db){\n this.onStoreReady();\n return;\n }\n\n this.db = event.target.result;\n\n if(typeof this.db.version == 'string'){\n this.onError(new Error('The IndexedDB implementation in this browser is outdated. Please upgrade your browser.'));\n return;\n }\n\n if(!this.db.objectStoreNames.contains(this.storeName)){\n // We should never ever get here.\n // Lets notify the user anyway.\n this.onError(new Error('Something is wrong with the IndexedDB implementation in this browser. Please upgrade your browser.'));\n return;\n }\n\n var emptyTransaction = this.db.transaction([this.storeName], this.consts.READ_ONLY);\n this.store = emptyTransaction.objectStore(this.storeName);\n\n // check indexes\n this.indexes.forEach(function(indexData){\n var indexName = indexData.name;\n\n if(!indexName){\n preventSuccessCallback = true;\n this.onError(new Error('Cannot create index: No index name given
));
require.define("/node_modules/fileliststream/package.json",Function(['require','module','exports','__dirname','__filename','process','global'],"module.exports = {\"main\":\"index.js\"}\n//@ sourceURL=/node_modules/fileliststream/package.json"
));
require.define("/node_modules/fileliststream/index.js",Function(['require','module','exports','__dirname','__filename','process','global'],"const Stream = require('stream');\n\nfunction FileListStream(fileList, options) {\n if (!(this instanceof FileListStream))\n return new FileListStream(fileList, options);\n this.files = [].slice.call(fileList).map(function (file) {\n return new FileStream(file, options);\n });\n this.files.forEach(function (file, idx) {\n this[idx] = file;\n }, this);\n};\n\nfunction FileStream(file, options) {\n if (!(this instanceof FileStream))\n return new FileStream(file, options);\n options = options || {};\n options.output = options.output || 'binary';\n this.options = options;\n this._file = file;\n this.readable = true;\n ['name',\n 'size',\n 'type',\n 'lastModifiedDate'].forEach(function (thing) {\n this[thing] = file[thing];\n }, this);\n};\n\nFileStream.prototype.pipe = function pipe(dest, options) {\n const outputType = this.options.output;\n const reader = new FileReader();\n reader.onload = function loaded(event) {\n dest.write(event.target.result);\n if (dest !== console && (!options || options.end !== false)) {\n if (dest.end)\n dest.end();\n if (dest.close)\n dest.close();\n }\n };\n\n if (outputType === 'binary')\n reader.readAsBinaryString(this._file);\n else if (outputType === 'dataurl')\n reader.readAsDataURL(this._file);\n else if (outputType === 'arraybuffer')\n reader.readAsArrayBuffer(this._file);\n else if (outputType === 'text')\n reader.readAsText(this._file);\n return dest;\n};\n\nmodule.exports = FileListStream;\n//@ sourceURL=/node_modules/fileliststream/index.js"
));
require.define("/example.js",Function(['require','module','exports','__dirname','__filename','process','global'],"const fs = require('./');\nconst FileListStream = require('fileliststream');\n\nconst logger = {\n write: function write(data) {\n const textAreaElem = document.getElementById('output');\n textAreaElem.innerHTML = data;\n }\n}\nconst body = document.body;\nfunction noop(name) {\n return function (event) {\n event.preventDefault();\n event.stopPropagation();\n return false;\n }\n};\n\nbody.addEventListener('dragenter', noop('dragEnter'));\nbody.addEventListener('dragleave', noop('dragLeave'));\nbody.addEventListener('dragexit', noop('dragExit'));\nbody.addEventListener('dragover', noop('dragOver'));\nbody.addEventListener('drop', function (event) {\n event.stopPropagation();\n event.preventDefault();\n\n const fileListStream = FileListStream(event.dataTransfer.files);\n const file = fileListStream[0];\n\n const writestream = fs.createWriteStream(file.name);\n file.pipe(writestream).on('close', function () {\n addLinkItem(writestream.path);\n });\n\n return false;\n});\n\nfunction addLinkItem(path) {\n const ol = document.getElementById('fileList');\n const liElem = document.createElement('li');\n const aElem = document.createElement('a');\n aElem.innerHTML = path;\n\n aElem.addEventListener('click', function () {\n const readstream = fs.createReadStream(path);\n readstream.pipe(logger);\n event.preventDefault();\n return false;\n }, false);\n\n liElem.appendChild(aElem);\n ol.appendChild(liElem);\n}\n\n(function () {\n fs.readdir('.', function (err, files) {\n files.map(addLinkItem);\n });\n})();\n\nwindow.fs = fs;\n//@ sourceURL=/example.js"
));
require("/example.js");
})();