From 848eb734b569b68154751409d3e1eb7daa1804ee Mon Sep 17 00:00:00 2001 From: Barry Tulchinsky Date: Thu, 19 Dec 2013 09:05:33 -0500 Subject: [PATCH 01/11] start of setxattr and getxattr implementation --- src/fs.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/fs.js b/src/fs.js index d5ad38d..61bc0ac 100644 --- a/src/fs.js +++ b/src/fs.js @@ -1531,14 +1531,24 @@ define(function(require) { }); } - function _getxattr(path, name, callback) { - // TODO - // if(!nullCheck(path, callback)) return; + function _getxattr(context, path, name, callback) { + if(!nullCheck(path, callback)) return; + } - function _setxattr(path, name, value, callback) { - // TODO - // if(!nullCheck(path, callback)) return; + function _setxattr(context, path, name, value, callback) { + if(!nullCheck(path, callback)) return; + + function check_result (error) { + if (error) { + callback(error); + } + else { + callback(null); + } + }; + + setxattr_file (context, path, name, value, check_result); } function _lseek(fs, context, fd, offset, whence, callback) { From 5e61be5668821b1e26a19b26321fb48062230e4b Mon Sep 17 00:00:00 2001 From: Barry Tulchinsky Date: Fri, 20 Dec 2013 03:34:05 -0500 Subject: [PATCH 02/11] rebased --- src/constants.js | 5 +++++ src/error.js | 10 +++++++++- src/fs.js | 39 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/constants.js b/src/constants.js index 5afb0a1..a8d8880 100644 --- a/src/constants.js +++ b/src/constants.js @@ -6,6 +6,8 @@ define(function(require) { var O_EXCLUSIVE = 'EXCLUSIVE'; var O_TRUNCATE = 'TRUNCATE'; var O_APPEND = 'APPEND'; + var XATTR_CREATE = 'CREATE'; + var XATTR_REPLACE = 'REPLACE'; return { FILE_SYSTEM_NAME: 'local', @@ -53,6 +55,9 @@ define(function(require) { 'ax+': [O_WRITE, O_READ, O_CREATE, O_EXCLUSIVE, O_APPEND] }, + XATTR_CREATE: XATTR_CREATE, + XATTR_REPLACE: XATTR_REPLACE, + FS_READY: 'READY', FS_PENDING: 'PENDING', FS_ERROR: 'ERROR', diff --git a/src/error.js b/src/error.js index 928b806..686fbf3 100644 --- a/src/error.js +++ b/src/error.js @@ -105,6 +105,13 @@ define(function(require) { EFileSystemError.prototype.name = "EFileSystemError"; EFileSystemError.prototype.constructor = EFileSystemError; + function ENoAttr(message) { + this.message = message || ''; + } + ENoAttr.prototype = new Error(); + ENoAttr.prototype.name = 'ENoAttr'; + ENoAttr.prototype.constructor = ENoAttr; + return { EExists: EExists, EIsDirectory: EIsDirectory, @@ -118,7 +125,8 @@ define(function(require) { EInvalid: EInvalid, EIO: EIO, ELoop: ELoop, - EFileSystemError: EFileSystemError + EFileSystemError: EFileSystemError, + ENoAttr: ENoAttr }; }); diff --git a/src/fs.js b/src/fs.js index 61bc0ac..6bccd04 100644 --- a/src/fs.js +++ b/src/fs.js @@ -47,6 +47,8 @@ define(function(require) { var O_TRUNCATE = require('src/constants').O_TRUNCATE; var O_APPEND = require('src/constants').O_APPEND; var O_FLAGS = require('src/constants').O_FLAGS; + var XATTR_CREATE = require('src/constants').XATTR_CREATE; + var XATTR_REPLACE = require('src/constants').XATTR_REPLACE; var providers = require('src/providers/providers'); var adapters = require('src/adapters/adapters'); @@ -1118,6 +1120,39 @@ define(function(require) { } } + function setxattr_file (context, path, name, value, flag, callback) { + path = normalize(path); + + function set_xattr (error, node) { + if (flag == XATTR_CREATE && node[name]) { + callback(new EExists('attribute already exists')); + } + else if (flag == XATTR_REPLACE && !node[name]) { + callback(new ENoAttr('attribute does not exist')); + } + else { + node.xattr[name] = value; + context.put(node.id, node, callback); + } + } + + if (typeof name != 'string') { + callback(new EInvalid('attribute name must be a string')); + } + else if (!name) { + callback(new EInvalid('attribute name cannot be an empty string')); + } + else if (!value) { + callback(new EInvalid('value cannot be empty')); + } + else if (flag && flag != XATTR_CREATE && flag != XATTR_REPLACE) { + callback(new EInvalid('invalid flag, must be null, XATTR_CREATE or XATTR_REPLACE')); + } + else { + find_node (context, path, set_xattr); + } + } + function validate_flags(flags) { if(!_(O_FLAGS).has(flags)) { return null; @@ -1536,7 +1571,7 @@ define(function(require) { } - function _setxattr(context, path, name, value, callback) { + function _setxattr(context, path, name, value, flag, callback) { if(!nullCheck(path, callback)) return; function check_result (error) { @@ -1548,7 +1583,7 @@ define(function(require) { } }; - setxattr_file (context, path, name, value, check_result); + setxattr_file (context, path, name, value, flags, check_result); } function _lseek(fs, context, fd, offset, whence, callback) { From a83ccf6154b2dbb1e2f7fb92e4fd8b6e2be79610 Mon Sep 17 00:00:00 2001 From: Barry Tulchinsky Date: Fri, 20 Dec 2013 04:36:25 -0500 Subject: [PATCH 03/11] implementation of getxattr --- src/fs.js | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/fs.js b/src/fs.js index 6bccd04..2476861 100644 --- a/src/fs.js +++ b/src/fs.js @@ -1124,10 +1124,13 @@ define(function(require) { path = normalize(path); function set_xattr (error, node) { - if (flag == XATTR_CREATE && node[name]) { + if (error) { + callback (error); + } + else if (flag === XATTR_CREATE && node[name]) { callback(new EExists('attribute already exists')); } - else if (flag == XATTR_REPLACE && !node[name]) { + else if (flag === XATTR_REPLACE && !node[name]) { callback(new ENoAttr('attribute does not exist')); } else { @@ -1145,7 +1148,7 @@ define(function(require) { else if (!value) { callback(new EInvalid('value cannot be empty')); } - else if (flag && flag != XATTR_CREATE && flag != XATTR_REPLACE) { + else if (!!flag && flag !== XATTR_CREATE && flag !== XATTR_REPLACE) { callback(new EInvalid('invalid flag, must be null, XATTR_CREATE or XATTR_REPLACE')); } else { @@ -1153,6 +1156,32 @@ define(function(require) { } } + function getxattr_file (context, path, name, callback) { + path = normalize(path); + + function get_xattr(error, node) { + if (error) { + callback (error); + } + else if (!node.xattr[name]) { + callback(new ENoAttr('attribute does not exist')); + } + else { + callback(null, node.xattr[name]); + } + } + + if (typeof name != 'string') { + callback(new EInvalid('attribute name must be a string')); + } + else if (!name) { + callback(new EInvalid('attribute name cannot be an empty string')); + } + else { + find_node(context, path, get_xattr); + } + } + function validate_flags(flags) { if(!_(O_FLAGS).has(flags)) { return null; From 5d022c3ca3cd21237587e668379eb7fe2c633920 Mon Sep 17 00:00:00 2001 From: Barry Tulchinsky Date: Fri, 20 Dec 2013 11:50:59 -0500 Subject: [PATCH 04/11] started spec tests and exposed to FileSystem prototype --- src/fs.js | 27 ++++++++++++++++++++++++++- tests/spec/fs.xattr.spec.js | 21 +++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/spec/fs.xattr.spec.js diff --git a/src/fs.js b/src/fs.js index 2476861..b820a8d 100644 --- a/src/fs.js +++ b/src/fs.js @@ -2076,7 +2076,32 @@ define(function(require) { } ); }; - + FileSystem.prototype.setxattr = function (path, name, value, flag, callback) { + callback = maybeCallback(arguments[arguments.length - 1]); + var fs = this; + var error = fs.queueOrRun( + function () { + var context = fs.provider.getReadWriteContext(); + _setxattr(context, path, name, value, flag, callback); + } + ); + if (error) { + callback(error); + } + }; + FileSystem.prototype.getxattr = function (path, name, callback) { + callback = maybeCallback(callback); + var fs = this; + var error = fs.queueOrRun( + function () { + var context = fs.provider.getReadWriteContext(); + _getxattr(context, path, name, callback); + } + ); + if (error) { + callback(error); + } + }; return FileSystem; }); diff --git a/tests/spec/fs.xattr.spec.js b/tests/spec/fs.xattr.spec.js new file mode 100644 index 0000000..a15b57f --- /dev/null +++ b/tests/spec/fs.xattr.spec.js @@ -0,0 +1,21 @@ +define(["IDBFS"], function(IDBFS) { + + describe('fs.utimes', function() { + beforeEach(function() { + this.db_name = mk_db_name(); + this.fs = new IDBFS.FileSystem({ + name: this.db_name, + flags: 'FORMAT' + }); + }); + + afterEach(function() { + indexedDB.deleteDatabase(this.db_name); + delete this.fs; + }); + }); + + it('should be a function', function () { + expect(typeof this.setxattr).toEqual('function'); + }); +} \ No newline at end of file From 37d998fb5552c49f801eb4b357a01ffa6326c3f9 Mon Sep 17 00:00:00 2001 From: Barry Tulchinsky Date: Fri, 20 Dec 2013 19:55:43 -0500 Subject: [PATCH 05/11] work on getxattr --- src/fs.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/fs.js b/src/fs.js index b820a8d..6b3ccc4 100644 --- a/src/fs.js +++ b/src/fs.js @@ -1598,6 +1598,16 @@ define(function(require) { function _getxattr(context, path, name, callback) { if(!nullCheck(path, callback)) return; + function fetch_value(error, value) { + if (error) { + callback(error); + } + else { + callback(null, value); + } + } + + getxattr_file(context, path, name, fetch_value); } function _setxattr(context, path, name, value, flag, callback) { From 55c08e6f085de46dde5034f17f7c7a329f59bf58 Mon Sep 17 00:00:00 2001 From: Barry Tulchinsky Date: Sat, 21 Dec 2013 16:30:40 -0500 Subject: [PATCH 06/11] added more tests and added spec file to test manifest --- src/fs.js | 20 ++-- tests/spec/fs.xattr.spec.js | 209 +++++++++++++++++++++++++++++++++++- tests/test-manifest.js | 1 + 3 files changed, 217 insertions(+), 13 deletions(-) diff --git a/src/fs.js b/src/fs.js index 6b3ccc4..7715842 100644 --- a/src/fs.js +++ b/src/fs.js @@ -27,6 +27,7 @@ define(function(require) { var EIO = require('src/error').EIO; var ELoop = require('src/error').ELoop; var EFileSystemError = require('src/error').EFileSystemError; + var ENoAttr = require('src/error').ENoAttr; var FILE_SYSTEM_NAME = require('src/constants').FILE_SYSTEM_NAME; var FS_FORMAT = require('src/constants').FS_FORMAT; @@ -1127,14 +1128,14 @@ define(function(require) { if (error) { callback (error); } - else if (flag === XATTR_CREATE && node[name]) { + else if (flag === XATTR_CREATE && node.xattrs[name]) { callback(new EExists('attribute already exists')); } - else if (flag === XATTR_REPLACE && !node[name]) { + else if (flag === XATTR_REPLACE && !node.xattrs[name]) { callback(new ENoAttr('attribute does not exist')); } else { - node.xattr[name] = value; + node.xattrs[name] = value; context.put(node.id, node, callback); } } @@ -1163,11 +1164,11 @@ define(function(require) { if (error) { callback (error); } - else if (!node.xattr[name]) { + else if (!node.xattrs[name]) { callback(new ENoAttr('attribute does not exist')); } else { - callback(null, node.xattr[name]); + callback(null, node.xattrs[name]); } } @@ -1622,7 +1623,7 @@ define(function(require) { } }; - setxattr_file (context, path, name, value, flags, check_result); + setxattr_file(context, path, name, value, flag, check_result); } function _lseek(fs, context, fd, offset, whence, callback) { @@ -2087,14 +2088,16 @@ define(function(require) { ); }; FileSystem.prototype.setxattr = function (path, name, value, flag, callback) { - callback = maybeCallback(arguments[arguments.length - 1]); + var callback = maybeCallback(arguments[arguments.length - 1]); + var _flag = (typeof flag != 'function') ? flag : null; var fs = this; var error = fs.queueOrRun( function () { var context = fs.provider.getReadWriteContext(); - _setxattr(context, path, name, value, flag, callback); + _setxattr(context, path, name, value, _flag, callback); } ); + if (error) { callback(error); } @@ -2108,6 +2111,7 @@ define(function(require) { _getxattr(context, path, name, callback); } ); + if (error) { callback(error); } diff --git a/tests/spec/fs.xattr.spec.js b/tests/spec/fs.xattr.spec.js index a15b57f..2acf792 100644 --- a/tests/spec/fs.xattr.spec.js +++ b/tests/spec/fs.xattr.spec.js @@ -1,6 +1,6 @@ define(["IDBFS"], function(IDBFS) { - describe('fs.utimes', function() { + describe('fs.xattr', function() { beforeEach(function() { this.db_name = mk_db_name(); this.fs = new IDBFS.FileSystem({ @@ -13,9 +13,208 @@ define(["IDBFS"], function(IDBFS) { indexedDB.deleteDatabase(this.db_name); delete this.fs; }); - }); - it('should be a function', function () { - expect(typeof this.setxattr).toEqual('function'); + it('should be a function', function () { + expect(typeof this.fs.setxattr).toEqual('function'); + expect(typeof this.fs.getxattr).toEqual('function'); + }); + + it('should error when setting with a name that is not a string', function () { + var complete = false; + var _error; + var that = this; + + that.fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + that.fs.setxattr('/testfile', 89, 'testvalue', function (error) { + _error = error; + complete = true; + }); + }); + + waitsFor(function () { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function () { + expect(_error).toBeDefined(); + expect(_error.name).toEqual('EInvalid'); + }); + }); + + it('should error when setting with a name that is null', function () { + var complete = false; + var _error; + var that = this; + + that.fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + that.fs.setxattr('/testfile', null, 'testvalue', function (error) { + _error = error; + complete = true; + }); + }); + + waitsFor(function () { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function () { + expect(_error).toBeDefined(); + expect(_error.name).toEqual('EInvalid'); + }); + }); + + it('should error when setting with a falsy value', function () { + var complete = false; + var _error; + var that = this; + + that.fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + that.fs.setxattr('/testfile', 'test', '', function (error) { + _error = error; + complete = true; + }); + }); + + waitsFor(function () { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function () { + expect(_error).toBeDefined(); + expect(_error.name).toEqual('EInvalid'); + }); + }); + + it('should error when setting with an invalid flag', function () { + var complete = false; + var _error; + var that = this; + + that.fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + that.fs.setxattr('/testfile', 'test', 'value', 'InvalidFlag', function (error) { + _error = error; + complete = true; + }); + }); + + waitsFor(function () { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function () { + expect(_error).toBeDefined(); + expect(_error.name).toEqual('EInvalid'); + }); + }); + + it('should error when when setting an extended attribute which exists with XATTR_CREATE flag', function (error) { + var complete = false; + var _error; + var that = this; + + that.fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + that.fs.setxattr('/testfile', 'test', 'value', function (error) { + if (error) throw error; + + that.fs.setxattr('/testfile', 'test', 'othervalue', 'CREATE', function (error) { + _error = error; + complete = true; + }); + }); + }); + + waitsFor(function () { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function () { + expect(_error).toBeDefined(); + expect(_error.name).toEqual('EExists'); + }); + }); + + it('should error when setting an extended attribute which does not exist with XATTR_REPLACE flag', function (error) { + var complete = false; + var _error; + var that = this; + + that.fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + that.fs.setxattr('/testfile', 'test', 'value', 'REPLACE', function (error) { + _error = error; + complete = true; + }); + }); + + waitsFor(function () { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function () { + expect(_error).toBeDefined(); + expect(_error.name).toEqual('ENoAttr'); + }); + }); + + it ('should error when getting an attribute with a falsy name', function (error) { + var complete = false; + var _error; + var that = this; + + that.fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + that.fs.getxattr('/testfile', '', function (error, value) { + _error = error; + complete = true; + }); + }); + + waitsFor(function () { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function () { + expect(_error).toBeDefined(); + expect(_error.name).toEqual('EInvalid'); + }); + }); + + it('should error when getting an attribute when a name is not a string', function (error) { + var complete = false; + var _error; + // var that = this; + + var fs = this.fs; + + fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + fs.getxattr('/testfile', 89, function (error, value) { + _error = error; + complete = true; + }); + }); + + waitsFor(function () { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function () { + expect(_error).toBeDefined(); + expect(_error.name).toEqual('EInvalid'); + }); + }); }); -} \ No newline at end of file +}); \ No newline at end of file diff --git a/tests/test-manifest.js b/tests/test-manifest.js index 124f36e..0e93836 100644 --- a/tests/test-manifest.js +++ b/tests/test-manifest.js @@ -28,6 +28,7 @@ define([ "spec/fs.readlink.spec", "spec/fs.truncate.spec", "spec/fs.utimes.spec", + "spec/fs.xattr.spec", "spec/path-resolution.spec", // IDBFS.FileSystem.providers.* From 7ae907cd5b6735d0b7b72b3d3ce405190ec5dc32 Mon Sep 17 00:00:00 2001 From: Barry Tulchinsky Date: Sun, 22 Dec 2013 20:58:00 -0500 Subject: [PATCH 07/11] changed behaviour to allow falsy values (ie. empty string), added more test cases and modified README.md --- README.md | 24 +++ src/fs.js | 166 +++++++++++++++++++-- tests/spec/fs.xattr.spec.js | 290 ++++++++++++++++++++++++++++++++++-- 3 files changed, 460 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 994d41e..7354faa 100644 --- a/README.md +++ b/README.md @@ -344,3 +344,27 @@ Asynchronous utimes(3). Callback gets no additional arguments. #### fs.futimes(fd, atime, mtime, callback) Asynchronous futimes(3). Callback gets no additional arguments. + +#### fs.setxattr(path, name, value, [flag], callback) + +Asynchronous setxattr(2). Sets an extended attribute of a file or directory. + +The optional flag parameter can be set to the following: + XATTR_CREATE: ensures that the extended attribute with the given name will be new and not previously set. If an attribute with the given name already exists, it will return EExists error to the callback. + XATTR_REPLACE: ensures that an extended attribute with the given name already exists. If an attribute with the given name does not exist, it will return an ENoAttr error to the callback. + +Callback gets no additional arguments. + +#### fs.getxattr(path, name, callback) + +Asynchronous getxattr(2). Gets an extended attribute value for a file or directory. + +Callback gets `(error, value)`, where value is the value for the extended attribute. + +#### fs.fsetxattr(fd, name, value, [flag], callback) + +Asynchronous fsetxattr(2). See `fs.setxattr` for flag options. Callback gets no additional arguments. + +#### fs.fgetxattr(fs, name, callback) + +Asynchronous fgetxattr(2). Callback gets `(error, value)`, See `fs.getxattr`. \ No newline at end of file diff --git a/src/fs.js b/src/fs.js index 7715842..95afaa5 100644 --- a/src/fs.js +++ b/src/fs.js @@ -1123,15 +1123,18 @@ define(function(require) { function setxattr_file (context, path, name, value, flag, callback) { path = normalize(path); + var undefined; function set_xattr (error, node) { + var xattr = (node ? node.xattrs[name] : null); + if (error) { callback (error); } - else if (flag === XATTR_CREATE && node.xattrs[name]) { + else if (flag === XATTR_CREATE && (xattr != null || xattr != undefined)) { callback(new EExists('attribute already exists')); } - else if (flag === XATTR_REPLACE && !node.xattrs[name]) { + else if (flag === XATTR_REPLACE && (xattr == null || xattr == undefined)) { callback(new ENoAttr('attribute does not exist')); } else { @@ -1146,10 +1149,11 @@ define(function(require) { else if (!name) { callback(new EInvalid('attribute name cannot be an empty string')); } - else if (!value) { - callback(new EInvalid('value cannot be empty')); + else if (value == null || value == undefined) { + callback(new EInvalid('value cannot be null or undefined')); } - else if (!!flag && flag !== XATTR_CREATE && flag !== XATTR_REPLACE) { + else if ((flag != null || flag != undefined) && + flag !== XATTR_CREATE && flag !== XATTR_REPLACE) { callback(new EInvalid('invalid flag, must be null, XATTR_CREATE or XATTR_REPLACE')); } else { @@ -1157,14 +1161,56 @@ define(function(require) { } } + function fsetxattr_file (context, ofd, name, value, flag, callback) { + var undefined; + + function set_xattr (error, node) { + var xattr = (node ? node.xattrs[name] : null); + + if (error) { + callback(error); + } + else if (flag === XATTR_CREATE && (xattr != null || xattr != undefined)) { + callback(new EExists('attribute already exists')); + } + else if (flag === XATTR_REPLACE && (xattr == null || xattr == undefined)) { + callback(new ENoAttr('attribute does not exist')); + } + else { + node.xattrs[name] = value; + context.put(node.id, node, callback); + } + } + + if (typeof name != 'string') { + callback(new EInvalid('attribute name must be a string')); + } + else if (!name) { + callback(new EInvalid('attribute name cannot be an empty string')); + } + else if (value == null || value == undefined) { + callback(new EInvalid('value cannot be empty')); + } + else if ((flag != null || flag != undefined) && + flag !== XATTR_CREATE && flag !== XATTR_REPLACE) { + callback(new EInvalid('invalid flag, must be null, XATTR_CREATE or XATTR_REPLACE')); + } + else { + context.get(ofd.id, set_xattr); + } + } + function getxattr_file (context, path, name, callback) { path = normalize(path); + var undefined; function get_xattr(error, node) { + var xattr = (node ? node.xattrs[name] : null); + if (error) { callback (error); } - else if (!node.xattrs[name]) { + else if (xattr == null || xattr == undefined) { callback(new ENoAttr('attribute does not exist')); } else { @@ -1183,6 +1229,34 @@ define(function(require) { } } + function fgetxattr_file (context, ofd, name, callback) { + var undefined; + + function get_xattr (error, node) { + var xattr = (node ? node.xattrs[name] : null); + + if (error) { + callback(error); + } + else if (xattr == null || xattr == undefined) { + callback(new ENoAttr('attribute does not exist')); + } + else { + callback(null, node.xattrs[name]); + } + } + + if (typeof name != 'string') { + callback(new EInvalid('attribute name must be a string')); + } + else if (!name) { + callback(new EInvalid('attribute name cannot be an empty string')); + } + else { + context.get(ofd.id, get_xattr); + } + } + function validate_flags(flags) { if(!_(O_FLAGS).has(flags)) { return null; @@ -1596,10 +1670,10 @@ define(function(require) { }); } - function _getxattr(context, path, name, callback) { - if(!nullCheck(path, callback)) return; + function _getxattr (context, path, name, callback) { + if (!nullCheck(path, callback)) return; - function fetch_value(error, value) { + function fetch_value (error, value) { if (error) { callback(error); } @@ -1611,8 +1685,29 @@ define(function(require) { getxattr_file(context, path, name, fetch_value); } - function _setxattr(context, path, name, value, flag, callback) { - if(!nullCheck(path, callback)) return; + function _fgetxattr (fs, context, fd, name, callback) { + + function get_result (error, value) { + if (error) { + callback(error); + } + else { + callback(null, value); + } + } + + var ofd = fs.openFiles[fd]; + + if (!ofd) { + callback(new EBadFileDescriptor('invalid file descriptor')); + } + else { + fgetxattr_file(context, ofd, name, get_result); + } + } + + function _setxattr (context, path, name, value, flag, callback) { + if (!nullCheck(path, callback)) return; function check_result (error) { if (error) { @@ -1626,6 +1721,29 @@ define(function(require) { setxattr_file(context, path, name, value, flag, check_result); } + function _fsetxattr (fs, context, fd, name, value, flag, callback) { + function check_result (error) { + if (error) { + callback(error); + } + else { + callback(null); + } + } + + var ofd = fs.openFiles[fd]; + + if (!ofd) { + callback(new EBadFileDescriptor('invalid file descriptor')); + } + else if (!_(ofd.flags).contains(O_WRITE)) { + callback(new EBadFileDescriptor('descriptor does not permit writing')); + } + else { + fsetxattr_file(context, ofd, name, value, flag, check_result); + } + } + function _lseek(fs, context, fd, offset, whence, callback) { function check_result(error, offset) { if(error) { @@ -2116,6 +2234,32 @@ define(function(require) { callback(error); } }; + FileSystem.prototype.fsetxattr = function (fd, name, value, flag, callback) { + var callback = maybeCallback(arguments[arguments.length - 1]); + var _flag = (typeof flag != 'function') ? flag : null; + var fs = this; + var error = fs.queueOrRun( + function () { + var context = fs.provider.getReadWriteContext(); + _fsetxattr(fs, context, fd, name, value, _flag, callback); + } + ); + + if (error) { + callback(error); + } + }; + FileSystem.prototype.fgetxattr = function (fd, name, callback) { + callback = maybeCallback(callback); + var fs = this; + var error = fs.queueOrRun( + function () { + var context = fs.provider.getReadWriteContext(); + _fgetxattr(fs, context, fd, name, callback); + } + ); + }; + return FileSystem; }); diff --git a/tests/spec/fs.xattr.spec.js b/tests/spec/fs.xattr.spec.js index 2acf792..a45802e 100644 --- a/tests/spec/fs.xattr.spec.js +++ b/tests/spec/fs.xattr.spec.js @@ -67,7 +67,7 @@ define(["IDBFS"], function(IDBFS) { }); }); - it('should error when setting with a falsy value', function () { + it('should error when setting with a null value', function () { var complete = false; var _error; var that = this; @@ -75,7 +75,7 @@ define(["IDBFS"], function(IDBFS) { that.fs.writeFile('/testfile', '', function (error) { if (error) throw error; - that.fs.setxattr('/testfile', 'test', '', function (error) { + that.fs.setxattr('/testfile', 'test', null, function (error) { _error = error; complete = true; }); @@ -167,7 +167,7 @@ define(["IDBFS"], function(IDBFS) { }); }); - it ('should error when getting an attribute with a falsy name', function (error) { + it ('should error when getting an attribute with a name that is empty', function (error) { var complete = false; var _error; var that = this; @@ -191,17 +191,15 @@ define(["IDBFS"], function(IDBFS) { }); }); - it('should error when getting an attribute when a name is not a string', function (error) { + it('should error when getting an attribute where the name is not a string', function (error) { var complete = false; var _error; - // var that = this; + var that = this; - var fs = this.fs; - - fs.writeFile('/testfile', '', function (error) { + that.fs.writeFile('/testfile', '', function (error) { if (error) throw error; - fs.getxattr('/testfile', 89, function (error, value) { + that.fs.getxattr('/testfile', 89, function (error, value) { _error = error; complete = true; }); @@ -216,5 +214,279 @@ define(["IDBFS"], function(IDBFS) { expect(_error.name).toEqual('EInvalid'); }); }); + + it('should error when getting an attribute that does not exist', function (error) { + var complete = false; + var _error; + var that = this; + + that.fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + that.fs.getxattr('/testfile', 'test', function (error, value) { + _error = error; + complete = true; + }); + }); + + waitsFor(function () { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function () { + expect(_error).toBeDefined(); + expect(_error.name).toEqual('ENoAttr'); + }); + }); + + it('should error when file descriptor is invalid', function (error) { + var completeSet, completeGet; + var _errorSet, _errorGet; + var that = this; + var _value; + + completeSet = completeGet = false; + + that.fs.fsetxattr(1, 'test', 'value', function (error) { + _errorSet = error; + completeSet = true; + }); + + that.fs.fgetxattr(1, 'test', function (error, value) { + _errorGet = error; + _value = value; + completeGet = true; + }); + + waitsFor(function () { + return completeSet && completeGet; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function () { + expect(_value).toEqual(null); + expect(_errorSet).toBeDefined(); + expect(_errorSet.name).toEqual('EBadFileDescriptor'); + expect(_errorGet).toBeDefined(); + expect(_errorGet.name).toEqual('EBadFileDescriptor'); + }); + }); + + it('should set and get an extended attribute of a path', function (error) { + var complete = false; + var _errorSet; + var that = this; + var name = 'test'; + var _value;; + + that.fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + that.fs.setxattr('/testfile', name, 'somevalue', function (error) { + _errorSet = error; + + that.fs.getxattr('/testfile', name, function (error, value) { + _errorGet = error; + _value = value; + complete = true; + }); + }); + }); + + waitsFor(function () { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function () { + expect(_errorSet).toEqual(null); + expect(_errorGet).toEqual(null); + expect(_value).toEqual('somevalue'); + }); + }); + + it('should set and get an empty string as a value', function (error) { + var complete = false; + var _error; + var _value; + var that = this; + + that.fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + that.fs.setxattr('/testfile', 'test', '', function (error) { + _error = error; + + that.fs.getxattr('/testfile', 'test', function (error, value) { + _error = error; + _value = value; + complete = true; + }); + }); + }); + + waitsFor(function () { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function () { + expect(_error).toEqual(null); + expect(_value).toBeDefined(); + expect(_value).toEqual(''); + }); + }); + + it('should set and get an extended attribute for a valid file descriptor', function (error) { + var complete = false; + var _errorSet, _errorGet; + var _value; + var that = this; + var ofd; + + that.fs.open('/testfile', 'w', function (error, result) { + if (error) throw error; + + ofd = result; + + that.fs.fsetxattr(ofd, 'test', 'value', function (error) { + _errorSet = error; + + that.fs.fgetxattr(ofd, 'test', function (error, value) { + _errorGet = error; + _value = value; + complete = true; + }); + }); + }); + + waitsFor(function () { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function () { + expect(_errorSet).toEqual(null); + expect(_errorGet).toEqual(null); + expect(_value).toBeDefined(); + expect(_value).toEqual('value'); + }); + }); + + it('should set/get an object to an extended attribute', function (error) { + var complete = false; + var _error; + var that = this; + var value; + + that.fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + that.fs.setxattr('/testfile', 'test', { key1: 'test', key2: 'value', key3: 87 }, function (error) { + _error = error; + + that.fs.getxattr('/testfile', 'test', function (error, value) { + _error = error; + _value = value; + complete = true; + }); + }); + }); + + waitsFor(function () { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function () { + expect(_error).toEqual(null); + expect(_value).toEqual({ key1: 'test', key2: 'value', key3: 87 }); + }); + }); + + it('should update/overwrite an existing extended attribute', function (error) { + var complete = false; + var _error; + var that = this; + var _value1, _value2, _value3; + + that.fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + that.fs.setxattr('/testfile', 'test', 'value', function (error) { + _error = error; + + that.fs.getxattr('/testfile', 'test', function (error, value) { + _error = error; + _value1 = value; + + that.fs.setxattr('/testfile', 'test', { o: 'object', t: 'test' }, function (error) { + _error = error; + + that.fs.getxattr('/testfile', 'test', function (error, value) { + _error = error; + _value2 = value; + + that.fs.setxattr('/testfile', 'test', 100, 'REPLACE', function (error) { + _error = error; + + that.fs.getxattr('/testfile', 'test', function (error, value) { + _error = error; + _value3 = value; + complete = true; + }); + }); + }); + }); + }); + }) + }); + + waitsFor(function () { + return complete; + }, 'test to complete' , DEFAULT_TIMEOUT); + + runs(function () { + expect(_error).toEqual(null); + expect(_value1).toEqual('value'); + expect(_value2).toEqual({ o: 'object', t: 'test' }); + expect(_value3).toEqual(100); + }); + }); + + it('should set multiple extended attributes for a path', function (error) { + var complete = false; + var _error; + var that = this; + var _value1, _value2; + + that.fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + that.fs.setxattr('/testfile', 'test', 89, function (error) { + _error = error; + + that.fs.setxattr('/testfile', 'other', 'attribute', function (error) { + _error = error; + + that.fs.getxattr('/testfile', 'test', function (error, value) { + _error = error; + _value1 = value; + + that.fs.getxattr('/testfile', 'other', function (error, value) { + _error = error; + _value2 = value; + complete = true; + }); + }); + }); + }); + }); + + waitsFor(function () { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function () { + expect(_error).toEqual(null); + expect(_value1).toEqual(89); + expect(_value2).toEqual('attribute'); + }); + }); }); }); \ No newline at end of file From 732218cc1d53e6535d6a5625c1822da850d8a83a Mon Sep 17 00:00:00 2001 From: Barry Tulchinsky Date: Tue, 24 Dec 2013 15:10:17 -0500 Subject: [PATCH 08/11] fixed unnecessary null checking and replaced it with hasOwnproperty method, also added removexattr and fremovexattr and tests for it --- src/fs.js | 155 ++++++++++++++++++++++++++++++++---- tests/spec/fs.xattr.spec.js | 71 ++++++++++++++++- 2 files changed, 208 insertions(+), 18 deletions(-) diff --git a/src/fs.js b/src/fs.js index 95afaa5..ba6e357 100644 --- a/src/fs.js +++ b/src/fs.js @@ -1123,7 +1123,6 @@ define(function(require) { function setxattr_file (context, path, name, value, flag, callback) { path = normalize(path); - var undefined; function set_xattr (error, node) { var xattr = (node ? node.xattrs[name] : null); @@ -1131,10 +1130,10 @@ define(function(require) { if (error) { callback (error); } - else if (flag === XATTR_CREATE && (xattr != null || xattr != undefined)) { + else if (flag == XATTR_CREATE && node.xattrs.hasOwnProperty(name)) { callback(new EExists('attribute already exists')); } - else if (flag === XATTR_REPLACE && (xattr == null || xattr == undefined)) { + else if (flag === XATTR_REPLACE && !node.xattrs.hasOwnProperty(name)) { callback(new ENoAttr('attribute does not exist')); } else { @@ -1149,10 +1148,10 @@ define(function(require) { else if (!name) { callback(new EInvalid('attribute name cannot be an empty string')); } - else if (value == null || value == undefined) { - callback(new EInvalid('value cannot be null or undefined')); + else if (value == null) { + callback(new EInvalid('value must be defined')); } - else if ((flag != null || flag != undefined) && + else if (flag != null && flag !== XATTR_CREATE && flag !== XATTR_REPLACE) { callback(new EInvalid('invalid flag, must be null, XATTR_CREATE or XATTR_REPLACE')); } @@ -1162,7 +1161,6 @@ define(function(require) { } function fsetxattr_file (context, ofd, name, value, flag, callback) { - var undefined; function set_xattr (error, node) { var xattr = (node ? node.xattrs[name] : null); @@ -1170,10 +1168,10 @@ define(function(require) { if (error) { callback(error); } - else if (flag === XATTR_CREATE && (xattr != null || xattr != undefined)) { + else if (flag === XATTR_CREATE && node.xattrs.hasOwnProperty(name)) { callback(new EExists('attribute already exists')); } - else if (flag === XATTR_REPLACE && (xattr == null || xattr == undefined)) { + else if (flag === XATTR_REPLACE && !node.xattrs.hasOwnProperty(name)) { callback(new ENoAttr('attribute does not exist')); } else { @@ -1188,10 +1186,10 @@ define(function(require) { else if (!name) { callback(new EInvalid('attribute name cannot be an empty string')); } - else if (value == null || value == undefined) { - callback(new EInvalid('value cannot be empty')); + else if (value == null) { + callback(new EInvalid('value must be defined')); } - else if ((flag != null || flag != undefined) && + else if (flag != null && flag !== XATTR_CREATE && flag !== XATTR_REPLACE) { callback(new EInvalid('invalid flag, must be null, XATTR_CREATE or XATTR_REPLACE')); } @@ -1202,7 +1200,6 @@ define(function(require) { function getxattr_file (context, path, name, callback) { path = normalize(path); - var undefined; function get_xattr(error, node) { var xattr = (node ? node.xattrs[name] : null); @@ -1210,7 +1207,7 @@ define(function(require) { if (error) { callback (error); } - else if (xattr == null || xattr == undefined) { + else if (!node.xattrs.hasOwnProperty(name)) { callback(new ENoAttr('attribute does not exist')); } else { @@ -1230,7 +1227,6 @@ define(function(require) { } function fgetxattr_file (context, ofd, name, callback) { - var undefined; function get_xattr (error, node) { var xattr = (node ? node.xattrs[name] : null); @@ -1238,7 +1234,7 @@ define(function(require) { if (error) { callback(error); } - else if (xattr == null || xattr == undefined) { + else if (!node.xattrs.hasOwnProperty(name)) { callback(new ENoAttr('attribute does not exist')); } else { @@ -1257,6 +1253,61 @@ define(function(require) { } } + function removexattr_file (context, path, name, callback) { + path = normalize(path); + + function remove_xattr (error, node) { + var xattr = (node ? node.xattrs : null); + + if (error) { + callback(error); + } + else if (!xattr.hasOwnProperty(name)) { + callback(new ENoAttr('attribute does not exist')); + } + else { + delete node.xattrs[name]; + context.put(node.id, node, callback); + } + } + + if (typeof name != 'string') { + callback(new EInvalid('attribute name must be a string')); + } + else if (!name) { + callback(new EInvalid('attribute name cannot be an empty string')); + } + else { + find_node(context, path, remove_xattr); + } + } + + function fremovexattr_file (context, ofd, name, callback) { + + function remove_xattr (error, node) { + if (error) { + callback(error); + } + else if (!node.xattrs.hasOwnProperty(name)) { + callback(new ENoAttr('attribute does not exist')); + } + else { + delete node.xattrs[name]; + context.put(node.id, node, callback); + } + } + + if (typeof name != 'string') { + callback(new EInvalid('attribute name must be a string')); + } + else if (!name) { + callback(new EInvalid('attribute name cannot be an empty string')); + } + else { + context.get(ofd.id, remove_xattr); + } + } + function validate_flags(flags) { if(!_(O_FLAGS).has(flags)) { return null; @@ -1744,6 +1795,45 @@ define(function(require) { } } + function _removexattr (context, path, name, callback) { + if (!nullCheck(path, callback)) return; + + function remove_xattr (error) { + if (error) { + callback(error); + } + else { + callback(null); + } + } + + removexattr_file (context, path, name, remove_xattr); + } + + function _fremovexattr (fs, context, fd, name, callback) { + + function remove_xattr (error) { + if (error) { + callback(error); + } + else { + callback(null); + } + } + + var ofd = fs.openFiles[fd]; + + if (!ofd) { + callback(new EBadFileDescriptor('invalid file descriptor')); + } + else if (!_(ofd.flags).contains(O_WRITE)) { + callback(new EBadFileDescriptor('descriptor does not permit writing')); + } + else { + fremovexattr_file(context, ofd, name, remove_xattr); + } + } + function _lseek(fs, context, fd, offset, whence, callback) { function check_result(error, offset) { if(error) { @@ -2258,8 +2348,39 @@ define(function(require) { _fgetxattr(fs, context, fd, name, callback); } ); - }; + if (error) { + callback(error); + } + }; + FileSystem.prototype.removexattr = function (path, name, callback) { + callback = maybeCallback(callback); + var fs = this; + var error = fs.queueOrRun( + function () { + var context = fs.provider.getReadWriteContext(); + _removexattr(context, path, name, callback); + } + ); + + if (error) { + callback(error); + } + }; + FileSystem.prototype.fremovexattr = function (fd, name, callback) { + callback = maybeCallback(callback); + var fs = this; + var error = fs.queueOrRun( + function () { + var context = fs.provider.getReadWriteContext(); + _fremovexattr(fs, context, fd, name, callback); + } + ); + + if (error) { + callback(error); + } + }; return FileSystem; }); diff --git a/tests/spec/fs.xattr.spec.js b/tests/spec/fs.xattr.spec.js index a45802e..737e8d3 100644 --- a/tests/spec/fs.xattr.spec.js +++ b/tests/spec/fs.xattr.spec.js @@ -303,6 +303,34 @@ define(["IDBFS"], function(IDBFS) { }); }); + it('should error when attempting to remove a non-existing attribute', function (error) { + var complete = false; + var _error; + var that = this; + + that.fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + that.fs.setxattr('/testfile', 'test', '', function (error) { + if (error) throw error; + + that.fs.removexattr('/testfile', 'testenoattr', function (error) { + _error = error; + complete = true; + }); + }); + }); + + waitsFor(function () { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function () { + expect(_error).toBeDefined(); + expect(_error.name).toEqual('ENoAttr'); + }); + }); + it('should set and get an empty string as a value', function (error) { var complete = false; var _error; @@ -369,7 +397,7 @@ define(["IDBFS"], function(IDBFS) { }); }); - it('should set/get an object to an extended attribute', function (error) { + it('should set and get an object to an extended attribute', function (error) { var complete = false; var _error; var that = this; @@ -488,5 +516,46 @@ define(["IDBFS"], function(IDBFS) { expect(_value2).toEqual('attribute'); }); }); + + it('should remove an extended attribute from a path', function (error) { + var complete = false; + var _error, _value; + var that = this; + + that.fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + that.fs.setxattr('/testfile', 'test', 'somevalue', function (error) { + if (error) throw error; + + that.fs.getxattr('/testfile', 'test', function (error, value) { + if (error) throw error; + + _value = value; + + that.fs.removexattr('/testfile', 'test', function (error) { + if (error) throw error; + + that.fs.getxattr('/testfile', 'test', function (error) { + _error = error; + complete = true; + }); + }); + }); + }); + }); + + waitsFor(function () { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function () { + expect(_error).toBeDefined(); + expect(_value).toBeDefined(); + expect(_value).toEqual('somevalue'); + expect(_error.name).toEqual('ENoAttr'); + }); + + }); }); }); \ No newline at end of file From c4dd0f560ce96b04716e7012dc14446ac2a4f841 Mon Sep 17 00:00:00 2001 From: Barry Tulchinsky Date: Thu, 2 Jan 2014 17:50:26 -0500 Subject: [PATCH 09/11] continue work on tests and clean-up code --- dist/idbfs.js | 5974 ----------------------------------- dist/idbfs.min.js | 5 - tests/spec/fs.xattr.spec.js | 68 +- 3 files changed, 64 insertions(+), 5983 deletions(-) delete mode 100644 dist/idbfs.js delete mode 100644 dist/idbfs.min.js diff --git a/dist/idbfs.js b/dist/idbfs.js deleted file mode 100644 index 13dff9e..0000000 --- a/dist/idbfs.js +++ /dev/null @@ -1,5974 +0,0 @@ -/* -Copyright (c) 2013, Alan Kligman -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Mozilla Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -(function( root, factory ) { - - if ( typeof exports === "object" ) { - // Node - module.exports = factory(); - } else if (typeof define === "function" && define.amd) { - // AMD. Register as an anonymous module. - define( factory ); - } else if( !root.IDBFS ) { - // Browser globals - root.IDBFS = factory(); - } - -}( this, function() { - -/** - * almond 0.2.5 Copyright (c) 2011-2012, The Dojo Foundation All Rights Reserved. - * Available via the MIT or new BSD license. - * see: http://github.com/jrburke/almond for details - */ -//Going sloppy to avoid 'use strict' string cost, but strict practices should -//be followed. -/*jslint sloppy: true */ -/*global setTimeout: false */ - -var requirejs, require, define; -(function (undef) { - var main, req, makeMap, handlers, - defined = {}, - waiting = {}, - config = {}, - defining = {}, - hasOwn = Object.prototype.hasOwnProperty, - aps = [].slice; - - function hasProp(obj, prop) { - return hasOwn.call(obj, prop); - } - - /** - * Given a relative module name, like ./something, normalize it to - * a real name that can be mapped to a path. - * @param {String} name the relative name - * @param {String} baseName a real name that the name arg is relative - * to. - * @returns {String} normalized name - */ - function normalize(name, baseName) { - var nameParts, nameSegment, mapValue, foundMap, - foundI, foundStarMap, starI, i, j, part, - baseParts = baseName && baseName.split("/"), - map = config.map, - starMap = (map && map['*']) || {}; - - //Adjust any relative paths. - if (name && name.charAt(0) === ".") { - //If have a base name, try to normalize against it, - //otherwise, assume it is a top-level require that will - //be relative to baseUrl in the end. - if (baseName) { - //Convert baseName to array, and lop off the last part, - //so that . matches that "directory" and not name of the baseName's - //module. For instance, baseName of "one/two/three", maps to - //"one/two/three.js", but we want the directory, "one/two" for - //this normalization. - baseParts = baseParts.slice(0, baseParts.length - 1); - - name = baseParts.concat(name.split("/")); - - //start trimDots - for (i = 0; i < name.length; i += 1) { - part = name[i]; - if (part === ".") { - name.splice(i, 1); - i -= 1; - } else if (part === "..") { - if (i === 1 && (name[2] === '..' || name[0] === '..')) { - //End of the line. Keep at least one non-dot - //path segment at the front so it can be mapped - //correctly to disk. Otherwise, there is likely - //no path mapping for a path starting with '..'. - //This can still fail, but catches the most reasonable - //uses of .. - break; - } else if (i > 0) { - name.splice(i - 1, 2); - i -= 2; - } - } - } - //end trimDots - - name = name.join("/"); - } else if (name.indexOf('./') === 0) { - // No baseName, so this is ID is resolved relative - // to baseUrl, pull off the leading dot. - name = name.substring(2); - } - } - - //Apply map config if available. - if ((baseParts || starMap) && map) { - nameParts = name.split('/'); - - for (i = nameParts.length; i > 0; i -= 1) { - nameSegment = nameParts.slice(0, i).join("/"); - - if (baseParts) { - //Find the longest baseName segment match in the config. - //So, do joins on the biggest to smallest lengths of baseParts. - for (j = baseParts.length; j > 0; j -= 1) { - mapValue = map[baseParts.slice(0, j).join('/')]; - - //baseName segment has config, find if it has one for - //this name. - if (mapValue) { - mapValue = mapValue[nameSegment]; - if (mapValue) { - //Match, update name to the new value. - foundMap = mapValue; - foundI = i; - break; - } - } - } - } - - if (foundMap) { - break; - } - - //Check for a star map match, but just hold on to it, - //if there is a shorter segment match later in a matching - //config, then favor over this star map. - if (!foundStarMap && starMap && starMap[nameSegment]) { - foundStarMap = starMap[nameSegment]; - starI = i; - } - } - - if (!foundMap && foundStarMap) { - foundMap = foundStarMap; - foundI = starI; - } - - if (foundMap) { - nameParts.splice(0, foundI, foundMap); - name = nameParts.join('/'); - } - } - - return name; - } - - function makeRequire(relName, forceSync) { - return function () { - //A version of a require function that passes a moduleName - //value for items that may need to - //look up paths relative to the moduleName - return req.apply(undef, aps.call(arguments, 0).concat([relName, forceSync])); - }; - } - - function makeNormalize(relName) { - return function (name) { - return normalize(name, relName); - }; - } - - function makeLoad(depName) { - return function (value) { - defined[depName] = value; - }; - } - - function callDep(name) { - if (hasProp(waiting, name)) { - var args = waiting[name]; - delete waiting[name]; - defining[name] = true; - main.apply(undef, args); - } - - if (!hasProp(defined, name) && !hasProp(defining, name)) { - throw new Error('No ' + name); - } - return defined[name]; - } - - //Turns a plugin!resource to [plugin, resource] - //with the plugin being undefined if the name - //did not have a plugin prefix. - function splitPrefix(name) { - var prefix, - index = name ? name.indexOf('!') : -1; - if (index > -1) { - prefix = name.substring(0, index); - name = name.substring(index + 1, name.length); - } - return [prefix, name]; - } - - /** - * Makes a name map, normalizing the name, and using a plugin - * for normalization if necessary. Grabs a ref to plugin - * too, as an optimization. - */ - makeMap = function (name, relName) { - var plugin, - parts = splitPrefix(name), - prefix = parts[0]; - - name = parts[1]; - - if (prefix) { - prefix = normalize(prefix, relName); - plugin = callDep(prefix); - } - - //Normalize according - if (prefix) { - if (plugin && plugin.normalize) { - name = plugin.normalize(name, makeNormalize(relName)); - } else { - name = normalize(name, relName); - } - } else { - name = normalize(name, relName); - parts = splitPrefix(name); - prefix = parts[0]; - name = parts[1]; - if (prefix) { - plugin = callDep(prefix); - } - } - - //Using ridiculous property names for space reasons - return { - f: prefix ? prefix + '!' + name : name, //fullName - n: name, - pr: prefix, - p: plugin - }; - }; - - function makeConfig(name) { - return function () { - return (config && config.config && config.config[name]) || {}; - }; - } - - handlers = { - require: function (name) { - return makeRequire(name); - }, - exports: function (name) { - var e = defined[name]; - if (typeof e !== 'undefined') { - return e; - } else { - return (defined[name] = {}); - } - }, - module: function (name) { - return { - id: name, - uri: '', - exports: defined[name], - config: makeConfig(name) - }; - } - }; - - main = function (name, deps, callback, relName) { - var cjsModule, depName, ret, map, i, - args = [], - usingExports; - - //Use name if no relName - relName = relName || name; - - //Call the callback to define the module, if necessary. - if (typeof callback === 'function') { - - //Pull out the defined dependencies and pass the ordered - //values to the callback. - //Default to [require, exports, module] if no deps - deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps; - for (i = 0; i < deps.length; i += 1) { - map = makeMap(deps[i], relName); - depName = map.f; - - //Fast path CommonJS standard dependencies. - if (depName === "require") { - args[i] = handlers.require(name); - } else if (depName === "exports") { - //CommonJS module spec 1.1 - args[i] = handlers.exports(name); - usingExports = true; - } else if (depName === "module") { - //CommonJS module spec 1.1 - cjsModule = args[i] = handlers.module(name); - } else if (hasProp(defined, depName) || - hasProp(waiting, depName) || - hasProp(defining, depName)) { - args[i] = callDep(depName); - } else if (map.p) { - map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {}); - args[i] = defined[depName]; - } else { - throw new Error(name + ' missing ' + depName); - } - } - - ret = callback.apply(defined[name], args); - - if (name) { - //If setting exports via "module" is in play, - //favor that over return value and exports. After that, - //favor a non-undefined return value over exports use. - if (cjsModule && cjsModule.exports !== undef && - cjsModule.exports !== defined[name]) { - defined[name] = cjsModule.exports; - } else if (ret !== undef || !usingExports) { - //Use the return value from the function. - defined[name] = ret; - } - } - } else if (name) { - //May just be an object definition for the module. Only - //worry about defining if have a module name. - defined[name] = callback; - } - }; - - requirejs = require = req = function (deps, callback, relName, forceSync, alt) { - if (typeof deps === "string") { - if (handlers[deps]) { - //callback in this case is really relName - return handlers[deps](callback); - } - //Just return the module wanted. In this scenario, the - //deps arg is the module name, and second arg (if passed) - //is just the relName. - //Normalize module name, if it contains . or .. - return callDep(makeMap(deps, callback).f); - } else if (!deps.splice) { - //deps is a config object, not an array. - config = deps; - if (callback.splice) { - //callback is an array, which means it is a dependency list. - //Adjust args if there are dependencies - deps = callback; - callback = relName; - relName = null; - } else { - deps = undef; - } - } - - //Support require(['a']) - callback = callback || function () {}; - - //If relName is a function, it is an errback handler, - //so remove it. - if (typeof relName === 'function') { - relName = forceSync; - forceSync = alt; - } - - //Simulate async callback; - if (forceSync) { - main(undef, deps, callback, relName); - } else { - //Using a non-zero value because of concern for what old browsers - //do, and latest browsers "upgrade" to 4 if lower value is used: - //http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#dom-windowtimers-settimeout: - //If want a value immediately, use require('id') instead -- something - //that works in almond on the global level, but not guaranteed and - //unlikely to work in other AMD implementations. - setTimeout(function () { - main(undef, deps, callback, relName); - }, 4); - } - - return req; - }; - - /** - * Just drops the config on the floor, but returns req in case - * the config return value is used. - */ - req.config = function (cfg) { - config = cfg; - if (config.deps) { - req(config.deps, config.callback); - } - return req; - }; - - define = function (name, deps, callback) { - - //This module may not have dependencies - if (!deps.splice) { - //deps is not an array, so probably means - //an object literal or factory function for - //the value. Adjust args. - callback = deps; - deps = []; - } - - if (!hasProp(defined, name) && !hasProp(waiting, name)) { - waiting[name] = [name, deps, callback]; - } - }; - - define.amd = { - jQuery: true - }; -}()); - -define("build/almond", function(){}); - -// Cherry-picked bits of underscore.js, lodash.js - -/** - * Lo-Dash 2.4.0 - * Copyright 2012-2013 The Dojo Foundation - * Based on Underscore.js 1.5.2 - * Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors - * Available under MIT license - */ - -define('nodash',['require'],function(require) { - - var ArrayProto = Array.prototype; - var nativeForEach = ArrayProto.forEach; - var nativeIndexOf = ArrayProto.indexOf; - var nativeSome = ArrayProto.some; - - var ObjProto = Object.prototype; - var hasOwnProperty = ObjProto.hasOwnProperty; - var nativeKeys = Object.keys; - - var breaker = {}; - - function has(obj, key) { - return hasOwnProperty.call(obj, key); - } - - var keys = nativeKeys || function(obj) { - if (obj !== Object(obj)) throw new TypeError('Invalid object'); - var keys = []; - for (var key in obj) if (has(obj, key)) keys.push(key); - return keys; - }; - - function size(obj) { - if (obj == null) return 0; - return (obj.length === +obj.length) ? obj.length : keys(obj).length; - } - - function identity(value) { - return value; - } - - function each(obj, iterator, context) { - var i, length; - if (obj == null) return; - if (nativeForEach && obj.forEach === nativeForEach) { - obj.forEach(iterator, context); - } else if (obj.length === +obj.length) { - for (i = 0, length = obj.length; i < length; i++) { - if (iterator.call(context, obj[i], i, obj) === breaker) return; - } - } else { - var keys = keys(obj); - for (i = 0, length = keys.length; i < length; i++) { - if (iterator.call(context, obj[keys[i]], keys[i], obj) === breaker) return; - } - } - }; - - function any(obj, iterator, context) { - iterator || (iterator = identity); - var result = false; - if (obj == null) return result; - if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context); - each(obj, function(value, index, list) { - if (result || (result = iterator.call(context, value, index, list))) return breaker; - }); - return !!result; - }; - - function contains(obj, target) { - if (obj == null) return false; - if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1; - return any(obj, function(value) { - return value === target; - }); - }; - - function Wrapped(value) { - this.value = value; - } - Wrapped.prototype.has = function(key) { - return has(this.value, key); - }; - Wrapped.prototype.contains = function(target) { - return contains(this.value, target); - }; - Wrapped.prototype.size = function() { - return size(this.value); - }; - - function nodash(value) { - // don't wrap if already wrapped, even if wrapped by a different `lodash` constructor - return (value && typeof value == 'object' && !Array.isArray(value) && hasOwnProperty.call(value, '__wrapped__')) - ? value - : new Wrapped(value); - } - - return nodash; - -}); - -// Hack to allow using encoding.js with only utf8. -// Right now there's a bug where it expects global['encoding-indexes']: -// -// function index(name) { -// if (!('encoding-indexes' in global)) -// throw new Error("Indexes missing. Did you forget to include encoding-indexes.js?"); -// return global['encoding-indexes'][name]; -// } -(function(global) { - global['encoding-indexes'] = global['encoding-indexes'] || []; -}(this)); - -define("encoding-indexes-shim", function(){}); - -/*! - * Shim implementation of the TextEncoder, TextDecoder spec: - * http://encoding.spec.whatwg.org/#interface-textencoder - * - * http://code.google.com/p/stringencoding/source/browse/encoding.js - * 09b44d71759d on Sep 19, 2013 - * Used under Apache License 2.0 - http://code.google.com/p/stringencoding/ - */ -(function(global) { - - - // - // Utilities - // - - /** - * @param {number} a The number to test. - * @param {number} min The minimum value in the range, inclusive. - * @param {number} max The maximum value in the range, inclusive. - * @return {boolean} True if a >= min and a <= max. - */ - function inRange(a, min, max) { - return min <= a && a <= max; - } - - /** - * @param {number} n The numerator. - * @param {number} d The denominator. - * @return {number} The result of the integer division of n by d. - */ - function div(n, d) { - return Math.floor(n / d); - } - - - // - // Implementation of Encoding specification - // http://dvcs.w3.org/hg/encoding/raw-file/tip/Overview.html - // - - // - // 3. Terminology - // - - // - // 4. Encodings - // - - /** @const */ var EOF_byte = -1; - /** @const */ var EOF_code_point = -1; - - /** - * @constructor - * @param {Uint8Array} bytes Array of bytes that provide the stream. - */ - function ByteInputStream(bytes) { - /** @type {number} */ - var pos = 0; - - /** @return {number} Get the next byte from the stream. */ - this.get = function() { - return (pos >= bytes.length) ? EOF_byte : Number(bytes[pos]); - }; - - /** @param {number} n Number (positive or negative) by which to - * offset the byte pointer. */ - this.offset = function(n) { - pos += n; - if (pos < 0) { - throw new Error('Seeking past start of the buffer'); - } - if (pos > bytes.length) { - throw new Error('Seeking past EOF'); - } - }; - - /** - * @param {Array.} test Array of bytes to compare against. - * @return {boolean} True if the start of the stream matches the test - * bytes. - */ - this.match = function(test) { - if (test.length > pos + bytes.length) { - return false; - } - var i; - for (i = 0; i < test.length; i += 1) { - if (Number(bytes[pos + i]) !== test[i]) { - return false; - } - } - return true; - }; - } - - /** - * @constructor - * @param {Array.} bytes The array to write bytes into. - */ - function ByteOutputStream(bytes) { - /** @type {number} */ - var pos = 0; - - /** - * @param {...number} var_args The byte or bytes to emit into the stream. - * @return {number} The last byte emitted. - */ - this.emit = function(var_args) { - /** @type {number} */ - var last = EOF_byte; - var i; - for (i = 0; i < arguments.length; ++i) { - last = Number(arguments[i]); - bytes[pos++] = last; - } - return last; - }; - } - - /** - * @constructor - * @param {string} string The source of code units for the stream. - */ - function CodePointInputStream(string) { - /** - * @param {string} string Input string of UTF-16 code units. - * @return {Array.} Code points. - */ - function stringToCodePoints(string) { - /** @type {Array.} */ - var cps = []; - // Based on http://www.w3.org/TR/WebIDL/#idl-DOMString - var i = 0, n = string.length; - while (i < string.length) { - var c = string.charCodeAt(i); - if (!inRange(c, 0xD800, 0xDFFF)) { - cps.push(c); - } else if (inRange(c, 0xDC00, 0xDFFF)) { - cps.push(0xFFFD); - } else { // (inRange(cu, 0xD800, 0xDBFF)) - if (i === n - 1) { - cps.push(0xFFFD); - } else { - var d = string.charCodeAt(i + 1); - if (inRange(d, 0xDC00, 0xDFFF)) { - var a = c & 0x3FF; - var b = d & 0x3FF; - i += 1; - cps.push(0x10000 + (a << 10) + b); - } else { - cps.push(0xFFFD); - } - } - } - i += 1; - } - return cps; - } - - /** @type {number} */ - var pos = 0; - /** @type {Array.} */ - var cps = stringToCodePoints(string); - - /** @param {number} n The number of bytes (positive or negative) - * to advance the code point pointer by.*/ - this.offset = function(n) { - pos += n; - if (pos < 0) { - throw new Error('Seeking past start of the buffer'); - } - if (pos > cps.length) { - throw new Error('Seeking past EOF'); - } - }; - - - /** @return {number} Get the next code point from the stream. */ - this.get = function() { - if (pos >= cps.length) { - return EOF_code_point; - } - return cps[pos]; - }; - } - - /** - * @constructor - */ - function CodePointOutputStream() { - /** @type {string} */ - var string = ''; - - /** @return {string} The accumulated string. */ - this.string = function() { - return string; - }; - - /** @param {number} c The code point to encode into the stream. */ - this.emit = function(c) { - if (c <= 0xFFFF) { - string += String.fromCharCode(c); - } else { - c -= 0x10000; - string += String.fromCharCode(0xD800 + ((c >> 10) & 0x3ff)); - string += String.fromCharCode(0xDC00 + (c & 0x3ff)); - } - }; - } - - /** - * @constructor - * @param {string} message Description of the error. - */ - function EncodingError(message) { - this.name = 'EncodingError'; - this.message = message; - this.code = 0; - } - EncodingError.prototype = Error.prototype; - - /** - * @param {boolean} fatal If true, decoding errors raise an exception. - * @param {number=} opt_code_point Override the standard fallback code point. - * @return {number} The code point to insert on a decoding error. - */ - function decoderError(fatal, opt_code_point) { - if (fatal) { - throw new EncodingError('Decoder error'); - } - return opt_code_point || 0xFFFD; - } - - /** - * @param {number} code_point The code point that could not be encoded. - */ - function encoderError(code_point) { - throw new EncodingError('The code point ' + code_point + - ' could not be encoded.'); - } - - /** - * @param {string} label The encoding label. - * @return {?{name:string,labels:Array.}} - */ - function getEncoding(label) { - label = String(label).trim().toLowerCase(); - if (Object.prototype.hasOwnProperty.call(label_to_encoding, label)) { - return label_to_encoding[label]; - } - return null; - } - - /** @type {Array.<{encodings: Array.<{name:string,labels:Array.}>, - * heading: string}>} */ - var encodings = [ - { - "encodings": [ - { - "labels": [ - "unicode-1-1-utf-8", - "utf-8", - "utf8" - ], - "name": "utf-8" - } - ], - "heading": "The Encoding" - }, - { - "encodings": [ - { - "labels": [ - "866", - "cp866", - "csibm866", - "ibm866" - ], - "name": "ibm866" - }, - { - "labels": [ - "csisolatin2", - "iso-8859-2", - "iso-ir-101", - "iso8859-2", - "iso88592", - "iso_8859-2", - "iso_8859-2:1987", - "l2", - "latin2" - ], - "name": "iso-8859-2" - }, - { - "labels": [ - "csisolatin3", - "iso-8859-3", - "iso-ir-109", - "iso8859-3", - "iso88593", - "iso_8859-3", - "iso_8859-3:1988", - "l3", - "latin3" - ], - "name": "iso-8859-3" - }, - { - "labels": [ - "csisolatin4", - "iso-8859-4", - "iso-ir-110", - "iso8859-4", - "iso88594", - "iso_8859-4", - "iso_8859-4:1988", - "l4", - "latin4" - ], - "name": "iso-8859-4" - }, - { - "labels": [ - "csisolatincyrillic", - "cyrillic", - "iso-8859-5", - "iso-ir-144", - "iso8859-5", - "iso88595", - "iso_8859-5", - "iso_8859-5:1988" - ], - "name": "iso-8859-5" - }, - { - "labels": [ - "arabic", - "asmo-708", - "csiso88596e", - "csiso88596i", - "csisolatinarabic", - "ecma-114", - "iso-8859-6", - "iso-8859-6-e", - "iso-8859-6-i", - "iso-ir-127", - "iso8859-6", - "iso88596", - "iso_8859-6", - "iso_8859-6:1987" - ], - "name": "iso-8859-6" - }, - { - "labels": [ - "csisolatingreek", - "ecma-118", - "elot_928", - "greek", - "greek8", - "iso-8859-7", - "iso-ir-126", - "iso8859-7", - "iso88597", - "iso_8859-7", - "iso_8859-7:1987", - "sun_eu_greek" - ], - "name": "iso-8859-7" - }, - { - "labels": [ - "csiso88598e", - "csisolatinhebrew", - "hebrew", - "iso-8859-8", - "iso-8859-8-e", - "iso-ir-138", - "iso8859-8", - "iso88598", - "iso_8859-8", - "iso_8859-8:1988", - "visual" - ], - "name": "iso-8859-8" - }, - { - "labels": [ - "csiso88598i", - "iso-8859-8-i", - "logical" - ], - "name": "iso-8859-8-i" - }, - { - "labels": [ - "csisolatin6", - "iso-8859-10", - "iso-ir-157", - "iso8859-10", - "iso885910", - "l6", - "latin6" - ], - "name": "iso-8859-10" - }, - { - "labels": [ - "iso-8859-13", - "iso8859-13", - "iso885913" - ], - "name": "iso-8859-13" - }, - { - "labels": [ - "iso-8859-14", - "iso8859-14", - "iso885914" - ], - "name": "iso-8859-14" - }, - { - "labels": [ - "csisolatin9", - "iso-8859-15", - "iso8859-15", - "iso885915", - "iso_8859-15", - "l9" - ], - "name": "iso-8859-15" - }, - { - "labels": [ - "iso-8859-16" - ], - "name": "iso-8859-16" - }, - { - "labels": [ - "cskoi8r", - "koi", - "koi8", - "koi8-r", - "koi8_r" - ], - "name": "koi8-r" - }, - { - "labels": [ - "koi8-u" - ], - "name": "koi8-u" - }, - { - "labels": [ - "csmacintosh", - "mac", - "macintosh", - "x-mac-roman" - ], - "name": "macintosh" - }, - { - "labels": [ - "dos-874", - "iso-8859-11", - "iso8859-11", - "iso885911", - "tis-620", - "windows-874" - ], - "name": "windows-874" - }, - { - "labels": [ - "cp1250", - "windows-1250", - "x-cp1250" - ], - "name": "windows-1250" - }, - { - "labels": [ - "cp1251", - "windows-1251", - "x-cp1251" - ], - "name": "windows-1251" - }, - { - "labels": [ - "ansi_x3.4-1968", - "ascii", - "cp1252", - "cp819", - "csisolatin1", - "ibm819", - "iso-8859-1", - "iso-ir-100", - "iso8859-1", - "iso88591", - "iso_8859-1", - "iso_8859-1:1987", - "l1", - "latin1", - "us-ascii", - "windows-1252", - "x-cp1252" - ], - "name": "windows-1252" - }, - { - "labels": [ - "cp1253", - "windows-1253", - "x-cp1253" - ], - "name": "windows-1253" - }, - { - "labels": [ - "cp1254", - "csisolatin5", - "iso-8859-9", - "iso-ir-148", - "iso8859-9", - "iso88599", - "iso_8859-9", - "iso_8859-9:1989", - "l5", - "latin5", - "windows-1254", - "x-cp1254" - ], - "name": "windows-1254" - }, - { - "labels": [ - "cp1255", - "windows-1255", - "x-cp1255" - ], - "name": "windows-1255" - }, - { - "labels": [ - "cp1256", - "windows-1256", - "x-cp1256" - ], - "name": "windows-1256" - }, - { - "labels": [ - "cp1257", - "windows-1257", - "x-cp1257" - ], - "name": "windows-1257" - }, - { - "labels": [ - "cp1258", - "windows-1258", - "x-cp1258" - ], - "name": "windows-1258" - }, - { - "labels": [ - "x-mac-cyrillic", - "x-mac-ukrainian" - ], - "name": "x-mac-cyrillic" - } - ], - "heading": "Legacy single-byte encodings" - }, - { - "encodings": [ - { - "labels": [ - "chinese", - "csgb2312", - "csiso58gb231280", - "gb2312", - "gb_2312", - "gb_2312-80", - "gbk", - "iso-ir-58", - "x-gbk" - ], - "name": "gbk" - }, - { - "labels": [ - "gb18030" - ], - "name": "gb18030" - }, - { - "labels": [ - "hz-gb-2312" - ], - "name": "hz-gb-2312" - } - ], - "heading": "Legacy multi-byte Chinese (simplified) encodings" - }, - { - "encodings": [ - { - "labels": [ - "big5", - "big5-hkscs", - "cn-big5", - "csbig5", - "x-x-big5" - ], - "name": "big5" - } - ], - "heading": "Legacy multi-byte Chinese (traditional) encodings" - }, - { - "encodings": [ - { - "labels": [ - "cseucpkdfmtjapanese", - "euc-jp", - "x-euc-jp" - ], - "name": "euc-jp" - }, - { - "labels": [ - "csiso2022jp", - "iso-2022-jp" - ], - "name": "iso-2022-jp" - }, - { - "labels": [ - "csshiftjis", - "ms_kanji", - "shift-jis", - "shift_jis", - "sjis", - "windows-31j", - "x-sjis" - ], - "name": "shift_jis" - } - ], - "heading": "Legacy multi-byte Japanese encodings" - }, - { - "encodings": [ - { - "labels": [ - "cseuckr", - "csksc56011987", - "euc-kr", - "iso-ir-149", - "korean", - "ks_c_5601-1987", - "ks_c_5601-1989", - "ksc5601", - "ksc_5601", - "windows-949" - ], - "name": "euc-kr" - } - ], - "heading": "Legacy multi-byte Korean encodings" - }, - { - "encodings": [ - { - "labels": [ - "csiso2022kr", - "iso-2022-kr", - "iso-2022-cn", - "iso-2022-cn-ext" - ], - "name": "replacement" - }, - { - "labels": [ - "utf-16be" - ], - "name": "utf-16be" - }, - { - "labels": [ - "utf-16", - "utf-16le" - ], - "name": "utf-16le" - }, - { - "labels": [ - "x-user-defined" - ], - "name": "x-user-defined" - } - ], - "heading": "Legacy miscellaneous encodings" - } - ]; - - var name_to_encoding = {}; - var label_to_encoding = {}; - encodings.forEach(function(category) { - category.encodings.forEach(function(encoding) { - name_to_encoding[encoding.name] = encoding; - encoding.labels.forEach(function(label) { - label_to_encoding[label] = encoding; - }); - }); - }); - - // - // 5. Indexes - // - - /** - * @param {number} pointer The |pointer| to search for. - * @param {Array.} index The |index| to search within. - * @return {?number} The code point corresponding to |pointer| in |index|, - * or null if |code point| is not in |index|. - */ - function indexCodePointFor(pointer, index) { - return (index || [])[pointer] || null; - } - - /** - * @param {number} code_point The |code point| to search for. - * @param {Array.} index The |index| to search within. - * @return {?number} The first pointer corresponding to |code point| in - * |index|, or null if |code point| is not in |index|. - */ - function indexPointerFor(code_point, index) { - var pointer = index.indexOf(code_point); - return pointer === -1 ? null : pointer; - } - - /** - * @param {string} name Name of the index. - * @return {(Array.|Array.>)} - * */ - function index(name) { - if (!('encoding-indexes' in global)) - throw new Error("Indexes missing. Did you forget to include encoding-indexes.js?"); - return global['encoding-indexes'][name]; - } - - /** - * @param {number} pointer The |pointer| to search for in the gb18030 index. - * @return {?number} The code point corresponding to |pointer| in |index|, - * or null if |code point| is not in the gb18030 index. - */ - function indexGB18030CodePointFor(pointer) { - if ((pointer > 39419 && pointer < 189000) || (pointer > 1237575)) { - return null; - } - var /** @type {number} */ offset = 0, - /** @type {number} */ code_point_offset = 0, - /** @type {Array.>} */ idx = index('gb18030'); - var i; - for (i = 0; i < idx.length; ++i) { - var entry = idx[i]; - if (entry[0] <= pointer) { - offset = entry[0]; - code_point_offset = entry[1]; - } else { - break; - } - } - return code_point_offset + pointer - offset; - } - - /** - * @param {number} code_point The |code point| to locate in the gb18030 index. - * @return {number} The first pointer corresponding to |code point| in the - * gb18030 index. - */ - function indexGB18030PointerFor(code_point) { - var /** @type {number} */ offset = 0, - /** @type {number} */ pointer_offset = 0, - /** @type {Array.>} */ idx = index('gb18030'); - var i; - for (i = 0; i < idx.length; ++i) { - var entry = idx[i]; - if (entry[1] <= code_point) { - offset = entry[1]; - pointer_offset = entry[0]; - } else { - break; - } - } - return pointer_offset + code_point - offset; - } - - // - // 7. The encoding - // - - // 7.1 utf-8 - - /** - * @constructor - * @param {{fatal: boolean}} options - */ - function UTF8Decoder(options) { - var fatal = options.fatal; - var /** @type {number} */ utf8_code_point = 0, - /** @type {number} */ utf8_bytes_needed = 0, - /** @type {number} */ utf8_bytes_seen = 0, - /** @type {number} */ utf8_lower_boundary = 0; - - /** - * @param {ByteInputStream} byte_pointer The byte stream to decode. - * @return {?number} The next code point decoded, or null if not enough - * data exists in the input stream to decode a complete code point. - */ - this.decode = function(byte_pointer) { - var bite = byte_pointer.get(); - if (bite === EOF_byte) { - if (utf8_bytes_needed !== 0) { - return decoderError(fatal); - } - return EOF_code_point; - } - byte_pointer.offset(1); - - if (utf8_bytes_needed === 0) { - if (inRange(bite, 0x00, 0x7F)) { - return bite; - } - if (inRange(bite, 0xC2, 0xDF)) { - utf8_bytes_needed = 1; - utf8_lower_boundary = 0x80; - utf8_code_point = bite - 0xC0; - } else if (inRange(bite, 0xE0, 0xEF)) { - utf8_bytes_needed = 2; - utf8_lower_boundary = 0x800; - utf8_code_point = bite - 0xE0; - } else if (inRange(bite, 0xF0, 0xF4)) { - utf8_bytes_needed = 3; - utf8_lower_boundary = 0x10000; - utf8_code_point = bite - 0xF0; - } else { - return decoderError(fatal); - } - utf8_code_point = utf8_code_point * Math.pow(64, utf8_bytes_needed); - return null; - } - if (!inRange(bite, 0x80, 0xBF)) { - utf8_code_point = 0; - utf8_bytes_needed = 0; - utf8_bytes_seen = 0; - utf8_lower_boundary = 0; - byte_pointer.offset(-1); - return decoderError(fatal); - } - utf8_bytes_seen += 1; - utf8_code_point = utf8_code_point + (bite - 0x80) * - Math.pow(64, utf8_bytes_needed - utf8_bytes_seen); - if (utf8_bytes_seen !== utf8_bytes_needed) { - return null; - } - var code_point = utf8_code_point; - var lower_boundary = utf8_lower_boundary; - utf8_code_point = 0; - utf8_bytes_needed = 0; - utf8_bytes_seen = 0; - utf8_lower_boundary = 0; - if (inRange(code_point, lower_boundary, 0x10FFFF) && - !inRange(code_point, 0xD800, 0xDFFF)) { - return code_point; - } - return decoderError(fatal); - }; - } - - /** - * @constructor - * @param {{fatal: boolean}} options - */ - function UTF8Encoder(options) { - var fatal = options.fatal; - /** - * @param {ByteOutputStream} output_byte_stream Output byte stream. - * @param {CodePointInputStream} code_point_pointer Input stream. - * @return {number} The last byte emitted. - */ - this.encode = function(output_byte_stream, code_point_pointer) { - var code_point = code_point_pointer.get(); - if (code_point === EOF_code_point) { - return EOF_byte; - } - code_point_pointer.offset(1); - if (inRange(code_point, 0xD800, 0xDFFF)) { - return encoderError(code_point); - } - if (inRange(code_point, 0x0000, 0x007f)) { - return output_byte_stream.emit(code_point); - } - var count, offset; - if (inRange(code_point, 0x0080, 0x07FF)) { - count = 1; - offset = 0xC0; - } else if (inRange(code_point, 0x0800, 0xFFFF)) { - count = 2; - offset = 0xE0; - } else if (inRange(code_point, 0x10000, 0x10FFFF)) { - count = 3; - offset = 0xF0; - } - var result = output_byte_stream.emit( - div(code_point, Math.pow(64, count)) + offset); - while (count > 0) { - var temp = div(code_point, Math.pow(64, count - 1)); - result = output_byte_stream.emit(0x80 + (temp % 64)); - count -= 1; - } - return result; - }; - } - - name_to_encoding['utf-8'].getEncoder = function(options) { - return new UTF8Encoder(options); - }; - name_to_encoding['utf-8'].getDecoder = function(options) { - return new UTF8Decoder(options); - }; - - // - // 8. Legacy single-byte encodings - // - - /** - * @constructor - * @param {Array.} index The encoding index. - * @param {{fatal: boolean}} options - */ - function SingleByteDecoder(index, options) { - var fatal = options.fatal; - /** - * @param {ByteInputStream} byte_pointer The byte stream to decode. - * @return {?number} The next code point decoded, or null if not enough - * data exists in the input stream to decode a complete code point. - */ - this.decode = function(byte_pointer) { - var bite = byte_pointer.get(); - if (bite === EOF_byte) { - return EOF_code_point; - } - byte_pointer.offset(1); - if (inRange(bite, 0x00, 0x7F)) { - return bite; - } - var code_point = index[bite - 0x80]; - if (code_point === null) { - return decoderError(fatal); - } - return code_point; - }; - } - - /** - * @constructor - * @param {Array.} index The encoding index. - * @param {{fatal: boolean}} options - */ - function SingleByteEncoder(index, options) { - var fatal = options.fatal; - /** - * @param {ByteOutputStream} output_byte_stream Output byte stream. - * @param {CodePointInputStream} code_point_pointer Input stream. - * @return {number} The last byte emitted. - */ - this.encode = function(output_byte_stream, code_point_pointer) { - var code_point = code_point_pointer.get(); - if (code_point === EOF_code_point) { - return EOF_byte; - } - code_point_pointer.offset(1); - if (inRange(code_point, 0x0000, 0x007F)) { - return output_byte_stream.emit(code_point); - } - var pointer = indexPointerFor(code_point, index); - if (pointer === null) { - encoderError(code_point); - } - return output_byte_stream.emit(pointer + 0x80); - }; - } - - (function() { - encodings.forEach(function(category) { - if (category.heading !== 'Legacy single-byte encodings') - return; - category.encodings.forEach(function(encoding) { - var idx = index(encoding.name); - encoding.getDecoder = function(options) { - return new SingleByteDecoder(idx, options); - }; - encoding.getEncoder = function(options) { - return new SingleByteEncoder(idx, options); - }; - }); - }); - }()); - - // - // 9. Legacy multi-byte Chinese (simplified) encodings - // - - // 9.1 gbk - - /** - * @constructor - * @param {boolean} gb18030 True if decoding gb18030, false otherwise. - * @param {{fatal: boolean}} options - */ - function GBKDecoder(gb18030, options) { - var fatal = options.fatal; - var /** @type {number} */ gbk_first = 0x00, - /** @type {number} */ gbk_second = 0x00, - /** @type {number} */ gbk_third = 0x00; - /** - * @param {ByteInputStream} byte_pointer The byte stream to decode. - * @return {?number} The next code point decoded, or null if not enough - * data exists in the input stream to decode a complete code point. - */ - this.decode = function(byte_pointer) { - var bite = byte_pointer.get(); - if (bite === EOF_byte && gbk_first === 0x00 && - gbk_second === 0x00 && gbk_third === 0x00) { - return EOF_code_point; - } - if (bite === EOF_byte && - (gbk_first !== 0x00 || gbk_second !== 0x00 || gbk_third !== 0x00)) { - gbk_first = 0x00; - gbk_second = 0x00; - gbk_third = 0x00; - decoderError(fatal); - } - byte_pointer.offset(1); - var code_point; - if (gbk_third !== 0x00) { - code_point = null; - if (inRange(bite, 0x30, 0x39)) { - code_point = indexGB18030CodePointFor( - (((gbk_first - 0x81) * 10 + (gbk_second - 0x30)) * 126 + - (gbk_third - 0x81)) * 10 + bite - 0x30); - } - gbk_first = 0x00; - gbk_second = 0x00; - gbk_third = 0x00; - if (code_point === null) { - byte_pointer.offset(-3); - return decoderError(fatal); - } - return code_point; - } - if (gbk_second !== 0x00) { - if (inRange(bite, 0x81, 0xFE)) { - gbk_third = bite; - return null; - } - byte_pointer.offset(-2); - gbk_first = 0x00; - gbk_second = 0x00; - return decoderError(fatal); - } - if (gbk_first !== 0x00) { - if (inRange(bite, 0x30, 0x39) && gb18030) { - gbk_second = bite; - return null; - } - var lead = gbk_first; - var pointer = null; - gbk_first = 0x00; - var offset = bite < 0x7F ? 0x40 : 0x41; - if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0x80, 0xFE)) { - pointer = (lead - 0x81) * 190 + (bite - offset); - } - code_point = pointer === null ? null : - indexCodePointFor(pointer, index('gbk')); - if (pointer === null) { - byte_pointer.offset(-1); - } - if (code_point === null) { - return decoderError(fatal); - } - return code_point; - } - if (inRange(bite, 0x00, 0x7F)) { - return bite; - } - if (bite === 0x80) { - return 0x20AC; - } - if (inRange(bite, 0x81, 0xFE)) { - gbk_first = bite; - return null; - } - return decoderError(fatal); - }; - } - - /** - * @constructor - * @param {boolean} gb18030 True if decoding gb18030, false otherwise. - * @param {{fatal: boolean}} options - */ - function GBKEncoder(gb18030, options) { - var fatal = options.fatal; - /** - * @param {ByteOutputStream} output_byte_stream Output byte stream. - * @param {CodePointInputStream} code_point_pointer Input stream. - * @return {number} The last byte emitted. - */ - this.encode = function(output_byte_stream, code_point_pointer) { - var code_point = code_point_pointer.get(); - if (code_point === EOF_code_point) { - return EOF_byte; - } - code_point_pointer.offset(1); - if (inRange(code_point, 0x0000, 0x007F)) { - return output_byte_stream.emit(code_point); - } - var pointer = indexPointerFor(code_point, index('gbk')); - if (pointer !== null) { - var lead = div(pointer, 190) + 0x81; - var trail = pointer % 190; - var offset = trail < 0x3F ? 0x40 : 0x41; - return output_byte_stream.emit(lead, trail + offset); - } - if (pointer === null && !gb18030) { - return encoderError(code_point); - } - pointer = indexGB18030PointerFor(code_point); - var byte1 = div(div(div(pointer, 10), 126), 10); - pointer = pointer - byte1 * 10 * 126 * 10; - var byte2 = div(div(pointer, 10), 126); - pointer = pointer - byte2 * 10 * 126; - var byte3 = div(pointer, 10); - var byte4 = pointer - byte3 * 10; - return output_byte_stream.emit(byte1 + 0x81, - byte2 + 0x30, - byte3 + 0x81, - byte4 + 0x30); - }; - } - - name_to_encoding['gbk'].getEncoder = function(options) { - return new GBKEncoder(false, options); - }; - name_to_encoding['gbk'].getDecoder = function(options) { - return new GBKDecoder(false, options); - }; - - // 9.2 gb18030 - name_to_encoding['gb18030'].getEncoder = function(options) { - return new GBKEncoder(true, options); - }; - name_to_encoding['gb18030'].getDecoder = function(options) { - return new GBKDecoder(true, options); - }; - - // 9.3 hz-gb-2312 - - /** - * @constructor - * @param {{fatal: boolean}} options - */ - function HZGB2312Decoder(options) { - var fatal = options.fatal; - var /** @type {boolean} */ hzgb2312 = false, - /** @type {number} */ hzgb2312_lead = 0x00; - /** - * @param {ByteInputStream} byte_pointer The byte stream to decode. - * @return {?number} The next code point decoded, or null if not enough - * data exists in the input stream to decode a complete code point. - */ - this.decode = function(byte_pointer) { - var bite = byte_pointer.get(); - if (bite === EOF_byte && hzgb2312_lead === 0x00) { - return EOF_code_point; - } - if (bite === EOF_byte && hzgb2312_lead !== 0x00) { - hzgb2312_lead = 0x00; - return decoderError(fatal); - } - byte_pointer.offset(1); - if (hzgb2312_lead === 0x7E) { - hzgb2312_lead = 0x00; - if (bite === 0x7B) { - hzgb2312 = true; - return null; - } - if (bite === 0x7D) { - hzgb2312 = false; - return null; - } - if (bite === 0x7E) { - return 0x007E; - } - if (bite === 0x0A) { - return null; - } - byte_pointer.offset(-1); - return decoderError(fatal); - } - if (hzgb2312_lead !== 0x00) { - var lead = hzgb2312_lead; - hzgb2312_lead = 0x00; - var code_point = null; - if (inRange(bite, 0x21, 0x7E)) { - code_point = indexCodePointFor((lead - 1) * 190 + - (bite + 0x3F), index('gbk')); - } - if (bite === 0x0A) { - hzgb2312 = false; - } - if (code_point === null) { - return decoderError(fatal); - } - return code_point; - } - if (bite === 0x7E) { - hzgb2312_lead = 0x7E; - return null; - } - if (hzgb2312) { - if (inRange(bite, 0x20, 0x7F)) { - hzgb2312_lead = bite; - return null; - } - if (bite === 0x0A) { - hzgb2312 = false; - } - return decoderError(fatal); - } - if (inRange(bite, 0x00, 0x7F)) { - return bite; - } - return decoderError(fatal); - }; - } - - /** - * @constructor - * @param {{fatal: boolean}} options - */ - function HZGB2312Encoder(options) { - var fatal = options.fatal; - var hzgb2312 = false; - /** - * @param {ByteOutputStream} output_byte_stream Output byte stream. - * @param {CodePointInputStream} code_point_pointer Input stream. - * @return {number} The last byte emitted. - */ - this.encode = function(output_byte_stream, code_point_pointer) { - var code_point = code_point_pointer.get(); - if (code_point === EOF_code_point) { - return EOF_byte; - } - code_point_pointer.offset(1); - if (inRange(code_point, 0x0000, 0x007F) && hzgb2312) { - code_point_pointer.offset(-1); - hzgb2312 = false; - return output_byte_stream.emit(0x7E, 0x7D); - } - if (code_point === 0x007E) { - return output_byte_stream.emit(0x7E, 0x7E); - } - if (inRange(code_point, 0x0000, 0x007F)) { - return output_byte_stream.emit(code_point); - } - if (!hzgb2312) { - code_point_pointer.offset(-1); - hzgb2312 = true; - return output_byte_stream.emit(0x7E, 0x7B); - } - var pointer = indexPointerFor(code_point, index('gbk')); - if (pointer === null) { - return encoderError(code_point); - } - var lead = div(pointer, 190) + 1; - var trail = pointer % 190 - 0x3F; - if (!inRange(lead, 0x21, 0x7E) || !inRange(trail, 0x21, 0x7E)) { - return encoderError(code_point); - } - return output_byte_stream.emit(lead, trail); - }; - } - - name_to_encoding['hz-gb-2312'].getEncoder = function(options) { - return new HZGB2312Encoder(options); - }; - name_to_encoding['hz-gb-2312'].getDecoder = function(options) { - return new HZGB2312Decoder(options); - }; - - // - // 10. Legacy multi-byte Chinese (traditional) encodings - // - - // 10.1 big5 - - /** - * @constructor - * @param {{fatal: boolean}} options - */ - function Big5Decoder(options) { - var fatal = options.fatal; - var /** @type {number} */ big5_lead = 0x00, - /** @type {?number} */ big5_pending = null; - - /** - * @param {ByteInputStream} byte_pointer The byte steram to decode. - * @return {?number} The next code point decoded, or null if not enough - * data exists in the input stream to decode a complete code point. - */ - this.decode = function(byte_pointer) { - // NOTE: Hack to support emitting two code points - if (big5_pending !== null) { - var pending = big5_pending; - big5_pending = null; - return pending; - } - var bite = byte_pointer.get(); - if (bite === EOF_byte && big5_lead === 0x00) { - return EOF_code_point; - } - if (bite === EOF_byte && big5_lead !== 0x00) { - big5_lead = 0x00; - return decoderError(fatal); - } - byte_pointer.offset(1); - if (big5_lead !== 0x00) { - var lead = big5_lead; - var pointer = null; - big5_lead = 0x00; - var offset = bite < 0x7F ? 0x40 : 0x62; - if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0xA1, 0xFE)) { - pointer = (lead - 0x81) * 157 + (bite - offset); - } - if (pointer === 1133) { - big5_pending = 0x0304; - return 0x00CA; - } - if (pointer === 1135) { - big5_pending = 0x030C; - return 0x00CA; - } - if (pointer === 1164) { - big5_pending = 0x0304; - return 0x00EA; - } - if (pointer === 1166) { - big5_pending = 0x030C; - return 0x00EA; - } - var code_point = (pointer === null) ? null : - indexCodePointFor(pointer, index('big5')); - if (pointer === null) { - byte_pointer.offset(-1); - } - if (code_point === null) { - return decoderError(fatal); - } - return code_point; - } - if (inRange(bite, 0x00, 0x7F)) { - return bite; - } - if (inRange(bite, 0x81, 0xFE)) { - big5_lead = bite; - return null; - } - return decoderError(fatal); - }; - } - - /** - * @constructor - * @param {{fatal: boolean}} options - */ - function Big5Encoder(options) { - var fatal = options.fatal; - /** - * @param {ByteOutputStream} output_byte_stream Output byte stream. - * @param {CodePointInputStream} code_point_pointer Input stream. - * @return {number} The last byte emitted. - */ - this.encode = function(output_byte_stream, code_point_pointer) { - var code_point = code_point_pointer.get(); - if (code_point === EOF_code_point) { - return EOF_byte; - } - code_point_pointer.offset(1); - if (inRange(code_point, 0x0000, 0x007F)) { - return output_byte_stream.emit(code_point); - } - var pointer = indexPointerFor(code_point, index('big5')); - if (pointer === null) { - return encoderError(code_point); - } - var lead = div(pointer, 157) + 0x81; - //if (lead < 0xA1) { - // return encoderError(code_point); - //} - var trail = pointer % 157; - var offset = trail < 0x3F ? 0x40 : 0x62; - return output_byte_stream.emit(lead, trail + offset); - }; - } - - name_to_encoding['big5'].getEncoder = function(options) { - return new Big5Encoder(options); - }; - name_to_encoding['big5'].getDecoder = function(options) { - return new Big5Decoder(options); - }; - - - // - // 11. Legacy multi-byte Japanese encodings - // - - // 11.1 euc.jp - - /** - * @constructor - * @param {{fatal: boolean}} options - */ - function EUCJPDecoder(options) { - var fatal = options.fatal; - var /** @type {number} */ eucjp_first = 0x00, - /** @type {number} */ eucjp_second = 0x00; - /** - * @param {ByteInputStream} byte_pointer The byte stream to decode. - * @return {?number} The next code point decoded, or null if not enough - * data exists in the input stream to decode a complete code point. - */ - this.decode = function(byte_pointer) { - var bite = byte_pointer.get(); - if (bite === EOF_byte) { - if (eucjp_first === 0x00 && eucjp_second === 0x00) { - return EOF_code_point; - } - eucjp_first = 0x00; - eucjp_second = 0x00; - return decoderError(fatal); - } - byte_pointer.offset(1); - - var lead, code_point; - if (eucjp_second !== 0x00) { - lead = eucjp_second; - eucjp_second = 0x00; - code_point = null; - if (inRange(lead, 0xA1, 0xFE) && inRange(bite, 0xA1, 0xFE)) { - code_point = indexCodePointFor((lead - 0xA1) * 94 + bite - 0xA1, - index('jis0212')); - } - if (!inRange(bite, 0xA1, 0xFE)) { - byte_pointer.offset(-1); - } - if (code_point === null) { - return decoderError(fatal); - } - return code_point; - } - if (eucjp_first === 0x8E && inRange(bite, 0xA1, 0xDF)) { - eucjp_first = 0x00; - return 0xFF61 + bite - 0xA1; - } - if (eucjp_first === 0x8F && inRange(bite, 0xA1, 0xFE)) { - eucjp_first = 0x00; - eucjp_second = bite; - return null; - } - if (eucjp_first !== 0x00) { - lead = eucjp_first; - eucjp_first = 0x00; - code_point = null; - if (inRange(lead, 0xA1, 0xFE) && inRange(bite, 0xA1, 0xFE)) { - code_point = indexCodePointFor((lead - 0xA1) * 94 + bite - 0xA1, - index('jis0208')); - } - if (!inRange(bite, 0xA1, 0xFE)) { - byte_pointer.offset(-1); - } - if (code_point === null) { - return decoderError(fatal); - } - return code_point; - } - if (inRange(bite, 0x00, 0x7F)) { - return bite; - } - if (bite === 0x8E || bite === 0x8F || (inRange(bite, 0xA1, 0xFE))) { - eucjp_first = bite; - return null; - } - return decoderError(fatal); - }; - } - - /** - * @constructor - * @param {{fatal: boolean}} options - */ - function EUCJPEncoder(options) { - var fatal = options.fatal; - /** - * @param {ByteOutputStream} output_byte_stream Output byte stream. - * @param {CodePointInputStream} code_point_pointer Input stream. - * @return {number} The last byte emitted. - */ - this.encode = function(output_byte_stream, code_point_pointer) { - var code_point = code_point_pointer.get(); - if (code_point === EOF_code_point) { - return EOF_byte; - } - code_point_pointer.offset(1); - if (inRange(code_point, 0x0000, 0x007F)) { - return output_byte_stream.emit(code_point); - } - if (code_point === 0x00A5) { - return output_byte_stream.emit(0x5C); - } - if (code_point === 0x203E) { - return output_byte_stream.emit(0x7E); - } - if (inRange(code_point, 0xFF61, 0xFF9F)) { - return output_byte_stream.emit(0x8E, code_point - 0xFF61 + 0xA1); - } - - var pointer = indexPointerFor(code_point, index('jis0208')); - if (pointer === null) { - return encoderError(code_point); - } - var lead = div(pointer, 94) + 0xA1; - var trail = pointer % 94 + 0xA1; - return output_byte_stream.emit(lead, trail); - }; - } - - name_to_encoding['euc-jp'].getEncoder = function(options) { - return new EUCJPEncoder(options); - }; - name_to_encoding['euc-jp'].getDecoder = function(options) { - return new EUCJPDecoder(options); - }; - - // 11.2 iso-2022-jp - - /** - * @constructor - * @param {{fatal: boolean}} options - */ - function ISO2022JPDecoder(options) { - var fatal = options.fatal; - /** @enum */ - var state = { - ASCII: 0, - escape_start: 1, - escape_middle: 2, - escape_final: 3, - lead: 4, - trail: 5, - Katakana: 6 - }; - var /** @type {number} */ iso2022jp_state = state.ASCII, - /** @type {boolean} */ iso2022jp_jis0212 = false, - /** @type {number} */ iso2022jp_lead = 0x00; - /** - * @param {ByteInputStream} byte_pointer The byte stream to decode. - * @return {?number} The next code point decoded, or null if not enough - * data exists in the input stream to decode a complete code point. - */ - this.decode = function(byte_pointer) { - var bite = byte_pointer.get(); - if (bite !== EOF_byte) { - byte_pointer.offset(1); - } - switch (iso2022jp_state) { - default: - case state.ASCII: - if (bite === 0x1B) { - iso2022jp_state = state.escape_start; - return null; - } - if (inRange(bite, 0x00, 0x7F)) { - return bite; - } - if (bite === EOF_byte) { - return EOF_code_point; - } - return decoderError(fatal); - - case state.escape_start: - if (bite === 0x24 || bite === 0x28) { - iso2022jp_lead = bite; - iso2022jp_state = state.escape_middle; - return null; - } - if (bite !== EOF_byte) { - byte_pointer.offset(-1); - } - iso2022jp_state = state.ASCII; - return decoderError(fatal); - - case state.escape_middle: - var lead = iso2022jp_lead; - iso2022jp_lead = 0x00; - if (lead === 0x24 && (bite === 0x40 || bite === 0x42)) { - iso2022jp_jis0212 = false; - iso2022jp_state = state.lead; - return null; - } - if (lead === 0x24 && bite === 0x28) { - iso2022jp_state = state.escape_final; - return null; - } - if (lead === 0x28 && (bite === 0x42 || bite === 0x4A)) { - iso2022jp_state = state.ASCII; - return null; - } - if (lead === 0x28 && bite === 0x49) { - iso2022jp_state = state.Katakana; - return null; - } - if (bite === EOF_byte) { - byte_pointer.offset(-1); - } else { - byte_pointer.offset(-2); - } - iso2022jp_state = state.ASCII; - return decoderError(fatal); - - case state.escape_final: - if (bite === 0x44) { - iso2022jp_jis0212 = true; - iso2022jp_state = state.lead; - return null; - } - if (bite === EOF_byte) { - byte_pointer.offset(-2); - } else { - byte_pointer.offset(-3); - } - iso2022jp_state = state.ASCII; - return decoderError(fatal); - - case state.lead: - if (bite === 0x0A) { - iso2022jp_state = state.ASCII; - return decoderError(fatal, 0x000A); - } - if (bite === 0x1B) { - iso2022jp_state = state.escape_start; - return null; - } - if (bite === EOF_byte) { - return EOF_code_point; - } - iso2022jp_lead = bite; - iso2022jp_state = state.trail; - return null; - - case state.trail: - iso2022jp_state = state.lead; - if (bite === EOF_byte) { - return decoderError(fatal); - } - var code_point = null; - var pointer = (iso2022jp_lead - 0x21) * 94 + bite - 0x21; - if (inRange(iso2022jp_lead, 0x21, 0x7E) && - inRange(bite, 0x21, 0x7E)) { - code_point = (iso2022jp_jis0212 === false) ? - indexCodePointFor(pointer, index('jis0208')) : - indexCodePointFor(pointer, index('jis0212')); - } - if (code_point === null) { - return decoderError(fatal); - } - return code_point; - - case state.Katakana: - if (bite === 0x1B) { - iso2022jp_state = state.escape_start; - return null; - } - if (inRange(bite, 0x21, 0x5F)) { - return 0xFF61 + bite - 0x21; - } - if (bite === EOF_byte) { - return EOF_code_point; - } - return decoderError(fatal); - } - }; - } - - /** - * @constructor - * @param {{fatal: boolean}} options - */ - function ISO2022JPEncoder(options) { - var fatal = options.fatal; - /** @enum */ - var state = { - ASCII: 0, - lead: 1, - Katakana: 2 - }; - var /** @type {number} */ iso2022jp_state = state.ASCII; - /** - * @param {ByteOutputStream} output_byte_stream Output byte stream. - * @param {CodePointInputStream} code_point_pointer Input stream. - * @return {number} The last byte emitted. - */ - this.encode = function(output_byte_stream, code_point_pointer) { - var code_point = code_point_pointer.get(); - if (code_point === EOF_code_point) { - return EOF_byte; - } - code_point_pointer.offset(1); - if ((inRange(code_point, 0x0000, 0x007F) || - code_point === 0x00A5 || code_point === 0x203E) && - iso2022jp_state !== state.ASCII) { - code_point_pointer.offset(-1); - iso2022jp_state = state.ASCII; - return output_byte_stream.emit(0x1B, 0x28, 0x42); - } - if (inRange(code_point, 0x0000, 0x007F)) { - return output_byte_stream.emit(code_point); - } - if (code_point === 0x00A5) { - return output_byte_stream.emit(0x5C); - } - if (code_point === 0x203E) { - return output_byte_stream.emit(0x7E); - } - if (inRange(code_point, 0xFF61, 0xFF9F) && - iso2022jp_state !== state.Katakana) { - code_point_pointer.offset(-1); - iso2022jp_state = state.Katakana; - return output_byte_stream.emit(0x1B, 0x28, 0x49); - } - if (inRange(code_point, 0xFF61, 0xFF9F)) { - return output_byte_stream.emit(code_point - 0xFF61 - 0x21); - } - if (iso2022jp_state !== state.lead) { - code_point_pointer.offset(-1); - iso2022jp_state = state.lead; - return output_byte_stream.emit(0x1B, 0x24, 0x42); - } - var pointer = indexPointerFor(code_point, index('jis0208')); - if (pointer === null) { - return encoderError(code_point); - } - var lead = div(pointer, 94) + 0x21; - var trail = pointer % 94 + 0x21; - return output_byte_stream.emit(lead, trail); - }; - } - - name_to_encoding['iso-2022-jp'].getEncoder = function(options) { - return new ISO2022JPEncoder(options); - }; - name_to_encoding['iso-2022-jp'].getDecoder = function(options) { - return new ISO2022JPDecoder(options); - }; - - // 11.3 shift_jis - - /** - * @constructor - * @param {{fatal: boolean}} options - */ - function ShiftJISDecoder(options) { - var fatal = options.fatal; - var /** @type {number} */ shiftjis_lead = 0x00; - /** - * @param {ByteInputStream} byte_pointer The byte stream to decode. - * @return {?number} The next code point decoded, or null if not enough - * data exists in the input stream to decode a complete code point. - */ - this.decode = function(byte_pointer) { - var bite = byte_pointer.get(); - if (bite === EOF_byte && shiftjis_lead === 0x00) { - return EOF_code_point; - } - if (bite === EOF_byte && shiftjis_lead !== 0x00) { - shiftjis_lead = 0x00; - return decoderError(fatal); - } - byte_pointer.offset(1); - if (shiftjis_lead !== 0x00) { - var lead = shiftjis_lead; - shiftjis_lead = 0x00; - if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0x80, 0xFC)) { - var offset = (bite < 0x7F) ? 0x40 : 0x41; - var lead_offset = (lead < 0xA0) ? 0x81 : 0xC1; - var code_point = indexCodePointFor((lead - lead_offset) * 188 + - bite - offset, index('jis0208')); - if (code_point === null) { - return decoderError(fatal); - } - return code_point; - } - byte_pointer.offset(-1); - return decoderError(fatal); - } - if (inRange(bite, 0x00, 0x80)) { - return bite; - } - if (inRange(bite, 0xA1, 0xDF)) { - return 0xFF61 + bite - 0xA1; - } - if (inRange(bite, 0x81, 0x9F) || inRange(bite, 0xE0, 0xFC)) { - shiftjis_lead = bite; - return null; - } - return decoderError(fatal); - }; - } - - /** - * @constructor - * @param {{fatal: boolean}} options - */ - function ShiftJISEncoder(options) { - var fatal = options.fatal; - /** - * @param {ByteOutputStream} output_byte_stream Output byte stream. - * @param {CodePointInputStream} code_point_pointer Input stream. - * @return {number} The last byte emitted. - */ - this.encode = function(output_byte_stream, code_point_pointer) { - var code_point = code_point_pointer.get(); - if (code_point === EOF_code_point) { - return EOF_byte; - } - code_point_pointer.offset(1); - if (inRange(code_point, 0x0000, 0x0080)) { - return output_byte_stream.emit(code_point); - } - if (code_point === 0x00A5) { - return output_byte_stream.emit(0x5C); - } - if (code_point === 0x203E) { - return output_byte_stream.emit(0x7E); - } - if (inRange(code_point, 0xFF61, 0xFF9F)) { - return output_byte_stream.emit(code_point - 0xFF61 + 0xA1); - } - var pointer = indexPointerFor(code_point, index('jis0208')); - if (pointer === null) { - return encoderError(code_point); - } - var lead = div(pointer, 188); - var lead_offset = lead < 0x1F ? 0x81 : 0xC1; - var trail = pointer % 188; - var offset = trail < 0x3F ? 0x40 : 0x41; - return output_byte_stream.emit(lead + lead_offset, trail + offset); - }; - } - - name_to_encoding['shift_jis'].getEncoder = function(options) { - return new ShiftJISEncoder(options); - }; - name_to_encoding['shift_jis'].getDecoder = function(options) { - return new ShiftJISDecoder(options); - }; - - // - // 12. Legacy multi-byte Korean encodings - // - - // 12.1 euc-kr - - /** - * @constructor - * @param {{fatal: boolean}} options - */ - function EUCKRDecoder(options) { - var fatal = options.fatal; - var /** @type {number} */ euckr_lead = 0x00; - /** - * @param {ByteInputStream} byte_pointer The byte stream to decode. - * @return {?number} The next code point decoded, or null if not enough - * data exists in the input stream to decode a complete code point. - */ - this.decode = function(byte_pointer) { - var bite = byte_pointer.get(); - if (bite === EOF_byte && euckr_lead === 0) { - return EOF_code_point; - } - if (bite === EOF_byte && euckr_lead !== 0) { - euckr_lead = 0x00; - return decoderError(fatal); - } - byte_pointer.offset(1); - if (euckr_lead !== 0x00) { - var lead = euckr_lead; - var pointer = null; - euckr_lead = 0x00; - - if (inRange(lead, 0x81, 0xC6)) { - var temp = (26 + 26 + 126) * (lead - 0x81); - if (inRange(bite, 0x41, 0x5A)) { - pointer = temp + bite - 0x41; - } else if (inRange(bite, 0x61, 0x7A)) { - pointer = temp + 26 + bite - 0x61; - } else if (inRange(bite, 0x81, 0xFE)) { - pointer = temp + 26 + 26 + bite - 0x81; - } - } - - if (inRange(lead, 0xC7, 0xFD) && inRange(bite, 0xA1, 0xFE)) { - pointer = (26 + 26 + 126) * (0xC7 - 0x81) + (lead - 0xC7) * 94 + - (bite - 0xA1); - } - - var code_point = (pointer === null) ? null : - indexCodePointFor(pointer, index('euc-kr')); - if (pointer === null) { - byte_pointer.offset(-1); - } - if (code_point === null) { - return decoderError(fatal); - } - return code_point; - } - - if (inRange(bite, 0x00, 0x7F)) { - return bite; - } - - if (inRange(bite, 0x81, 0xFD)) { - euckr_lead = bite; - return null; - } - - return decoderError(fatal); - }; - } - - /** - * @constructor - * @param {{fatal: boolean}} options - */ - function EUCKREncoder(options) { - var fatal = options.fatal; - /** - * @param {ByteOutputStream} output_byte_stream Output byte stream. - * @param {CodePointInputStream} code_point_pointer Input stream. - * @return {number} The last byte emitted. - */ - this.encode = function(output_byte_stream, code_point_pointer) { - var code_point = code_point_pointer.get(); - if (code_point === EOF_code_point) { - return EOF_byte; - } - code_point_pointer.offset(1); - if (inRange(code_point, 0x0000, 0x007F)) { - return output_byte_stream.emit(code_point); - } - var pointer = indexPointerFor(code_point, index('euc-kr')); - if (pointer === null) { - return encoderError(code_point); - } - var lead, trail; - if (pointer < ((26 + 26 + 126) * (0xC7 - 0x81))) { - lead = div(pointer, (26 + 26 + 126)) + 0x81; - trail = pointer % (26 + 26 + 126); - var offset = trail < 26 ? 0x41 : trail < 26 + 26 ? 0x47 : 0x4D; - return output_byte_stream.emit(lead, trail + offset); - } - pointer = pointer - (26 + 26 + 126) * (0xC7 - 0x81); - lead = div(pointer, 94) + 0xC7; - trail = pointer % 94 + 0xA1; - return output_byte_stream.emit(lead, trail); - }; - } - - name_to_encoding['euc-kr'].getEncoder = function(options) { - return new EUCKREncoder(options); - }; - name_to_encoding['euc-kr'].getDecoder = function(options) { - return new EUCKRDecoder(options); - }; - - - // - // 13. Legacy utf-16 encodings - // - - // 13.1 utf-16 - - /** - * @constructor - * @param {boolean} utf16_be True if big-endian, false if little-endian. - * @param {{fatal: boolean}} options - */ - function UTF16Decoder(utf16_be, options) { - var fatal = options.fatal; - var /** @type {?number} */ utf16_lead_byte = null, - /** @type {?number} */ utf16_lead_surrogate = null; - /** - * @param {ByteInputStream} byte_pointer The byte stream to decode. - * @return {?number} The next code point decoded, or null if not enough - * data exists in the input stream to decode a complete code point. - */ - this.decode = function(byte_pointer) { - var bite = byte_pointer.get(); - if (bite === EOF_byte && utf16_lead_byte === null && - utf16_lead_surrogate === null) { - return EOF_code_point; - } - if (bite === EOF_byte && (utf16_lead_byte !== null || - utf16_lead_surrogate !== null)) { - return decoderError(fatal); - } - byte_pointer.offset(1); - if (utf16_lead_byte === null) { - utf16_lead_byte = bite; - return null; - } - var code_point; - if (utf16_be) { - code_point = (utf16_lead_byte << 8) + bite; - } else { - code_point = (bite << 8) + utf16_lead_byte; - } - utf16_lead_byte = null; - if (utf16_lead_surrogate !== null) { - var lead_surrogate = utf16_lead_surrogate; - utf16_lead_surrogate = null; - if (inRange(code_point, 0xDC00, 0xDFFF)) { - return 0x10000 + (lead_surrogate - 0xD800) * 0x400 + - (code_point - 0xDC00); - } - byte_pointer.offset(-2); - return decoderError(fatal); - } - if (inRange(code_point, 0xD800, 0xDBFF)) { - utf16_lead_surrogate = code_point; - return null; - } - if (inRange(code_point, 0xDC00, 0xDFFF)) { - return decoderError(fatal); - } - return code_point; - }; - } - - /** - * @constructor - * @param {boolean} utf16_be True if big-endian, false if little-endian. - * @param {{fatal: boolean}} options - */ - function UTF16Encoder(utf16_be, options) { - var fatal = options.fatal; - /** - * @param {ByteOutputStream} output_byte_stream Output byte stream. - * @param {CodePointInputStream} code_point_pointer Input stream. - * @return {number} The last byte emitted. - */ - this.encode = function(output_byte_stream, code_point_pointer) { - function convert_to_bytes(code_unit) { - var byte1 = code_unit >> 8; - var byte2 = code_unit & 0x00FF; - if (utf16_be) { - return output_byte_stream.emit(byte1, byte2); - } - return output_byte_stream.emit(byte2, byte1); - } - var code_point = code_point_pointer.get(); - if (code_point === EOF_code_point) { - return EOF_byte; - } - code_point_pointer.offset(1); - if (inRange(code_point, 0xD800, 0xDFFF)) { - encoderError(code_point); - } - if (code_point <= 0xFFFF) { - return convert_to_bytes(code_point); - } - var lead = div((code_point - 0x10000), 0x400) + 0xD800; - var trail = ((code_point - 0x10000) % 0x400) + 0xDC00; - convert_to_bytes(lead); - return convert_to_bytes(trail); - }; - } - - name_to_encoding['utf-16le'].getEncoder = function(options) { - return new UTF16Encoder(false, options); - }; - name_to_encoding['utf-16le'].getDecoder = function(options) { - return new UTF16Decoder(false, options); - }; - - // 13.2 utf-16be - name_to_encoding['utf-16be'].getEncoder = function(options) { - return new UTF16Encoder(true, options); - }; - name_to_encoding['utf-16be'].getDecoder = function(options) { - return new UTF16Decoder(true, options); - }; - - - // NOTE: currently unused - /** - * @param {string} label The encoding label. - * @param {ByteInputStream} input_stream The byte stream to test. - */ - function detectEncoding(label, input_stream) { - if (input_stream.match([0xFF, 0xFE])) { - input_stream.offset(2); - return 'utf-16le'; - } - if (input_stream.match([0xFE, 0xFF])) { - input_stream.offset(2); - return 'utf-16be'; - } - if (input_stream.match([0xEF, 0xBB, 0xBF])) { - input_stream.offset(3); - return 'utf-8'; - } - return label; - } - - // - // Implementation of Text Encoding Web API - // - - /** @const */ var DEFAULT_ENCODING = 'utf-8'; - - /** - * @constructor - * @param {string=} opt_encoding The label of the encoding; - * defaults to 'utf-8'. - * @param {{fatal: boolean}=} options - */ - function TextEncoder(opt_encoding, options) { - if (!(this instanceof TextEncoder)) { - throw new TypeError('Constructor cannot be called as a function'); - } - opt_encoding = opt_encoding ? String(opt_encoding) : DEFAULT_ENCODING; - options = Object(options); - /** @private */ - this._encoding = getEncoding(opt_encoding); - if (this._encoding === null || (this._encoding.name !== 'utf-8' && - this._encoding.name !== 'utf-16le' && - this._encoding.name !== 'utf-16be')) - throw new TypeError('Unknown encoding: ' + opt_encoding); - /** @private @type {boolean} */ - this._streaming = false; - /** @private */ - this._encoder = null; - /** @private @type {{fatal: boolean}=} */ - this._options = { fatal: Boolean(options.fatal) }; - - if (Object.defineProperty) { - Object.defineProperty( - this, 'encoding', - { get: function() { return this._encoding.name; } }); - } else { - this.encoding = this._encoding.name; - } - - return this; - } - - TextEncoder.prototype = { - /** - * @param {string=} opt_string The string to encode. - * @param {{stream: boolean}=} options - */ - encode: function encode(opt_string, options) { - opt_string = opt_string ? String(opt_string) : ''; - options = Object(options); - // TODO: any options? - if (!this._streaming) { - this._encoder = this._encoding.getEncoder(this._options); - } - this._streaming = Boolean(options.stream); - - var bytes = []; - var output_stream = new ByteOutputStream(bytes); - var input_stream = new CodePointInputStream(opt_string); - while (input_stream.get() !== EOF_code_point) { - this._encoder.encode(output_stream, input_stream); - } - if (!this._streaming) { - var last_byte; - do { - last_byte = this._encoder.encode(output_stream, input_stream); - } while (last_byte !== EOF_byte); - this._encoder = null; - } - return new Uint8Array(bytes); - } - }; - - - /** - * @constructor - * @param {string=} opt_encoding The label of the encoding; - * defaults to 'utf-8'. - * @param {{fatal: boolean}=} options - */ - function TextDecoder(opt_encoding, options) { - if (!(this instanceof TextDecoder)) { - throw new TypeError('Constructor cannot be called as a function'); - } - opt_encoding = opt_encoding ? String(opt_encoding) : DEFAULT_ENCODING; - options = Object(options); - /** @private */ - this._encoding = getEncoding(opt_encoding); - if (this._encoding === null) - throw new TypeError('Unknown encoding: ' + opt_encoding); - - /** @private @type {boolean} */ - this._streaming = false; - /** @private */ - this._decoder = null; - /** @private @type {{fatal: boolean}=} */ - this._options = { fatal: Boolean(options.fatal) }; - - if (Object.defineProperty) { - Object.defineProperty( - this, 'encoding', - { get: function() { return this._encoding.name; } }); - } else { - this.encoding = this._encoding.name; - } - - return this; - } - - // TODO: Issue if input byte stream is offset by decoder - // TODO: BOM detection will not work if stream header spans multiple calls - // (last N bytes of previous stream may need to be retained?) - TextDecoder.prototype = { - /** - * @param {ArrayBufferView=} opt_view The buffer of bytes to decode. - * @param {{stream: boolean}=} options - */ - decode: function decode(opt_view, options) { - if (opt_view && !('buffer' in opt_view && 'byteOffset' in opt_view && - 'byteLength' in opt_view)) { - throw new TypeError('Expected ArrayBufferView'); - } else if (!opt_view) { - opt_view = new Uint8Array(0); - } - options = Object(options); - - if (!this._streaming) { - this._decoder = this._encoding.getDecoder(this._options); - this._BOMseen = false; - } - this._streaming = Boolean(options.stream); - - var bytes = new Uint8Array(opt_view.buffer, - opt_view.byteOffset, - opt_view.byteLength); - var input_stream = new ByteInputStream(bytes); - - var output_stream = new CodePointOutputStream(), code_point; - while (input_stream.get() !== EOF_byte) { - code_point = this._decoder.decode(input_stream); - if (code_point !== null && code_point !== EOF_code_point) { - output_stream.emit(code_point); - } - } - if (!this._streaming) { - do { - code_point = this._decoder.decode(input_stream); - if (code_point !== null && code_point !== EOF_code_point) { - output_stream.emit(code_point); - } - } while (code_point !== EOF_code_point && - input_stream.get() != EOF_byte); - this._decoder = null; - } - - var result = output_stream.string(); - if (!this._BOMseen && result.length) { - this._BOMseen = true; - if (['utf-8', 'utf-16le', 'utf-16be'].indexOf(this.encoding) !== -1 && - result.charCodeAt(0) === 0xFEFF) { - result = result.substring(1); - } - } - - return result; - } - }; - - global['TextEncoder'] = global['TextEncoder'] || TextEncoder; - global['TextDecoder'] = global['TextDecoder'] || TextDecoder; -}(this)); - -define("encoding", ["encoding-indexes-shim"], function(){}); - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Based on https://github.com/joyent/node/blob/41e53e557992a7d552a8e23de035f9463da25c99/lib/path.js -define('src/path',[],function() { - - // resolves . and .. elements in a path array with directory names there - // must be no slashes, empty elements, or device names (c:\) in the array - // (so also no leading and trailing slashes - it does not distinguish - // relative and absolute paths) - function normalizeArray(parts, allowAboveRoot) { - // if the path tries to go above the root, `up` ends up > 0 - var up = 0; - for (var i = parts.length - 1; i >= 0; i--) { - var last = parts[i]; - if (last === '.') { - parts.splice(i, 1); - } else if (last === '..') { - parts.splice(i, 1); - up++; - } else if (up) { - parts.splice(i, 1); - up--; - } - } - - // if the path is allowed to go above the root, restore leading ..s - if (allowAboveRoot) { - for (; up--; up) { - parts.unshift('..'); - } - } - - return parts; - } - - // Split a filename into [root, dir, basename, ext], unix version - // 'root' is just a slash, or nothing. - var splitPathRe = - /^(\/?)([\s\S]+\/(?!$)|\/)?((?:\.{1,2}$|[\s\S]+?)?(\.[^.\/]*)?)$/; - var splitPath = function(filename) { - var result = splitPathRe.exec(filename); - return [result[1] || '', result[2] || '', result[3] || '', result[4] || '']; - }; - - // path.resolve([from ...], to) - function resolve() { - var resolvedPath = '', - resolvedAbsolute = false; - - for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { - // XXXidbfs: we don't have process.cwd() so we use '/' as a fallback - var path = (i >= 0) ? arguments[i] : '/'; - - // 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(resolvedPath.split('/').filter(function(p) { - return !!p; - }), !resolvedAbsolute).join('/'); - - return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; - } - - // path.normalize(path) - function normalize(path) { - var isAbsolute = path.charAt(0) === '/', - trailingSlash = path.substr(-1) === '/'; - - // Normalize the path - path = normalizeArray(path.split('/').filter(function(p) { - return !!p; - }), !isAbsolute).join('/'); - - if (!path && !isAbsolute) { - path = '.'; - } - if (path && trailingSlash) { - path += '/'; - } - - return (isAbsolute ? '/' : '') + path; - } - - function join() { - var paths = Array.prototype.slice.call(arguments, 0); - return normalize(paths.filter(function(p, index) { - return p && typeof p === 'string'; - }).join('/')); - } - - // path.relative(from, to) - function relative(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('/'); - } - - function dirname(path) { - var result = splitPath(path), - root = result[0], - dir = result[1]; - - if (!root && !dir) { - // No dirname whatsoever - return '.'; - } - - if (dir) { - // It has a dirname, strip trailing slash - dir = dir.substr(0, dir.length - 1); - } - - return root + dir; - } - - function basename(path, ext) { - var f = splitPath(path)[2]; - // TODO: make this comparison case-insensitive on windows? - if (ext && f.substr(-1 * ext.length) === ext) { - f = f.substr(0, f.length - ext.length); - } - // XXXidbfs: node.js just does `return f` - return f === "" ? "/" : f; - } - - function extname(path) { - return splitPath(path)[3]; - } - - // XXXidbfs: we don't support path.exists() or path.existsSync(), which - // are deprecated, and need a FileSystem instance to work. Use fs.stat(). - - return { - normalize: normalize, - resolve: resolve, - join: join, - relative: relative, - sep: '/', - delimiter: ':', - dirname: dirname, - basename: basename, - extname: extname - }; - -}); - -/* -CryptoJS v3.0.2 -code.google.com/p/crypto-js -(c) 2009-2012 by Jeff Mott. All rights reserved. -code.google.com/p/crypto-js/wiki/License -*/ -var CryptoJS=CryptoJS||function(i,p){var f={},q=f.lib={},j=q.Base=function(){function a(){}return{extend:function(h){a.prototype=this;var d=new a;h&&d.mixIn(h);d.$super=this;return d},create:function(){var a=this.extend();a.init.apply(a,arguments);return a},init:function(){},mixIn:function(a){for(var d in a)a.hasOwnProperty(d)&&(this[d]=a[d]);a.hasOwnProperty("toString")&&(this.toString=a.toString)},clone:function(){return this.$super.extend(this)}}}(),k=q.WordArray=j.extend({init:function(a,h){a= -this.words=a||[];this.sigBytes=h!=p?h:4*a.length},toString:function(a){return(a||m).stringify(this)},concat:function(a){var h=this.words,d=a.words,c=this.sigBytes,a=a.sigBytes;this.clamp();if(c%4)for(var b=0;b>>2]|=(d[b>>>2]>>>24-8*(b%4)&255)<<24-8*((c+b)%4);else if(65535>>2]=d[b>>>2];else h.push.apply(h,d);this.sigBytes+=a;return this},clamp:function(){var a=this.words,b=this.sigBytes;a[b>>>2]&=4294967295<<32-8*(b%4);a.length=i.ceil(b/4)},clone:function(){var a= -j.clone.call(this);a.words=this.words.slice(0);return a},random:function(a){for(var b=[],d=0;d>>2]>>>24-8*(c%4)&255;d.push((e>>>4).toString(16));d.push((e&15).toString(16))}return d.join("")},parse:function(a){for(var b=a.length,d=[],c=0;c>>3]|=parseInt(a.substr(c,2),16)<<24-4*(c%8);return k.create(d,b/2)}},s=r.Latin1={stringify:function(a){for(var b= -a.words,a=a.sigBytes,d=[],c=0;c>>2]>>>24-8*(c%4)&255));return d.join("")},parse:function(a){for(var b=a.length,d=[],c=0;c>>2]|=(a.charCodeAt(c)&255)<<24-8*(c%4);return k.create(d,b)}},g=r.Utf8={stringify:function(a){try{return decodeURIComponent(escape(s.stringify(a)))}catch(b){throw Error("Malformed UTF-8 data");}},parse:function(a){return s.parse(unescape(encodeURIComponent(a)))}},b=q.BufferedBlockAlgorithm=j.extend({reset:function(){this._data=k.create(); -this._nDataBytes=0},_append:function(a){"string"==typeof a&&(a=g.parse(a));this._data.concat(a);this._nDataBytes+=a.sigBytes},_process:function(a){var b=this._data,d=b.words,c=b.sigBytes,e=this.blockSize,f=c/(4*e),f=a?i.ceil(f):i.max((f|0)-this._minBufferSize,0),a=f*e,c=i.min(4*a,c);if(a){for(var g=0;ge;)f(b)&&(8>e&&(k[e]=g(i.pow(b,0.5))),r[e]=g(i.pow(b,1/3)),e++),b++})();var m=[],j=j.SHA256=f.extend({_doReset:function(){this._hash=q.create(k.slice(0))},_doProcessBlock:function(f,g){for(var b=this._hash.words,e=b[0],a=b[1],h=b[2],d=b[3],c=b[4],i=b[5],j=b[6],k=b[7],l=0;64> -l;l++){if(16>l)m[l]=f[g+l]|0;else{var n=m[l-15],o=m[l-2];m[l]=((n<<25|n>>>7)^(n<<14|n>>>18)^n>>>3)+m[l-7]+((o<<15|o>>>17)^(o<<13|o>>>19)^o>>>10)+m[l-16]}n=k+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&i^~c&j)+r[l]+m[l];o=((e<<30|e>>>2)^(e<<19|e>>>13)^(e<<10|e>>>22))+(e&a^e&h^a&h);k=j;j=i;i=c;c=d+n|0;d=h;h=a;a=e;e=n+o|0}b[0]=b[0]+e|0;b[1]=b[1]+a|0;b[2]=b[2]+h|0;b[3]=b[3]+d|0;b[4]=b[4]+c|0;b[5]=b[5]+i|0;b[6]=b[6]+j|0;b[7]=b[7]+k|0},_doFinalize:function(){var f=this._data,g=f.words,b=8*this._nDataBytes, -e=8*f.sigBytes;g[e>>>5]|=128<<24-e%32;g[(e+64>>>9<<4)+15]=b;f.sigBytes=4*g.length;this._process()}});p.SHA256=f._createHelper(j);p.HmacSHA256=f._createHmacHelper(j)})(Math); - -define("crypto-js/rollups/sha256", function(){}); - -define('src/shared',['require','crypto-js/rollups/sha256'],function(require) { - - require("crypto-js/rollups/sha256"); var Crypto = CryptoJS; - - function guid() { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { - var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); - return v.toString(16); - }).toUpperCase(); - } - - function hash(string) { - return Crypto.SHA256(string).toString(Crypto.enc.hex); - } - - function nop() {} - - return { - guid: guid, - hash: hash, - nop: nop - }; - -}); - -/* -Copyright (c) 2012, Alan Kligman -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Mozilla Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -define('src/error',['require'],function(require) { - // - - function EExists(message){ - this.message = message || ''; - } - EExists.prototype = new Error(); - EExists.prototype.name = "EExists"; - EExists.prototype.constructor = EExists; - - function EIsDirectory(message){ - this.message = message || ''; - } - EIsDirectory.prototype = new Error(); - EIsDirectory.prototype.name = "EIsDirectory"; - EIsDirectory.prototype.constructor = EIsDirectory; - - function ENoEntry(message){ - this.message = message || ''; - } - ENoEntry.prototype = new Error(); - ENoEntry.prototype.name = "ENoEntry"; - ENoEntry.prototype.constructor = ENoEntry; - - function EBusy(message){ - this.message = message || ''; - } - EBusy.prototype = new Error(); - EBusy.prototype.name = "EBusy"; - EBusy.prototype.constructor = EBusy; - - function ENotEmpty(message){ - this.message = message || ''; - } - ENotEmpty.prototype = new Error(); - ENotEmpty.prototype.name = "ENotEmpty"; - ENotEmpty.prototype.constructor = ENotEmpty; - - function ENotDirectory(message){ - this.message = message || ''; - } - ENotDirectory.prototype = new Error(); - ENotDirectory.prototype.name = "ENotDirectory"; - ENotDirectory.prototype.constructor = ENotDirectory; - - function EBadFileDescriptor(message){ - this.message = message || ''; - } - EBadFileDescriptor.prototype = new Error(); - EBadFileDescriptor.prototype.name = "EBadFileDescriptor"; - EBadFileDescriptor.prototype.constructor = EBadFileDescriptor; - - function ENotImplemented(message){ - this.message = message || ''; - } - ENotImplemented.prototype = new Error(); - ENotImplemented.prototype.name = "ENotImplemented"; - ENotImplemented.prototype.constructor = ENotImplemented; - - function ENotMounted(message){ - this.message = message || ''; - } - ENotMounted.prototype = new Error(); - ENotMounted.prototype.name = "ENotMounted"; - ENotMounted.prototype.constructor = ENotMounted; - - function EInvalid(message){ - this.message = message || ''; - } - EInvalid.prototype = new Error(); - EInvalid.prototype.name = "EInvalid"; - EInvalid.prototype.constructor = EInvalid; - - function EIO(message){ - this.message = message || ''; - } - EIO.prototype = new Error(); - EIO.prototype.name = "EIO"; - EIO.prototype.constructor = EIO; - - function ELoop(message){ - this.message = message || ''; - } - ELoop.prototype = new Error(); - ELoop.prototype.name = "ELoop"; - ELoop.prototype.constructor = ELoop; - - function EFileSystemError(message){ - this.message = message || ''; - } - EFileSystemError.prototype = new Error(); - EFileSystemError.prototype.name = "EFileSystemError"; - EFileSystemError.prototype.constructor = EFileSystemError; - - return { - EExists: EExists, - EIsDirectory: EIsDirectory, - ENoEntry: ENoEntry, - EBusy: EBusy, - ENotEmpty: ENotEmpty, - ENotDirectory: ENotDirectory, - EBadFileDescriptor: EBadFileDescriptor, - ENotImplemented: ENotImplemented, - ENotMounted: ENotMounted, - EInvalid: EInvalid, - EIO: EIO, - ELoop: ELoop, - EFileSystemError: EFileSystemError - }; - -}); - -define('src/constants',['require'],function(require) { - - var O_READ = 'READ'; - var O_WRITE = 'WRITE'; - var O_CREATE = 'CREATE'; - var O_EXCLUSIVE = 'EXCLUSIVE'; - var O_TRUNCATE = 'TRUNCATE'; - var O_APPEND = 'APPEND'; - - return { - FILE_SYSTEM_NAME: 'local', - - FILE_STORE_NAME: 'files', - - IDB_RO: 'readonly', - IDB_RW: 'readwrite', - - WSQL_VERSION: "1", - WSQL_SIZE: 5 * 1024 * 1024, - WSQL_DESC: "FileSystem Storage", - - MODE_FILE: 'FILE', - MODE_DIRECTORY: 'DIRECTORY', - MODE_SYMBOLIC_LINK: 'SYMLINK', - MODE_META: 'META', - - SYMLOOP_MAX: 10, - - BINARY_MIME_TYPE: 'application/octet-stream', - JSON_MIME_TYPE: 'application/json', - - ROOT_DIRECTORY_NAME: '/', // basename(normalize(path)) - - FS_FORMAT: 'FORMAT', - - O_READ: O_READ, - O_WRITE: O_WRITE, - O_CREATE: O_CREATE, - O_EXCLUSIVE: O_EXCLUSIVE, - O_TRUNCATE: O_TRUNCATE, - O_APPEND: O_APPEND, - - O_FLAGS: { - 'r': [O_READ], - 'r+': [O_READ, O_WRITE], - 'w': [O_WRITE, O_CREATE, O_TRUNCATE], - 'w+': [O_WRITE, O_READ, O_CREATE, O_TRUNCATE], - 'wx': [O_WRITE, O_CREATE, O_EXCLUSIVE, O_TRUNCATE], - 'wx+': [O_WRITE, O_READ, O_CREATE, O_EXCLUSIVE, O_TRUNCATE], - 'a': [O_WRITE, O_CREATE, O_APPEND], - 'a+': [O_WRITE, O_READ, O_CREATE, O_APPEND], - 'ax': [O_WRITE, O_CREATE, O_EXCLUSIVE, O_APPEND], - 'ax+': [O_WRITE, O_READ, O_CREATE, O_EXCLUSIVE, O_APPEND] - }, - - FS_READY: 'READY', - FS_PENDING: 'PENDING', - FS_ERROR: 'ERROR', - - SUPER_NODE_ID: '00000000-0000-0000-0000-000000000000' - }; - -}); -define('src/providers/indexeddb',['require','src/constants','src/constants','src/constants','src/constants'],function(require) { - var FILE_SYSTEM_NAME = require('src/constants').FILE_SYSTEM_NAME; - var FILE_STORE_NAME = require('src/constants').FILE_STORE_NAME; - - var indexedDB = window.indexedDB || - window.mozIndexedDB || - window.webkitIndexedDB || - window.msIndexedDB; - - var IDB_RW = require('src/constants').IDB_RW; - var IDB_RO = require('src/constants').IDB_RO; - - function IndexedDBContext(db, mode) { - var transaction = db.transaction(FILE_STORE_NAME, mode); - this.objectStore = transaction.objectStore(FILE_STORE_NAME); - } - IndexedDBContext.prototype.clear = function(callback) { - try { - var request = this.objectStore.clear(); - request.onsuccess = function(event) { - callback(); - }; - request.onerror = function(error) { - callback(error); - }; - } catch(e) { - callback(e); - } - }; - IndexedDBContext.prototype.get = function(key, callback) { - try { - var request = this.objectStore.get(key); - request.onsuccess = function onsuccess(event) { - var result = event.target.result; - callback(null, result); - }; - request.onerror = function onerror(error) { - callback(error); - }; - } catch(e) { - callback(e); - } - }; - IndexedDBContext.prototype.put = function(key, value, callback) { - try { - var request = this.objectStore.put(value, key); - request.onsuccess = function onsuccess(event) { - var result = event.target.result; - callback(null, result); - }; - request.onerror = function onerror(error) { - callback(error); - }; - } catch(e) { - callback(e); - } - }; - IndexedDBContext.prototype.delete = function(key, callback) { - try { - var request = this.objectStore.delete(key); - request.onsuccess = function onsuccess(event) { - var result = event.target.result; - callback(null, result); - }; - request.onerror = function(error) { - callback(error); - }; - } catch(e) { - callback(e); - } - }; - - - function IndexedDB(name) { - this.name = name || FILE_SYSTEM_NAME; - this.db = null; - } - IndexedDB.isSupported = function() { - return !!indexedDB; - }; - - IndexedDB.prototype.open = function(callback) { - var that = this; - - // Bail if we already have a db open - if( that.db ) { - callback(null, false); - return; - } - - // Keep track of whether we're accessing this db for the first time - // and therefore needs to get formatted. - var firstAccess = false; - - // NOTE: we're not using versioned databases. - var openRequest = indexedDB.open(that.name); - - // If the db doesn't exist, we'll create it - openRequest.onupgradeneeded = function onupgradeneeded(event) { - var db = event.target.result; - - if(db.objectStoreNames.contains(FILE_STORE_NAME)) { - db.deleteObjectStore(FILE_STORE_NAME); - } - db.createObjectStore(FILE_STORE_NAME); - - firstAccess = true; - }; - - openRequest.onsuccess = function onsuccess(event) { - that.db = event.target.result; - callback(null, firstAccess); - }; - openRequest.onerror = function onerror(error) { - callback(error); - }; - }; - IndexedDB.prototype.getReadOnlyContext = function() { - return new IndexedDBContext(this.db, IDB_RO); - }; - IndexedDB.prototype.getReadWriteContext = function() { - return new IndexedDBContext(this.db, IDB_RW); - }; - - return IndexedDB; -}); - -define('src/providers/websql',['require','src/constants','src/constants','src/constants','src/constants','src/constants'],function(require) { - var FILE_SYSTEM_NAME = require('src/constants').FILE_SYSTEM_NAME; - var FILE_STORE_NAME = require('src/constants').FILE_STORE_NAME; - var WSQL_VERSION = require('src/constants').WSQL_VERSION; - var WSQL_SIZE = require('src/constants').WSQL_SIZE; - var WSQL_DESC = require('src/constants').WSQL_DESC; - - function WebSQLContext(db, isReadOnly) { - var that = this; - this.getTransaction = function(callback) { - if(that.transaction) { - callback(that.transaction); - return; - } - // Either do readTransaction() (read-only) or transaction() (read/write) - db[isReadOnly ? 'readTransaction' : 'transaction'](function(transaction) { - that.transaction = transaction; - callback(transaction); - }); - }; - } - WebSQLContext.prototype.clear = function(callback) { - function onError(transaction, error) { - callback(error); - } - function onSuccess(transaction, result) { - callback(null); - } - this.getTransaction(function(transaction) { - transaction.executeSql("DELETE FROM " + FILE_STORE_NAME, - [], onSuccess, onError); - }); - }; - WebSQLContext.prototype.get = function(key, callback) { - function onSuccess(transaction, result) { - // If the key isn't found, return null - var value = result.rows.length === 0 ? null : result.rows.item(0).data; - callback(null, value); - } - function onError(transaction, error) { - callback(error); - } - this.getTransaction(function(transaction) { - transaction.executeSql("SELECT data FROM " + FILE_STORE_NAME + " WHERE id = ?", - [key], onSuccess, onError); - }); - }; - WebSQLContext.prototype.put = function(key, value, callback) { - function onSuccess(transaction, result) { - callback(null); - } - function onError(transaction, error) { - callback(error); - } - this.getTransaction(function(transaction) { - transaction.executeSql("INSERT OR REPLACE INTO " + FILE_STORE_NAME + " (id, data) VALUES (?, ?)", - [key, value], onSuccess, onError); - }); - }; - WebSQLContext.prototype.delete = function(key, callback) { - function onSuccess(transaction, result) { - callback(null); - } - function onError(transaction, error) { - callback(error); - } - this.getTransaction(function(transaction) { - transaction.executeSql("DELETE FROM " + FILE_STORE_NAME + " WHERE id = ?", - [key], onSuccess, onError); - }); - }; - - - function WebSQL(name) { - this.name = name || FILE_SYSTEM_NAME; - this.db = null; - } - WebSQL.isSupported = function() { - return !!window.openDatabase; - }; - - WebSQL.prototype.open = function(callback) { - var that = this; - - // Bail if we already have a db open - if(that.db) { - callback(null, false); - return; - } - - var db = window.openDatabase(that.name, WSQL_VERSION, WSQL_DESC, WSQL_SIZE); - if(!db) { - callback("[WebSQL] Unable to open database."); - return; - } - - function onError(transaction, error) { - callback(error); - } - function onSuccess(transaction, result) { - that.db = db; - - function gotCount(transaction, result) { - var firstAccess = result.rows.item(0).count === 0; - callback(null, firstAccess); - } - function onError(transaction, error) { - callback(error); - } - // Keep track of whether we're accessing this db for the first time - // and therefore needs to get formatted. - transaction.executeSql("SELECT COUNT(id) AS count FROM " + FILE_STORE_NAME + ";", - [], gotCount, onError); - } - - db.transaction(function(transaction) { - transaction.executeSql("CREATE TABLE IF NOT EXISTS " + FILE_STORE_NAME + " (id unique, data)", - [], onSuccess, onError); - }); - }; - WebSQL.prototype.getReadOnlyContext = function() { - return new WebSQLContext(this.db, true); - }; - WebSQL.prototype.getReadWriteContext = function() { - return new WebSQLContext(this.db, false); - }; - - return WebSQL; -}); - -define('src/providers/memory',['require','src/constants'],function(require) { - var FILE_SYSTEM_NAME = require('src/constants').FILE_SYSTEM_NAME; - - function MemoryContext(db, readOnly) { - this.readOnly = readOnly; - this.objectStore = db; - } - MemoryContext.prototype.clear = function(callback) { - if(this.readOnly) { - return callback("[MemoryContext] Error: write operation on read only context"); - } - var objectStore = this.objectStore; - Object.keys(objectStore).forEach(function(key){ - delete objectStore[key]; - }); - callback(null); - }; - MemoryContext.prototype.get = function(key, callback) { - callback(null, this.objectStore[key]); - }; - MemoryContext.prototype.put = function(key, value, callback) { - if(this.readOnly) { - return callback("[MemoryContext] Error: write operation on read only context"); - } - this.objectStore[key] = value; - callback(null); - }; - MemoryContext.prototype.delete = function(key, callback) { - if(this.readOnly) { - return callback("[MemoryContext] Error: write operation on read only context"); - } - delete this.objectStore[key]; - callback(null); - }; - - - function Memory(name) { - this.name = name || FILE_SYSTEM_NAME; - this.db = {}; - } - Memory.isSupported = function() { - return true; - }; - - Memory.prototype.open = function(callback) { - callback(null, true); - }; - Memory.prototype.getReadOnlyContext = function() { - return new MemoryContext(this.db, true); - }; - Memory.prototype.getReadWriteContext = function() { - return new MemoryContext(this.db, false); - }; - - return Memory; -}); - -define('src/providers/providers',['require','src/providers/indexeddb','src/providers/websql','src/providers/memory'],function(require) { - - var IndexedDB = require('src/providers/indexeddb'); - var WebSQL = require('src/providers/websql'); - var Memory = require('src/providers/memory'); - - return { - IndexedDB: IndexedDB, - WebSQL: WebSQL, - Memory: Memory, - - /** - * Convenience Provider references - */ - - // The default provider to use when none is specified - Default: IndexedDB, - - // The Fallback provider does automatic fallback checks - Fallback: (function() { - if(IndexedDB.isSupported()) { - return IndexedDB; - } - - if(WebSQL.isSupported()) { - return WebSQL; - } - - function NotSupported() { - throw "[IDBFS Error] Your browser doesn't support IndexedDB or WebSQL."; - } - NotSupported.isSupported = function() { - return false; - }; - return NotSupported; - }()) - }; -}); - -/* -CryptoJS v3.0.2 -code.google.com/p/crypto-js -(c) 2009-2012 by Jeff Mott. All rights reserved. -code.google.com/p/crypto-js/wiki/License -*/ -var CryptoJS=CryptoJS||function(p,h){var i={},l=i.lib={},r=l.Base=function(){function a(){}return{extend:function(e){a.prototype=this;var c=new a;e&&c.mixIn(e);c.$super=this;return c},create:function(){var a=this.extend();a.init.apply(a,arguments);return a},init:function(){},mixIn:function(a){for(var c in a)a.hasOwnProperty(c)&&(this[c]=a[c]);a.hasOwnProperty("toString")&&(this.toString=a.toString)},clone:function(){return this.$super.extend(this)}}}(),o=l.WordArray=r.extend({init:function(a,e){a= -this.words=a||[];this.sigBytes=e!=h?e:4*a.length},toString:function(a){return(a||s).stringify(this)},concat:function(a){var e=this.words,c=a.words,b=this.sigBytes,a=a.sigBytes;this.clamp();if(b%4)for(var d=0;d>>2]|=(c[d>>>2]>>>24-8*(d%4)&255)<<24-8*((b+d)%4);else if(65535>>2]=c[d>>>2];else e.push.apply(e,c);this.sigBytes+=a;return this},clamp:function(){var a=this.words,e=this.sigBytes;a[e>>>2]&=4294967295<<32-8*(e%4);a.length=p.ceil(e/4)},clone:function(){var a= -r.clone.call(this);a.words=this.words.slice(0);return a},random:function(a){for(var e=[],c=0;c>>2]>>>24-8*(b%4)&255;c.push((d>>>4).toString(16));c.push((d&15).toString(16))}return c.join("")},parse:function(a){for(var e=a.length,c=[],b=0;b>>3]|=parseInt(a.substr(b,2),16)<<24-4*(b%8);return o.create(c,e/2)}},n=m.Latin1={stringify:function(a){for(var e= -a.words,a=a.sigBytes,c=[],b=0;b>>2]>>>24-8*(b%4)&255));return c.join("")},parse:function(a){for(var e=a.length,c=[],b=0;b>>2]|=(a.charCodeAt(b)&255)<<24-8*(b%4);return o.create(c,e)}},k=m.Utf8={stringify:function(a){try{return decodeURIComponent(escape(n.stringify(a)))}catch(e){throw Error("Malformed UTF-8 data");}},parse:function(a){return n.parse(unescape(encodeURIComponent(a)))}},f=l.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=o.create(); -this._nDataBytes=0},_append:function(a){"string"==typeof a&&(a=k.parse(a));this._data.concat(a);this._nDataBytes+=a.sigBytes},_process:function(a){var e=this._data,c=e.words,b=e.sigBytes,d=this.blockSize,q=b/(4*d),q=a?p.ceil(q):p.max((q|0)-this._minBufferSize,0),a=q*d,b=p.min(4*a,b);if(a){for(var j=0;j>>2]>>>24-8*(m%4)&255)<<16|(l[m+1>>>2]>>>24-8*((m+1)%4)&255)<<8|l[m+2>>>2]>>>24-8*((m+2)%4)&255,n=0;4>n&&m+0.75*n>>6*(3-n)&63));if(l=o.charAt(64))for(;i.length%4;)i.push(l);return i.join("")},parse:function(i){var i=i.replace(/\s/g,""),l=i.length,r=this._map,o=r.charAt(64);o&&(o=i.indexOf(o),-1!=o&&(l=o)); -for(var o=[],m=0,s=0;s>>6-2*(s%4);o[m>>>2]|=(n|k)<<24-8*(m%4);m++}return h.create(o,m)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}})(); -(function(p){function h(f,g,a,e,c,b,d){f=f+(g&a|~g&e)+c+d;return(f<>>32-b)+g}function i(f,g,a,e,c,b,d){f=f+(g&e|a&~e)+c+d;return(f<>>32-b)+g}function l(f,g,a,e,c,b,d){f=f+(g^a^e)+c+d;return(f<>>32-b)+g}function r(f,g,a,e,c,b,d){f=f+(a^(g|~e))+c+d;return(f<>>32-b)+g}var o=CryptoJS,m=o.lib,s=m.WordArray,m=m.Hasher,n=o.algo,k=[];(function(){for(var f=0;64>f;f++)k[f]=4294967296*p.abs(p.sin(f+1))|0})();n=n.MD5=m.extend({_doReset:function(){this._hash=s.create([1732584193,4023233417, -2562383102,271733878])},_doProcessBlock:function(f,g){for(var a=0;16>a;a++){var e=g+a,c=f[e];f[e]=(c<<8|c>>>24)&16711935|(c<<24|c>>>8)&4278255360}for(var e=this._hash.words,c=e[0],b=e[1],d=e[2],q=e[3],a=0;64>a;a+=4)16>a?(c=h(c,b,d,q,f[g+a],7,k[a]),q=h(q,c,b,d,f[g+a+1],12,k[a+1]),d=h(d,q,c,b,f[g+a+2],17,k[a+2]),b=h(b,d,q,c,f[g+a+3],22,k[a+3])):32>a?(c=i(c,b,d,q,f[g+(a+1)%16],5,k[a]),q=i(q,c,b,d,f[g+(a+6)%16],9,k[a+1]),d=i(d,q,c,b,f[g+(a+11)%16],14,k[a+2]),b=i(b,d,q,c,f[g+a%16],20,k[a+3])):48>a?(c= -l(c,b,d,q,f[g+(3*a+5)%16],4,k[a]),q=l(q,c,b,d,f[g+(3*a+8)%16],11,k[a+1]),d=l(d,q,c,b,f[g+(3*a+11)%16],16,k[a+2]),b=l(b,d,q,c,f[g+(3*a+14)%16],23,k[a+3])):(c=r(c,b,d,q,f[g+3*a%16],6,k[a]),q=r(q,c,b,d,f[g+(3*a+7)%16],10,k[a+1]),d=r(d,q,c,b,f[g+(3*a+14)%16],15,k[a+2]),b=r(b,d,q,c,f[g+(3*a+5)%16],21,k[a+3]));e[0]=e[0]+c|0;e[1]=e[1]+b|0;e[2]=e[2]+d|0;e[3]=e[3]+q|0},_doFinalize:function(){var f=this._data,g=f.words,a=8*this._nDataBytes,e=8*f.sigBytes;g[e>>>5]|=128<<24-e%32;g[(e+64>>>9<<4)+14]=(a<<8|a>>> -24)&16711935|(a<<24|a>>>8)&4278255360;f.sigBytes=4*(g.length+1);this._process();f=this._hash.words;for(g=0;4>g;g++)a=f[g],f[g]=(a<<8|a>>>24)&16711935|(a<<24|a>>>8)&4278255360}});o.MD5=m._createHelper(n);o.HmacMD5=m._createHmacHelper(n)})(Math); -(function(){var p=CryptoJS,h=p.lib,i=h.Base,l=h.WordArray,h=p.algo,r=h.EvpKDF=i.extend({cfg:i.extend({keySize:4,hasher:h.MD5,iterations:1}),init:function(i){this.cfg=this.cfg.extend(i)},compute:function(i,m){for(var h=this.cfg,n=h.hasher.create(),k=l.create(),f=k.words,g=h.keySize,h=h.iterations;f.length>>2]&255}};i.BlockCipher=n.extend({cfg:n.cfg.extend({mode:k,padding:g}),reset:function(){n.reset.call(this);var b=this.cfg,a=b.iv,b=b.mode;if(this._xformMode==this._ENC_XFORM_MODE)var c=b.createEncryptor;else c=b.createDecryptor, -this._minBufferSize=1;this._mode=c.call(b,this,a&&a.words)},_doProcessBlock:function(b,a){this._mode.processBlock(b,a)},_doFinalize:function(){var b=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){b.pad(this._data,this.blockSize);var a=this._process(!0)}else a=this._process(!0),b.unpad(a);return a},blockSize:4});var a=i.CipherParams=l.extend({init:function(a){this.mixIn(a)},toString:function(a){return(a||this.formatter).stringify(this)}}),k=(h.format={}).OpenSSL={stringify:function(a){var d= -a.ciphertext,a=a.salt,d=(a?r.create([1398893684,1701076831]).concat(a).concat(d):d).toString(m);return d=d.replace(/(.{64})/g,"$1\n")},parse:function(b){var b=m.parse(b),d=b.words;if(1398893684==d[0]&&1701076831==d[1]){var c=r.create(d.slice(2,4));d.splice(0,4);b.sigBytes-=16}return a.create({ciphertext:b,salt:c})}},e=i.SerializableCipher=l.extend({cfg:l.extend({format:k}),encrypt:function(b,d,c,e){var e=this.cfg.extend(e),f=b.createEncryptor(c,e),d=f.finalize(d),f=f.cfg;return a.create({ciphertext:d, -key:c,iv:f.iv,algorithm:b,mode:f.mode,padding:f.padding,blockSize:b.blockSize,formatter:e.format})},decrypt:function(a,c,e,f){f=this.cfg.extend(f);c=this._parse(c,f.format);return a.createDecryptor(e,f).finalize(c.ciphertext)},_parse:function(a,c){return"string"==typeof a?c.parse(a):a}}),h=(h.kdf={}).OpenSSL={compute:function(b,c,e,f){f||(f=r.random(8));b=s.create({keySize:c+e}).compute(b,f);e=r.create(b.words.slice(c),4*e);b.sigBytes=4*c;return a.create({key:b,iv:e,salt:f})}},c=i.PasswordBasedCipher= -e.extend({cfg:e.cfg.extend({kdf:h}),encrypt:function(a,c,f,j){j=this.cfg.extend(j);f=j.kdf.compute(f,a.keySize,a.ivSize);j.iv=f.iv;a=e.encrypt.call(this,a,c,f.key,j);a.mixIn(f);return a},decrypt:function(a,c,f,j){j=this.cfg.extend(j);c=this._parse(c,j.format);f=j.kdf.compute(f,a.keySize,a.ivSize,c.salt);j.iv=f.iv;return e.decrypt.call(this,a,c,f.key,j)}})}(); -(function(){var p=CryptoJS,h=p.lib.BlockCipher,i=p.algo,l=[],r=[],o=[],m=[],s=[],n=[],k=[],f=[],g=[],a=[];(function(){for(var c=[],b=0;256>b;b++)c[b]=128>b?b<<1:b<<1^283;for(var d=0,e=0,b=0;256>b;b++){var j=e^e<<1^e<<2^e<<3^e<<4,j=j>>>8^j&255^99;l[d]=j;r[j]=d;var i=c[d],h=c[i],p=c[h],t=257*c[j]^16843008*j;o[d]=t<<24|t>>>8;m[d]=t<<16|t>>>16;s[d]=t<<8|t>>>24;n[d]=t;t=16843009*p^65537*h^257*i^16843008*d;k[j]=t<<24|t>>>8;f[j]=t<<16|t>>>16;g[j]=t<<8|t>>>24;a[j]=t;d?(d=i^c[c[c[p^i]]],e^=c[c[e]]):d=e=1}})(); -var e=[0,1,2,4,8,16,32,64,128,27,54],i=i.AES=h.extend({_doReset:function(){for(var c=this._key,b=c.words,d=c.sigBytes/4,c=4*((this._nRounds=d+6)+1),i=this._keySchedule=[],j=0;j>>24]<<24|l[h>>>16&255]<<16|l[h>>>8&255]<<8|l[h&255]):(h=h<<8|h>>>24,h=l[h>>>24]<<24|l[h>>>16&255]<<16|l[h>>>8&255]<<8|l[h&255],h^=e[j/d|0]<<24);i[j]=i[j-d]^h}b=this._invKeySchedule=[];for(d=0;dd||4>=j?h:k[l[h>>>24]]^f[l[h>>> -16&255]]^g[l[h>>>8&255]]^a[l[h&255]]},encryptBlock:function(a,b){this._doCryptBlock(a,b,this._keySchedule,o,m,s,n,l)},decryptBlock:function(c,b){var d=c[b+1];c[b+1]=c[b+3];c[b+3]=d;this._doCryptBlock(c,b,this._invKeySchedule,k,f,g,a,r);d=c[b+1];c[b+1]=c[b+3];c[b+3]=d},_doCryptBlock:function(a,b,d,e,f,h,i,g){for(var l=this._nRounds,k=a[b]^d[0],m=a[b+1]^d[1],o=a[b+2]^d[2],n=a[b+3]^d[3],p=4,r=1;r>>24]^f[m>>>16&255]^h[o>>>8&255]^i[n&255]^d[p++],u=e[m>>>24]^f[o>>>16&255]^h[n>>>8&255]^ -i[k&255]^d[p++],v=e[o>>>24]^f[n>>>16&255]^h[k>>>8&255]^i[m&255]^d[p++],n=e[n>>>24]^f[k>>>16&255]^h[m>>>8&255]^i[o&255]^d[p++],k=s,m=u,o=v;s=(g[k>>>24]<<24|g[m>>>16&255]<<16|g[o>>>8&255]<<8|g[n&255])^d[p++];u=(g[m>>>24]<<24|g[o>>>16&255]<<16|g[n>>>8&255]<<8|g[k&255])^d[p++];v=(g[o>>>24]<<24|g[n>>>16&255]<<16|g[k>>>8&255]<<8|g[m&255])^d[p++];n=(g[n>>>24]<<24|g[k>>>16&255]<<16|g[m>>>8&255]<<8|g[o&255])^d[p++];a[b]=s;a[b+1]=u;a[b+2]=v;a[b+3]=n},keySize:8});p.AES=h._createHelper(i)})(); - -define("crypto-js/rollups/aes", function(){}); - -/* -CryptoJS v3.0.2 -code.google.com/p/crypto-js -(c) 2009-2012 by Jeff Mott. All rights reserved. -code.google.com/p/crypto-js/wiki/License -*/ -var CryptoJS=CryptoJS||function(q,i){var h={},j=h.lib={},p=j.Base=function(){function a(){}return{extend:function(c){a.prototype=this;var b=new a;c&&b.mixIn(c);b.$super=this;return b},create:function(){var a=this.extend();a.init.apply(a,arguments);return a},init:function(){},mixIn:function(a){for(var b in a)a.hasOwnProperty(b)&&(this[b]=a[b]);a.hasOwnProperty("toString")&&(this.toString=a.toString)},clone:function(){return this.$super.extend(this)}}}(),l=j.WordArray=p.extend({init:function(a,c){a= -this.words=a||[];this.sigBytes=c!=i?c:4*a.length},toString:function(a){return(a||r).stringify(this)},concat:function(a){var c=this.words,b=a.words,g=this.sigBytes,a=a.sigBytes;this.clamp();if(g%4)for(var e=0;e>>2]|=(b[e>>>2]>>>24-8*(e%4)&255)<<24-8*((g+e)%4);else if(65535>>2]=b[e>>>2];else c.push.apply(c,b);this.sigBytes+=a;return this},clamp:function(){var a=this.words,c=this.sigBytes;a[c>>>2]&=4294967295<<32-8*(c%4);a.length=q.ceil(c/4)},clone:function(){var a= -p.clone.call(this);a.words=this.words.slice(0);return a},random:function(a){for(var c=[],b=0;b>>2]>>>24-8*(g%4)&255;b.push((e>>>4).toString(16));b.push((e&15).toString(16))}return b.join("")},parse:function(a){for(var c=a.length,b=[],g=0;g>>3]|=parseInt(a.substr(g,2),16)<<24-4*(g%8);return l.create(b,c/2)}},o=k.Latin1={stringify:function(a){for(var c= -a.words,a=a.sigBytes,b=[],g=0;g>>2]>>>24-8*(g%4)&255));return b.join("")},parse:function(a){for(var c=a.length,b=[],g=0;g>>2]|=(a.charCodeAt(g)&255)<<24-8*(g%4);return l.create(b,c)}},m=k.Utf8={stringify:function(a){try{return decodeURIComponent(escape(o.stringify(a)))}catch(c){throw Error("Malformed UTF-8 data");}},parse:function(a){return o.parse(unescape(encodeURIComponent(a)))}},d=j.BufferedBlockAlgorithm=p.extend({reset:function(){this._data=l.create(); -this._nDataBytes=0},_append:function(a){"string"==typeof a&&(a=m.parse(a));this._data.concat(a);this._nDataBytes+=a.sigBytes},_process:function(a){var c=this._data,b=c.words,g=c.sigBytes,e=this.blockSize,n=g/(4*e),n=a?q.ceil(n):q.max((n|0)-this._minBufferSize,0),a=n*e,g=q.min(4*a,g);if(a){for(var d=0;d>>2]>>>24-8*(k%4)&255)<<16|(j[k+1>>>2]>>>24-8*((k+1)%4)&255)<<8|j[k+2>>>2]>>>24-8*((k+2)%4)&255,o=0;4>o&&k+0.75*o>>6*(3-o)&63));if(j=l.charAt(64))for(;h.length%4;)h.push(j);return h.join("")},parse:function(h){var h=h.replace(/\s/g,""),j=h.length,p=this._map,l=p.charAt(64);l&&(l=h.indexOf(l),-1!=l&&(j=l)); -for(var l=[],k=0,r=0;r>>6-2*(r%4);l[k>>>2]|=(o|m)<<24-8*(k%4);k++}return i.create(l,k)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}})(); -(function(q){function i(d,f,a,c,b,g,e){d=d+(f&a|~f&c)+b+e;return(d<>>32-g)+f}function h(d,f,a,c,b,g,e){d=d+(f&c|a&~c)+b+e;return(d<>>32-g)+f}function j(d,f,a,c,b,g,e){d=d+(f^a^c)+b+e;return(d<>>32-g)+f}function p(d,f,a,c,b,g,e){d=d+(a^(f|~c))+b+e;return(d<>>32-g)+f}var l=CryptoJS,k=l.lib,r=k.WordArray,k=k.Hasher,o=l.algo,m=[];(function(){for(var d=0;64>d;d++)m[d]=4294967296*q.abs(q.sin(d+1))|0})();o=o.MD5=k.extend({_doReset:function(){this._hash=r.create([1732584193,4023233417, -2562383102,271733878])},_doProcessBlock:function(d,f){for(var a=0;16>a;a++){var c=f+a,b=d[c];d[c]=(b<<8|b>>>24)&16711935|(b<<24|b>>>8)&4278255360}for(var c=this._hash.words,b=c[0],g=c[1],e=c[2],n=c[3],a=0;64>a;a+=4)16>a?(b=i(b,g,e,n,d[f+a],7,m[a]),n=i(n,b,g,e,d[f+a+1],12,m[a+1]),e=i(e,n,b,g,d[f+a+2],17,m[a+2]),g=i(g,e,n,b,d[f+a+3],22,m[a+3])):32>a?(b=h(b,g,e,n,d[f+(a+1)%16],5,m[a]),n=h(n,b,g,e,d[f+(a+6)%16],9,m[a+1]),e=h(e,n,b,g,d[f+(a+11)%16],14,m[a+2]),g=h(g,e,n,b,d[f+a%16],20,m[a+3])):48>a?(b= -j(b,g,e,n,d[f+(3*a+5)%16],4,m[a]),n=j(n,b,g,e,d[f+(3*a+8)%16],11,m[a+1]),e=j(e,n,b,g,d[f+(3*a+11)%16],16,m[a+2]),g=j(g,e,n,b,d[f+(3*a+14)%16],23,m[a+3])):(b=p(b,g,e,n,d[f+3*a%16],6,m[a]),n=p(n,b,g,e,d[f+(3*a+7)%16],10,m[a+1]),e=p(e,n,b,g,d[f+(3*a+14)%16],15,m[a+2]),g=p(g,e,n,b,d[f+(3*a+5)%16],21,m[a+3]));c[0]=c[0]+b|0;c[1]=c[1]+g|0;c[2]=c[2]+e|0;c[3]=c[3]+n|0},_doFinalize:function(){var d=this._data,f=d.words,a=8*this._nDataBytes,c=8*d.sigBytes;f[c>>>5]|=128<<24-c%32;f[(c+64>>>9<<4)+14]=(a<<8|a>>> -24)&16711935|(a<<24|a>>>8)&4278255360;d.sigBytes=4*(f.length+1);this._process();d=this._hash.words;for(f=0;4>f;f++)a=d[f],d[f]=(a<<8|a>>>24)&16711935|(a<<24|a>>>8)&4278255360}});l.MD5=k._createHelper(o);l.HmacMD5=k._createHmacHelper(o)})(Math); -(function(){var q=CryptoJS,i=q.lib,h=i.Base,j=i.WordArray,i=q.algo,p=i.EvpKDF=h.extend({cfg:h.extend({keySize:4,hasher:i.MD5,iterations:1}),init:function(h){this.cfg=this.cfg.extend(h)},compute:function(h,k){for(var i=this.cfg,o=i.hasher.create(),m=j.create(),d=m.words,f=i.keySize,i=i.iterations;d.length>>2]&255}};h.BlockCipher=o.extend({cfg:o.cfg.extend({mode:m,padding:f}),reset:function(){o.reset.call(this);var a=this.cfg,e=a.iv,a=a.mode;if(this._xformMode==this._ENC_XFORM_MODE)var b=a.createEncryptor;else b=a.createDecryptor, -this._minBufferSize=1;this._mode=b.call(a,this,e&&e.words)},_doProcessBlock:function(a,b){this._mode.processBlock(a,b)},_doFinalize:function(){var a=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){a.pad(this._data,this.blockSize);var b=this._process(!0)}else b=this._process(!0),a.unpad(b);return b},blockSize:4});var a=h.CipherParams=j.extend({init:function(a){this.mixIn(a)},toString:function(a){return(a||this.formatter).stringify(this)}}),m=(i.format={}).OpenSSL={stringify:function(a){var b= -a.ciphertext,a=a.salt,b=(a?p.create([1398893684,1701076831]).concat(a).concat(b):b).toString(k);return b=b.replace(/(.{64})/g,"$1\n")},parse:function(b){var b=k.parse(b),e=b.words;if(1398893684==e[0]&&1701076831==e[1]){var c=p.create(e.slice(2,4));e.splice(0,4);b.sigBytes-=16}return a.create({ciphertext:b,salt:c})}},c=h.SerializableCipher=j.extend({cfg:j.extend({format:m}),encrypt:function(b,e,c,d){var d=this.cfg.extend(d),f=b.createEncryptor(c,d),e=f.finalize(e),f=f.cfg;return a.create({ciphertext:e, -key:c,iv:f.iv,algorithm:b,mode:f.mode,padding:f.padding,blockSize:b.blockSize,formatter:d.format})},decrypt:function(a,b,c,d){d=this.cfg.extend(d);b=this._parse(b,d.format);return a.createDecryptor(c,d).finalize(b.ciphertext)},_parse:function(a,b){return"string"==typeof a?b.parse(a):a}}),i=(i.kdf={}).OpenSSL={compute:function(b,c,d,f){f||(f=p.random(8));b=r.create({keySize:c+d}).compute(b,f);d=p.create(b.words.slice(c),4*d);b.sigBytes=4*c;return a.create({key:b,iv:d,salt:f})}},b=h.PasswordBasedCipher= -c.extend({cfg:c.cfg.extend({kdf:i}),encrypt:function(a,b,d,f){f=this.cfg.extend(f);d=f.kdf.compute(d,a.keySize,a.ivSize);f.iv=d.iv;a=c.encrypt.call(this,a,b,d.key,f);a.mixIn(d);return a},decrypt:function(a,b,d,f){f=this.cfg.extend(f);b=this._parse(b,f.format);d=f.kdf.compute(d,a.keySize,a.ivSize,b.salt);f.iv=d.iv;return c.decrypt.call(this,a,b,d.key,f)}})}(); -(function(){function q(a,c){var b=(this._lBlock>>>a^this._rBlock)&c;this._rBlock^=b;this._lBlock^=b<>>a^this._lBlock)&c;this._lBlock^=b;this._rBlock^=b<b;b++){var d=k[b]-1;c[b]=a[d>>>5]>>>31-d%32&1}a=this._subKeys=[];for(d=0;16>d;d++){for(var e=a[d]=[],f=o[d],b=0;24>b;b++)e[b/6|0]|=c[(r[b]-1+f)%28]<<31-b%6,e[4+(b/6|0)]|=c[28+(r[b+24]-1+f)%28]<<31-b%6;e[0]=e[0]<<1|e[0]>>>31;for(b=1;7>b;b++)e[b]>>>= -4*(b-1)+3;e[7]=e[7]<<5|e[7]>>>27}c=this._invSubKeys=[];for(b=0;16>b;b++)c[b]=a[15-b]},encryptBlock:function(a,c){this._doCryptBlock(a,c,this._subKeys)},decryptBlock:function(a,c){this._doCryptBlock(a,c,this._invSubKeys)},_doCryptBlock:function(a,c,b){this._lBlock=a[c];this._rBlock=a[c+1];q.call(this,4,252645135);q.call(this,16,65535);i.call(this,2,858993459);i.call(this,8,16711935);q.call(this,1,1431655765);for(var f=0;16>f;f++){for(var e=b[f],h=this._lBlock,j=this._rBlock,k=0,l=0;8>l;l++)k|=m[l][((j^ -e[l])&d[l])>>>0];this._lBlock=j;this._rBlock=h^k}b=this._lBlock;this._lBlock=this._rBlock;this._rBlock=b;q.call(this,1,1431655765);i.call(this,8,16711935);i.call(this,2,858993459);q.call(this,16,65535);q.call(this,4,252645135);a[c]=this._lBlock;a[c+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});h.DES=j._createHelper(f);l=l.TripleDES=j.extend({_doReset:function(){var a=this._key.words;this._des1=f.createEncryptor(p.create(a.slice(0,2)));this._des2=f.createEncryptor(p.create(a.slice(2,4)));this._des3= -f.createEncryptor(p.create(a.slice(4,6)))},encryptBlock:function(a,c){this._des1.encryptBlock(a,c);this._des2.decryptBlock(a,c);this._des3.encryptBlock(a,c)},decryptBlock:function(a,c){this._des3.decryptBlock(a,c);this._des2.encryptBlock(a,c);this._des1.decryptBlock(a,c)},keySize:6,ivSize:2,blockSize:2});h.TripleDES=j._createHelper(l)})(); - -define("crypto-js/rollups/tripledes", function(){}); - -/* -CryptoJS v3.0.2 -code.google.com/p/crypto-js -(c) 2009-2012 by Jeff Mott. All rights reserved. -code.google.com/p/crypto-js/wiki/License -*/ -var CryptoJS=CryptoJS||function(n,l){var i={},j=i.lib={},k=j.Base=function(){function b(){}return{extend:function(p){b.prototype=this;var a=new b;p&&a.mixIn(p);a.$super=this;return a},create:function(){var b=this.extend();b.init.apply(b,arguments);return b},init:function(){},mixIn:function(b){for(var a in b)b.hasOwnProperty(a)&&(this[a]=b[a]);b.hasOwnProperty("toString")&&(this.toString=b.toString)},clone:function(){return this.$super.extend(this)}}}(),e=j.WordArray=k.extend({init:function(b,a){b= -this.words=b||[];this.sigBytes=a!=l?a:4*b.length},toString:function(b){return(b||c).stringify(this)},concat:function(b){var a=this.words,c=b.words,g=this.sigBytes,b=b.sigBytes;this.clamp();if(g%4)for(var h=0;h>>2]|=(c[h>>>2]>>>24-8*(h%4)&255)<<24-8*((g+h)%4);else if(65535>>2]=c[h>>>2];else a.push.apply(a,c);this.sigBytes+=b;return this},clamp:function(){var b=this.words,a=this.sigBytes;b[a>>>2]&=4294967295<<32-8*(a%4);b.length=n.ceil(a/4)},clone:function(){var b= -k.clone.call(this);b.words=this.words.slice(0);return b},random:function(b){for(var a=[],c=0;c>>2]>>>24-8*(g%4)&255;c.push((h>>>4).toString(16));c.push((h&15).toString(16))}return c.join("")},parse:function(b){for(var a=b.length,c=[],g=0;g>>3]|=parseInt(b.substr(g,2),16)<<24-4*(g%8);return e.create(c,a/2)}},a=d.Latin1={stringify:function(b){for(var a= -b.words,b=b.sigBytes,c=[],g=0;g>>2]>>>24-8*(g%4)&255));return c.join("")},parse:function(b){for(var a=b.length,c=[],g=0;g>>2]|=(b.charCodeAt(g)&255)<<24-8*(g%4);return e.create(c,a)}},f=d.Utf8={stringify:function(b){try{return decodeURIComponent(escape(a.stringify(b)))}catch(c){throw Error("Malformed UTF-8 data");}},parse:function(b){return a.parse(unescape(encodeURIComponent(b)))}},o=j.BufferedBlockAlgorithm=k.extend({reset:function(){this._data=e.create(); -this._nDataBytes=0},_append:function(b){"string"==typeof b&&(b=f.parse(b));this._data.concat(b);this._nDataBytes+=b.sigBytes},_process:function(b){var a=this._data,c=a.words,g=a.sigBytes,h=this.blockSize,m=g/(4*h),m=b?n.ceil(m):n.max((m|0)-this._minBufferSize,0),b=m*h,g=n.min(4*b,g);if(b){for(var o=0;o>>2]>>>24-8*(d%4)&255)<<16|(j[d+1>>>2]>>>24-8*((d+1)%4)&255)<<8|j[d+2>>>2]>>>24-8*((d+2)%4)&255,a=0;4>a&&d+0.75*a>>6*(3-a)&63));if(j=e.charAt(64))for(;i.length%4;)i.push(j);return i.join("")},parse:function(i){var i=i.replace(/\s/g,""),j=i.length,k=this._map,e=k.charAt(64);e&&(e=i.indexOf(e),-1!=e&&(j=e)); -for(var e=[],d=0,c=0;c>>6-2*(c%4);e[d>>>2]|=(a|f)<<24-8*(d%4);d++}return l.create(e,d)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}})(); -(function(n){function l(a,c,b,d,f,g,h){a=a+(c&b|~c&d)+f+h;return(a<>>32-g)+c}function i(a,c,b,d,f,g,h){a=a+(c&d|b&~d)+f+h;return(a<>>32-g)+c}function j(a,c,b,d,f,g,h){a=a+(c^b^d)+f+h;return(a<>>32-g)+c}function k(a,c,b,d,f,g,h){a=a+(b^(c|~d))+f+h;return(a<>>32-g)+c}var e=CryptoJS,d=e.lib,c=d.WordArray,d=d.Hasher,a=e.algo,f=[];(function(){for(var a=0;64>a;a++)f[a]=4294967296*n.abs(n.sin(a+1))|0})();a=a.MD5=d.extend({_doReset:function(){this._hash=c.create([1732584193,4023233417, -2562383102,271733878])},_doProcessBlock:function(a,c){for(var b=0;16>b;b++){var d=c+b,e=a[d];a[d]=(e<<8|e>>>24)&16711935|(e<<24|e>>>8)&4278255360}for(var d=this._hash.words,e=d[0],g=d[1],h=d[2],m=d[3],b=0;64>b;b+=4)16>b?(e=l(e,g,h,m,a[c+b],7,f[b]),m=l(m,e,g,h,a[c+b+1],12,f[b+1]),h=l(h,m,e,g,a[c+b+2],17,f[b+2]),g=l(g,h,m,e,a[c+b+3],22,f[b+3])):32>b?(e=i(e,g,h,m,a[c+(b+1)%16],5,f[b]),m=i(m,e,g,h,a[c+(b+6)%16],9,f[b+1]),h=i(h,m,e,g,a[c+(b+11)%16],14,f[b+2]),g=i(g,h,m,e,a[c+b%16],20,f[b+3])):48>b?(e= -j(e,g,h,m,a[c+(3*b+5)%16],4,f[b]),m=j(m,e,g,h,a[c+(3*b+8)%16],11,f[b+1]),h=j(h,m,e,g,a[c+(3*b+11)%16],16,f[b+2]),g=j(g,h,m,e,a[c+(3*b+14)%16],23,f[b+3])):(e=k(e,g,h,m,a[c+3*b%16],6,f[b]),m=k(m,e,g,h,a[c+(3*b+7)%16],10,f[b+1]),h=k(h,m,e,g,a[c+(3*b+14)%16],15,f[b+2]),g=k(g,h,m,e,a[c+(3*b+5)%16],21,f[b+3]));d[0]=d[0]+e|0;d[1]=d[1]+g|0;d[2]=d[2]+h|0;d[3]=d[3]+m|0},_doFinalize:function(){var a=this._data,c=a.words,b=8*this._nDataBytes,d=8*a.sigBytes;c[d>>>5]|=128<<24-d%32;c[(d+64>>>9<<4)+14]=(b<<8|b>>> -24)&16711935|(b<<24|b>>>8)&4278255360;a.sigBytes=4*(c.length+1);this._process();a=this._hash.words;for(c=0;4>c;c++)b=a[c],a[c]=(b<<8|b>>>24)&16711935|(b<<24|b>>>8)&4278255360}});e.MD5=d._createHelper(a);e.HmacMD5=d._createHmacHelper(a)})(Math); -(function(){var n=CryptoJS,l=n.lib,i=l.Base,j=l.WordArray,l=n.algo,k=l.EvpKDF=i.extend({cfg:i.extend({keySize:4,hasher:l.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,d){for(var c=this.cfg,a=c.hasher.create(),f=j.create(),i=f.words,k=c.keySize,c=c.iterations;i.length>>2]&255}};i.BlockCipher=a.extend({cfg:a.cfg.extend({mode:f,padding:q}),reset:function(){a.reset.call(this);var b=this.cfg,c=b.iv,b=b.mode;if(this._xformMode==this._ENC_XFORM_MODE)var d=b.createEncryptor;else d=b.createDecryptor, -this._minBufferSize=1;this._mode=d.call(b,this,c&&c.words)},_doProcessBlock:function(a,b){this._mode.processBlock(a,b)},_doFinalize:function(){var a=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){a.pad(this._data,this.blockSize);var b=this._process(!0)}else b=this._process(!0),a.unpad(b);return b},blockSize:4});var b=i.CipherParams=j.extend({init:function(a){this.mixIn(a)},toString:function(a){return(a||this.formatter).stringify(this)}}),f=(l.format={}).OpenSSL={stringify:function(a){var b= -a.ciphertext,a=a.salt,b=(a?k.create([1398893684,1701076831]).concat(a).concat(b):b).toString(d);return b=b.replace(/(.{64})/g,"$1\n")},parse:function(a){var a=d.parse(a),c=a.words;if(1398893684==c[0]&&1701076831==c[1]){var f=k.create(c.slice(2,4));c.splice(0,4);a.sigBytes-=16}return b.create({ciphertext:a,salt:f})}},p=i.SerializableCipher=j.extend({cfg:j.extend({format:f}),encrypt:function(a,c,d,f){var f=this.cfg.extend(f),e=a.createEncryptor(d,f),c=e.finalize(c),e=e.cfg;return b.create({ciphertext:c, -key:d,iv:e.iv,algorithm:a,mode:e.mode,padding:e.padding,blockSize:a.blockSize,formatter:f.format})},decrypt:function(a,b,c,d){d=this.cfg.extend(d);b=this._parse(b,d.format);return a.createDecryptor(c,d).finalize(b.ciphertext)},_parse:function(a,b){return"string"==typeof a?b.parse(a):a}}),l=(l.kdf={}).OpenSSL={compute:function(a,d,f,e){e||(e=k.random(8));a=c.create({keySize:d+f}).compute(a,e);f=k.create(a.words.slice(d),4*f);a.sigBytes=4*d;return b.create({key:a,iv:f,salt:e})}},r=i.PasswordBasedCipher= -p.extend({cfg:p.cfg.extend({kdf:l}),encrypt:function(a,b,c,d){d=this.cfg.extend(d);c=d.kdf.compute(c,a.keySize,a.ivSize);d.iv=c.iv;a=p.encrypt.call(this,a,b,c.key,d);a.mixIn(c);return a},decrypt:function(a,b,c,d){d=this.cfg.extend(d);b=this._parse(b,d.format);c=d.kdf.compute(c,a.keySize,a.ivSize,b.salt);d.iv=c.iv;return p.decrypt.call(this,a,b,c.key,d)}})}(); -(function(){function n(){var d=this._X,c=this._C;c[0]=c[0]+1295307597+this._b|0;c[1]=c[1]+3545052371+(1295307597>c[0]>>>0?1:0)|0;c[2]=c[2]+886263092+(3545052371>c[1]>>>0?1:0)|0;c[3]=c[3]+1295307597+(886263092>c[2]>>>0?1:0)|0;c[4]=c[4]+3545052371+(1295307597>c[3]>>>0?1:0)|0;c[5]=c[5]+886263092+(3545052371>c[4]>>>0?1:0)|0;c[6]=c[6]+1295307597+(886263092>c[5]>>>0?1:0)|0;c[7]=c[7]+3545052371+(1295307597>c[6]>>>0?1:0)|0;this._b=3545052371>c[7]>>>0?1:0;for(var a=0;8>a;a++){var f=d[a]+c[a],e=f&65535,i=f>>> -16;k[a]=((e*e>>>17)+e*i>>>15)+i*i^((f&4294901760)*f|0)+((f&65535)*f|0)}var c=k[0],a=k[1],f=k[2],e=k[3],i=k[4],b=k[5],j=k[6],l=k[7];d[0]=c+(l<<16|l>>>16)+(j<<16|j>>>16)|0;d[1]=a+(c<<8|c>>>24)+l|0;d[2]=f+(a<<16|a>>>16)+(c<<16|c>>>16)|0;d[3]=e+(f<<8|f>>>24)+a|0;d[4]=i+(e<<16|e>>>16)+(f<<16|f>>>16)|0;d[5]=b+(i<<8|i>>>24)+e|0;d[6]=j+(b<<16|b>>>16)+(i<<16|i>>>16)|0;d[7]=l+(j<<8|j>>>24)+b|0}var l=CryptoJS,i=l.lib.StreamCipher,j=[],k=[],e=l.algo.Rabbit=i.extend({_doReset:function(){for(var d=this._key.words, -c=d[0],a=d[1],f=d[2],e=d[3],d=this._X=[c,e<<16|f>>>16,a,c<<16|e>>>16,f,a<<16|c>>>16,e,f<<16|a>>>16],c=this._C=[f<<16|f>>>16,c&4294901760|a&65535,e<<16|e>>>16,a&4294901760|f&65535,c<<16|c>>>16,f&4294901760|e&65535,a<<16|a>>>16,e&4294901760|c&65535],a=this._b=0;4>a;a++)n.call(this);for(a=0;8>a;a++)c[a]^=d[a+4&7];if(d=this.cfg.iv){a=d.words;d=a[0];a=a[1];d=(d<<8|d>>>24)&16711935|(d<<24|d>>>8)&4278255360;a=(a<<8|a>>>24)&16711935|(a<<24|a>>>8)&4278255360;f=d>>>16|a&4294901760;e=a<<16|d&65535;c[0]^=d;c[1]^= -f;c[2]^=a;c[3]^=e;c[4]^=d;c[5]^=f;c[6]^=a;c[7]^=e;for(a=0;4>a;a++)n.call(this)}},_doProcessBlock:function(d,c){var a=this._X;n.call(this);j[0]=a[0]^a[5]>>>16^a[3]<<16;j[1]=a[2]^a[7]>>>16^a[5]<<16;j[2]=a[4]^a[1]>>>16^a[7]<<16;j[3]=a[6]^a[3]>>>16^a[1]<<16;for(a=0;4>a;a++){var e=j[a],e=(e<<8|e>>>24)&16711935|(e<<24|e>>>8)&4278255360;d[c+a]^=e}},blockSize:4,ivSize:2});l.Rabbit=i._createHelper(e)})(); - -define("crypto-js/rollups/rabbit", function(){}); - -define('src/adapters/crypto',['require','crypto-js/rollups/aes','crypto-js/rollups/tripledes','crypto-js/rollups/rabbit','encoding'],function(require) { - - // AES encryption, see http://code.google.com/p/crypto-js/#AES - require("crypto-js/rollups/aes"); - // DES, Triple DES, see http://code.google.com/p/crypto-js/#DES,_Triple_DES - require("crypto-js/rollups/tripledes"); - // Rabbit, see http://code.google.com/p/crypto-js/#Rabbit - require("crypto-js/rollups/rabbit"); - - - // Move back and forth from Uint8Arrays and CryptoJS WordArray - // See http://code.google.com/p/crypto-js/#The_Cipher_Input and - // https://groups.google.com/forum/#!topic/crypto-js/TOb92tcJlU0 - var WordArray = CryptoJS.lib.WordArray; - function fromWordArray(wordArray) { - var words = wordArray.words; - var sigBytes = wordArray.sigBytes; - var u8 = new Uint8Array(sigBytes); - var b; - for (var i = 0; i < sigBytes; i++) { - b = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; - u8[i] = b; - } - return u8; - } - function toWordArray(u8arr) { - var len = u8arr.length; - var words = []; - for (var i = 0; i < len; i++) { - words[i >>> 2] |= (u8arr[i] & 0xff) << (24 - (i % 4) * 8); - } - return WordArray.create(words, len); - } - - - // UTF8 Text De/Encoders - require('encoding'); - function encode(str) { - return (new TextEncoder('utf-8')).encode(str); - } - function decode(u8arr) { - return (new TextDecoder('utf-8')).decode(u8arr); - } - - - function CryptoContext(context, encrypt, decrypt) { - this.context = context; - this.encrypt = encrypt; - this.decrypt = decrypt; - } - CryptoContext.prototype.clear = function(callback) { - this.context.clear(callback); - }; - CryptoContext.prototype.get = function(key, callback) { - var decrypt = this.decrypt; - this.context.get(key, function(err, value) { - if(err) { - callback(err); - return; - } - if(value) { - value = decrypt(value); - } - callback(null, value); - }); - }; - CryptoContext.prototype.put = function(key, value, callback) { - var encryptedValue = this.encrypt(value); - this.context.put(key, encryptedValue, callback); - }; - CryptoContext.prototype.delete = function(key, callback) { - this.context.delete(key, callback); - }; - - - function buildCryptoAdapter(encryptionType) { - // It is up to the app using this wrapper how the passphrase is acquired, probably by - // prompting the user to enter it when the file system is being opened. - function CryptoAdapter(passphrase, provider) { - this.provider = provider; - - // Cache cipher algorithm we'll use in encrypt/decrypt - var cipher = CryptoJS[encryptionType]; - - // To encrypt: - // 1) accept a buffer (Uint8Array) containing binary data - // 2) convert the buffer to a CipherJS WordArray - // 3) encrypt the WordArray using the chosen cipher algorithm + passphrase - // 4) convert the resulting ciphertext to a UTF8 encoded Uint8Array and return - this.encrypt = function(buffer) { - var wordArray = toWordArray(buffer); - var encrypted = cipher.encrypt(wordArray, passphrase); - var utf8EncodedBuf = encode(encrypted); - return utf8EncodedBuf; - }; - - // To decrypt: - // 1) accept a buffer (Uint8Array) containing a UTF8 encoded Uint8Array - // 2) convert the buffer to string (i.e., the ciphertext we got from encrypting) - // 3) decrypt the ciphertext string - // 4) convert the decrypted cipherParam object to a UTF8 string - // 5) encode the UTF8 string to a Uint8Array buffer and return - this.decrypt = function(buffer) { - var encryptedStr = decode(buffer); - var decrypted = cipher.decrypt(encryptedStr, passphrase); - var decryptedUtf8 = decrypted.toString(CryptoJS.enc.Utf8); - var utf8EncodedBuf = encode(decryptedUtf8); - return utf8EncodedBuf; - }; - } - CryptoAdapter.isSupported = function() { - return true; - }; - - CryptoAdapter.prototype.open = function(callback) { - this.provider.open(callback); - }; - CryptoAdapter.prototype.getReadOnlyContext = function() { - return new CryptoContext(this.provider.getReadOnlyContext(), - this.encrypt, - this.decrypt); - }; - CryptoAdapter.prototype.getReadWriteContext = function() { - return new CryptoContext(this.provider.getReadWriteContext(), - this.encrypt, - this.decrypt); - }; - - return CryptoAdapter; - } - - return { - AES: buildCryptoAdapter('AES'), - TripleDES: buildCryptoAdapter('TripleDES'), - Rabbit: buildCryptoAdapter('Rabbit') - }; -}); - -/** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */(function() {function l(d){throw d;}var u=void 0,x=!0,aa=this;function z(d,a){var c=d.split("."),f=aa;!(c[0]in f)&&f.execScript&&f.execScript("var "+c[0]);for(var b;c.length&&(b=c.shift());)!c.length&&a!==u?f[b]=a:f=f[b]?f[b]:f[b]={}};var E="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array;function G(d,a){this.index="number"===typeof a?a:0;this.i=0;this.buffer=d instanceof(E?Uint8Array:Array)?d:new (E?Uint8Array:Array)(32768);2*this.buffer.length<=this.index&&l(Error("invalid index"));this.buffer.length<=this.index&&this.f()}G.prototype.f=function(){var d=this.buffer,a,c=d.length,f=new (E?Uint8Array:Array)(c<<1);if(E)f.set(d);else for(a=0;a>>8&255]<<16|N[d>>>16&255]<<8|N[d>>>24&255])>>32-a:N[d]>>8-a);if(8>a+e)g=g<>a-h-1&1,8===++e&&(e=0,f[b++]=N[g],g=0,b===f.length&&(f=this.f()));f[b]=g;this.buffer=f;this.i=e;this.index=b};G.prototype.finish=function(){var d=this.buffer,a=this.index,c;0O;++O){for(var P=O,Q=P,ga=7,P=P>>>1;P;P>>>=1)Q<<=1,Q|=P&1,--ga;fa[O]=(Q<>>0}var N=fa;function ha(d){this.buffer=new (E?Uint16Array:Array)(2*d);this.length=0}ha.prototype.getParent=function(d){return 2*((d-2)/4|0)};ha.prototype.push=function(d,a){var c,f,b=this.buffer,e;c=this.length;b[this.length++]=a;for(b[this.length++]=d;0b[f])e=b[c],b[c]=b[f],b[f]=e,e=b[c+1],b[c+1]=b[f+1],b[f+1]=e,c=f;else break;return this.length}; -ha.prototype.pop=function(){var d,a,c=this.buffer,f,b,e;a=c[0];d=c[1];this.length-=2;c[0]=c[this.length];c[1]=c[this.length+1];for(e=0;;){b=2*e+2;if(b>=this.length)break;b+2c[b]&&(b+=2);if(c[b]>c[e])f=c[e],c[e]=c[b],c[b]=f,f=c[e+1],c[e+1]=c[b+1],c[b+1]=f;else break;e=b}return{index:d,value:a,length:this.length}};function R(d){var a=d.length,c=0,f=Number.POSITIVE_INFINITY,b,e,g,h,k,n,q,r,p;for(r=0;rc&&(c=d[r]),d[r]>=1;for(p=n;pS;S++)switch(x){case 143>=S:oa.push([S+48,8]);break;case 255>=S:oa.push([S-144+400,9]);break;case 279>=S:oa.push([S-256+0,7]);break;case 287>=S:oa.push([S-280+192,8]);break;default:l("invalid literal: "+S)} -ia.prototype.j=function(){var d,a,c,f,b=this.input;switch(this.h){case 0:c=0;for(f=b.length;c>>8&255;p[m++]=n&255;p[m++]=n>>>8&255;if(E)p.set(e,m),m+=e.length,p=p.subarray(0,m);else{q=0;for(r=e.length;qv)for(;0< -v--;)H[F++]=0,K[0]++;else for(;0v?v:138,C>v-3&&C=C?(H[F++]=17,H[F++]=C-3,K[17]++):(H[F++]=18,H[F++]=C-11,K[18]++),v-=C;else if(H[F++]=I[t],K[I[t]]++,v--,3>v)for(;0v?v:6,C>v-3&&CA;A++)ra[A]=ka[gb[A]];for(W=19;4=b:return[265,b-11,1];case 14>=b:return[266,b-13,1];case 16>=b:return[267,b-15,1];case 18>=b:return[268,b-17,1];case 22>=b:return[269,b-19,2];case 26>=b:return[270,b-23,2];case 30>=b:return[271,b-27,2];case 34>=b:return[272, -b-31,2];case 42>=b:return[273,b-35,3];case 50>=b:return[274,b-43,3];case 58>=b:return[275,b-51,3];case 66>=b:return[276,b-59,3];case 82>=b:return[277,b-67,4];case 98>=b:return[278,b-83,4];case 114>=b:return[279,b-99,4];case 130>=b:return[280,b-115,4];case 162>=b:return[281,b-131,5];case 194>=b:return[282,b-163,5];case 226>=b:return[283,b-195,5];case 257>=b:return[284,b-227,5];case 258===b:return[285,b-258,0];default:l("invalid length: "+b)}}var a=[],c,f;for(c=3;258>=c;c++)f=d(c),a[c]=f[2]<<24|f[1]<< -16|f[0];return a}(),wa=E?new Uint32Array(va):va; -function pa(d,a){function c(b,c){var a=b.G,d=[],e=0,f;f=wa[b.length];d[e++]=f&65535;d[e++]=f>>16&255;d[e++]=f>>24;var g;switch(x){case 1===a:g=[0,a-1,0];break;case 2===a:g=[1,a-2,0];break;case 3===a:g=[2,a-3,0];break;case 4===a:g=[3,a-4,0];break;case 6>=a:g=[4,a-5,1];break;case 8>=a:g=[5,a-7,1];break;case 12>=a:g=[6,a-9,2];break;case 16>=a:g=[7,a-13,2];break;case 24>=a:g=[8,a-17,3];break;case 32>=a:g=[9,a-25,3];break;case 48>=a:g=[10,a-33,4];break;case 64>=a:g=[11,a-49,4];break;case 96>=a:g=[12,a- -65,5];break;case 128>=a:g=[13,a-97,5];break;case 192>=a:g=[14,a-129,6];break;case 256>=a:g=[15,a-193,6];break;case 384>=a:g=[16,a-257,7];break;case 512>=a:g=[17,a-385,7];break;case 768>=a:g=[18,a-513,8];break;case 1024>=a:g=[19,a-769,8];break;case 1536>=a:g=[20,a-1025,9];break;case 2048>=a:g=[21,a-1537,9];break;case 3072>=a:g=[22,a-2049,10];break;case 4096>=a:g=[23,a-3073,10];break;case 6144>=a:g=[24,a-4097,11];break;case 8192>=a:g=[25,a-6145,11];break;case 12288>=a:g=[26,a-8193,12];break;case 16384>= -a:g=[27,a-12289,12];break;case 24576>=a:g=[28,a-16385,13];break;case 32768>=a:g=[29,a-24577,13];break;default:l("invalid distance")}f=g;d[e++]=f[0];d[e++]=f[1];d[e++]=f[2];var h,k;h=0;for(k=d.length;h=e;)w[e++]=0;for(e=0;29>=e;)y[e++]=0}w[256]=1;f=0;for(b=a.length;f=b){r&&c(r,-1);e=0;for(g=b-f;eg&&a+ge&&(b=f,e=g);if(258===g)break}return new ta(e,a-b)} -function qa(d,a){var c=d.length,f=new ha(572),b=new (E?Uint8Array:Array)(c),e,g,h,k,n;if(!E)for(k=0;k2*b[m-1]+e[m]&&(b[m]=2*b[m-1]+e[m]),h[m]=Array(b[m]),k[m]=Array(b[m]);for(p=0;pd[p]?(h[m][s]=w,k[m][s]=a,y+=2):(h[m][s]=d[p],k[m][s]=p,++p);n[m]=0;1===e[m]&&f(m)}return g} -function sa(d){var a=new (E?Uint16Array:Array)(d.length),c=[],f=[],b=0,e,g,h,k;e=0;for(g=d.length;e>>=1}return a};function T(d,a){this.l=[];this.m=32768;this.e=this.g=this.c=this.q=0;this.input=E?new Uint8Array(d):d;this.s=!1;this.n=za;this.B=!1;if(a||!(a={}))a.index&&(this.c=a.index),a.bufferSize&&(this.m=a.bufferSize),a.bufferType&&(this.n=a.bufferType),a.resize&&(this.B=a.resize);switch(this.n){case Aa:this.b=32768;this.a=new (E?Uint8Array:Array)(32768+this.m+258);break;case za:this.b=0;this.a=new (E?Uint8Array:Array)(this.m);this.f=this.J;this.t=this.H;this.o=this.I;break;default:l(Error("invalid inflate mode"))}} -var Aa=0,za=1,Ba={D:Aa,C:za}; -T.prototype.p=function(){for(;!this.s;){var d=Y(this,3);d&1&&(this.s=x);d>>>=1;switch(d){case 0:var a=this.input,c=this.c,f=this.a,b=this.b,e=u,g=u,h=u,k=f.length,n=u;this.e=this.g=0;e=a[c++];e===u&&l(Error("invalid uncompressed block header: LEN (first byte)"));g=e;e=a[c++];e===u&&l(Error("invalid uncompressed block header: LEN (second byte)"));g|=e<<8;e=a[c++];e===u&&l(Error("invalid uncompressed block header: NLEN (first byte)"));h=e;e=a[c++];e===u&&l(Error("invalid uncompressed block header: NLEN (second byte)"));h|= -e<<8;g===~h&&l(Error("invalid uncompressed block header: length verify"));c+g>a.length&&l(Error("input buffer is broken"));switch(this.n){case Aa:for(;b+g>f.length;){n=k-b;g-=n;if(E)f.set(a.subarray(c,c+n),b),b+=n,c+=n;else for(;n--;)f[b++]=a[c++];this.b=b;f=this.f();b=this.b}break;case za:for(;b+g>f.length;)f=this.f({v:2});break;default:l(Error("invalid inflate mode"))}if(E)f.set(a.subarray(c,c+g),b),b+=g,c+=g;else for(;g--;)f[b++]=a[c++];this.c=c;this.b=b;this.a=f;break;case 1:this.o(Ca,Ra);break; -case 2:Sa(this);break;default:l(Error("unknown BTYPE: "+d))}}return this.t()}; -var Ta=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],Ua=E?new Uint16Array(Ta):Ta,Va=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258],Wa=E?new Uint16Array(Va):Va,Xa=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0],Ya=E?new Uint8Array(Xa):Xa,Za=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],$a=E?new Uint16Array(Za):Za,ab=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10, -10,11,11,12,12,13,13],bb=E?new Uint8Array(ab):ab,cb=new (E?Uint8Array:Array)(288),Z,db;Z=0;for(db=cb.length;Z=Z?8:255>=Z?9:279>=Z?7:8;var Ca=R(cb),eb=new (E?Uint8Array:Array)(30),fb,hb;fb=0;for(hb=eb.length;fb>>a;d.e=f-a;d.c=e;return g} -function ib(d,a){for(var c=d.g,f=d.e,b=d.input,e=d.c,g=a[0],h=a[1],k,n,q;f>>16;d.g=c>>q;d.e=f-q;d.c=e;return n&65535} -function Sa(d){function a(a,b,c){var d,f,e,g;for(g=0;ge)f>=b&&(this.b=f,c=this.f(),f=this.b),c[f++]=e;else{g=e-257;k=Wa[g];0=b&&(this.b=f,c=this.f(),f=this.b);for(;k--;)c[f]=c[f++-h]}for(;8<=this.e;)this.e-=8,this.c--;this.b=f}; -T.prototype.I=function(d,a){var c=this.a,f=this.b;this.u=d;for(var b=c.length,e,g,h,k;256!==(e=ib(this,d));)if(256>e)f>=b&&(c=this.f(),b=c.length),c[f++]=e;else{g=e-257;k=Wa[g];0b&&(c=this.f(),b=c.length);for(;k--;)c[f]=c[f++-h]}for(;8<=this.e;)this.e-=8,this.c--;this.b=f}; -T.prototype.f=function(){var d=new (E?Uint8Array:Array)(this.b-32768),a=this.b-32768,c,f,b=this.a;if(E)d.set(b.subarray(32768,d.length));else{c=0;for(f=d.length;cc;++c)b[c]=b[a+c];this.b=32768;return b}; -T.prototype.J=function(d){var a,c=this.input.length/this.c+1|0,f,b,e,g=this.input,h=this.a;d&&("number"===typeof d.v&&(c=d.v),"number"===typeof d.F&&(c+=d.F));2>c?(f=(g.length-this.c)/this.u[2],e=258*(f/2)|0,b=ea&&(this.a.length=a),d=this.a);return this.buffer=d};function jb(d){if("string"===typeof d){var a=d.split(""),c,f;c=0;for(f=a.length;c>>0;d=a}for(var b=1,e=0,g=d.length,h,k=0;0>>0};function kb(d,a){var c,f;this.input=d;this.c=0;if(a||!(a={}))a.index&&(this.c=a.index),a.verify&&(this.M=a.verify);c=d[this.c++];f=d[this.c++];switch(c&15){case lb:this.method=lb;break;default:l(Error("unsupported compression method"))}0!==((c<<8)+f)%31&&l(Error("invalid fcheck flag:"+((c<<8)+f)%31));f&32&&l(Error("fdict flag is not supported"));this.A=new T(d,{index:this.c,bufferSize:a.bufferSize,bufferType:a.bufferType,resize:a.resize})} -kb.prototype.p=function(){var d=this.input,a,c;a=this.A.p();this.c=this.A.c;this.M&&(c=(d[this.c++]<<24|d[this.c++]<<16|d[this.c++]<<8|d[this.c++])>>>0,c!==jb(a)&&l(Error("invalid adler-32 checksum")));return a};var lb=8;function mb(d,a){this.input=d;this.a=new (E?Uint8Array:Array)(32768);this.h=$.k;var c={},f;if((a||!(a={}))&&"number"===typeof a.compressionType)this.h=a.compressionType;for(f in a)c[f]=a[f];c.outputBuffer=this.a;this.z=new ia(this.input,c)}var $=na; -mb.prototype.j=function(){var d,a,c,f,b,e,g,h=0;g=this.a;d=lb;switch(d){case lb:a=Math.LOG2E*Math.log(32768)-8;break;default:l(Error("invalid compression method"))}c=a<<4|d;g[h++]=c;switch(d){case lb:switch(this.h){case $.NONE:b=0;break;case $.r:b=1;break;case $.k:b=2;break;default:l(Error("unsupported compression type"))}break;default:l(Error("invalid compression method"))}f=b<<6|0;g[h++]=f|31-(256*c+f)%31;e=jb(this.input);this.z.b=h;g=this.z.j();h=g.length;E&&(g=new Uint8Array(g.buffer),g.length<= -h+4&&(this.a=new Uint8Array(g.length+4),this.a.set(g),g=this.a),g=g.subarray(0,h+4));g[h++]=e>>24&255;g[h++]=e>>16&255;g[h++]=e>>8&255;g[h++]=e&255;return g};function nb(d,a){var c,f,b,e;if(Object.keys)c=Object.keys(a);else for(f in c=[],b=0,a)c[b++]=f;b=0;for(e=c.length;b SYMLOOP_MAX){ - callback(new ELoop('too many symbolic links were encountered')); - } else { - follow_symbolic_link(node.data); - } - } else { - callback(null, node); - } - } - } - - function follow_symbolic_link(data) { - data = normalize(data); - parentPath = dirname(data); - name = basename(data); - if(ROOT_DIRECTORY_NAME == name) { - context.get(SUPER_NODE_ID, read_root_directory_node); - } else { - find_node(context, parentPath, read_parent_directory_data); - } - } - - if(ROOT_DIRECTORY_NAME == name) { - context.get(SUPER_NODE_ID, read_root_directory_node); - } else { - find_node(context, parentPath, read_parent_directory_data); - } - } - - /* - * make_root_directory - */ - - // Note: this should only be invoked when formatting a new file system - function make_root_directory(context, callback) { - var superNode; - var directoryNode; - var directoryData; - - function write_super_node(error, existingNode) { - if(!error && existingNode) { - callback(new EExists()); - } else if(error && !error instanceof ENoEntry) { - callback(error); - } else { - superNode = new SuperNode(); - context.put(superNode.id, superNode, write_directory_node); - } - } - - function write_directory_node(error) { - if(error) { - callback(error); - } else { - directoryNode = new Node(superNode.rnode, MODE_DIRECTORY); - directoryNode.nlinks += 1; - context.put(directoryNode.id, directoryNode, write_directory_data); - } - } - - function write_directory_data(error) { - if(error) { - callback(error); - } else { - directoryData = {}; - context.put(directoryNode.data, directoryData, callback); - } - } - - context.get(SUPER_NODE_ID, write_super_node); - } - - /* - * make_directory - */ - - function make_directory(context, path, callback) { - path = normalize(path); - var name = basename(path); - var parentPath = dirname(path); - - var directoryNode; - var directoryData; - var parentDirectoryNode; - var parentDirectoryData; - - function check_if_directory_exists(error, result) { - if(!error && result) { - callback(new EExists()); - } else if(error && !error instanceof ENoEntry) { - callback(error); - } else { - find_node(context, parentPath, read_parent_directory_data); - } - } - - function read_parent_directory_data(error, result) { - if(error) { - callback(error); - } else { - parentDirectoryNode = result; - context.get(parentDirectoryNode.data, write_directory_node); - } - } - - function write_directory_node(error, result) { - if(error) { - callback(error); - } else { - parentDirectoryData = result; - directoryNode = new Node(undefined, MODE_DIRECTORY); - directoryNode.nlinks += 1; - context.put(directoryNode.id, directoryNode, write_directory_data); - } - } - - function write_directory_data(error) { - if(error) { - callback(error); - } else { - directoryData = {}; - context.put(directoryNode.data, directoryData, update_parent_directory_data); - } - } - - function update_parent_directory_data(error) { - if(error) { - callback(error); - } else { - parentDirectoryData[name] = new DirectoryEntry(directoryNode.id, MODE_DIRECTORY); - context.put(parentDirectoryNode.data, parentDirectoryData, callback); - } - } - - find_node(context, path, check_if_directory_exists); - } - - /* - * remove_directory - */ - - function remove_directory(context, path, callback) { - path = normalize(path); - var name = basename(path); - var parentPath = dirname(path); - - var directoryNode; - var directoryData; - var parentDirectoryNode; - var parentDirectoryData; - - function read_parent_directory_data(error, result) { - if(error) { - callback(error); - } else { - parentDirectoryNode = result; - context.get(parentDirectoryNode.data, check_if_node_exists); - } - } - - function check_if_node_exists(error, result) { - if(error) { - callback(error); - } else if(ROOT_DIRECTORY_NAME == name) { - callback(new EBusy()); - } else if(!_(result).has(name)) { - callback(new ENoEntry()); - } else { - parentDirectoryData = result; - directoryNode = parentDirectoryData[name].id; - context.get(directoryNode, check_if_node_is_directory); - } - } - - function check_if_node_is_directory(error, result) { - if(error) { - callback(error); - } else if(result.mode != MODE_DIRECTORY) { - callback(new ENotDirectory()); - } else { - directoryNode = result; - context.get(directoryNode.data, check_if_directory_is_empty); - } - } - - function check_if_directory_is_empty(error, result) { - if(error) { - callback(error); - } else { - directoryData = result; - if(_(directoryData).size() > 0) { - callback(new ENotEmpty()); - } else { - remove_directory_entry_from_parent_directory_node(); - } - } - } - - function remove_directory_entry_from_parent_directory_node() { - delete parentDirectoryData[name]; - context.put(parentDirectoryNode.data, parentDirectoryData, remove_directory_node); - } - - function remove_directory_node(error) { - if(error) { - callback(error); - } else { - context.delete(directoryNode.id, remove_directory_data); - } - } - - function remove_directory_data(error) { - if(error) { - callback(error); - } else { - context.delete(directoryNode.data, callback); - } - } - - find_node(context, parentPath, read_parent_directory_data); - } - - function open_file(context, path, flags, callback) { - path = normalize(path); - var name = basename(path); - var parentPath = dirname(path); - - var directoryNode; - var directoryData; - var directoryEntry; - var fileNode; - var fileData; - - var followedCount = 0; - - if(ROOT_DIRECTORY_NAME == name) { - if(_(flags).contains(O_WRITE)) { - callback(new EIsDirectory('the named file is a directory and O_WRITE is set')); - } else { - find_node(context, path, set_file_node); - } - } else { - find_node(context, parentPath, read_directory_data); - } - - function read_directory_data(error, result) { - if(error) { - callback(error); - } else { - directoryNode = result; - context.get(directoryNode.data, check_if_file_exists); - } - } - - function check_if_file_exists(error, result) { - if(error) { - callback(error); - } else { - directoryData = result; - if(_(directoryData).has(name)) { - if(_(flags).contains(O_EXCLUSIVE)) { - callback(new ENoEntry('O_CREATE and O_EXCLUSIVE are set, and the named file exists')); - } else { - directoryEntry = directoryData[name]; - if(directoryEntry.type == MODE_DIRECTORY && _(flags).contains(O_WRITE)) { - callback(new EIsDirectory('the named file is a directory and O_WRITE is set')); - } else { - context.get(directoryEntry.id, check_if_symbolic_link); - } - } - } else { - if(!_(flags).contains(O_CREATE)) { - callback(new ENoEntry('O_CREATE is not set and the named file does not exist')); - } else { - write_file_node(); - } - } - } - } - - function check_if_symbolic_link(error, result) { - if(error) { - callback(error); - } else { - var node = result; - if(node.mode == MODE_SYMBOLIC_LINK) { - followedCount++; - if(followedCount > SYMLOOP_MAX){ - callback(new ELoop('too many symbolic links were encountered')); - } else { - follow_symbolic_link(node.data); - } - } else { - set_file_node(undefined, node); - } - } - } - - function follow_symbolic_link(data) { - data = normalize(data); - parentPath = dirname(data); - name = basename(data); - if(ROOT_DIRECTORY_NAME == name) { - if(_(flags).contains(O_WRITE)) { - callback(new EIsDirectory('the named file is a directory and O_WRITE is set')); - } else { - find_node(context, path, set_file_node); - } - } - find_node(context, parentPath, read_directory_data); - } - - function set_file_node(error, result) { - if(error) { - callback(error); - } else { - fileNode = result; - callback(null, fileNode); - } - } - - function write_file_node() { - fileNode = new Node(undefined, MODE_FILE); - fileNode.nlinks += 1; - context.put(fileNode.id, fileNode, write_file_data); - } - - function write_file_data(error) { - if(error) { - callback(error); - } else { - fileData = new Uint8Array(0); - context.put(fileNode.data, fileData, update_directory_data); - } - } - - function update_directory_data(error) { - if(error) { - callback(error); - } else { - directoryData[name] = new DirectoryEntry(fileNode.id, MODE_FILE); - context.put(directoryNode.data, directoryData, handle_update_result); - } - } - - function handle_update_result(error) { - if(error) { - callback(error); - } else { - callback(null, fileNode); - } - } - } - - function write_data(context, ofd, buffer, offset, length, position, callback) { - var fileNode; - var fileData; - - function return_nbytes(error) { - if(error) { - callback(error); - } else { - callback(null, length); - } - } - - function update_file_node(error) { - if(error) { - callback(error); - } else { - context.put(fileNode.id, fileNode, return_nbytes); - } - } - - function update_file_data(error, result) { - if(error) { - callback(error); - } else { - fileData = result; - var _position = (!(undefined === position || null === position)) ? position : ofd.position; - var newSize = Math.max(fileData.length, _position + length); - var newData = new Uint8Array(newSize); - if(fileData) { - newData.set(fileData); - } - newData.set(buffer, _position); - if(undefined === position) { - ofd.position += length; - } - - fileNode.size = newSize; - fileNode.mtime = Date.now(); - fileNode.version += 1; - - context.put(fileNode.data, newData, update_file_node); - } - } - - function read_file_data(error, result) { - if(error) { - callback(error); - } else { - fileNode = result; - context.get(fileNode.data, update_file_data); - } - } - - context.get(ofd.id, read_file_data); - } - - function read_data(context, ofd, buffer, offset, length, position, callback) { - var fileNode; - var fileData; - - function handle_file_data(error, result) { - if(error) { - callback(error); - } else { - fileData = result; - var _position = (!(undefined === position || null === position)) ? position : ofd.position; - length = (_position + length > buffer.length) ? length - _position : length; - var dataView = fileData.subarray(_position, _position + length); - buffer.set(dataView, offset); - if(undefined === position) { - ofd.position += length; - } - callback(null, length); - } - } - - function read_file_data(error, result) { - if(error) { - callback(error); - } else { - fileNode = result; - context.get(fileNode.data, handle_file_data); - } - } - - context.get(ofd.id, read_file_data); - } - - function stat_file(context, path, callback) { - path = normalize(path); - var name = basename(path); - - function check_file(error, result) { - if(error) { - callback(error); - } else { - callback(null, result); - } - } - - find_node(context, path, check_file); - } - - function fstat_file(context, ofd, callback) { - function check_file(error, result) { - if(error) { - callback(error); - } else { - callback(null, result); - } - } - - context.get(ofd.id, check_file); - } - - function lstat_file(context, path, callback) { - path = normalize(path); - var name = basename(path); - var parentPath = dirname(path); - - var directoryNode; - var directoryData; - - if(ROOT_DIRECTORY_NAME == name) { - find_node(context, path, check_file); - } else { - find_node(context, parentPath, read_directory_data); - } - - function read_directory_data(error, result) { - if(error) { - callback(error); - } else { - directoryNode = result; - context.get(directoryNode.data, check_if_file_exists); - } - } - - function check_if_file_exists(error, result) { - if(error) { - callback(error); - } else { - directoryData = result; - if(!_(directoryData).has(name)) { - callback(new ENoEntry('a component of the path does not name an existing file')); - } else { - context.get(directoryData[name].id, check_file); - } - } - } - - function check_file(error, result) { - if(error) { - callback(error); - } else { - callback(null, result); - } - } - } - - function link_node(context, oldpath, newpath, callback) { - oldpath = normalize(oldpath); - var oldname = basename(oldpath); - var oldParentPath = dirname(oldpath); - - newpath = normalize(newpath); - var newname = basename(newpath); - var newParentPath = dirname(newpath); - - var oldDirectoryNode; - var oldDirectoryData; - var newDirectoryNode; - var newDirectoryData; - var fileNode; - - function update_file_node(error, result) { - if(error) { - callback(error); - } else { - fileNode = result; - fileNode.nlinks += 1; - context.put(fileNode.id, fileNode, callback); - } - } - - function read_directory_entry(error, result) { - if(error) { - callback(error); - } else { - context.get(newDirectoryData[newname].id, update_file_node); - } - } - - function check_if_new_file_exists(error, result) { - if(error) { - callback(error); - } else { - newDirectoryData = result; - if(_(newDirectoryData).has(newname)) { - callback(new EExists('newpath resolves to an existing file')); - } else { - newDirectoryData[newname] = oldDirectoryData[oldname]; - context.put(newDirectoryNode.data, newDirectoryData, read_directory_entry); - } - } - } - - function read_new_directory_data(error, result) { - if(error) { - callback(error); - } else { - newDirectoryNode = result; - context.get(newDirectoryNode.data, check_if_new_file_exists); - } - } - - function check_if_old_file_exists(error, result) { - if(error) { - callback(error); - } else { - oldDirectoryData = result; - if(!_(oldDirectoryData).has(oldname)) { - callback(new ENoEntry('a component of either path prefix does not exist')); - } else { - find_node(context, newParentPath, read_new_directory_data); - } - } - } - - function read_old_directory_data(error, result) { - if(error) { - callback(error); - } else { - oldDirectoryNode = result; - context.get(oldDirectoryNode.data, check_if_old_file_exists); - } - } - - find_node(context, oldParentPath, read_old_directory_data); - } - - function unlink_node(context, path, callback) { - path = normalize(path); - var name = basename(path); - var parentPath = dirname(path); - - var directoryNode; - var directoryData; - var fileNode; - - function update_directory_data(error) { - if(error) { - callback(error); - } else { - delete directoryData[name]; - context.put(directoryNode.data, directoryData, callback); - } - } - - function delete_file_data(error) { - if(error) { - callback(error); - } else { - context.delete(fileNode.data, update_directory_data); - } - } - - function update_file_node(error, result) { - if(error) { - callback(error); - } else { - fileNode = result; - fileNode.nlinks -= 1; - if(fileNode.nlinks < 1) { - context.delete(fileNode.id, delete_file_data); - } else { - context.put(fileNode.id, fileNode, update_directory_data); - } - } - } - - function check_if_file_exists(error, result) { - if(error) { - callback(error); - } else { - directoryData = result; - if(!_(directoryData).has(name)) { - callback(new ENoEntry('a component of the path does not name an existing file')); - } else { - context.get(directoryData[name].id, update_file_node); - } - } - } - - function read_directory_data(error, result) { - if(error) { - callback(error); - } else { - directoryNode = result; - context.get(directoryNode.data, check_if_file_exists); - } - } - - find_node(context, parentPath, read_directory_data); - } - - function read_directory(context, path, callback) { - path = normalize(path); - var name = basename(path); - - var directoryNode; - var directoryData; - - function handle_directory_data(error, result) { - if(error) { - callback(error); - } else { - directoryData = result; - var files = Object.keys(directoryData); - callback(null, files); - } - } - - function read_directory_data(error, result) { - if(error) { - callback(error); - } else { - directoryNode = result; - context.get(directoryNode.data, handle_directory_data); - } - } - - find_node(context, path, read_directory_data); - } - - function make_symbolic_link(context, srcpath, dstpath, callback) { - dstpath = normalize(dstpath); - var name = basename(dstpath); - var parentPath = dirname(dstpath); - - var directoryNode; - var directoryData; - var fileNode; - - if(ROOT_DIRECTORY_NAME == name) { - callback(new EExists('the destination path already exists')); - } else { - find_node(context, parentPath, read_directory_data); - } - - function read_directory_data(error, result) { - if(error) { - callback(error); - } else { - directoryNode = result; - context.get(directoryNode.data, check_if_file_exists); - } - } - - function check_if_file_exists(error, result) { - if(error) { - callback(error); - } else { - directoryData = result; - if(_(directoryData).has(name)) { - callback(new EExists('the destination path already exists')); - } else { - write_file_node(); - } - } - } - - function write_file_node() { - fileNode = new Node(undefined, MODE_SYMBOLIC_LINK); - fileNode.nlinks += 1; - fileNode.size = srcpath.length; - fileNode.data = srcpath; - context.put(fileNode.id, fileNode, update_directory_data); - } - - function update_directory_data(error) { - if(error) { - callback(error); - } else { - directoryData[name] = new DirectoryEntry(fileNode.id, MODE_SYMBOLIC_LINK); - context.put(directoryNode.data, directoryData, callback); - } - } - } - - function read_link(context, path, callback) { - path = normalize(path); - var name = basename(path); - var parentPath = dirname(path); - - var directoryNode; - var directoryData; - - find_node(context, parentPath, read_directory_data); - - function read_directory_data(error, result) { - if(error) { - callback(error); - } else { - directoryNode = result; - context.get(directoryNode.data, check_if_file_exists); - } - } - - function check_if_file_exists(error, result) { - if(error) { - callback(error); - } else { - directoryData = result; - if(!_(directoryData).has(name)) { - callback(new ENoEntry('a component of the path does not name an existing file')); - } else { - context.get(directoryData[name].id, check_if_symbolic); - } - } - } - - function check_if_symbolic(error, result) { - if(error) { - callback(error); - } else { - if(result.mode != MODE_SYMBOLIC_LINK) { - callback(new EInvalid("path not a symbolic link")); - } else { - callback(null, result.data); - } - } - } - } - - function truncate_file(context, path, length, callback) { - path = normalize(path); - - var fileNode; - - function read_file_data (error, node) { - if (error) { - callback(error); - } else if(node.mode == MODE_DIRECTORY ) { - callback(new EIsDirectory('the named file is a directory')); - } else{ - fileNode = node; - context.get(fileNode.data, truncate_file_data); - } - } - - function truncate_file_data(error, fileData) { - if (error) { - callback(error); - } else { - var data = new Uint8Array(length); - if(fileData) { - data.set(fileData.subarray(0, length)); - } - context.put(fileNode.data, data, update_file_node); - } - } - - function update_file_node (error) { - if(error) { - callback(error); - } else { - fileNode.size = length; - fileNode.mtime = Date.now(); - fileNode.version += 1; - context.put(fileNode.id, fileNode, callback); - } - } - - if(length < 0) { - callback(new EInvalid('length cannot be negative')); - } else { - find_node(context, path, read_file_data); - } - } - - function ftruncate_file(context, ofd, length, callback) { - var fileNode; - - function read_file_data (error, node) { - if (error) { - callback(error); - } else if(node.mode == MODE_DIRECTORY ) { - callback(new EIsDirectory('the named file is a directory')); - } else{ - fileNode = node; - context.get(fileNode.data, truncate_file_data); - } - } - - function truncate_file_data(error, fileData) { - if (error) { - callback(error); - } else { - var data = new Uint8Array(length); - if(fileData) { - data.set(fileData.subarray(0, length)); - } - context.put(fileNode.data, data, update_file_node); - } - } - - function update_file_node (error) { - if(error) { - callback(error); - } else { - fileNode.size = length; - fileNode.mtime = Date.now(); - fileNode.version += 1; - context.put(fileNode.id, fileNode, callback); - } - } - - if(length < 0) { - callback(new EInvalid('length cannot be negative')); - } else { - context.get(ofd.id, read_file_data); - } - } - - function validate_flags(flags) { - if(!_(O_FLAGS).has(flags)) { - return null; - } - return O_FLAGS[flags]; - } - - // nullCheck from https://github.com/joyent/node/blob/master/lib/fs.js - function nullCheck(path, callback) { - if (('' + path).indexOf('\u0000') !== -1) { - var er = new Error('Path must be a string without null bytes.'); - callback(er); - return false; - } - return true; - } - - // node.js supports a calling pattern that leaves off a callback. - function maybeCallback(callback) { - if(typeof callback === "function") { - return callback; - } - return function(err) { - if(err) { - throw err; - } - }; - } - - - /* - * FileSystem - * - * A FileSystem takes an `options` object, which can specify a number of, - * options. All options are optional, and include: - * - * name: the name of the file system, defaults to "local" - * - * flags: one or more flags to use when creating/opening the file system. - * For example: "FORMAT" will cause the file system to be formatted. - * No explicit flags are set by default. - * - * provider: an explicit storage provider to use for the file - * system's database context provider. A number of context - * providers are included (see /src/providers), and users - * can write one of their own and pass it in to be used. - * By default an IndexedDB provider is used. - * - * callback: a callback function to be executed when the file system becomes - * ready for use. Depending on the context provider used, this might - * be right away, or could take some time. The callback should expect - * an `error` argument, which will be null if everything worked. Also - * users should check the file system's `readyState` and `error` - * properties to make sure it is usable. - */ - function FileSystem(options, callback) { - options = options || {}; - callback = callback || nop; - - var name = options.name || FILE_SYSTEM_NAME; - var flags = options.flags; - var provider = options.provider || new providers.Default(name); - var forceFormatting = _(flags).contains(FS_FORMAT); - - var fs = this; - fs.readyState = FS_PENDING; - fs.name = name; - fs.error = null; - - // Safely expose the list of open files and file - // descriptor management functions - var openFiles = {}; - var nextDescriptor = 1; - Object.defineProperty(this, "openFiles", { - get: function() { return openFiles; } - }); - this.allocDescriptor = function(openFileDescription) { - var fd = nextDescriptor ++; - openFiles[fd] = openFileDescription; - return fd; - }; - this.releaseDescriptor = function(fd) { - delete openFiles[fd]; - }; - - // Safely expose the operation queue - var queue = []; - this.queueOrRun = function(operation) { - var error; - - if(FS_READY == fs.readyState) { - operation.call(fs); - } else if(FS_ERROR == fs.readyState) { - error = new EFileSystemError('unknown error'); - } else { - queue.push(operation); - } - - return error; - }; - function runQueued() { - queue.forEach(function(operation) { - operation.call(this); - }.bind(fs)); - queue = null; - } - - // Open file system storage provider - provider.open(function(err, needsFormatting) { - function complete(error) { - fs.provider = provider; - if(error) { - fs.readyState = FS_ERROR; - } else { - fs.readyState = FS_READY; - runQueued(); - } - callback(error); - } - - if(err) { - return complete(err); - } - - // If we don't need or want formatting, we're done - if(!(forceFormatting || needsFormatting)) { - return complete(null); - } - // otherwise format the fs first - var context = provider.getReadWriteContext(); - context.clear(function(err) { - if(err) { - complete(err); - return; - } - make_root_directory(context, complete); - }); - }); - } - - // Expose storage providers on FileSystem constructor - FileSystem.providers = providers; - - // Expose adatpers on FileSystem constructor - FileSystem.adapters = adapters; - - function _open(fs, context, path, flags, callback) { - if(!nullCheck(path, callback)) return; - - function check_result(error, fileNode) { - if(error) { - callback(error); - } else { - var position; - if(_(flags).contains(O_APPEND)) { - position = fileNode.size; - } else { - position = 0; - } - var openFileDescription = new OpenFileDescription(fileNode.id, flags, position); - var fd = fs.allocDescriptor(openFileDescription); - callback(null, fd); - } - } - - flags = validate_flags(flags); - if(!flags) { - callback(new EInvalid('flags is not valid')); - } - - open_file(context, path, flags, check_result); - } - - function _close(fs, fd, callback) { - if(!_(fs.openFiles).has(fd)) { - callback(new EBadFileDescriptor('invalid file descriptor')); - } else { - fs.releaseDescriptor(fd); - callback(null); - } - } - - function _mkdir(context, path, callback) { - if(!nullCheck(path, callback)) return; - - function check_result(error) { - if(error) { - callback(error); - } else { - callback(null); - } - } - - make_directory(context, path, check_result); - } - - function _rmdir(context, path, callback) { - if(!nullCheck(path, callback)) return; - - function check_result(error) { - if(error) { - callback(error); - } else { - callback(null); - } - } - - remove_directory(context, path, check_result); - } - - function _stat(context, name, path, callback) { - if(!nullCheck(path, callback)) return; - - function check_result(error, result) { - if(error) { - callback(error); - } else { - var stats = new Stats(result, name); - callback(null, stats); - } - } - - stat_file(context, path, check_result); - } - - function _fstat(fs, context, fd, callback) { - function check_result(error, result) { - if(error) { - callback(error); - } else { - var stats = new Stats(result, fs.name); - callback(null, stats); - } - } - - var ofd = fs.openFiles[fd]; - - if(!ofd) { - callback(new EBadFileDescriptor('invalid file descriptor')); - } else { - fstat_file(context, ofd, check_result); - } - } - - function _link(context, oldpath, newpath, callback) { - if(!nullCheck(oldpath, callback)) return; - if(!nullCheck(newpath, callback)) return; - - function check_result(error) { - if(error) { - callback(error); - } else { - callback(null); - } - } - - link_node(context, oldpath, newpath, check_result); - } - - function _unlink(context, path, callback) { - if(!nullCheck(path, callback)) return; - - function check_result(error) { - if(error) { - callback(error); - } else { - callback(null); - } - } - - unlink_node(context, path, check_result); - } - - function _read(fs, context, fd, buffer, offset, length, position, callback) { - offset = (undefined === offset) ? 0 : offset; - length = (undefined === length) ? buffer.length - offset : length; - - function check_result(error, nbytes) { - if(error) { - callback(error); - } else { - callback(null, nbytes); - } - } - - var ofd = fs.openFiles[fd]; - - if(!ofd) { - callback(new EBadFileDescriptor('invalid file descriptor')); - } else if(!_(ofd.flags).contains(O_READ)) { - callback(new EBadFileDescriptor('descriptor does not permit reading')); - } else { - read_data(context, ofd, buffer, offset, length, position, check_result); - } - } - - function _readFile(fs, context, path, options, callback) { - if(!options) { - options = { encoding: null, flag: 'r' }; - } else if(typeof options === "function") { - options = { encoding: null, flag: 'r' }; - } else if(typeof options === "string") { - options = { encoding: options, flag: 'r' }; - } - - if(!nullCheck(path, callback)) return; - - var flags = validate_flags(options.flag || 'r'); - if(!flags) { - callback(new EInvalid('flags is not valid')); - } - - open_file(context, path, flags, function(err, fileNode) { - if(err) { - return callback(err); - } - var ofd = new OpenFileDescription(fileNode.id, flags, 0); - var fd = fs.allocDescriptor(ofd); - - fstat_file(context, ofd, function(err2, fstatResult) { - if(err2) { - return callback(err2); - } - - var stats = new Stats(fstatResult, fs.name); - var size = stats.size; - var buffer = new Uint8Array(size); - - read_data(context, ofd, buffer, 0, size, 0, function(err3, nbytes) { - if(err3) { - return callback(err3); - } - fs.releaseDescriptor(fd); - - var data; - if(options.encoding === 'utf8') { - data = new TextDecoder('utf-8').decode(buffer); - } else { - data = buffer; - } - callback(null, data); - }); - }); - - }); - } - - function _write(fs, context, fd, buffer, offset, length, position, callback) { - offset = (undefined === offset) ? 0 : offset; - length = (undefined === length) ? buffer.length - offset : length; - - function check_result(error, nbytes) { - if(error) { - callback(error); - } else { - callback(null, nbytes); - } - } - - var ofd = fs.openFiles[fd]; - - if(!ofd) { - callback(new EBadFileDescriptor('invalid file descriptor')); - } else if(!_(ofd.flags).contains(O_WRITE)) { - callback(new EBadFileDescriptor('descriptor does not permit writing')); - } else if(buffer.length - offset < length) { - callback(new EIO('intput buffer is too small')); - } else { - write_data(context, ofd, buffer, offset, length, position, check_result); - } - } - - function _writeFile(fs, context, path, data, options, callback) { - if(!options) { - options = { encoding: 'utf8', flag: 'w' }; - } else if(typeof options === "function") { - options = { encoding: 'utf8', flag: 'w' }; - } else if(typeof options === "string") { - options = { encoding: options, flag: 'w' }; - } - - if(!nullCheck(path, callback)) return; - - var flags = validate_flags(options.flag || 'w'); - if(!flags) { - callback(new EInvalid('flags is not valid')); - } - - data = data || ''; - if(typeof data === "number") { - data = '' + data; - } - if(typeof data === "string" && options.encoding === 'utf8') { - data = new TextEncoder('utf-8').encode(data); - } - - open_file(context, path, flags, function(err, fileNode) { - if(err) { - return callback(err); - } - var ofd = new OpenFileDescription(fileNode.id, flags, 0); - var fd = fs.allocDescriptor(ofd); - - write_data(context, ofd, data, 0, data.length, 0, function(err2, nbytes) { - if(err2) { - return callback(err2); - } - fs.releaseDescriptor(fd); - callback(null); - }); - }); - } - - function _getxattr(path, name, callback) { - // TODO - // if(!nullCheck(path, callback)) return; - } - - function _setxattr(path, name, value, callback) { - // TODO - // if(!nullCheck(path, callback)) return; - } - - function _lseek(fs, context, fd, offset, whence, callback) { - function check_result(error, offset) { - if(error) { - callback(error); - } else { - callback(offset); - } - } - - function update_descriptor_position(error, stats) { - if(error) { - callback(error); - } else { - if(stats.size + offset < 0) { - callback(new EInvalid('resulting file offset would be negative')); - } else { - ofd.position = stats.size + offset; - callback(null, ofd.position); - } - } - } - - var ofd = fs.openFiles[fd]; - - if(!ofd) { - callback(new EBadFileDescriptor('invalid file descriptor')); - } - - if('SET' === whence) { - if(offset < 0) { - callback(new EInvalid('resulting file offset would be negative')); - } else { - ofd.position = offset; - callback(null, ofd.position); - } - } else if('CUR' === whence) { - if(ofd.position + offset < 0) { - callback(new EInvalid('resulting file offset would be negative')); - } else { - ofd.position += offset; - callback(null, ofd.position); - } - } else if('END' === whence) { - fstat_file(context, ofd, update_descriptor_position); - } else { - callback(new EInvalid('whence argument is not a proper value')); - } - } - - function _readdir(context, path, callback) { - if(!nullCheck(path, callback)) return; - - function check_result(error, files) { - if(error) { - callback(error); - } else { - callback(null, files); - } - } - - read_directory(context, path, check_result); - } - - function _utimes(path, atime, mtime, callback) { - // TODO - // if(!nullCheck(path, callback)) return; - } - - function _rename(context, oldpath, newpath, callback) { - if(!nullCheck(oldpath, callback)) return; - if(!nullCheck(newpath, callback)) return; - - function check_result(error) { - if(error) { - callback(error); - } else { - callback(null); - } - } - - function unlink_old_node(error) { - if(error) { - callback(error); - } else { - unlink_node(context, oldpath, check_result); - } - } - - link_node(context, oldpath, newpath, unlink_old_node); - } - - function _symlink(context, srcpath, dstpath, callback) { - if(!nullCheck(srcpath, callback)) return; - if(!nullCheck(dstpath, callback)) return; - - function check_result(error) { - if(error) { - callback(error); - } else { - callback(null); - } - } - - make_symbolic_link(context, srcpath, dstpath, check_result); - } - - function _readlink(context, path, callback) { - if(!nullCheck(path, callback)) return; - - function check_result(error, result) { - if(error) { - callback(error); - } else { - callback(null, result); - } - } - - read_link(context, path, check_result); - } - - function _realpath(fd, length, callback) { - // TODO - } - - function _lstat(fs, context, path, callback) { - if(!nullCheck(path, callback)) return; - - function check_result(error, result) { - if(error) { - callback(error); - } else { - var stats = new Stats(result, fs.name); - callback(null, stats); - } - } - - lstat_file(context, path, check_result); - } - - function _truncate(context, path, length, callback) { - if(!nullCheck(path, callback)) return; - - function check_result(error) { - if(error) { - callback(error); - } else { - callback(null); - } - } - - truncate_file(context, path, length, check_result); - } - - function _ftruncate(fs, context, fd, length, callback) { - function check_result(error) { - if(error) { - callback(error); - } else { - callback(null); - } - } - - var ofd = fs.openFiles[fd]; - - if(!ofd) { - callback(new EBadFileDescriptor('invalid file descriptor')); - } else if(!_(ofd.flags).contains(O_WRITE)) { - callback(new EBadFileDescriptor('descriptor does not permit writing')); - } else { - ftruncate_file(context, ofd, length, check_result); - } - } - - - /** - * Public API for FileSystem - */ - - FileSystem.prototype.open = function(path, flags, mode, callback) { - // We support the same signature as node with a `mode` arg, but - // ignore it. Find the callback. - callback = maybeCallback(arguments[arguments.length - 1]); - var fs = this; - var error = fs.queueOrRun( - function() { - var context = fs.provider.getReadWriteContext(); - _open(fs, context, path, flags, callback); - } - ); - if(error) callback(error); - }; - FileSystem.prototype.close = function(fd, callback) { - _close(this, fd, maybeCallback(callback)); - }; - FileSystem.prototype.mkdir = function(path, mode, callback) { - // Support passing a mode arg, but we ignore it internally for now. - if(typeof mode === 'function') { - callback = mode; - } - callback = maybeCallback(callback); - var fs = this; - var error = fs.queueOrRun( - function() { - var context = fs.provider.getReadWriteContext(); - _mkdir(context, path, callback); - } - ); - if(error) callback(error); - }; - FileSystem.prototype.rmdir = function(path, callback) { - callback = maybeCallback(callback); - var fs = this; - var error = fs.queueOrRun( - function() { - var context = fs.provider.getReadWriteContext(); - _rmdir(context, path, callback); - } - ); - if(error) callback(error); - }; - FileSystem.prototype.stat = function(path, callback) { - callback = maybeCallback(callback); - var fs = this; - var error = fs.queueOrRun( - function() { - var context = fs.provider.getReadWriteContext(); - _stat(context, fs.name, path, callback); - } - ); - if(error) callback(error); - }; - FileSystem.prototype.fstat = function(fd, callback) { - callback = maybeCallback(callback); - var fs = this; - var error = fs.queueOrRun( - function() { - var context = fs.provider.getReadWriteContext(); - _fstat(fs, context, fd, callback); - } - ); - if(error) callback(error); - }; - FileSystem.prototype.link = function(oldpath, newpath, callback) { - callback = maybeCallback(callback); - var fs = this; - var error = fs.queueOrRun( - function() { - var context = fs.provider.getReadWriteContext(); - _link(context, oldpath, newpath, callback); - } - ); - if(error) callback(error); - }; - FileSystem.prototype.unlink = function(path, callback) { - callback = maybeCallback(callback); - var fs = this; - var error = fs.queueOrRun( - function() { - var context = fs.provider.getReadWriteContext(); - _unlink(context, path, callback); - } - ); - if(error) callback(error); - }; - FileSystem.prototype.read = function(fd, buffer, offset, length, position, callback) { - // Follow how node.js does this - callback = maybeCallback(callback); - function wrapper(err, bytesRead) { - // Retain a reference to buffer so that it can't be GC'ed too soon. - callback(err, bytesRead || 0, buffer); - } - var fs = this; - var error = fs.queueOrRun( - function() { - var context = fs.provider.getReadWriteContext(); - _read(fs, context, fd, buffer, offset, length, position, wrapper); - } - ); - if(error) callback(error); - }; - FileSystem.prototype.readFile = function(path, options, callback_) { - var callback = maybeCallback(arguments[arguments.length - 1]); - var fs = this; - var error = fs.queueOrRun( - function() { - var context = fs.provider.getReadWriteContext(); - _readFile(fs, context, path, options, callback); - } - ); - if(error) callback(error); - }; - FileSystem.prototype.write = function(fd, buffer, offset, length, position, callback) { - callback = maybeCallback(callback); - var fs = this; - var error = fs.queueOrRun( - function() { - var context = fs.provider.getReadWriteContext(); - _write(fs, context, fd, buffer, offset, length, position, callback); - } - ); - - if(error) callback(error); - }; - FileSystem.prototype.writeFile = function(path, data, options, callback_) { - var callback = maybeCallback(arguments[arguments.length - 1]); - var fs = this; - var error = fs.queueOrRun( - function() { - var context = fs.provider.getReadWriteContext(); - _writeFile(fs, context, path, data, options, callback); - } - ); - if(error) callback(error); - }; - FileSystem.prototype.lseek = function(fd, offset, whence, callback) { - callback = maybeCallback(callback); - var fs = this; - var error = fs.queueOrRun( - function() { - var context = fs.provider.getReadWriteContext(); - _lseek(fs, context, fd, offset, whence, callback); - } - ); - if(error) callback(error); - }; - FileSystem.prototype.readdir = function(path, callback) { - callback = maybeCallback(callback); - var fs = this; - var error = fs.queueOrRun( - function() { - var context = fs.provider.getReadWriteContext(); - _readdir(context, path, callback); - } - ); - if(error) callback(error); - }; - FileSystem.prototype.rename = function(oldpath, newpath, callback) { - callback = maybeCallback(callback); - var fs = this; - var error = fs.queueOrRun( - function() { - var context = fs.provider.getReadWriteContext(); - _rename(context, oldpath, newpath, callback); - } - ); - if(error) callback(error); - }; - FileSystem.prototype.readlink = function(path, callback) { - callback = maybeCallback(callback); - var fs = this; - var error = fs.queueOrRun( - function() { - var context = fs.provider.getReadWriteContext(); - _readlink(context, path, callback); - } - ); - if(error) callback(error); - }; - FileSystem.prototype.symlink = function(srcpath, dstpath, type, callback_) { - // Follow node.js in allowing the `type` arg to be passed, but we ignore it. - var callback = maybeCallback(arguments[arguments.length - 1]); - var fs = this; - var error = fs.queueOrRun( - function() { - var context = fs.provider.getReadWriteContext(); - _symlink(context, srcpath, dstpath, callback); - } - ); - if(error) callback(error); - }; - FileSystem.prototype.lstat = function(path, callback) { - callback = maybeCallback(callback); - var fs = this; - var error = fs.queueOrRun( - function() { - var context = fs.provider.getReadWriteContext(); - _lstat(fs, context, path, callback); - } - ); - if(error) callback(error); - }; - FileSystem.prototype.truncate = function(path, length, callback) { - callback = maybeCallback(callback); - var fs = this; - var error = fs.queueOrRun( - function() { - var context = fs.provider.getReadWriteContext(); - _truncate(context, path, length, callback); - } - ); - if(error) callback(error); - }; - FileSystem.prototype.ftruncate = function(fd, length, callback) { - callback = maybeCallback(callback); - var fs = this; - var error = fs.queueOrRun( - function() { - var context = fs.provider.getReadWriteContext(); - _ftruncate(fs, context, fd, length, callback); - } - ); - if(error) callback(error); - }; - - return FileSystem; - -}); - -define('src/index',['require','src/fs','src/fs','src/path'],function(require) { - - var fs = require('src/fs'); - - return { - FileSystem: require('src/fs'), - Path: require('src/path') - } - -}); - var IDBFS = require( "src/index" ); - - return IDBFS; - -})); - diff --git a/dist/idbfs.min.js b/dist/idbfs.min.js deleted file mode 100644 index 6cd0baa..0000000 --- a/dist/idbfs.min.js +++ /dev/null @@ -1,5 +0,0 @@ -/*! filer 2013-12-14 */ -(function(t,e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):t.IDBFS||(t.IDBFS=e())})(this,function(){var t,e,n;(function(r){function i(t,e){return b.call(t,e)}function o(t,e){var n,r,i,o,s,a,c,u,f,l,h=e&&e.split("/"),d=m.map,p=d&&d["*"]||{};if(t&&"."===t.charAt(0))if(e){for(h=h.slice(0,h.length-1),t=h.concat(t.split("/")),u=0;t.length>u;u+=1)if(l=t[u],"."===l)t.splice(u,1),u-=1;else if(".."===l){if(1===u&&(".."===t[2]||".."===t[0]))break;u>0&&(t.splice(u-1,2),u-=2)}t=t.join("/")}else 0===t.indexOf("./")&&(t=t.substring(2));if((h||p)&&d){for(n=t.split("/"),u=n.length;u>0;u-=1){if(r=n.slice(0,u).join("/"),h)for(f=h.length;f>0;f-=1)if(i=d[h.slice(0,f).join("/")],i&&(i=i[r])){o=i,s=u;break}if(o)break;!a&&p&&p[r]&&(a=p[r],c=u)}!o&&a&&(o=a,s=c),o&&(n.splice(0,s,o),t=n.join("/"))}return t}function s(t,e){return function(){return d.apply(r,w.call(arguments,0).concat([t,e]))}}function a(t){return function(e){return o(e,t)}}function c(t){return function(e){y[t]=e}}function u(t){if(i(v,t)){var e=v[t];delete v[t],_[t]=!0,h.apply(r,e)}if(!i(y,t)&&!i(_,t))throw Error("No "+t);return y[t]}function f(t){var e,n=t?t.indexOf("!"):-1;return n>-1&&(e=t.substring(0,n),t=t.substring(n+1,t.length)),[e,t]}function l(t){return function(){return m&&m.config&&m.config[t]||{}}}var h,d,p,g,y={},v={},m={},_={},b=Object.prototype.hasOwnProperty,w=[].slice;p=function(t,e){var n,r=f(t),i=r[0];return t=r[1],i&&(i=o(i,e),n=u(i)),i?t=n&&n.normalize?n.normalize(t,a(e)):o(t,e):(t=o(t,e),r=f(t),i=r[0],t=r[1],i&&(n=u(i))),{f:i?i+"!"+t:t,n:t,pr:i,p:n}},g={require:function(t){return s(t)},exports:function(t){var e=y[t];return e!==void 0?e:y[t]={}},module:function(t){return{id:t,uri:"",exports:y[t],config:l(t)}}},h=function(t,e,n,o){var a,f,l,h,d,m,b=[];if(o=o||t,"function"==typeof n){for(e=!e.length&&n.length?["require","exports","module"]:e,d=0;e.length>d;d+=1)if(h=p(e[d],o),f=h.f,"require"===f)b[d]=g.require(t);else if("exports"===f)b[d]=g.exports(t),m=!0;else if("module"===f)a=b[d]=g.module(t);else if(i(y,f)||i(v,f)||i(_,f))b[d]=u(f);else{if(!h.p)throw Error(t+" missing "+f);h.p.load(h.n,s(o,!0),c(f),{}),b[d]=y[f]}l=n.apply(y[t],b),t&&(a&&a.exports!==r&&a.exports!==y[t]?y[t]=a.exports:l===r&&m||(y[t]=l))}else t&&(y[t]=n)},t=e=d=function(t,e,n,i,o){return"string"==typeof t?g[t]?g[t](e):u(p(t,e).f):(t.splice||(m=t,e.splice?(t=e,e=n,n=null):t=r),e=e||function(){},"function"==typeof n&&(n=i,i=o),i?h(r,t,e,n):setTimeout(function(){h(r,t,e,n)},4),d)},d.config=function(t){return m=t,m.deps&&d(m.deps,m.callback),d},n=function(t,e,n){e.splice||(n=e,e=[]),i(y,t)||i(v,t)||(v[t]=[t,e,n])},n.amd={jQuery:!0}})(),n("build/almond",function(){}),n("nodash",["require"],function(){function t(t,e){return d.call(t,e)}function e(t){return null==t?0:t.length===+t.length?t.length:y(t).length}function n(t){return t}function r(t,e,n){var r,i;if(null!=t)if(u&&t.forEach===u)t.forEach(e,n);else if(t.length===+t.length){for(r=0,i=t.length;i>r;r++)if(e.call(n,t[r],r,t)===g)return}else{var o=o(t);for(r=0,i=o.length;i>r;r++)if(e.call(n,t[o[r]],o[r],t)===g)return}}function i(t,e,i){e||(e=n);var o=!1;return null==t?o:l&&t.some===l?t.some(e,i):(r(t,function(t,n,r){return o||(o=e.call(i,t,n,r))?g:void 0}),!!o)}function o(t,e){return null==t?!1:f&&t.indexOf===f?-1!=t.indexOf(e):i(t,function(t){return t===e})}function s(t){this.value=t}function a(t){return t&&"object"==typeof t&&!Array.isArray(t)&&d.call(t,"__wrapped__")?t:new s(t)}var c=Array.prototype,u=c.forEach,f=c.indexOf,l=c.some,h=Object.prototype,d=h.hasOwnProperty,p=Object.keys,g={},y=p||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var n=[];for(var r in e)t(e,r)&&n.push(r);return n};return s.prototype.has=function(e){return t(this.value,e)},s.prototype.contains=function(t){return o(this.value,t)},s.prototype.size=function(){return e(this.value)},a}),function(t){t["encoding-indexes"]=t["encoding-indexes"]||[]}(this),n("encoding-indexes-shim",function(){}),function(t){function e(t,e,n){return t>=e&&n>=t}function n(t,e){return Math.floor(t/e)}function r(t){var e=0;this.get=function(){return e>=t.length?U:Number(t[e])},this.offset=function(n){if(e+=n,0>e)throw Error("Seeking past start of the buffer");if(e>t.length)throw Error("Seeking past EOF")},this.match=function(n){if(n.length>e+t.length)return!1;var r;for(r=0;n.length>r;r+=1)if(Number(t[e+r])!==n[r])return!1;return!0}}function i(t){var e=0;this.emit=function(){var n,r=U;for(n=0;arguments.length>n;++n)r=Number(arguments[n]),t[e++]=r;return r}}function o(t){function n(t){for(var n=[],r=0,i=t.length;t.length>r;){var o=t.charCodeAt(r);if(e(o,55296,57343))if(e(o,56320,57343))n.push(65533);else if(r===i-1)n.push(65533);else{var s=t.charCodeAt(r+1);if(e(s,56320,57343)){var a=1023&o,c=1023&s;r+=1,n.push(65536+(a<<10)+c)}else n.push(65533)}else n.push(o);r+=1}return n}var r=0,i=n(t);this.offset=function(t){if(r+=t,0>r)throw Error("Seeking past start of the buffer");if(r>i.length)throw Error("Seeking past EOF")},this.get=function(){return r>=i.length?N:i[r]}}function s(){var t="";this.string=function(){return t},this.emit=function(e){65535>=e?t+=String.fromCharCode(e):(e-=65536,t+=String.fromCharCode(55296+(1023&e>>10)),t+=String.fromCharCode(56320+(1023&e)))}}function a(t){this.name="EncodingError",this.message=t,this.code=0}function c(t,e){if(t)throw new a("Decoder error");return e||65533}function u(t){throw new a("The code point "+t+" could not be encoded.")}function f(t){return t=(t+"").trim().toLowerCase(),Object.prototype.hasOwnProperty.call(P,t)?P[t]:null}function l(t,e){return(e||[])[t]||null}function h(t,e){var n=e.indexOf(t);return-1===n?null:n}function d(e){if(!("encoding-indexes"in t))throw Error("Indexes missing. Did you forget to include encoding-indexes.js?");return t["encoding-indexes"][e]}function p(t){if(t>39419&&189e3>t||t>1237575)return null;var e,n=0,r=0,i=d("gb18030");for(e=0;i.length>e;++e){var o=i[e];if(!(t>=o[0]))break;n=o[0],r=o[1]}return r+t-n}function g(t){var e,n=0,r=0,i=d("gb18030");for(e=0;i.length>e;++e){var o=i[e];if(!(t>=o[1]))break;n=o[1],r=o[0]}return r+t-n}function y(t){var n=t.fatal,r=0,i=0,o=0,s=0;this.decode=function(t){var a=t.get();if(a===U)return 0!==i?c(n):N;if(t.offset(1),0===i){if(e(a,0,127))return a;if(e(a,194,223))i=1,s=128,r=a-192;else if(e(a,224,239))i=2,s=2048,r=a-224;else{if(!e(a,240,244))return c(n);i=3,s=65536,r=a-240}return r*=Math.pow(64,i),null}if(!e(a,128,191))return r=0,i=0,o=0,s=0,t.offset(-1),c(n);if(o+=1,r+=(a-128)*Math.pow(64,i-o),o!==i)return null;var u=r,f=s;return r=0,i=0,o=0,s=0,e(u,f,1114111)&&!e(u,55296,57343)?u:c(n)}}function v(t){t.fatal,this.encode=function(t,r){var i=r.get();if(i===N)return U;if(r.offset(1),e(i,55296,57343))return u(i);if(e(i,0,127))return t.emit(i);var o,s;e(i,128,2047)?(o=1,s=192):e(i,2048,65535)?(o=2,s=224):e(i,65536,1114111)&&(o=3,s=240);for(var a=t.emit(n(i,Math.pow(64,o))+s);o>0;){var c=n(i,Math.pow(64,o-1));a=t.emit(128+c%64),o-=1}return a}}function m(t,n){var r=n.fatal;this.decode=function(n){var i=n.get();if(i===U)return N;if(n.offset(1),e(i,0,127))return i;var o=t[i-128];return null===o?c(r):o}}function _(t,n){n.fatal,this.encode=function(n,r){var i=r.get();if(i===N)return U;if(r.offset(1),e(i,0,127))return n.emit(i);var o=h(i,t);return null===o&&u(i),n.emit(o+128)}}function b(t,n){var r=n.fatal,i=0,o=0,s=0;this.decode=function(n){var a=n.get();if(a===U&&0===i&&0===o&&0===s)return N;a!==U||0===i&&0===o&&0===s||(i=0,o=0,s=0,c(r)),n.offset(1);var u;if(0!==s)return u=null,e(a,48,57)&&(u=p(10*(126*(10*(i-129)+(o-48))+(s-129))+a-48)),i=0,o=0,s=0,null===u?(n.offset(-3),c(r)):u;if(0!==o)return e(a,129,254)?(s=a,null):(n.offset(-2),i=0,o=0,c(r));if(0!==i){if(e(a,48,57)&&t)return o=a,null;var f=i,h=null;i=0;var g=127>a?64:65;return(e(a,64,126)||e(a,128,254))&&(h=190*(f-129)+(a-g)),u=null===h?null:l(h,d("gbk")),null===h&&n.offset(-1),null===u?c(r):u}return e(a,0,127)?a:128===a?8364:e(a,129,254)?(i=a,null):c(r)}}function w(t,r){r.fatal,this.encode=function(r,i){var o=i.get();if(o===N)return U;if(i.offset(1),e(o,0,127))return r.emit(o);var s=h(o,d("gbk"));if(null!==s){var a=n(s,190)+129,c=s%190,f=63>c?64:65;return r.emit(a,c+f)}if(null===s&&!t)return u(o);s=g(o);var l=n(n(n(s,10),126),10);s-=10*126*10*l;var p=n(n(s,10),126);s-=126*10*p;var y=n(s,10),v=s-10*y;return r.emit(l+129,p+48,y+129,v+48)}}function E(t){var n=t.fatal,r=!1,i=0;this.decode=function(t){var o=t.get();if(o===U&&0===i)return N;if(o===U&&0!==i)return i=0,c(n);if(t.offset(1),126===i)return i=0,123===o?(r=!0,null):125===o?(r=!1,null):126===o?126:10===o?null:(t.offset(-1),c(n));if(0!==i){var s=i;i=0;var a=null;return e(o,33,126)&&(a=l(190*(s-1)+(o+63),d("gbk"))),10===o&&(r=!1),null===a?c(n):a}return 126===o?(i=126,null):r?e(o,32,127)?(i=o,null):(10===o&&(r=!1),c(n)):e(o,0,127)?o:c(n)}}function x(t){t.fatal;var r=!1;this.encode=function(t,i){var o=i.get();if(o===N)return U;if(i.offset(1),e(o,0,127)&&r)return i.offset(-1),r=!1,t.emit(126,125);if(126===o)return t.emit(126,126);if(e(o,0,127))return t.emit(o);if(!r)return i.offset(-1),r=!0,t.emit(126,123);var s=h(o,d("gbk"));if(null===s)return u(o);var a=n(s,190)+1,c=s%190-63;return e(a,33,126)&&e(c,33,126)?t.emit(a,c):u(o)}}function k(t){var n=t.fatal,r=0,i=null;this.decode=function(t){if(null!==i){var o=i;return i=null,o}var s=t.get();if(s===U&&0===r)return N;if(s===U&&0!==r)return r=0,c(n);if(t.offset(1),0!==r){var a=r,u=null;r=0;var f=127>s?64:98;if((e(s,64,126)||e(s,161,254))&&(u=157*(a-129)+(s-f)),1133===u)return i=772,202;if(1135===u)return i=780,202;if(1164===u)return i=772,234;if(1166===u)return i=780,234;var h=null===u?null:l(u,d("big5"));return null===u&&t.offset(-1),null===h?c(n):h}return e(s,0,127)?s:e(s,129,254)?(r=s,null):c(n)}}function S(t){t.fatal,this.encode=function(t,r){var i=r.get();if(i===N)return U;if(r.offset(1),e(i,0,127))return t.emit(i);var o=h(i,d("big5"));if(null===o)return u(i);var s=n(o,157)+129,a=o%157,c=63>a?64:98;return t.emit(s,a+c)}}function B(t){var n=t.fatal,r=0,i=0;this.decode=function(t){var o=t.get();if(o===U)return 0===r&&0===i?N:(r=0,i=0,c(n));t.offset(1);var s,a;return 0!==i?(s=i,i=0,a=null,e(s,161,254)&&e(o,161,254)&&(a=l(94*(s-161)+o-161,d("jis0212"))),e(o,161,254)||t.offset(-1),null===a?c(n):a):142===r&&e(o,161,223)?(r=0,65377+o-161):143===r&&e(o,161,254)?(r=0,i=o,null):0!==r?(s=r,r=0,a=null,e(s,161,254)&&e(o,161,254)&&(a=l(94*(s-161)+o-161,d("jis0208"))),e(o,161,254)||t.offset(-1),null===a?c(n):a):e(o,0,127)?o:142===o||143===o||e(o,161,254)?(r=o,null):c(n)}}function A(t){t.fatal,this.encode=function(t,r){var i=r.get();if(i===N)return U;if(r.offset(1),e(i,0,127))return t.emit(i);if(165===i)return t.emit(92);if(8254===i)return t.emit(126);if(e(i,65377,65439))return t.emit(142,i-65377+161);var o=h(i,d("jis0208"));if(null===o)return u(i);var s=n(o,94)+161,a=o%94+161;return t.emit(s,a)}}function O(t){var n=t.fatal,r={ASCII:0,escape_start:1,escape_middle:2,escape_final:3,lead:4,trail:5,Katakana:6},i=r.ASCII,o=!1,s=0;this.decode=function(t){var a=t.get();switch(a!==U&&t.offset(1),i){default:case r.ASCII:return 27===a?(i=r.escape_start,null):e(a,0,127)?a:a===U?N:c(n);case r.escape_start:return 36===a||40===a?(s=a,i=r.escape_middle,null):(a!==U&&t.offset(-1),i=r.ASCII,c(n));case r.escape_middle:var u=s;return s=0,36!==u||64!==a&&66!==a?36===u&&40===a?(i=r.escape_final,null):40!==u||66!==a&&74!==a?40===u&&73===a?(i=r.Katakana,null):(a===U?t.offset(-1):t.offset(-2),i=r.ASCII,c(n)):(i=r.ASCII,null):(o=!1,i=r.lead,null);case r.escape_final:return 68===a?(o=!0,i=r.lead,null):(a===U?t.offset(-2):t.offset(-3),i=r.ASCII,c(n));case r.lead:return 10===a?(i=r.ASCII,c(n,10)):27===a?(i=r.escape_start,null):a===U?N:(s=a,i=r.trail,null);case r.trail:if(i=r.lead,a===U)return c(n);var f=null,h=94*(s-33)+a-33;return e(s,33,126)&&e(a,33,126)&&(f=o===!1?l(h,d("jis0208")):l(h,d("jis0212"))),null===f?c(n):f;case r.Katakana:return 27===a?(i=r.escape_start,null):e(a,33,95)?65377+a-33:a===U?N:c(n)}}}function D(t){t.fatal;var r={ASCII:0,lead:1,Katakana:2},i=r.ASCII;this.encode=function(t,o){var s=o.get();if(s===N)return U;if(o.offset(1),(e(s,0,127)||165===s||8254===s)&&i!==r.ASCII)return o.offset(-1),i=r.ASCII,t.emit(27,40,66);if(e(s,0,127))return t.emit(s);if(165===s)return t.emit(92);if(8254===s)return t.emit(126);if(e(s,65377,65439)&&i!==r.Katakana)return o.offset(-1),i=r.Katakana,t.emit(27,40,73);if(e(s,65377,65439))return t.emit(s-65377-33);if(i!==r.lead)return o.offset(-1),i=r.lead,t.emit(27,36,66);var a=h(s,d("jis0208"));if(null===a)return u(s);var c=n(a,94)+33,f=a%94+33;return t.emit(c,f)}}function C(t){var n=t.fatal,r=0;this.decode=function(t){var i=t.get();if(i===U&&0===r)return N;if(i===U&&0!==r)return r=0,c(n);if(t.offset(1),0!==r){var o=r;if(r=0,e(i,64,126)||e(i,128,252)){var s=127>i?64:65,a=160>o?129:193,u=l(188*(o-a)+i-s,d("jis0208"));return null===u?c(n):u}return t.offset(-1),c(n)}return e(i,0,128)?i:e(i,161,223)?65377+i-161:e(i,129,159)||e(i,224,252)?(r=i,null):c(n)}}function R(t){t.fatal,this.encode=function(t,r){var i=r.get();if(i===N)return U;if(r.offset(1),e(i,0,128))return t.emit(i);if(165===i)return t.emit(92);if(8254===i)return t.emit(126);if(e(i,65377,65439))return t.emit(i-65377+161);var o=h(i,d("jis0208"));if(null===o)return u(i);var s=n(o,188),a=31>s?129:193,c=o%188,f=63>c?64:65;return t.emit(s+a,c+f)}}function z(t){var n=t.fatal,r=0;this.decode=function(t){var i=t.get();if(i===U&&0===r)return N;if(i===U&&0!==r)return r=0,c(n);if(t.offset(1),0!==r){var o=r,s=null;if(r=0,e(o,129,198)){var a=178*(o-129);e(i,65,90)?s=a+i-65:e(i,97,122)?s=a+26+i-97:e(i,129,254)&&(s=a+26+26+i-129)}e(o,199,253)&&e(i,161,254)&&(s=12460+94*(o-199)+(i-161));var u=null===s?null:l(s,d("euc-kr"));return null===s&&t.offset(-1),null===u?c(n):u}return e(i,0,127)?i:e(i,129,253)?(r=i,null):c(n)}}function M(t){t.fatal,this.encode=function(t,r){var i=r.get();if(i===N)return U;if(r.offset(1),e(i,0,127))return t.emit(i);var o=h(i,d("euc-kr"));if(null===o)return u(i);var s,a;if(12460>o){s=n(o,178)+129,a=o%178;var c=26>a?65:52>a?71:77;return t.emit(s,a+c)}return o-=12460,s=n(o,94)+199,a=o%94+161,t.emit(s,a)}}function I(t,n){var r=n.fatal,i=null,o=null;this.decode=function(n){var s=n.get();if(s===U&&null===i&&null===o)return N;if(s===U&&(null!==i||null!==o))return c(r);if(n.offset(1),null===i)return i=s,null;var a;if(a=t?(i<<8)+s:(s<<8)+i,i=null,null!==o){var u=o;return o=null,e(a,56320,57343)?65536+1024*(u-55296)+(a-56320):(n.offset(-2),c(r))}return e(a,55296,56319)?(o=a,null):e(a,56320,57343)?c(r):a}}function j(t,r){r.fatal,this.encode=function(r,i){function o(e){var n=e>>8,i=255&e;return t?r.emit(n,i):r.emit(i,n)}var s=i.get();if(s===N)return U;if(i.offset(1),e(s,55296,57343)&&u(s),65535>=s)return o(s);var a=n(s-65536,1024)+55296,c=(s-65536)%1024+56320;return o(a),o(c)}}function F(t,e){if(!(this instanceof F))throw new TypeError("Constructor cannot be called as a function");if(t=t?t+"":H,e=Object(e),this._encoding=f(t),null===this._encoding||"utf-8"!==this._encoding.name&&"utf-16le"!==this._encoding.name&&"utf-16be"!==this._encoding.name)throw new TypeError("Unknown encoding: "+t);return this._streaming=!1,this._encoder=null,this._options={fatal:Boolean(e.fatal)},Object.defineProperty?Object.defineProperty(this,"encoding",{get:function(){return this._encoding.name}}):this.encoding=this._encoding.name,this}function T(t,e){if(!(this instanceof T))throw new TypeError("Constructor cannot be called as a function");if(t=t?t+"":H,e=Object(e),this._encoding=f(t),null===this._encoding)throw new TypeError("Unknown encoding: "+t);return this._streaming=!1,this._decoder=null,this._options={fatal:Boolean(e.fatal)},Object.defineProperty?Object.defineProperty(this,"encoding",{get:function(){return this._encoding.name}}):this.encoding=this._encoding.name,this}var U=-1,N=-1;a.prototype=Error.prototype;var L=[{encodings:[{labels:["unicode-1-1-utf-8","utf-8","utf8"],name:"utf-8"}],heading:"The Encoding"},{encodings:[{labels:["866","cp866","csibm866","ibm866"],name:"ibm866"},{labels:["csisolatin2","iso-8859-2","iso-ir-101","iso8859-2","iso88592","iso_8859-2","iso_8859-2:1987","l2","latin2"],name:"iso-8859-2"},{labels:["csisolatin3","iso-8859-3","iso-ir-109","iso8859-3","iso88593","iso_8859-3","iso_8859-3:1988","l3","latin3"],name:"iso-8859-3"},{labels:["csisolatin4","iso-8859-4","iso-ir-110","iso8859-4","iso88594","iso_8859-4","iso_8859-4:1988","l4","latin4"],name:"iso-8859-4"},{labels:["csisolatincyrillic","cyrillic","iso-8859-5","iso-ir-144","iso8859-5","iso88595","iso_8859-5","iso_8859-5:1988"],name:"iso-8859-5"},{labels:["arabic","asmo-708","csiso88596e","csiso88596i","csisolatinarabic","ecma-114","iso-8859-6","iso-8859-6-e","iso-8859-6-i","iso-ir-127","iso8859-6","iso88596","iso_8859-6","iso_8859-6:1987"],name:"iso-8859-6"},{labels:["csisolatingreek","ecma-118","elot_928","greek","greek8","iso-8859-7","iso-ir-126","iso8859-7","iso88597","iso_8859-7","iso_8859-7:1987","sun_eu_greek"],name:"iso-8859-7"},{labels:["csiso88598e","csisolatinhebrew","hebrew","iso-8859-8","iso-8859-8-e","iso-ir-138","iso8859-8","iso88598","iso_8859-8","iso_8859-8:1988","visual"],name:"iso-8859-8"},{labels:["csiso88598i","iso-8859-8-i","logical"],name:"iso-8859-8-i"},{labels:["csisolatin6","iso-8859-10","iso-ir-157","iso8859-10","iso885910","l6","latin6"],name:"iso-8859-10"},{labels:["iso-8859-13","iso8859-13","iso885913"],name:"iso-8859-13"},{labels:["iso-8859-14","iso8859-14","iso885914"],name:"iso-8859-14"},{labels:["csisolatin9","iso-8859-15","iso8859-15","iso885915","iso_8859-15","l9"],name:"iso-8859-15"},{labels:["iso-8859-16"],name:"iso-8859-16"},{labels:["cskoi8r","koi","koi8","koi8-r","koi8_r"],name:"koi8-r"},{labels:["koi8-u"],name:"koi8-u"},{labels:["csmacintosh","mac","macintosh","x-mac-roman"],name:"macintosh"},{labels:["dos-874","iso-8859-11","iso8859-11","iso885911","tis-620","windows-874"],name:"windows-874"},{labels:["cp1250","windows-1250","x-cp1250"],name:"windows-1250"},{labels:["cp1251","windows-1251","x-cp1251"],name:"windows-1251"},{labels:["ansi_x3.4-1968","ascii","cp1252","cp819","csisolatin1","ibm819","iso-8859-1","iso-ir-100","iso8859-1","iso88591","iso_8859-1","iso_8859-1:1987","l1","latin1","us-ascii","windows-1252","x-cp1252"],name:"windows-1252"},{labels:["cp1253","windows-1253","x-cp1253"],name:"windows-1253"},{labels:["cp1254","csisolatin5","iso-8859-9","iso-ir-148","iso8859-9","iso88599","iso_8859-9","iso_8859-9:1989","l5","latin5","windows-1254","x-cp1254"],name:"windows-1254"},{labels:["cp1255","windows-1255","x-cp1255"],name:"windows-1255"},{labels:["cp1256","windows-1256","x-cp1256"],name:"windows-1256"},{labels:["cp1257","windows-1257","x-cp1257"],name:"windows-1257"},{labels:["cp1258","windows-1258","x-cp1258"],name:"windows-1258"},{labels:["x-mac-cyrillic","x-mac-ukrainian"],name:"x-mac-cyrillic"}],heading:"Legacy single-byte encodings"},{encodings:[{labels:["chinese","csgb2312","csiso58gb231280","gb2312","gb_2312","gb_2312-80","gbk","iso-ir-58","x-gbk"],name:"gbk"},{labels:["gb18030"],name:"gb18030"},{labels:["hz-gb-2312"],name:"hz-gb-2312"}],heading:"Legacy multi-byte Chinese (simplified) encodings"},{encodings:[{labels:["big5","big5-hkscs","cn-big5","csbig5","x-x-big5"],name:"big5"}],heading:"Legacy multi-byte Chinese (traditional) encodings"},{encodings:[{labels:["cseucpkdfmtjapanese","euc-jp","x-euc-jp"],name:"euc-jp"},{labels:["csiso2022jp","iso-2022-jp"],name:"iso-2022-jp"},{labels:["csshiftjis","ms_kanji","shift-jis","shift_jis","sjis","windows-31j","x-sjis"],name:"shift_jis"}],heading:"Legacy multi-byte Japanese encodings"},{encodings:[{labels:["cseuckr","csksc56011987","euc-kr","iso-ir-149","korean","ks_c_5601-1987","ks_c_5601-1989","ksc5601","ksc_5601","windows-949"],name:"euc-kr"}],heading:"Legacy multi-byte Korean encodings"},{encodings:[{labels:["csiso2022kr","iso-2022-kr","iso-2022-cn","iso-2022-cn-ext"],name:"replacement"},{labels:["utf-16be"],name:"utf-16be"},{labels:["utf-16","utf-16le"],name:"utf-16le"},{labels:["x-user-defined"],name:"x-user-defined"}],heading:"Legacy miscellaneous encodings"}],W={},P={};L.forEach(function(t){t.encodings.forEach(function(t){W[t.name]=t,t.labels.forEach(function(e){P[e]=t})})}),W["utf-8"].getEncoder=function(t){return new v(t)},W["utf-8"].getDecoder=function(t){return new y(t)},function(){L.forEach(function(t){"Legacy single-byte encodings"===t.heading&&t.encodings.forEach(function(t){var e=d(t.name);t.getDecoder=function(t){return new m(e,t)},t.getEncoder=function(t){return new _(e,t)}})})}(),W.gbk.getEncoder=function(t){return new w(!1,t)},W.gbk.getDecoder=function(t){return new b(!1,t)},W.gb18030.getEncoder=function(t){return new w(!0,t)},W.gb18030.getDecoder=function(t){return new b(!0,t)},W["hz-gb-2312"].getEncoder=function(t){return new x(t)},W["hz-gb-2312"].getDecoder=function(t){return new E(t)},W.big5.getEncoder=function(t){return new S(t)},W.big5.getDecoder=function(t){return new k(t)},W["euc-jp"].getEncoder=function(t){return new A(t)},W["euc-jp"].getDecoder=function(t){return new B(t)},W["iso-2022-jp"].getEncoder=function(t){return new D(t)},W["iso-2022-jp"].getDecoder=function(t){return new O(t)},W.shift_jis.getEncoder=function(t){return new R(t)},W.shift_jis.getDecoder=function(t){return new C(t)},W["euc-kr"].getEncoder=function(t){return new M(t)},W["euc-kr"].getDecoder=function(t){return new z(t)},W["utf-16le"].getEncoder=function(t){return new j(!1,t)},W["utf-16le"].getDecoder=function(t){return new I(!1,t)},W["utf-16be"].getEncoder=function(t){return new j(!0,t)},W["utf-16be"].getDecoder=function(t){return new I(!0,t)};var H="utf-8";F.prototype={encode:function(t,e){t=t?t+"":"",e=Object(e),this._streaming||(this._encoder=this._encoding.getEncoder(this._options)),this._streaming=Boolean(e.stream);for(var n=[],r=new i(n),s=new o(t);s.get()!==N;)this._encoder.encode(r,s);if(!this._streaming){var a;do a=this._encoder.encode(r,s);while(a!==U);this._encoder=null}return new Uint8Array(n)}},T.prototype={decode:function(t,e){if(t&&!("buffer"in t&&"byteOffset"in t&&"byteLength"in t))throw new TypeError("Expected ArrayBufferView");t||(t=new Uint8Array(0)),e=Object(e),this._streaming||(this._decoder=this._encoding.getDecoder(this._options),this._BOMseen=!1),this._streaming=Boolean(e.stream);for(var n,i=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),o=new r(i),a=new s;o.get()!==U;)n=this._decoder.decode(o),null!==n&&n!==N&&a.emit(n);if(!this._streaming){do n=this._decoder.decode(o),null!==n&&n!==N&&a.emit(n);while(n!==N&&o.get()!=U);this._decoder=null}var c=a.string();return!this._BOMseen&&c.length&&(this._BOMseen=!0,-1!==["utf-8","utf-16le","utf-16be"].indexOf(this.encoding)&&65279===c.charCodeAt(0)&&(c=c.substring(1))),c}},t.TextEncoder=t.TextEncoder||F,t.TextDecoder=t.TextDecoder||T}(this),n("encoding",["encoding-indexes-shim"],function(){}),n("src/path",[],function(){function t(t,e){for(var n=0,r=t.length-1;r>=0;r--){var i=t[r];"."===i?t.splice(r,1):".."===i?(t.splice(r,1),n++):n&&(t.splice(r,1),n--)}if(e)for(;n--;n)t.unshift("..");return t}function e(){for(var e="",n=!1,r=arguments.length-1;r>=-1&&!n;r--){var i=r>=0?arguments[r]:"/";"string"==typeof i&&i&&(e=i+"/"+e,n="/"===i.charAt(0))}return e=t(e.split("/").filter(function(t){return!!t}),!n).join("/"),(n?"/":"")+e||"."}function n(e){var n="/"===e.charAt(0),r="/"===e.substr(-1);return e=t(e.split("/").filter(function(t){return!!t}),!n).join("/"),e||n||(e="."),e&&r&&(e+="/"),(n?"/":"")+e}function r(){var t=Array.prototype.slice.call(arguments,0);return n(t.filter(function(t){return t&&"string"==typeof t}).join("/"))}function i(t,e){function n(t){for(var e=0;t.length>e&&""===t[e];e++);for(var n=t.length-1;n>=0&&""===t[n];n--);return e>n?[]:t.slice(e,n-e+1)}t=exports.resolve(t).substr(1),e=exports.resolve(e).substr(1);for(var r=n(t.split("/")),i=n(e.split("/")),o=Math.min(r.length,i.length),s=o,a=0;o>a;a++)if(r[a]!==i[a]){s=a;break}for(var c=[],a=s;r.length>a;a++)c.push("..");return c=c.concat(i.slice(s)),c.join("/")}function o(t){var e=u(t),n=e[0],r=e[1];return n||r?(r&&(r=r.substr(0,r.length-1)),n+r):"."}function s(t,e){var n=u(t)[2];return e&&n.substr(-1*e.length)===e&&(n=n.substr(0,n.length-e.length)),""===n?"/":n}function a(t){return u(t)[3]}var c=/^(\/?)([\s\S]+\/(?!$)|\/)?((?:\.{1,2}$|[\s\S]+?)?(\.[^.\/]*)?)$/,u=function(t){var e=c.exec(t);return[e[1]||"",e[2]||"",e[3]||"",e[4]||""]};return{normalize:n,resolve:e,join:r,relative:i,sep:"/",delimiter:":",dirname:o,basename:s,extname:a}});var r=r||function(t,e){var n={},r=n.lib={},i=r.Base=function(){function t(){}return{extend:function(e){t.prototype=this;var n=new t;return e&&n.mixIn(e),n.$super=this,n},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var e in t)t.hasOwnProperty(e)&&(this[e]=t[e]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.$super.extend(this)}}}(),o=r.WordArray=i.extend({init:function(t,n){t=this.words=t||[],this.sigBytes=n!=e?n:4*t.length},toString:function(t){return(t||a).stringify(this)},concat:function(t){var e=this.words,n=t.words,r=this.sigBytes,t=t.sigBytes;if(this.clamp(),r%4)for(var i=0;t>i;i++)e[r+i>>>2]|=(255&n[i>>>2]>>>24-8*(i%4))<<24-8*((r+i)%4);else if(n.length>65535)for(i=0;t>i;i+=4)e[r+i>>>2]=n[i>>>2];else e.push.apply(e,n);return this.sigBytes+=t,this},clamp:function(){var e=this.words,n=this.sigBytes;e[n>>>2]&=4294967295<<32-8*(n%4),e.length=t.ceil(n/4)},clone:function(){var t=i.clone.call(this);return t.words=this.words.slice(0),t},random:function(e){for(var n=[],r=0;e>r;r+=4)n.push(0|4294967296*t.random());return o.create(n,e)}}),s=n.enc={},a=s.Hex={stringify:function(t){for(var e=t.words,t=t.sigBytes,n=[],r=0;t>r;r++){var i=255&e[r>>>2]>>>24-8*(r%4);n.push((i>>>4).toString(16)),n.push((15&i).toString(16))}return n.join("")},parse:function(t){for(var e=t.length,n=[],r=0;e>r;r+=2)n[r>>>3]|=parseInt(t.substr(r,2),16)<<24-4*(r%8);return o.create(n,e/2)}},c=s.Latin1={stringify:function(t){for(var e=t.words,t=t.sigBytes,n=[],r=0;t>r;r++)n.push(String.fromCharCode(255&e[r>>>2]>>>24-8*(r%4)));return n.join("")},parse:function(t){for(var e=t.length,n=[],r=0;e>r;r++)n[r>>>2]|=(255&t.charCodeAt(r))<<24-8*(r%4);return o.create(n,e)}},u=s.Utf8={stringify:function(t){try{return decodeURIComponent(escape(c.stringify(t)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(t){return c.parse(unescape(encodeURIComponent(t)))}},f=r.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=o.create(),this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=u.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(e){var n=this._data,r=n.words,i=n.sigBytes,s=this.blockSize,a=i/(4*s),a=e?t.ceil(a):t.max((0|a)-this._minBufferSize,0),e=a*s,i=t.min(4*e,i);if(e){for(var c=0;e>c;c+=s)this._doProcessBlock(r,c);c=r.splice(0,e),n.sigBytes-=i}return o.create(c,i)},clone:function(){var t=i.clone.call(this);return t._data=this._data.clone(),t},_minBufferSize:0});r.Hasher=f.extend({init:function(){this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(t){return this._append(t),this._process(),this},finalize:function(t){return t&&this._append(t),this._doFinalize(),this._hash},clone:function(){var t=f.clone.call(this);return t._hash=this._hash.clone(),t},blockSize:16,_createHelper:function(t){return function(e,n){return t.create(n).finalize(e)}},_createHmacHelper:function(t){return function(e,n){return l.HMAC.create(t,n).finalize(e)}}});var l=n.algo={};return n}(Math);(function(t){var e=r,n=e.lib,i=n.WordArray,n=n.Hasher,o=e.algo,s=[],a=[];(function(){function e(e){for(var n=t.sqrt(e),r=2;n>=r;r++)if(!(e%r))return!1;return!0}function n(t){return 0|4294967296*(t-(0|t))}for(var r=2,i=0;64>i;)e(r)&&(8>i&&(s[i]=n(t.pow(r,.5))),a[i]=n(t.pow(r,1/3)),i++),r++})();var c=[],o=o.SHA256=n.extend({_doReset:function(){this._hash=i.create(s.slice(0))},_doProcessBlock:function(t,e){for(var n=this._hash.words,r=n[0],i=n[1],o=n[2],s=n[3],u=n[4],f=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)c[d]=0|t[e+d];else{var p=c[d-15],g=c[d-2];c[d]=((p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3)+c[d-7]+((g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10)+c[d-16]}p=h+((u<<26|u>>>6)^(u<<21|u>>>11)^(u<<7|u>>>25))+(u&f^~u&l)+a[d]+c[d],g=((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+(r&i^r&o^i&o),h=l,l=f,f=u,u=0|s+p,s=o,o=i,i=r,r=0|p+g}n[0]=0|n[0]+r,n[1]=0|n[1]+i,n[2]=0|n[2]+o,n[3]=0|n[3]+s,n[4]=0|n[4]+u,n[5]=0|n[5]+f,n[6]=0|n[6]+l,n[7]=0|n[7]+h},_doFinalize:function(){var t=this._data,e=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;e[r>>>5]|=128<<24-r%32,e[(r+64>>>9<<4)+15]=n,t.sigBytes=4*e.length,this._process()}});e.SHA256=n._createHelper(o),e.HmacSHA256=n._createHmacHelper(o)})(Math),n("crypto-js/rollups/sha256",function(){}),n("src/shared",["require","crypto-js/rollups/sha256"],function(t){function e(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=0|16*Math.random(),n="x"==t?e:8|3&e;return n.toString(16)}).toUpperCase()}function n(t){return o.SHA256(t).toString(o.enc.hex)}function i(){}t("crypto-js/rollups/sha256");var o=r;return{guid:e,hash:n,nop:i}}),n("src/error",["require"],function(){function t(t){this.message=t||""}function e(t){this.message=t||""}function n(t){this.message=t||""}function r(t){this.message=t||""}function i(t){this.message=t||""}function o(t){this.message=t||""}function s(t){this.message=t||""}function a(t){this.message=t||""}function c(t){this.message=t||""}function u(t){this.message=t||""}function f(t){this.message=t||""}function l(t){this.message=t||""}function h(t){this.message=t||""}return t.prototype=Error(),t.prototype.name="EExists",t.prototype.constructor=t,e.prototype=Error(),e.prototype.name="EIsDirectory",e.prototype.constructor=e,n.prototype=Error(),n.prototype.name="ENoEntry",n.prototype.constructor=n,r.prototype=Error(),r.prototype.name="EBusy",r.prototype.constructor=r,i.prototype=Error(),i.prototype.name="ENotEmpty",i.prototype.constructor=i,o.prototype=Error(),o.prototype.name="ENotDirectory",o.prototype.constructor=o,s.prototype=Error(),s.prototype.name="EBadFileDescriptor",s.prototype.constructor=s,a.prototype=Error(),a.prototype.name="ENotImplemented",a.prototype.constructor=a,c.prototype=Error(),c.prototype.name="ENotMounted",c.prototype.constructor=c,u.prototype=Error(),u.prototype.name="EInvalid",u.prototype.constructor=u,f.prototype=Error(),f.prototype.name="EIO",f.prototype.constructor=f,l.prototype=Error(),l.prototype.name="ELoop",l.prototype.constructor=l,h.prototype=Error(),h.prototype.name="EFileSystemError",h.prototype.constructor=h,{EExists:t,EIsDirectory:e,ENoEntry:n,EBusy:r,ENotEmpty:i,ENotDirectory:o,EBadFileDescriptor:s,ENotImplemented:a,ENotMounted:c,EInvalid:u,EIO:f,ELoop:l,EFileSystemError:h}}),n("src/constants",["require"],function(){var t="READ",e="WRITE",n="CREATE",r="EXCLUSIVE",i="TRUNCATE",o="APPEND";return{FILE_SYSTEM_NAME:"local",FILE_STORE_NAME:"files",IDB_RO:"readonly",IDB_RW:"readwrite",WSQL_VERSION:"1",WSQL_SIZE:5242880,WSQL_DESC:"FileSystem Storage",MODE_FILE:"FILE",MODE_DIRECTORY:"DIRECTORY",MODE_SYMBOLIC_LINK:"SYMLINK",MODE_META:"META",SYMLOOP_MAX:10,BINARY_MIME_TYPE:"application/octet-stream",JSON_MIME_TYPE:"application/json",ROOT_DIRECTORY_NAME:"/",FS_FORMAT:"FORMAT",O_READ:t,O_WRITE:e,O_CREATE:n,O_EXCLUSIVE:r,O_TRUNCATE:i,O_APPEND:o,O_FLAGS:{r:[t],"r+":[t,e],w:[e,n,i],"w+":[e,t,n,i],wx:[e,n,r,i],"wx+":[e,t,n,r,i],a:[e,n,o],"a+":[e,t,n,o],ax:[e,n,r,o],"ax+":[e,t,n,r,o]},FS_READY:"READY",FS_PENDING:"PENDING",FS_ERROR:"ERROR",SUPER_NODE_ID:"00000000-0000-0000-0000-000000000000"}}),n("src/providers/indexeddb",["require","src/constants","src/constants","src/constants","src/constants"],function(t){function e(t,e){var n=t.transaction(i,e);this.objectStore=n.objectStore(i)}function n(t){this.name=t||r,this.db=null}var r=t("src/constants").FILE_SYSTEM_NAME,i=t("src/constants").FILE_STORE_NAME,o=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB,s=t("src/constants").IDB_RW,a=t("src/constants").IDB_RO;return e.prototype.clear=function(t){try{var e=this.objectStore.clear(); -e.onsuccess=function(){t()},e.onerror=function(e){t(e)}}catch(n){t(n)}},e.prototype.get=function(t,e){try{var n=this.objectStore.get(t);n.onsuccess=function(t){var n=t.target.result;e(null,n)},n.onerror=function(t){e(t)}}catch(r){e(r)}},e.prototype.put=function(t,e,n){try{var r=this.objectStore.put(e,t);r.onsuccess=function(t){var e=t.target.result;n(null,e)},r.onerror=function(t){n(t)}}catch(i){n(i)}},e.prototype.delete=function(t,e){try{var n=this.objectStore.delete(t);n.onsuccess=function(t){var n=t.target.result;e(null,n)},n.onerror=function(t){e(t)}}catch(r){e(r)}},n.isSupported=function(){return!!o},n.prototype.open=function(t){var e=this;if(e.db)return t(null,!1),void 0;var n=!1,r=o.open(e.name);r.onupgradeneeded=function(t){var e=t.target.result;e.objectStoreNames.contains(i)&&e.deleteObjectStore(i),e.createObjectStore(i),n=!0},r.onsuccess=function(r){e.db=r.target.result,t(null,n)},r.onerror=function(e){t(e)}},n.prototype.getReadOnlyContext=function(){return new e(this.db,a)},n.prototype.getReadWriteContext=function(){return new e(this.db,s)},n}),n("src/providers/websql",["require","src/constants","src/constants","src/constants","src/constants","src/constants"],function(t){function e(t,e){var n=this;this.getTransaction=function(r){return n.transaction?(r(n.transaction),void 0):(t[e?"readTransaction":"transaction"](function(t){n.transaction=t,r(t)}),void 0)}}function n(t){this.name=t||r,this.db=null}var r=t("src/constants").FILE_SYSTEM_NAME,i=t("src/constants").FILE_STORE_NAME,o=t("src/constants").WSQL_VERSION,s=t("src/constants").WSQL_SIZE,a=t("src/constants").WSQL_DESC;return e.prototype.clear=function(t){function e(e,n){t(n)}function n(){t(null)}this.getTransaction(function(t){t.executeSql("DELETE FROM "+i,[],n,e)})},e.prototype.get=function(t,e){function n(t,n){var r=0===n.rows.length?null:n.rows.item(0).data;e(null,r)}function r(t,n){e(n)}this.getTransaction(function(e){e.executeSql("SELECT data FROM "+i+" WHERE id = ?",[t],n,r)})},e.prototype.put=function(t,e,n){function r(){n(null)}function o(t,e){n(e)}this.getTransaction(function(n){n.executeSql("INSERT OR REPLACE INTO "+i+" (id, data) VALUES (?, ?)",[t,e],r,o)})},e.prototype.delete=function(t,e){function n(){e(null)}function r(t,n){e(n)}this.getTransaction(function(e){e.executeSql("DELETE FROM "+i+" WHERE id = ?",[t],n,r)})},n.isSupported=function(){return!!window.openDatabase},n.prototype.open=function(t){function e(e,n){t(n)}function n(e){function n(e,n){var r=0===n.rows.item(0).count;t(null,r)}function o(e,n){t(n)}r.db=c,e.executeSql("SELECT COUNT(id) AS count FROM "+i+";",[],n,o)}var r=this;if(r.db)return t(null,!1),void 0;var c=window.openDatabase(r.name,o,a,s);return c?(c.transaction(function(t){t.executeSql("CREATE TABLE IF NOT EXISTS "+i+" (id unique, data)",[],n,e)}),void 0):(t("[WebSQL] Unable to open database."),void 0)},n.prototype.getReadOnlyContext=function(){return new e(this.db,!0)},n.prototype.getReadWriteContext=function(){return new e(this.db,!1)},n}),n("src/providers/memory",["require","src/constants"],function(t){function e(t,e){this.readOnly=e,this.objectStore=t}function n(t){this.name=t||r,this.db={}}var r=t("src/constants").FILE_SYSTEM_NAME;return e.prototype.clear=function(t){if(this.readOnly)return t("[MemoryContext] Error: write operation on read only context");var e=this.objectStore;Object.keys(e).forEach(function(t){delete e[t]}),t(null)},e.prototype.get=function(t,e){e(null,this.objectStore[t])},e.prototype.put=function(t,e,n){return this.readOnly?n("[MemoryContext] Error: write operation on read only context"):(this.objectStore[t]=e,n(null),void 0)},e.prototype.delete=function(t,e){return this.readOnly?e("[MemoryContext] Error: write operation on read only context"):(delete this.objectStore[t],e(null),void 0)},n.isSupported=function(){return!0},n.prototype.open=function(t){t(null,!0)},n.prototype.getReadOnlyContext=function(){return new e(this.db,!0)},n.prototype.getReadWriteContext=function(){return new e(this.db,!1)},n}),n("src/providers/providers",["require","src/providers/indexeddb","src/providers/websql","src/providers/memory"],function(t){var e=t("src/providers/indexeddb"),n=t("src/providers/websql"),r=t("src/providers/memory");return{IndexedDB:e,WebSQL:n,Memory:r,Default:e,Fallback:function(){function t(){throw"[IDBFS Error] Your browser doesn't support IndexedDB or WebSQL."}return e.isSupported()?e:n.isSupported()?n:(t.isSupported=function(){return!1},t)}()}});var r=r||function(t,e){var n={},r=n.lib={},i=r.Base=function(){function t(){}return{extend:function(e){t.prototype=this;var n=new t;return e&&n.mixIn(e),n.$super=this,n},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var e in t)t.hasOwnProperty(e)&&(this[e]=t[e]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.$super.extend(this)}}}(),o=r.WordArray=i.extend({init:function(t,n){t=this.words=t||[],this.sigBytes=n!=e?n:4*t.length},toString:function(t){return(t||a).stringify(this)},concat:function(t){var e=this.words,n=t.words,r=this.sigBytes,t=t.sigBytes;if(this.clamp(),r%4)for(var i=0;t>i;i++)e[r+i>>>2]|=(255&n[i>>>2]>>>24-8*(i%4))<<24-8*((r+i)%4);else if(n.length>65535)for(i=0;t>i;i+=4)e[r+i>>>2]=n[i>>>2];else e.push.apply(e,n);return this.sigBytes+=t,this},clamp:function(){var e=this.words,n=this.sigBytes;e[n>>>2]&=4294967295<<32-8*(n%4),e.length=t.ceil(n/4)},clone:function(){var t=i.clone.call(this);return t.words=this.words.slice(0),t},random:function(e){for(var n=[],r=0;e>r;r+=4)n.push(0|4294967296*t.random());return o.create(n,e)}}),s=n.enc={},a=s.Hex={stringify:function(t){for(var e=t.words,t=t.sigBytes,n=[],r=0;t>r;r++){var i=255&e[r>>>2]>>>24-8*(r%4);n.push((i>>>4).toString(16)),n.push((15&i).toString(16))}return n.join("")},parse:function(t){for(var e=t.length,n=[],r=0;e>r;r+=2)n[r>>>3]|=parseInt(t.substr(r,2),16)<<24-4*(r%8);return o.create(n,e/2)}},c=s.Latin1={stringify:function(t){for(var e=t.words,t=t.sigBytes,n=[],r=0;t>r;r++)n.push(String.fromCharCode(255&e[r>>>2]>>>24-8*(r%4)));return n.join("")},parse:function(t){for(var e=t.length,n=[],r=0;e>r;r++)n[r>>>2]|=(255&t.charCodeAt(r))<<24-8*(r%4);return o.create(n,e)}},u=s.Utf8={stringify:function(t){try{return decodeURIComponent(escape(c.stringify(t)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(t){return c.parse(unescape(encodeURIComponent(t)))}},f=r.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=o.create(),this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=u.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(e){var n=this._data,r=n.words,i=n.sigBytes,s=this.blockSize,a=i/(4*s),a=e?t.ceil(a):t.max((0|a)-this._minBufferSize,0),e=a*s,i=t.min(4*e,i);if(e){for(var c=0;e>c;c+=s)this._doProcessBlock(r,c);c=r.splice(0,e),n.sigBytes-=i}return o.create(c,i)},clone:function(){var t=i.clone.call(this);return t._data=this._data.clone(),t},_minBufferSize:0});r.Hasher=f.extend({init:function(){this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(t){return this._append(t),this._process(),this},finalize:function(t){return t&&this._append(t),this._doFinalize(),this._hash},clone:function(){var t=f.clone.call(this);return t._hash=this._hash.clone(),t},blockSize:16,_createHelper:function(t){return function(e,n){return t.create(n).finalize(e)}},_createHmacHelper:function(t){return function(e,n){return l.HMAC.create(t,n).finalize(e)}}});var l=n.algo={};return n}(Math);(function(){var t=r,e=t.lib.WordArray;t.enc.Base64={stringify:function(t){var e=t.words,n=t.sigBytes,r=this._map;t.clamp();for(var t=[],i=0;n>i;i+=3)for(var o=(255&e[i>>>2]>>>24-8*(i%4))<<16|(255&e[i+1>>>2]>>>24-8*((i+1)%4))<<8|255&e[i+2>>>2]>>>24-8*((i+2)%4),s=0;4>s&&n>i+.75*s;s++)t.push(r.charAt(63&o>>>6*(3-s)));if(e=r.charAt(64))for(;t.length%4;)t.push(e);return t.join("")},parse:function(t){var t=t.replace(/\s/g,""),n=t.length,r=this._map,i=r.charAt(64);i&&(i=t.indexOf(i),-1!=i&&(n=i));for(var i=[],o=0,s=0;n>s;s++)if(s%4){var a=r.indexOf(t.charAt(s-1))<<2*(s%4),c=r.indexOf(t.charAt(s))>>>6-2*(s%4);i[o>>>2]|=(a|c)<<24-8*(o%4),o++}return e.create(i,o)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}})(),function(t){function e(t,e,n,r,i,o,s){return t=t+(e&n|~e&r)+i+s,(t<>>32-o)+e}function n(t,e,n,r,i,o,s){return t=t+(e&r|n&~r)+i+s,(t<>>32-o)+e}function i(t,e,n,r,i,o,s){return t=t+(e^n^r)+i+s,(t<>>32-o)+e}function o(t,e,n,r,i,o,s){return t=t+(n^(e|~r))+i+s,(t<>>32-o)+e}var s=r,a=s.lib,c=a.WordArray,a=a.Hasher,u=s.algo,f=[];(function(){for(var e=0;64>e;e++)f[e]=0|4294967296*t.abs(t.sin(e+1))})(),u=u.MD5=a.extend({_doReset:function(){this._hash=c.create([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(t,r){for(var s=0;16>s;s++){var a=r+s,c=t[a];t[a]=16711935&(c<<8|c>>>24)|4278255360&(c<<24|c>>>8)}for(var a=this._hash.words,c=a[0],u=a[1],l=a[2],h=a[3],s=0;64>s;s+=4)16>s?(c=e(c,u,l,h,t[r+s],7,f[s]),h=e(h,c,u,l,t[r+s+1],12,f[s+1]),l=e(l,h,c,u,t[r+s+2],17,f[s+2]),u=e(u,l,h,c,t[r+s+3],22,f[s+3])):32>s?(c=n(c,u,l,h,t[r+(s+1)%16],5,f[s]),h=n(h,c,u,l,t[r+(s+6)%16],9,f[s+1]),l=n(l,h,c,u,t[r+(s+11)%16],14,f[s+2]),u=n(u,l,h,c,t[r+s%16],20,f[s+3])):48>s?(c=i(c,u,l,h,t[r+(3*s+5)%16],4,f[s]),h=i(h,c,u,l,t[r+(3*s+8)%16],11,f[s+1]),l=i(l,h,c,u,t[r+(3*s+11)%16],16,f[s+2]),u=i(u,l,h,c,t[r+(3*s+14)%16],23,f[s+3])):(c=o(c,u,l,h,t[r+3*s%16],6,f[s]),h=o(h,c,u,l,t[r+(3*s+7)%16],10,f[s+1]),l=o(l,h,c,u,t[r+(3*s+14)%16],15,f[s+2]),u=o(u,l,h,c,t[r+(3*s+5)%16],21,f[s+3]));a[0]=0|a[0]+c,a[1]=0|a[1]+u,a[2]=0|a[2]+l,a[3]=0|a[3]+h},_doFinalize:function(){var t=this._data,e=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;for(e[r>>>5]|=128<<24-r%32,e[(r+64>>>9<<4)+14]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(e.length+1),this._process(),t=this._hash.words,e=0;4>e;e++)n=t[e],t[e]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}}),s.MD5=a._createHelper(u),s.HmacMD5=a._createHmacHelper(u)}(Math),function(){var t=r,e=t.lib,n=e.Base,i=e.WordArray,e=t.algo,o=e.EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(t){this.cfg=this.cfg.extend(t)},compute:function(t,e){for(var n=this.cfg,r=n.hasher.create(),o=i.create(),s=o.words,a=n.keySize,n=n.iterations;a>s.length;){c&&r.update(c);var c=r.update(t).finalize(e);r.reset();for(var u=1;n>u;u++)c=r.finalize(c),r.reset();o.concat(c)}return o.sigBytes=4*a,o}});t.EvpKDF=function(t,e,n){return o.create(n).compute(t,e)}}(),r.lib.Cipher||function(t){var e=r,n=e.lib,i=n.Base,o=n.WordArray,s=n.BufferedBlockAlgorithm,a=e.enc.Base64,c=e.algo.EvpKDF,u=n.Cipher=s.extend({cfg:i.extend(),createEncryptor:function(t,e){return this.create(this._ENC_XFORM_MODE,t,e)},createDecryptor:function(t,e){return this.create(this._DEC_XFORM_MODE,t,e)},init:function(t,e,n){this.cfg=this.cfg.extend(n),this._xformMode=t,this._key=e,this.reset()},reset:function(){s.reset.call(this),this._doReset()},process:function(t){return this._append(t),this._process()},finalize:function(t){return t&&this._append(t),this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(){return function(t){return{encrypt:function(e,n,r){return("string"==typeof n?g:p).encrypt(t,e,n,r)},decrypt:function(e,n,r){return("string"==typeof n?g:p).decrypt(t,e,n,r)}}}}()});n.StreamCipher=u.extend({_doFinalize:function(){return this._process(!0)},blockSize:1});var f=e.mode={},l=n.BlockCipherMode=i.extend({createEncryptor:function(t,e){return this.Encryptor.create(t,e)},createDecryptor:function(t,e){return this.Decryptor.create(t,e)},init:function(t,e){this._cipher=t,this._iv=e}}),f=f.CBC=function(){function e(e,n,r){var i=this._iv;i?this._iv=t:i=this._prevBlock;for(var o=0;r>o;o++)e[n+o]^=i[o]}var n=l.extend();return n.Encryptor=n.extend({processBlock:function(t,n){var r=this._cipher,i=r.blockSize;e.call(this,t,n,i),r.encryptBlock(t,n),this._prevBlock=t.slice(n,n+i)}}),n.Decryptor=n.extend({processBlock:function(t,n){var r=this._cipher,i=r.blockSize,o=t.slice(n,n+i);r.decryptBlock(t,n),e.call(this,t,n,i),this._prevBlock=o}}),n}(),h=(e.pad={}).Pkcs7={pad:function(t,e){for(var n=4*e,n=n-t.sigBytes%n,r=n<<24|n<<16|n<<8|n,i=[],s=0;n>s;s+=4)i.push(r);n=o.create(i,n),t.concat(n)},unpad:function(t){t.sigBytes-=255&t.words[t.sigBytes-1>>>2]}};n.BlockCipher=u.extend({cfg:u.cfg.extend({mode:f,padding:h}),reset:function(){u.reset.call(this);var t=this.cfg,e=t.iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(t,e){this._mode.processBlock(t,e)},_doFinalize:function(){var t=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){t.pad(this._data,this.blockSize);var e=this._process(!0)}else e=this._process(!0),t.unpad(e);return e},blockSize:4});var d=n.CipherParams=i.extend({init:function(t){this.mixIn(t)},toString:function(t){return(t||this.formatter).stringify(this)}}),f=(e.format={}).OpenSSL={stringify:function(t){var e=t.ciphertext,t=t.salt,e=(t?o.create([1398893684,1701076831]).concat(t).concat(e):e).toString(a);return e=e.replace(/(.{64})/g,"$1\n")},parse:function(t){var t=a.parse(t),e=t.words;if(1398893684==e[0]&&1701076831==e[1]){var n=o.create(e.slice(2,4));e.splice(0,4),t.sigBytes-=16}return d.create({ciphertext:t,salt:n})}},p=n.SerializableCipher=i.extend({cfg:i.extend({format:f}),encrypt:function(t,e,n,r){var r=this.cfg.extend(r),i=t.createEncryptor(n,r),e=i.finalize(e),i=i.cfg;return d.create({ciphertext:e,key:n,iv:i.iv,algorithm:t,mode:i.mode,padding:i.padding,blockSize:t.blockSize,formatter:r.format})},decrypt:function(t,e,n,r){return r=this.cfg.extend(r),e=this._parse(e,r.format),t.createDecryptor(n,r).finalize(e.ciphertext)},_parse:function(t,e){return"string"==typeof t?e.parse(t):t}}),e=(e.kdf={}).OpenSSL={compute:function(t,e,n,r){return r||(r=o.random(8)),t=c.create({keySize:e+n}).compute(t,r),n=o.create(t.words.slice(e),4*n),t.sigBytes=4*e,d.create({key:t,iv:n,salt:r})}},g=n.PasswordBasedCipher=p.extend({cfg:p.cfg.extend({kdf:e}),encrypt:function(t,e,n,r){return r=this.cfg.extend(r),n=r.kdf.compute(n,t.keySize,t.ivSize),r.iv=n.iv,t=p.encrypt.call(this,t,e,n.key,r),t.mixIn(n),t},decrypt:function(t,e,n,r){return r=this.cfg.extend(r),e=this._parse(e,r.format),n=r.kdf.compute(n,t.keySize,t.ivSize,e.salt),r.iv=n.iv,p.decrypt.call(this,t,e,n.key,r)}})}(),function(){var t=r,e=t.lib.BlockCipher,n=t.algo,i=[],o=[],s=[],a=[],c=[],u=[],f=[],l=[],h=[],d=[];(function(){for(var t=[],e=0;256>e;e++)t[e]=128>e?e<<1:283^e<<1;for(var n=0,r=0,e=0;256>e;e++){var p=r^r<<1^r<<2^r<<3^r<<4,p=99^(p>>>8^255&p);i[n]=p,o[p]=n;var g=t[n],y=t[g],v=t[y],m=257*t[p]^16843008*p;s[n]=m<<24|m>>>8,a[n]=m<<16|m>>>16,c[n]=m<<8|m>>>24,u[n]=m,m=16843009*v^65537*y^257*g^16843008*n,f[p]=m<<24|m>>>8,l[p]=m<<16|m>>>16,h[p]=m<<8|m>>>24,d[p]=m,n?(n=g^t[t[t[v^g]]],r^=t[t[r]]):n=r=1}})();var p=[0,1,2,4,8,16,32,64,128,27,54],n=n.AES=e.extend({_doReset:function(){for(var t=this._key,e=t.words,n=t.sigBytes/4,t=4*((this._nRounds=n+6)+1),r=this._keySchedule=[],o=0;t>o;o++)if(n>o)r[o]=e[o];else{var s=r[o-1];o%n?n>6&&4==o%n&&(s=i[s>>>24]<<24|i[255&s>>>16]<<16|i[255&s>>>8]<<8|i[255&s]):(s=s<<8|s>>>24,s=i[s>>>24]<<24|i[255&s>>>16]<<16|i[255&s>>>8]<<8|i[255&s],s^=p[0|o/n]<<24),r[o]=r[o-n]^s}for(e=this._invKeySchedule=[],n=0;t>n;n++)o=t-n,s=n%4?r[o]:r[o-4],e[n]=4>n||4>=o?s:f[i[s>>>24]]^l[i[255&s>>>16]]^h[i[255&s>>>8]]^d[i[255&s]]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._keySchedule,s,a,c,u,i)},decryptBlock:function(t,e){var n=t[e+1];t[e+1]=t[e+3],t[e+3]=n,this._doCryptBlock(t,e,this._invKeySchedule,f,l,h,d,o),n=t[e+1],t[e+1]=t[e+3],t[e+3]=n},_doCryptBlock:function(t,e,n,r,i,o,s,a){for(var c=this._nRounds,u=t[e]^n[0],f=t[e+1]^n[1],l=t[e+2]^n[2],h=t[e+3]^n[3],d=4,p=1;c>p;p++)var g=r[u>>>24]^i[255&f>>>16]^o[255&l>>>8]^s[255&h]^n[d++],y=r[f>>>24]^i[255&l>>>16]^o[255&h>>>8]^s[255&u]^n[d++],v=r[l>>>24]^i[255&h>>>16]^o[255&u>>>8]^s[255&f]^n[d++],h=r[h>>>24]^i[255&u>>>16]^o[255&f>>>8]^s[255&l]^n[d++],u=g,f=y,l=v;g=(a[u>>>24]<<24|a[255&f>>>16]<<16|a[255&l>>>8]<<8|a[255&h])^n[d++],y=(a[f>>>24]<<24|a[255&l>>>16]<<16|a[255&h>>>8]<<8|a[255&u])^n[d++],v=(a[l>>>24]<<24|a[255&h>>>16]<<16|a[255&u>>>8]<<8|a[255&f])^n[d++],h=(a[h>>>24]<<24|a[255&u>>>16]<<16|a[255&f>>>8]<<8|a[255&l])^n[d++],t[e]=g,t[e+1]=y,t[e+2]=v,t[e+3]=h},keySize:8});t.AES=e._createHelper(n)}(),n("crypto-js/rollups/aes",function(){});var r=r||function(t,e){var n={},r=n.lib={},i=r.Base=function(){function t(){}return{extend:function(e){t.prototype=this;var n=new t;return e&&n.mixIn(e),n.$super=this,n},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var e in t)t.hasOwnProperty(e)&&(this[e]=t[e]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.$super.extend(this)}}}(),o=r.WordArray=i.extend({init:function(t,n){t=this.words=t||[],this.sigBytes=n!=e?n:4*t.length},toString:function(t){return(t||a).stringify(this)},concat:function(t){var e=this.words,n=t.words,r=this.sigBytes,t=t.sigBytes;if(this.clamp(),r%4)for(var i=0;t>i;i++)e[r+i>>>2]|=(255&n[i>>>2]>>>24-8*(i%4))<<24-8*((r+i)%4);else if(n.length>65535)for(i=0;t>i;i+=4)e[r+i>>>2]=n[i>>>2];else e.push.apply(e,n);return this.sigBytes+=t,this},clamp:function(){var e=this.words,n=this.sigBytes;e[n>>>2]&=4294967295<<32-8*(n%4),e.length=t.ceil(n/4)},clone:function(){var t=i.clone.call(this);return t.words=this.words.slice(0),t},random:function(e){for(var n=[],r=0;e>r;r+=4)n.push(0|4294967296*t.random());return o.create(n,e)}}),s=n.enc={},a=s.Hex={stringify:function(t){for(var e=t.words,t=t.sigBytes,n=[],r=0;t>r;r++){var i=255&e[r>>>2]>>>24-8*(r%4);n.push((i>>>4).toString(16)),n.push((15&i).toString(16))}return n.join("")},parse:function(t){for(var e=t.length,n=[],r=0;e>r;r+=2)n[r>>>3]|=parseInt(t.substr(r,2),16)<<24-4*(r%8);return o.create(n,e/2)}},c=s.Latin1={stringify:function(t){for(var e=t.words,t=t.sigBytes,n=[],r=0;t>r;r++)n.push(String.fromCharCode(255&e[r>>>2]>>>24-8*(r%4)));return n.join("")},parse:function(t){for(var e=t.length,n=[],r=0;e>r;r++)n[r>>>2]|=(255&t.charCodeAt(r))<<24-8*(r%4);return o.create(n,e)}},u=s.Utf8={stringify:function(t){try{return decodeURIComponent(escape(c.stringify(t)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(t){return c.parse(unescape(encodeURIComponent(t)))}},f=r.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=o.create(),this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=u.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(e){var n=this._data,r=n.words,i=n.sigBytes,s=this.blockSize,a=i/(4*s),a=e?t.ceil(a):t.max((0|a)-this._minBufferSize,0),e=a*s,i=t.min(4*e,i);if(e){for(var c=0;e>c;c+=s)this._doProcessBlock(r,c);c=r.splice(0,e),n.sigBytes-=i}return o.create(c,i)},clone:function(){var t=i.clone.call(this);return t._data=this._data.clone(),t},_minBufferSize:0});r.Hasher=f.extend({init:function(){this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(t){return this._append(t),this._process(),this},finalize:function(t){return t&&this._append(t),this._doFinalize(),this._hash},clone:function(){var t=f.clone.call(this);return t._hash=this._hash.clone(),t},blockSize:16,_createHelper:function(t){return function(e,n){return t.create(n).finalize(e)}},_createHmacHelper:function(t){return function(e,n){return l.HMAC.create(t,n).finalize(e)}}});var l=n.algo={};return n}(Math);(function(){var t=r,e=t.lib.WordArray;t.enc.Base64={stringify:function(t){var e=t.words,n=t.sigBytes,r=this._map;t.clamp();for(var t=[],i=0;n>i;i+=3)for(var o=(255&e[i>>>2]>>>24-8*(i%4))<<16|(255&e[i+1>>>2]>>>24-8*((i+1)%4))<<8|255&e[i+2>>>2]>>>24-8*((i+2)%4),s=0;4>s&&n>i+.75*s;s++)t.push(r.charAt(63&o>>>6*(3-s)));if(e=r.charAt(64))for(;t.length%4;)t.push(e);return t.join("")},parse:function(t){var t=t.replace(/\s/g,""),n=t.length,r=this._map,i=r.charAt(64);i&&(i=t.indexOf(i),-1!=i&&(n=i));for(var i=[],o=0,s=0;n>s;s++)if(s%4){var a=r.indexOf(t.charAt(s-1))<<2*(s%4),c=r.indexOf(t.charAt(s))>>>6-2*(s%4);i[o>>>2]|=(a|c)<<24-8*(o%4),o++}return e.create(i,o)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}})(),function(t){function e(t,e,n,r,i,o,s){return t=t+(e&n|~e&r)+i+s,(t<>>32-o)+e}function n(t,e,n,r,i,o,s){return t=t+(e&r|n&~r)+i+s,(t<>>32-o)+e}function i(t,e,n,r,i,o,s){return t=t+(e^n^r)+i+s,(t<>>32-o)+e}function o(t,e,n,r,i,o,s){return t=t+(n^(e|~r))+i+s,(t<>>32-o)+e}var s=r,a=s.lib,c=a.WordArray,a=a.Hasher,u=s.algo,f=[];(function(){for(var e=0;64>e;e++)f[e]=0|4294967296*t.abs(t.sin(e+1))})(),u=u.MD5=a.extend({_doReset:function(){this._hash=c.create([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(t,r){for(var s=0;16>s;s++){var a=r+s,c=t[a];t[a]=16711935&(c<<8|c>>>24)|4278255360&(c<<24|c>>>8)}for(var a=this._hash.words,c=a[0],u=a[1],l=a[2],h=a[3],s=0;64>s;s+=4)16>s?(c=e(c,u,l,h,t[r+s],7,f[s]),h=e(h,c,u,l,t[r+s+1],12,f[s+1]),l=e(l,h,c,u,t[r+s+2],17,f[s+2]),u=e(u,l,h,c,t[r+s+3],22,f[s+3])):32>s?(c=n(c,u,l,h,t[r+(s+1)%16],5,f[s]),h=n(h,c,u,l,t[r+(s+6)%16],9,f[s+1]),l=n(l,h,c,u,t[r+(s+11)%16],14,f[s+2]),u=n(u,l,h,c,t[r+s%16],20,f[s+3])):48>s?(c=i(c,u,l,h,t[r+(3*s+5)%16],4,f[s]),h=i(h,c,u,l,t[r+(3*s+8)%16],11,f[s+1]),l=i(l,h,c,u,t[r+(3*s+11)%16],16,f[s+2]),u=i(u,l,h,c,t[r+(3*s+14)%16],23,f[s+3])):(c=o(c,u,l,h,t[r+3*s%16],6,f[s]),h=o(h,c,u,l,t[r+(3*s+7)%16],10,f[s+1]),l=o(l,h,c,u,t[r+(3*s+14)%16],15,f[s+2]),u=o(u,l,h,c,t[r+(3*s+5)%16],21,f[s+3]));a[0]=0|a[0]+c,a[1]=0|a[1]+u,a[2]=0|a[2]+l,a[3]=0|a[3]+h},_doFinalize:function(){var t=this._data,e=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;for(e[r>>>5]|=128<<24-r%32,e[(r+64>>>9<<4)+14]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(e.length+1),this._process(),t=this._hash.words,e=0;4>e;e++)n=t[e],t[e]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}}),s.MD5=a._createHelper(u),s.HmacMD5=a._createHmacHelper(u)}(Math),function(){var t=r,e=t.lib,n=e.Base,i=e.WordArray,e=t.algo,o=e.EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(t){this.cfg=this.cfg.extend(t)},compute:function(t,e){for(var n=this.cfg,r=n.hasher.create(),o=i.create(),s=o.words,a=n.keySize,n=n.iterations;a>s.length;){c&&r.update(c);var c=r.update(t).finalize(e);r.reset();for(var u=1;n>u;u++)c=r.finalize(c),r.reset();o.concat(c)}return o.sigBytes=4*a,o}});t.EvpKDF=function(t,e,n){return o.create(n).compute(t,e)}}(),r.lib.Cipher||function(t){var e=r,n=e.lib,i=n.Base,o=n.WordArray,s=n.BufferedBlockAlgorithm,a=e.enc.Base64,c=e.algo.EvpKDF,u=n.Cipher=s.extend({cfg:i.extend(),createEncryptor:function(t,e){return this.create(this._ENC_XFORM_MODE,t,e)},createDecryptor:function(t,e){return this.create(this._DEC_XFORM_MODE,t,e)},init:function(t,e,n){this.cfg=this.cfg.extend(n),this._xformMode=t,this._key=e,this.reset()},reset:function(){s.reset.call(this),this._doReset()},process:function(t){return this._append(t),this._process()},finalize:function(t){return t&&this._append(t),this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(){return function(t){return{encrypt:function(e,n,r){return("string"==typeof n?g:p).encrypt(t,e,n,r)},decrypt:function(e,n,r){return("string"==typeof n?g:p).decrypt(t,e,n,r)}}}}()});n.StreamCipher=u.extend({_doFinalize:function(){return this._process(!0)},blockSize:1});var f=e.mode={},l=n.BlockCipherMode=i.extend({createEncryptor:function(t,e){return this.Encryptor.create(t,e)},createDecryptor:function(t,e){return this.Decryptor.create(t,e)},init:function(t,e){this._cipher=t,this._iv=e}}),f=f.CBC=function(){function e(e,n,r){var i=this._iv;i?this._iv=t:i=this._prevBlock;for(var o=0;r>o;o++)e[n+o]^=i[o]}var n=l.extend();return n.Encryptor=n.extend({processBlock:function(t,n){var r=this._cipher,i=r.blockSize;e.call(this,t,n,i),r.encryptBlock(t,n),this._prevBlock=t.slice(n,n+i)}}),n.Decryptor=n.extend({processBlock:function(t,n){var r=this._cipher,i=r.blockSize,o=t.slice(n,n+i);r.decryptBlock(t,n),e.call(this,t,n,i),this._prevBlock=o}}),n}(),h=(e.pad={}).Pkcs7={pad:function(t,e){for(var n=4*e,n=n-t.sigBytes%n,r=n<<24|n<<16|n<<8|n,i=[],s=0;n>s;s+=4)i.push(r);n=o.create(i,n),t.concat(n)},unpad:function(t){t.sigBytes-=255&t.words[t.sigBytes-1>>>2]}};n.BlockCipher=u.extend({cfg:u.cfg.extend({mode:f,padding:h}),reset:function(){u.reset.call(this);var t=this.cfg,e=t.iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(t,e){this._mode.processBlock(t,e)},_doFinalize:function(){var t=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){t.pad(this._data,this.blockSize);var e=this._process(!0)}else e=this._process(!0),t.unpad(e);return e},blockSize:4});var d=n.CipherParams=i.extend({init:function(t){this.mixIn(t)},toString:function(t){return(t||this.formatter).stringify(this)}}),f=(e.format={}).OpenSSL={stringify:function(t){var e=t.ciphertext,t=t.salt,e=(t?o.create([1398893684,1701076831]).concat(t).concat(e):e).toString(a);return e=e.replace(/(.{64})/g,"$1\n")},parse:function(t){var t=a.parse(t),e=t.words;if(1398893684==e[0]&&1701076831==e[1]){var n=o.create(e.slice(2,4));e.splice(0,4),t.sigBytes-=16}return d.create({ciphertext:t,salt:n})}},p=n.SerializableCipher=i.extend({cfg:i.extend({format:f}),encrypt:function(t,e,n,r){var r=this.cfg.extend(r),i=t.createEncryptor(n,r),e=i.finalize(e),i=i.cfg;return d.create({ciphertext:e,key:n,iv:i.iv,algorithm:t,mode:i.mode,padding:i.padding,blockSize:t.blockSize,formatter:r.format})},decrypt:function(t,e,n,r){return r=this.cfg.extend(r),e=this._parse(e,r.format),t.createDecryptor(n,r).finalize(e.ciphertext)},_parse:function(t,e){return"string"==typeof t?e.parse(t):t}}),e=(e.kdf={}).OpenSSL={compute:function(t,e,n,r){return r||(r=o.random(8)),t=c.create({keySize:e+n}).compute(t,r),n=o.create(t.words.slice(e),4*n),t.sigBytes=4*e,d.create({key:t,iv:n,salt:r})}},g=n.PasswordBasedCipher=p.extend({cfg:p.cfg.extend({kdf:e}),encrypt:function(t,e,n,r){return r=this.cfg.extend(r),n=r.kdf.compute(n,t.keySize,t.ivSize),r.iv=n.iv,t=p.encrypt.call(this,t,e,n.key,r),t.mixIn(n),t},decrypt:function(t,e,n,r){return r=this.cfg.extend(r),e=this._parse(e,r.format),n=r.kdf.compute(n,t.keySize,t.ivSize,e.salt),r.iv=n.iv,p.decrypt.call(this,t,e,n.key,r)}})}(),function(){function t(t,e){var n=(this._lBlock>>>t^this._rBlock)&e;this._rBlock^=n,this._lBlock^=n<>>t^this._lBlock)&e;this._lBlock^=n,this._rBlock^=n<n;n++){var r=a[n]-1; -e[n]=1&t[r>>>5]>>>31-r%32}for(t=this._subKeys=[],r=0;16>r;r++){for(var i=t[r]=[],o=u[r],n=0;24>n;n++)i[0|n/6]|=e[(c[n]-1+o)%28]<<31-n%6,i[4+(0|n/6)]|=e[28+(c[n+24]-1+o)%28]<<31-n%6;for(i[0]=i[0]<<1|i[0]>>>31,n=1;7>n;n++)i[n]>>>=4*(n-1)+3;i[7]=i[7]<<5|i[7]>>>27}for(e=this._invSubKeys=[],n=0;16>n;n++)e[n]=t[15-n]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._subKeys)},decryptBlock:function(t,e){this._doCryptBlock(t,e,this._invSubKeys)},_doCryptBlock:function(n,r,i){this._lBlock=n[r],this._rBlock=n[r+1],t.call(this,4,252645135),t.call(this,16,65535),e.call(this,2,858993459),e.call(this,8,16711935),t.call(this,1,1431655765);for(var o=0;16>o;o++){for(var s=i[o],a=this._lBlock,c=this._rBlock,u=0,h=0;8>h;h++)u|=f[h][((c^s[h])&l[h])>>>0];this._lBlock=c,this._rBlock=a^u}i=this._lBlock,this._lBlock=this._rBlock,this._rBlock=i,t.call(this,1,1431655765),e.call(this,8,16711935),e.call(this,2,858993459),t.call(this,16,65535),t.call(this,4,252645135),n[r]=this._lBlock,n[r+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});n.DES=i._createHelper(h),s=s.TripleDES=i.extend({_doReset:function(){var t=this._key.words;this._des1=h.createEncryptor(o.create(t.slice(0,2))),this._des2=h.createEncryptor(o.create(t.slice(2,4))),this._des3=h.createEncryptor(o.create(t.slice(4,6)))},encryptBlock:function(t,e){this._des1.encryptBlock(t,e),this._des2.decryptBlock(t,e),this._des3.encryptBlock(t,e)},decryptBlock:function(t,e){this._des3.decryptBlock(t,e),this._des2.encryptBlock(t,e),this._des1.decryptBlock(t,e)},keySize:6,ivSize:2,blockSize:2}),n.TripleDES=i._createHelper(s)}(),n("crypto-js/rollups/tripledes",function(){});var r=r||function(t,e){var n={},r=n.lib={},i=r.Base=function(){function t(){}return{extend:function(e){t.prototype=this;var n=new t;return e&&n.mixIn(e),n.$super=this,n},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var e in t)t.hasOwnProperty(e)&&(this[e]=t[e]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.$super.extend(this)}}}(),o=r.WordArray=i.extend({init:function(t,n){t=this.words=t||[],this.sigBytes=n!=e?n:4*t.length},toString:function(t){return(t||a).stringify(this)},concat:function(t){var e=this.words,n=t.words,r=this.sigBytes,t=t.sigBytes;if(this.clamp(),r%4)for(var i=0;t>i;i++)e[r+i>>>2]|=(255&n[i>>>2]>>>24-8*(i%4))<<24-8*((r+i)%4);else if(n.length>65535)for(i=0;t>i;i+=4)e[r+i>>>2]=n[i>>>2];else e.push.apply(e,n);return this.sigBytes+=t,this},clamp:function(){var e=this.words,n=this.sigBytes;e[n>>>2]&=4294967295<<32-8*(n%4),e.length=t.ceil(n/4)},clone:function(){var t=i.clone.call(this);return t.words=this.words.slice(0),t},random:function(e){for(var n=[],r=0;e>r;r+=4)n.push(0|4294967296*t.random());return o.create(n,e)}}),s=n.enc={},a=s.Hex={stringify:function(t){for(var e=t.words,t=t.sigBytes,n=[],r=0;t>r;r++){var i=255&e[r>>>2]>>>24-8*(r%4);n.push((i>>>4).toString(16)),n.push((15&i).toString(16))}return n.join("")},parse:function(t){for(var e=t.length,n=[],r=0;e>r;r+=2)n[r>>>3]|=parseInt(t.substr(r,2),16)<<24-4*(r%8);return o.create(n,e/2)}},c=s.Latin1={stringify:function(t){for(var e=t.words,t=t.sigBytes,n=[],r=0;t>r;r++)n.push(String.fromCharCode(255&e[r>>>2]>>>24-8*(r%4)));return n.join("")},parse:function(t){for(var e=t.length,n=[],r=0;e>r;r++)n[r>>>2]|=(255&t.charCodeAt(r))<<24-8*(r%4);return o.create(n,e)}},u=s.Utf8={stringify:function(t){try{return decodeURIComponent(escape(c.stringify(t)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(t){return c.parse(unescape(encodeURIComponent(t)))}},f=r.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=o.create(),this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=u.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(e){var n=this._data,r=n.words,i=n.sigBytes,s=this.blockSize,a=i/(4*s),a=e?t.ceil(a):t.max((0|a)-this._minBufferSize,0),e=a*s,i=t.min(4*e,i);if(e){for(var c=0;e>c;c+=s)this._doProcessBlock(r,c);c=r.splice(0,e),n.sigBytes-=i}return o.create(c,i)},clone:function(){var t=i.clone.call(this);return t._data=this._data.clone(),t},_minBufferSize:0});r.Hasher=f.extend({init:function(){this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(t){return this._append(t),this._process(),this},finalize:function(t){return t&&this._append(t),this._doFinalize(),this._hash},clone:function(){var t=f.clone.call(this);return t._hash=this._hash.clone(),t},blockSize:16,_createHelper:function(t){return function(e,n){return t.create(n).finalize(e)}},_createHmacHelper:function(t){return function(e,n){return l.HMAC.create(t,n).finalize(e)}}});var l=n.algo={};return n}(Math);(function(){var t=r,e=t.lib.WordArray;t.enc.Base64={stringify:function(t){var e=t.words,n=t.sigBytes,r=this._map;t.clamp();for(var t=[],i=0;n>i;i+=3)for(var o=(255&e[i>>>2]>>>24-8*(i%4))<<16|(255&e[i+1>>>2]>>>24-8*((i+1)%4))<<8|255&e[i+2>>>2]>>>24-8*((i+2)%4),s=0;4>s&&n>i+.75*s;s++)t.push(r.charAt(63&o>>>6*(3-s)));if(e=r.charAt(64))for(;t.length%4;)t.push(e);return t.join("")},parse:function(t){var t=t.replace(/\s/g,""),n=t.length,r=this._map,i=r.charAt(64);i&&(i=t.indexOf(i),-1!=i&&(n=i));for(var i=[],o=0,s=0;n>s;s++)if(s%4){var a=r.indexOf(t.charAt(s-1))<<2*(s%4),c=r.indexOf(t.charAt(s))>>>6-2*(s%4);i[o>>>2]|=(a|c)<<24-8*(o%4),o++}return e.create(i,o)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}})(),function(t){function e(t,e,n,r,i,o,s){return t=t+(e&n|~e&r)+i+s,(t<>>32-o)+e}function n(t,e,n,r,i,o,s){return t=t+(e&r|n&~r)+i+s,(t<>>32-o)+e}function i(t,e,n,r,i,o,s){return t=t+(e^n^r)+i+s,(t<>>32-o)+e}function o(t,e,n,r,i,o,s){return t=t+(n^(e|~r))+i+s,(t<>>32-o)+e}var s=r,a=s.lib,c=a.WordArray,a=a.Hasher,u=s.algo,f=[];(function(){for(var e=0;64>e;e++)f[e]=0|4294967296*t.abs(t.sin(e+1))})(),u=u.MD5=a.extend({_doReset:function(){this._hash=c.create([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(t,r){for(var s=0;16>s;s++){var a=r+s,c=t[a];t[a]=16711935&(c<<8|c>>>24)|4278255360&(c<<24|c>>>8)}for(var a=this._hash.words,c=a[0],u=a[1],l=a[2],h=a[3],s=0;64>s;s+=4)16>s?(c=e(c,u,l,h,t[r+s],7,f[s]),h=e(h,c,u,l,t[r+s+1],12,f[s+1]),l=e(l,h,c,u,t[r+s+2],17,f[s+2]),u=e(u,l,h,c,t[r+s+3],22,f[s+3])):32>s?(c=n(c,u,l,h,t[r+(s+1)%16],5,f[s]),h=n(h,c,u,l,t[r+(s+6)%16],9,f[s+1]),l=n(l,h,c,u,t[r+(s+11)%16],14,f[s+2]),u=n(u,l,h,c,t[r+s%16],20,f[s+3])):48>s?(c=i(c,u,l,h,t[r+(3*s+5)%16],4,f[s]),h=i(h,c,u,l,t[r+(3*s+8)%16],11,f[s+1]),l=i(l,h,c,u,t[r+(3*s+11)%16],16,f[s+2]),u=i(u,l,h,c,t[r+(3*s+14)%16],23,f[s+3])):(c=o(c,u,l,h,t[r+3*s%16],6,f[s]),h=o(h,c,u,l,t[r+(3*s+7)%16],10,f[s+1]),l=o(l,h,c,u,t[r+(3*s+14)%16],15,f[s+2]),u=o(u,l,h,c,t[r+(3*s+5)%16],21,f[s+3]));a[0]=0|a[0]+c,a[1]=0|a[1]+u,a[2]=0|a[2]+l,a[3]=0|a[3]+h},_doFinalize:function(){var t=this._data,e=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;for(e[r>>>5]|=128<<24-r%32,e[(r+64>>>9<<4)+14]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(e.length+1),this._process(),t=this._hash.words,e=0;4>e;e++)n=t[e],t[e]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}}),s.MD5=a._createHelper(u),s.HmacMD5=a._createHmacHelper(u)}(Math),function(){var t=r,e=t.lib,n=e.Base,i=e.WordArray,e=t.algo,o=e.EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(t){this.cfg=this.cfg.extend(t)},compute:function(t,e){for(var n=this.cfg,r=n.hasher.create(),o=i.create(),s=o.words,a=n.keySize,n=n.iterations;a>s.length;){c&&r.update(c);var c=r.update(t).finalize(e);r.reset();for(var u=1;n>u;u++)c=r.finalize(c),r.reset();o.concat(c)}return o.sigBytes=4*a,o}});t.EvpKDF=function(t,e,n){return o.create(n).compute(t,e)}}(),r.lib.Cipher||function(t){var e=r,n=e.lib,i=n.Base,o=n.WordArray,s=n.BufferedBlockAlgorithm,a=e.enc.Base64,c=e.algo.EvpKDF,u=n.Cipher=s.extend({cfg:i.extend(),createEncryptor:function(t,e){return this.create(this._ENC_XFORM_MODE,t,e)},createDecryptor:function(t,e){return this.create(this._DEC_XFORM_MODE,t,e)},init:function(t,e,n){this.cfg=this.cfg.extend(n),this._xformMode=t,this._key=e,this.reset()},reset:function(){s.reset.call(this),this._doReset()},process:function(t){return this._append(t),this._process()},finalize:function(t){return t&&this._append(t),this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(){return function(t){return{encrypt:function(e,n,r){return("string"==typeof n?g:p).encrypt(t,e,n,r)},decrypt:function(e,n,r){return("string"==typeof n?g:p).decrypt(t,e,n,r)}}}}()});n.StreamCipher=u.extend({_doFinalize:function(){return this._process(!0)},blockSize:1});var f=e.mode={},l=n.BlockCipherMode=i.extend({createEncryptor:function(t,e){return this.Encryptor.create(t,e)},createDecryptor:function(t,e){return this.Decryptor.create(t,e)},init:function(t,e){this._cipher=t,this._iv=e}}),f=f.CBC=function(){function e(e,n,r){var i=this._iv;i?this._iv=t:i=this._prevBlock;for(var o=0;r>o;o++)e[n+o]^=i[o]}var n=l.extend();return n.Encryptor=n.extend({processBlock:function(t,n){var r=this._cipher,i=r.blockSize;e.call(this,t,n,i),r.encryptBlock(t,n),this._prevBlock=t.slice(n,n+i)}}),n.Decryptor=n.extend({processBlock:function(t,n){var r=this._cipher,i=r.blockSize,o=t.slice(n,n+i);r.decryptBlock(t,n),e.call(this,t,n,i),this._prevBlock=o}}),n}(),h=(e.pad={}).Pkcs7={pad:function(t,e){for(var n=4*e,n=n-t.sigBytes%n,r=n<<24|n<<16|n<<8|n,i=[],s=0;n>s;s+=4)i.push(r);n=o.create(i,n),t.concat(n)},unpad:function(t){t.sigBytes-=255&t.words[t.sigBytes-1>>>2]}};n.BlockCipher=u.extend({cfg:u.cfg.extend({mode:f,padding:h}),reset:function(){u.reset.call(this);var t=this.cfg,e=t.iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(t,e){this._mode.processBlock(t,e)},_doFinalize:function(){var t=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){t.pad(this._data,this.blockSize);var e=this._process(!0)}else e=this._process(!0),t.unpad(e);return e},blockSize:4});var d=n.CipherParams=i.extend({init:function(t){this.mixIn(t)},toString:function(t){return(t||this.formatter).stringify(this)}}),f=(e.format={}).OpenSSL={stringify:function(t){var e=t.ciphertext,t=t.salt,e=(t?o.create([1398893684,1701076831]).concat(t).concat(e):e).toString(a);return e=e.replace(/(.{64})/g,"$1\n")},parse:function(t){var t=a.parse(t),e=t.words;if(1398893684==e[0]&&1701076831==e[1]){var n=o.create(e.slice(2,4));e.splice(0,4),t.sigBytes-=16}return d.create({ciphertext:t,salt:n})}},p=n.SerializableCipher=i.extend({cfg:i.extend({format:f}),encrypt:function(t,e,n,r){var r=this.cfg.extend(r),i=t.createEncryptor(n,r),e=i.finalize(e),i=i.cfg;return d.create({ciphertext:e,key:n,iv:i.iv,algorithm:t,mode:i.mode,padding:i.padding,blockSize:t.blockSize,formatter:r.format})},decrypt:function(t,e,n,r){return r=this.cfg.extend(r),e=this._parse(e,r.format),t.createDecryptor(n,r).finalize(e.ciphertext)},_parse:function(t,e){return"string"==typeof t?e.parse(t):t}}),e=(e.kdf={}).OpenSSL={compute:function(t,e,n,r){return r||(r=o.random(8)),t=c.create({keySize:e+n}).compute(t,r),n=o.create(t.words.slice(e),4*n),t.sigBytes=4*e,d.create({key:t,iv:n,salt:r})}},g=n.PasswordBasedCipher=p.extend({cfg:p.cfg.extend({kdf:e}),encrypt:function(t,e,n,r){return r=this.cfg.extend(r),n=r.kdf.compute(n,t.keySize,t.ivSize),r.iv=n.iv,t=p.encrypt.call(this,t,e,n.key,r),t.mixIn(n),t},decrypt:function(t,e,n,r){return r=this.cfg.extend(r),e=this._parse(e,r.format),n=r.kdf.compute(n,t.keySize,t.ivSize,e.salt),r.iv=n.iv,p.decrypt.call(this,t,e,n.key,r)}})}(),function(){function t(){var t=this._X,e=this._C;e[0]=0|e[0]+1295307597+this._b,e[1]=0|e[1]+3545052371+(1295307597>e[0]>>>0?1:0),e[2]=0|e[2]+886263092+(3545052371>e[1]>>>0?1:0),e[3]=0|e[3]+1295307597+(886263092>e[2]>>>0?1:0),e[4]=0|e[4]+3545052371+(1295307597>e[3]>>>0?1:0),e[5]=0|e[5]+886263092+(3545052371>e[4]>>>0?1:0),e[6]=0|e[6]+1295307597+(886263092>e[5]>>>0?1:0),e[7]=0|e[7]+3545052371+(1295307597>e[6]>>>0?1:0),this._b=3545052371>e[7]>>>0?1:0;for(var n=0;8>n;n++){var r=t[n]+e[n],i=65535&r,s=r>>>16;o[n]=((i*i>>>17)+i*s>>>15)+s*s^(0|(4294901760&r)*r)+(0|(65535&r)*r)}var e=o[0],n=o[1],r=o[2],i=o[3],s=o[4],a=o[5],c=o[6],u=o[7];t[0]=0|e+(u<<16|u>>>16)+(c<<16|c>>>16),t[1]=0|n+(e<<8|e>>>24)+u,t[2]=0|r+(n<<16|n>>>16)+(e<<16|e>>>16),t[3]=0|i+(r<<8|r>>>24)+n,t[4]=0|s+(i<<16|i>>>16)+(r<<16|r>>>16),t[5]=0|a+(s<<8|s>>>24)+i,t[6]=0|c+(a<<16|a>>>16)+(s<<16|s>>>16),t[7]=0|u+(c<<8|c>>>24)+a}var e=r,n=e.lib.StreamCipher,i=[],o=[],s=e.algo.Rabbit=n.extend({_doReset:function(){for(var e=this._key.words,n=e[0],r=e[1],i=e[2],o=e[3],e=this._X=[n,o<<16|i>>>16,r,n<<16|o>>>16,i,r<<16|n>>>16,o,i<<16|r>>>16],n=this._C=[i<<16|i>>>16,4294901760&n|65535&r,o<<16|o>>>16,4294901760&r|65535&i,n<<16|n>>>16,4294901760&i|65535&o,r<<16|r>>>16,4294901760&o|65535&n],r=this._b=0;4>r;r++)t.call(this);for(r=0;8>r;r++)n[r]^=e[7&r+4];if(e=this.cfg.iv)for(r=e.words,e=r[0],r=r[1],e=16711935&(e<<8|e>>>24)|4278255360&(e<<24|e>>>8),r=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),i=e>>>16|4294901760&r,o=r<<16|65535&e,n[0]^=e,n[1]^=i,n[2]^=r,n[3]^=o,n[4]^=e,n[5]^=i,n[6]^=r,n[7]^=o,r=0;4>r;r++)t.call(this)},_doProcessBlock:function(e,n){var r=this._X;for(t.call(this),i[0]=r[0]^r[5]>>>16^r[3]<<16,i[1]=r[2]^r[7]>>>16^r[5]<<16,i[2]=r[4]^r[1]>>>16^r[7]<<16,i[3]=r[6]^r[3]>>>16^r[1]<<16,r=0;4>r;r++){var o=i[r],o=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8);e[n+r]^=o}},blockSize:4,ivSize:2});e.Rabbit=n._createHelper(s)}(),n("crypto-js/rollups/rabbit",function(){}),n("src/adapters/crypto",["require","crypto-js/rollups/aes","crypto-js/rollups/tripledes","crypto-js/rollups/rabbit","encoding"],function(t){function e(t){for(var e=t.length,n=[],r=0;e>r;r++)n[r>>>2]|=(255&t[r])<<24-8*(r%4);return a.create(n,e)}function n(t){return new TextEncoder("utf-8").encode(t)}function i(t){return new TextDecoder("utf-8").decode(t)}function o(t,e,n){this.context=t,this.encrypt=e,this.decrypt=n}function s(t){function s(o,s){this.provider=s;var a=r[t];this.encrypt=function(t){var r=e(t),i=a.encrypt(r,o),s=n(i);return s},this.decrypt=function(t){var e=i(t),s=a.decrypt(e,o),c=s.toString(r.enc.Utf8),u=n(c);return u}}return s.isSupported=function(){return!0},s.prototype.open=function(t){this.provider.open(t)},s.prototype.getReadOnlyContext=function(){return new o(this.provider.getReadOnlyContext(),this.encrypt,this.decrypt)},s.prototype.getReadWriteContext=function(){return new o(this.provider.getReadWriteContext(),this.encrypt,this.decrypt)},s}t("crypto-js/rollups/aes"),t("crypto-js/rollups/tripledes"),t("crypto-js/rollups/rabbit");var a=r.lib.WordArray;return t("encoding"),o.prototype.clear=function(t){this.context.clear(t)},o.prototype.get=function(t,e){var n=this.decrypt;this.context.get(t,function(t,r){return t?(e(t),void 0):(r&&(r=n(r)),e(null,r),void 0)})},o.prototype.put=function(t,e,n){var r=this.encrypt(e);this.context.put(t,r,n)},o.prototype.delete=function(t,e){this.context.delete(t,e)},{AES:s("AES"),TripleDES:s("TripleDES"),Rabbit:s("Rabbit")}}),function(){function t(t){throw t}function e(t,e){var n=t.split("."),r=E;!(n[0]in r)&&r.execScript&&r.execScript("var "+n[0]);for(var i;n.length&&(i=n.shift());)n.length||e===b?r=r[i]?r[i]:r[i]={}:r[i]=e}function n(e,n){this.index="number"==typeof n?n:0,this.i=0,this.buffer=e instanceof(x?Uint8Array:Array)?e:new(x?Uint8Array:Array)(32768),2*this.buffer.length<=this.index&&t(Error("invalid index")),this.buffer.length<=this.index&&this.f()}function r(t){this.buffer=new(x?Uint16Array:Array)(2*t),this.length=0}function i(t){var e,n,r,i,o,s,a,c,u,f=t.length,l=0,h=Number.POSITIVE_INFINITY;for(c=0;f>c;++c)t[c]>l&&(l=t[c]),h>t[c]&&(h=t[c]);for(e=1<=r;){for(c=0;f>c;++c)if(t[c]===r){for(s=0,a=i,u=0;r>u;++u)s=s<<1|1&a,a>>=1;for(u=s;e>u;u+=o)n[u]=r<<16|c;++i}++r,i<<=1,o<<=1}return[n,l,h]}function o(t,e){this.h=R,this.w=0,this.input=x&&t instanceof Array?new Uint8Array(t):t,this.b=0,e&&(e.lazy&&(this.w=e.lazy),"number"==typeof e.compressionType&&(this.h=e.compressionType),e.outputBuffer&&(this.a=x&&e.outputBuffer instanceof Array?new Uint8Array(e.outputBuffer):e.outputBuffer),"number"==typeof e.outputIndex&&(this.b=e.outputIndex)),this.a||(this.a=new(x?Uint8Array:Array)(32768))}function s(t,e){this.length=t,this.G=e}function a(e,n){function r(e,n){var r,i=e.G,o=[],s=0;r=j[e.length],o[s++]=65535&r,o[s++]=255&r>>16,o[s++]=r>>24;var a;switch(w){case 1===i:a=[0,i-1,0];break;case 2===i:a=[1,i-2,0];break;case 3===i:a=[2,i-3,0];break;case 4===i:a=[3,i-4,0];break;case 6>=i:a=[4,i-5,1];break;case 8>=i:a=[5,i-7,1];break;case 12>=i:a=[6,i-9,2];break;case 16>=i:a=[7,i-13,2];break;case 24>=i:a=[8,i-17,3];break;case 32>=i:a=[9,i-25,3];break;case 48>=i:a=[10,i-33,4];break;case 64>=i:a=[11,i-49,4];break;case 96>=i:a=[12,i-65,5];break;case 128>=i:a=[13,i-97,5];break;case 192>=i:a=[14,i-129,6];break;case 256>=i:a=[15,i-193,6];break;case 384>=i:a=[16,i-257,7];break;case 512>=i:a=[17,i-385,7];break;case 768>=i:a=[18,i-513,8];break;case 1024>=i:a=[19,i-769,8];break;case 1536>=i:a=[20,i-1025,9];break;case 2048>=i:a=[21,i-1537,9];break;case 3072>=i:a=[22,i-2049,10];break;case 4096>=i:a=[23,i-3073,10];break;case 6144>=i:a=[24,i-4097,11];break;case 8192>=i:a=[25,i-6145,11];break;case 12288>=i:a=[26,i-8193,12];break;case 16384>=i:a=[27,i-12289,12];break;case 24576>=i:a=[28,i-16385,13];break;case 32768>=i:a=[29,i-24577,13];break;default:t("invalid distance")}r=a,o[s++]=r[0],o[s++]=r[1],o[s++]=r[2];var c,u;for(c=0,u=o.length;u>c;++c)g[y++]=o[c];m[o[0]]++,_[o[3]]++,v=e.length+n-1,h=null}var i,o,s,a,u,f,l,h,d,p={},g=x?new Uint16Array(2*n.length):[],y=0,v=0,m=new(x?Uint32Array:Array)(286),_=new(x?Uint32Array:Array)(30),E=e.w;if(!x){for(s=0;285>=s;)m[s++]=0;for(s=0;29>=s;)_[s++]=0}for(m[256]=1,i=0,o=n.length;o>i;++i){for(s=u=0,a=3;a>s&&i+s!==o;++s)u=u<<8|n[i+s];if(p[u]===b&&(p[u]=[]),f=p[u],!(v-->0)){for(;f.length>0&&i-f[0]>32768;)f.shift();if(i+3>=o){for(h&&r(h,-1),s=0,a=o-i;a>s;++s)d=n[i+s],g[y++]=d,++m[d];break}f.length>0?(l=c(n,i,f),h?h.lengthl.length?h=l:r(l,0)):h?r(h,-1):(d=n[i],g[y++]=d,++m[d])}f.push(i)}return g[y++]=256,m[256]++,e.L=m,e.K=_,x?g.subarray(0,y):g}function c(t,e,n){var r,i,o,a,c,u,f=0,l=t.length;a=0,u=n.length;t:for(;u>a;a++){if(r=n[u-a-1],o=3,f>3){for(c=f;c>3;c--)if(t[r+c-1]!==t[e+c-1])continue t;o=f}for(;258>o&&l>e+o&&t[r+o]===t[e+o];)++o;if(o>f&&(i=r,f=o),258===o)break}return new s(f,e-i)}function u(t,e){var n,i,o,s,a,c=t.length,u=new r(572),l=new(x?Uint8Array:Array)(c);if(!x)for(s=0;c>s;s++)l[s]=0;for(s=0;c>s;++s)t[s]>0&&u.push(s,t[s]);if(n=Array(u.length/2),i=new(x?Uint32Array:Array)(u.length/2),1===n.length)return l[u.pop().index]=1,l;for(s=0,a=u.length/2;a>s;++s)n[s]=u.pop(),i[s]=n[s].value;for(o=f(i,i.length,e),s=0,a=n.length;a>s;++s)l[n[s].index]=o[s];return l}function f(t,e,n){function r(t){var n=d[t][p[t]];n===e?(r(t+1),r(t+1)):--l[n],++p[t]}var i,o,s,a,c,u=new(x?Uint16Array:Array)(n),f=new(x?Uint8Array:Array)(n),l=new(x?Uint8Array:Array)(e),h=Array(n),d=Array(n),p=Array(n),g=(1<o;++o)y>g?f[o]=0:(f[o]=1,g-=y),g<<=1,u[n-2-o]=(0|u[n-1-o]/2)+e;for(u[0]=f[0],h[0]=Array(u[0]),d[0]=Array(u[0]),o=1;n>o;++o)u[o]>2*u[o-1]+f[o]&&(u[o]=2*u[o-1]+f[o]),h[o]=Array(u[o]),d[o]=Array(u[o]);for(i=0;e>i;++i)l[i]=n;for(s=0;u[n-1]>s;++s)h[n-1][s]=t[s],d[n-1][s]=s;for(i=0;n>i;++i)p[i]=0;for(1===f[n-1]&&(--l[0],++p[n-1]),o=n-2;o>=0;--o){for(a=i=0,c=p[o+1],s=0;u[o]>s;s++)a=h[o+1][c]+h[o+1][c+1],a>t[i]?(h[o][s]=a,d[o][s]=e,c+=2):(h[o][s]=t[i],d[o][s]=i,++i);p[o]=0,1===f[o]&&r(o)}return l}function l(t){var e,n,r,i,o=new(x?Uint16Array:Array)(t.length),s=[],a=[],c=0;for(e=0,n=t.length;n>e;e++)s[t[e]]=(0|s[t[e]])+1;for(e=1,n=16;n>=e;e++)a[e]=c,c+=0|s[e],c<<=1;for(e=0,n=t.length;n>e;e++)for(c=a[t[e]],a[t[e]]+=1,r=o[e]=0,i=t[e];i>r;r++)o[e]=o[e]<<1|1&c,c>>>=1;return o}function h(e,n){switch(this.l=[],this.m=32768,this.e=this.g=this.c=this.q=0,this.input=x?new Uint8Array(e):e,this.s=!1,this.n=T,this.B=!1,(n||!(n={}))&&(n.index&&(this.c=n.index),n.bufferSize&&(this.m=n.bufferSize),n.bufferType&&(this.n=n.bufferType),n.resize&&(this.B=n.resize)),this.n){case F:this.b=32768,this.a=new(x?Uint8Array:Array)(32768+this.m+258);break;case T:this.b=0,this.a=new(x?Uint8Array:Array)(this.m),this.f=this.J,this.t=this.H,this.o=this.I;break;default:t(Error("invalid inflate mode"))}}function d(e,n){for(var r,i=e.g,o=e.e,s=e.input,a=e.c;n>o;)r=s[a++],r===b&&t(Error("input buffer is broken")),i|=r<>>n,e.e=o-n,e.c=a,r}function p(t,e){for(var n,r,i,o=t.g,s=t.e,a=t.input,c=t.c,u=e[0],f=e[1];f>s&&(n=a[c++],n!==b);)o|=n<>>16,t.g=o>>i,t.e=s-i,t.c=c,65535&r}function g(t){function e(t,e,n){var r,i,o,s;for(s=0;t>s;)switch(r=p(this,e)){case 16:for(o=3+d(this,2);o--;)n[s++]=i;break;case 17:for(o=3+d(this,3);o--;)n[s++]=0;i=0;break;case 18:for(o=11+d(this,7);o--;)n[s++]=0;i=0;break;default:i=n[s++]=r}return n}var n,r,o,s,a=d(t,5)+257,c=d(t,5)+1,u=d(t,4)+4,f=new(x?Uint8Array:Array)(P.length);for(s=0;u>s;++s)f[P[s]]=d(t,3);n=i(f),r=new(x?Uint8Array:Array)(a),o=new(x?Uint8Array:Array)(c),t.o(i(e.call(t,a,n,r)),i(e.call(t,c,n,o)))}function y(t){if("string"==typeof t){var e,n,r=t.split("");for(e=0,n=r.length;n>e;e++)r[e]=(255&r[e].charCodeAt(0))>>>0;t=r}for(var i,o=1,s=0,a=t.length,c=0;a>0;){i=a>1024?1024:a,a-=i;do o+=t[c++],s+=o;while(--i);o%=65521,s%=65521}return(s<<16|o)>>>0}function v(e,n){var r,i;switch(this.input=e,this.c=0,(n||!(n={}))&&(n.index&&(this.c=n.index),n.verify&&(this.M=n.verify)),r=e[this.c++],i=e[this.c++],15&r){case re:this.method=re;break;default:t(Error("unsupported compression method"))}0!==((r<<8)+i)%31&&t(Error("invalid fcheck flag:"+((r<<8)+i)%31)),32&i&&t(Error("fdict flag is not supported")),this.A=new h(e,{index:this.c,bufferSize:n.bufferSize,bufferType:n.bufferType,resize:n.resize})}function m(t,e){this.input=t,this.a=new(x?Uint8Array:Array)(32768),this.h=ie.k;var n,r={};!e&&(e={})||"number"!=typeof e.compressionType||(this.h=e.compressionType);for(n in e)r[n]=e[n];r.outputBuffer=this.a,this.z=new o(this.input,r)}function _(t,n){var r,i,o,s;if(Object.keys)r=Object.keys(n);else for(i in r=[],o=0,n)r[o++]=i;for(o=0,s=r.length;s>o;++o)i=r[o],e(t+"."+i,n[i])}var b=void 0,w=!0,E=this,x="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array;n.prototype.f=function(){var t,e=this.buffer,n=e.length,r=new(x?Uint8Array:Array)(n<<1);if(x)r.set(e);else for(t=0;n>t;++t)r[t]=e[t];return this.buffer=r},n.prototype.d=function(t,e,n){var r,i=this.buffer,o=this.index,s=this.i,a=i[o];if(n&&e>1&&(t=e>8?(D[255&t]<<24|D[255&t>>>8]<<16|D[255&t>>>16]<<8|D[255&t>>>24])>>32-e:D[t]>>8-e),8>e+s)a=a<r;++r)a=a<<1|1&t>>e-r-1,8===++s&&(s=0,i[o++]=D[a],a=0,o===i.length&&(i=this.f()));i[o]=a,this.buffer=i,this.i=s,this.index=o},n.prototype.finish=function(){var t,e=this.buffer,n=this.index;return this.i>0&&(e[n]<<=8-this.i,e[n]=D[e[n]],n++),x?t=e.subarray(0,n):(e.length=n,t=e),t};var k,S=new(x?Uint8Array:Array)(256);for(k=0;256>k;++k){for(var B=k,A=B,O=7,B=B>>>1;B;B>>>=1)A<<=1,A|=1&B,--O;S[k]=(255&A<>>0}var D=S;r.prototype.getParent=function(t){return 2*(0|(t-2)/4)},r.prototype.push=function(t,e){var n,r,i,o=this.buffer;for(n=this.length,o[this.length++]=e,o[this.length++]=t;n>0&&(r=this.getParent(n),o[n]>o[r]);)i=o[n],o[n]=o[r],o[r]=i,i=o[n+1],o[n+1]=o[r+1],o[r+1]=i,n=r;return this.length},r.prototype.pop=function(){var t,e,n,r,i,o=this.buffer;for(e=o[0],t=o[1],this.length-=2,o[0]=o[this.length],o[1]=o[this.length+1],i=0;(r=2*i+2,!(r>=this.length))&&(this.length>r+2&&o[r+2]>o[r]&&(r+=2),o[r]>o[i]);)n=o[i],o[i]=o[r],o[r]=n,n=o[i+1],o[i+1]=o[r+1],o[r+1]=n,i=r;return{index:t,value:e,length:this.length}};var C,R=2,z={NONE:0,r:1,k:R,N:3},M=[];for(C=0;288>C;C++)switch(w){case 143>=C:M.push([C+48,8]);break;case 255>=C:M.push([C-144+400,9]);break;case 279>=C:M.push([C-256+0,7]);break;case 287>=C:M.push([C-280+192,8]);break;default:t("invalid literal: "+C)}o.prototype.j=function(){var e,r,i,o,s=this.input;switch(this.h){case 0:for(i=0,o=s.length;o>i;){r=x?s.subarray(i,i+65535):s.slice(i,i+65535),i+=r.length;var c=r,f=i===o,h=b,d=b,p=b,g=b,y=b,v=this.a,m=this.b;if(x){for(v=new Uint8Array(this.a.buffer);v.length<=m+c.length+5;)v=new Uint8Array(v.length<<1);v.set(this.a)}if(h=f?1:0,v[m++]=0|h,d=c.length,p=65535&~d+65536,v[m++]=255&d,v[m++]=255&d>>>8,v[m++]=255&p,v[m++]=255&p>>>8,x)v.set(c,m),m+=c.length,v=v.subarray(0,m);else{for(g=0,y=c.length;y>g;++g)v[m++]=c[g];v.length=m}this.b=m,this.a=v}break;case 1:var _=new n(x?new Uint8Array(this.a.buffer):this.a,this.b);_.d(1,1,w),_.d(1,2,w);var E,k,S,B=a(this,s);for(E=0,k=B.length;k>E;E++)if(S=B[E],n.prototype.d.apply(_,M[S]),S>256)_.d(B[++E],B[++E],w),_.d(B[++E],5),_.d(B[++E],B[++E],w);else if(256===S)break;this.a=_.finish(),this.b=this.a.length;break;case R:var A,O,D,C,z,I,j,F,T,U,N,L,W,P,H,q=new n(x?new Uint8Array(this.a.buffer):this.a,this.b),X=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],K=Array(19);for(A=R,q.d(1,1,w),q.d(A,2,w),O=a(this,s),I=u(this.L,15),j=l(I),F=u(this.K,7),T=l(F),D=286;D>257&&0===I[D-1];D--);for(C=30;C>1&&0===F[C-1];C--);var Y,Z,$,Q,V,G,J=D,te=C,ee=new(x?Uint32Array:Array)(J+te),ne=new(x?Uint32Array:Array)(316),re=new(x?Uint8Array:Array)(19);for(Y=Z=0;J>Y;Y++)ee[Z++]=I[Y];for(Y=0;te>Y;Y++)ee[Z++]=F[Y];if(!x)for(Y=0,Q=re.length;Q>Y;++Y)re[Y]=0;for(Y=V=0,Q=ee.length;Q>Y;Y+=Z){for(Z=1;Q>Y+Z&&ee[Y+Z]===ee[Y];++Z);if($=Z,0===ee[Y])if(3>$)for(;$-->0;)ne[V++]=0,re[0]++;else for(;$>0;)G=138>$?$:138,G>$-3&&$>G&&(G=$-3),10>=G?(ne[V++]=17,ne[V++]=G-3,re[17]++):(ne[V++]=18,ne[V++]=G-11,re[18]++),$-=G;else if(ne[V++]=ee[Y],re[ee[Y]]++,$--,3>$)for(;$-->0;)ne[V++]=ee[Y],re[ee[Y]]++;else for(;$>0;)G=6>$?$:6,G>$-3&&$>G&&(G=$-3),ne[V++]=16,ne[V++]=G-3,re[16]++,$-=G}for(e=x?ne.subarray(0,V):ne.slice(0,V),U=u(re,7),P=0;19>P;P++)K[P]=U[X[P]];for(z=19;z>4&&0===K[z-1];z--);for(N=l(U),q.d(D-257,5,w),q.d(C-1,5,w),q.d(z-4,4,w),P=0;z>P;P++)q.d(K[P],3,w);for(P=0,H=e.length;H>P;P++)if(L=e[P],q.d(N[L],U[L],w),L>=16){switch(P++,L){case 16:W=2;break;case 17:W=3;break;case 18:W=7;break;default:t("invalid code: "+L)}q.d(e[P],W,w)}var ie,oe,se,ae,ce,ue,fe,le,he=[j,I],de=[T,F];for(ce=he[0],ue=he[1],fe=de[0],le=de[1],ie=0,oe=O.length;oe>ie;++ie)if(se=O[ie],q.d(ce[se],ue[se],w),se>256)q.d(O[++ie],O[++ie],w),ae=O[++ie],q.d(fe[ae],le[ae],w),q.d(O[++ie],O[++ie],w);else if(256===se)break;this.a=q.finish(),this.b=this.a.length;break;default:t("invalid compression type")}return this.a};var I=function(){function e(e){switch(w){case 3===e:return[257,e-3,0];case 4===e:return[258,e-4,0];case 5===e:return[259,e-5,0];case 6===e:return[260,e-6,0];case 7===e:return[261,e-7,0];case 8===e:return[262,e-8,0];case 9===e:return[263,e-9,0];case 10===e:return[264,e-10,0];case 12>=e:return[265,e-11,1];case 14>=e:return[266,e-13,1];case 16>=e:return[267,e-15,1];case 18>=e:return[268,e-17,1];case 22>=e:return[269,e-19,2];case 26>=e:return[270,e-23,2];case 30>=e:return[271,e-27,2];case 34>=e:return[272,e-31,2];case 42>=e:return[273,e-35,3];case 50>=e:return[274,e-43,3];case 58>=e:return[275,e-51,3];case 66>=e:return[276,e-59,3];case 82>=e:return[277,e-67,4];case 98>=e:return[278,e-83,4];case 114>=e:return[279,e-99,4];case 130>=e:return[280,e-115,4];case 162>=e:return[281,e-131,5];case 194>=e:return[282,e-163,5];case 226>=e:return[283,e-195,5];case 257>=e:return[284,e-227,5];case 258===e:return[285,e-258,0];default:t("invalid length: "+e)}}var n,r,i=[];for(n=3;258>=n;n++)r=e(n),i[n]=r[2]<<24|r[1]<<16|r[0];return i}(),j=x?new Uint32Array(I):I,F=0,T=1,U={D:F,C:T};h.prototype.p=function(){for(;!this.s;){var e=d(this,3);switch(1&e&&(this.s=w),e>>>=1){case 0:var n=this.input,r=this.c,i=this.a,o=this.b,s=b,a=b,c=b,u=i.length,f=b;switch(this.e=this.g=0,s=n[r++],s===b&&t(Error("invalid uncompressed block header: LEN (first byte)")),a=s,s=n[r++],s===b&&t(Error("invalid uncompressed block header: LEN (second byte)")),a|=s<<8,s=n[r++],s===b&&t(Error("invalid uncompressed block header: NLEN (first byte)")),c=s,s=n[r++],s===b&&t(Error("invalid uncompressed block header: NLEN (second byte)")),c|=s<<8,a===~c&&t(Error("invalid uncompressed block header: length verify")),r+a>n.length&&t(Error("input buffer is broken")),this.n){case F:for(;o+a>i.length;){if(f=u-o,a-=f,x)i.set(n.subarray(r,r+f),o),o+=f,r+=f;else for(;f--;)i[o++]=n[r++];this.b=o,i=this.f(),o=this.b}break;case T:for(;o+a>i.length;)i=this.f({v:2});break;default:t(Error("invalid inflate mode"))}if(x)i.set(n.subarray(r,r+a),o),o+=a,r+=a;else for(;a--;)i[o++]=n[r++];this.c=r,this.b=o,this.a=i;break;case 1:this.o(te,ne);break;case 2:g(this);break;default:t(Error("unknown BTYPE: "+e))}}return this.t()};var N,L,W=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],P=x?new Uint16Array(W):W,H=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258],q=x?new Uint16Array(H):H,X=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0],K=x?new Uint8Array(X):X,Y=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],Z=x?new Uint16Array(Y):Y,$=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],Q=x?new Uint8Array($):$,V=new(x?Uint8Array:Array)(288);for(N=0,L=V.length;L>N;++N)V[N]=143>=N?8:255>=N?9:279>=N?7:8;var G,J,te=i(V),ee=new(x?Uint8Array:Array)(30);for(G=0,J=ee.length;J>G;++G)ee[G]=5;var ne=i(ee);h.prototype.o=function(t,e){var n=this.a,r=this.b;this.u=t;for(var i,o,s,a,c=n.length-258;256!==(i=p(this,t));)if(256>i)r>=c&&(this.b=r,n=this.f(),r=this.b),n[r++]=i;else for(o=i-257,a=q[o],K[o]>0&&(a+=d(this,K[o])),i=p(this,e),s=Z[i],Q[i]>0&&(s+=d(this,Q[i])),r>=c&&(this.b=r,n=this.f(),r=this.b);a--;)n[r]=n[r++-s];for(;this.e>=8;)this.e-=8,this.c--;this.b=r},h.prototype.I=function(t,e){var n=this.a,r=this.b;this.u=t;for(var i,o,s,a,c=n.length;256!==(i=p(this,t));)if(256>i)r>=c&&(n=this.f(),c=n.length),n[r++]=i;else for(o=i-257,a=q[o],K[o]>0&&(a+=d(this,K[o])),i=p(this,e),s=Z[i],Q[i]>0&&(s+=d(this,Q[i])),r+a>c&&(n=this.f(),c=n.length);a--;)n[r]=n[r++-s];for(;this.e>=8;)this.e-=8,this.c--;this.b=r},h.prototype.f=function(){var t,e,n=new(x?Uint8Array:Array)(this.b-32768),r=this.b-32768,i=this.a;if(x)n.set(i.subarray(32768,n.length));else for(t=0,e=n.length;e>t;++t)n[t]=i[t+32768];if(this.l.push(n),this.q+=n.length,x)i.set(i.subarray(r,r+32768));else for(t=0;32768>t;++t)i[t]=i[r+t];return this.b=32768,i},h.prototype.J=function(t){var e,n,r,i,o=0|this.input.length/this.c+1,s=this.input,a=this.a;return t&&("number"==typeof t.v&&(o=t.v),"number"==typeof t.F&&(o+=t.F)),2>o?(n=(s.length-this.c)/this.u[2],i=0|258*(n/2),r=a.length>i?a.length+i:a.length<<1):r=a.length*o,x?(e=new Uint8Array(r),e.set(a)):e=a,this.a=e},h.prototype.t=function(){var t,e,n,r,i,o=0,s=this.a,a=this.l,c=new(x?Uint8Array:Array)(this.q+(this.b-32768));if(0===a.length)return x?this.a.subarray(32768,this.b):this.a.slice(32768,this.b);for(e=0,n=a.length;n>e;++e)for(t=a[e],r=0,i=t.length;i>r;++r)c[o++]=t[r];for(e=32768,n=this.b;n>e;++e)c[o++]=s[e];return this.l=[],this.buffer=c},h.prototype.H=function(){var t,e=this.b;return x?this.B?(t=new Uint8Array(e),t.set(this.a.subarray(0,e))):t=this.a.subarray(0,e):(this.a.length>e&&(this.a.length=e),t=this.a),this.buffer=t},v.prototype.p=function(){var e,n,r=this.input;return e=this.A.p(),this.c=this.A.c,this.M&&(n=(r[this.c++]<<24|r[this.c++]<<16|r[this.c++]<<8|r[this.c++])>>>0,n!==y(e)&&t(Error("invalid adler-32 checksum"))),e};var re=8,ie=z;m.prototype.j=function(){var e,n,r,i,o,s,a,c=0;switch(a=this.a,e=re){case re:n=Math.LOG2E*Math.log(32768)-8;break;default:t(Error("invalid compression method"))}switch(r=n<<4|e,a[c++]=r,e){case re:switch(this.h){case ie.NONE:o=0;break;case ie.r:o=1;break;case ie.k:o=2;break;default:t(Error("unsupported compression type"))}break;default:t(Error("invalid compression method"))}return i=0|o<<6,a[c++]=i|31-(256*r+i)%31,s=y(this.input),this.z.b=c,a=this.z.j(),c=a.length,x&&(a=new Uint8Array(a.buffer),c+4>=a.length&&(this.a=new Uint8Array(a.length+4),this.a.set(a),a=this.a),a=a.subarray(0,c+4)),a[c++]=255&s>>24,a[c++]=255&s>>16,a[c++]=255&s>>8,a[c++]=255&s,a -},e("Zlib.Inflate",v),e("Zlib.Inflate.prototype.decompress",v.prototype.p),_("Zlib.Inflate.BufferType",{ADAPTIVE:U.C,BLOCK:U.D}),e("Zlib.Deflate",m),e("Zlib.Deflate.compress",function(t,e){return new m(t,e).j()}),e("Zlib.Deflate.prototype.compress",m.prototype.j),_("Zlib.Deflate.CompressionType",{NONE:ie.NONE,FIXED:ie.r,DYNAMIC:ie.k})}.call(this),n("zlib",function(){}),n("src/adapters/zlib",["require","zlib"],function(t){function e(t){return new o(t).decompress()}function n(t){return new s(t).compress()}function r(t){this.context=t}function i(t){this.provider=t}t("zlib");var o=Zlib.Inflate,s=Zlib.Deflate;return r.prototype.clear=function(t){this.context.clear(t)},r.prototype.get=function(t,n){this.context.get(t,function(t,r){return t?(n(t),void 0):(r&&(r=e(r)),n(null,r),void 0)})},r.prototype.put=function(t,e,r){e=n(e),this.context.put(t,e,r)},r.prototype.delete=function(t,e){this.context.delete(t,e)},i.isSupported=function(){return!0},i.prototype.open=function(t){this.provider.open(t)},i.prototype.getReadOnlyContext=function(){return new r(this.provider.getReadOnlyContext())},i.prototype.getReadWriteContext=function(){return new r(this.provider.getReadWriteContext())},i}),n("src/adapters/adapters",["require","src/adapters/crypto","src/adapters/zlib"],function(t){var e=t("src/adapters/crypto"),n=t("src/adapters/zlib");return{AES:e.AES,TripleDES:e.TripleDES,Rabbit:e.Rabbit,Zlib:n,Compression:n,Encryption:e.AES}}),n("src/fs",["require","nodash","encoding","src/path","src/path","src/path","src/shared","src/shared","src/shared","src/error","src/error","src/error","src/error","src/error","src/error","src/error","src/error","src/error","src/error","src/error","src/error","src/error","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/providers/providers","src/adapters/adapters"],function(t){function e(t,e){this.id=t,this.type=e||he}function n(t,e,n){this.id=t,this.flags=e,this.position=n}function r(t,e,n){var r=Date.now();this.id=ve,this.mode=ge,this.atime=t||r,this.ctime=e||r,this.mtime=n||r,this.rnode=V()}function i(t,e,n,r,i,o,s,a,c,u){var f=Date.now();this.id=t||V(),this.mode=e||he,this.size=n||0,this.atime=r||f,this.ctime=i||f,this.mtime=o||f,this.flags=s||[],this.xattrs=a||{},this.nlinks=c||0,this.version=u||0,this.blksize=void 0,this.nblocks=1,this.data=V()}function o(t,e){this.node=t.id,this.dev=e,this.size=t.size,this.nlinks=t.nlinks,this.atime=t.atime,this.mtime=t.mtime,this.ctime=t.ctime,this.type=t.mode}function s(t,e,n){function r(e,r){e?n(e):r&&r.mode===ge&&r.rnode?t.get(r.rnode,i):n(new ue("missing super node"))}function i(t,e){t?n(t):e?n(null,e):n(new ee("path does not exist"))}function o(e,r){e?n(e):r.mode===de&&r.data?t.get(r.data,a):n(new ie("a component of the path prefix is not a directory"))}function a(e,r){if(e)n(e);else if(Y(r).has(f)){var i=r[f].id;t.get(i,c)}else n(new ee("path does not exist"))}function c(t,e){t?n(t):e.mode==pe?(h++,h>me?n(new ce("too many symbolic links were encountered")):u(e.data)):n(null,e)}function u(e){e=Z(e),l=$(e),f=Q(e),ye==f?t.get(ve,r):s(t,l,o)}if(e=Z(e),!e)return n(new ee("path is an empty string"));var f=Q(e),l=$(e),h=0;ye==f?t.get(ve,r):s(t,l,o)}function a(t,e){function n(n,i){!n&&i?e(new J):n&&!n instanceof ee?e(n):(a=new r,t.put(a.id,a,o))}function o(n){n?e(n):(c=new i(a.rnode,de),c.nlinks+=1,t.put(c.id,c,s))}function s(n){n?e(n):(u={},t.put(c.data,u,e))}var a,c,u;t.get(ve,n)}function c(t,n,r){function o(e,n){!e&&n?r(new J):e&&!e instanceof ee?r(e):s(t,y,a)}function a(e,n){e?r(e):(d=n,t.get(d.data,c))}function c(e,n){e?r(e):(p=n,l=new i(void 0,de),l.nlinks+=1,t.put(l.id,l,u))}function u(e){e?r(e):(h={},t.put(l.data,h,f))}function f(n){n?r(n):(p[g]=new e(l.id,de),t.put(d.data,p,r))}n=Z(n);var l,h,d,p,g=Q(n),y=$(n);s(t,n,o)}function u(t,e,n){function r(e,r){e?n(e):(d=r,t.get(d.data,i))}function i(e,r){e?n(e):ye==g?n(new ne):Y(r).has(g)?(p=r,l=p[g].id,t.get(l,o)):n(new ee)}function o(e,r){e?n(e):r.mode!=de?n(new ie):(l=r,t.get(l.data,a))}function a(t,e){t?n(t):(h=e,Y(h).size()>0?n(new re):c())}function c(){delete p[g],t.put(d.data,p,u)}function u(e){e?n(e):t.delete(l.id,f)}function f(e){e?n(e):t.delete(l.data,n)}e=Z(e);var l,h,d,p,g=Q(e),y=$(e);s(t,y,r)}function f(t,n,r,o){function a(e,n){e?o(e):(y=n,t.get(y.data,c))}function c(e,n){e?o(e):(v=n,Y(v).has(w)?Y(r).contains(Se)?o(new ee("O_CREATE and O_EXCLUSIVE are set, and the named file exists")):(m=v[w],m.type==de&&Y(r).contains(xe)?o(new te("the named file is a directory and O_WRITE is set")):t.get(m.id,u)):Y(r).contains(ke)?h():o(new ee("O_CREATE is not set and the named file does not exist")))}function u(t,e){if(t)o(t);else{var n=e;n.mode==pe?(x++,x>me?o(new ce("too many symbolic links were encountered")):f(n.data)):l(void 0,n)}}function f(e){e=Z(e),E=$(e),w=Q(e),ye==w&&(Y(r).contains(xe)?o(new te("the named file is a directory and O_WRITE is set")):s(t,n,l)),s(t,E,a)}function l(t,e){t?o(t):(_=e,o(null,_))}function h(){_=new i(void 0,he),_.nlinks+=1,t.put(_.id,_,d)}function d(e){e?o(e):(b=new Uint8Array(0),t.put(_.data,b,p))}function p(n){n?o(n):(v[w]=new e(_.id,he),t.put(y.data,v,g))}function g(t){t?o(t):o(null,_)}n=Z(n);var y,v,m,_,b,w=Q(n),E=$(n),x=0;ye==w?Y(r).contains(xe)?o(new te("the named file is a directory and O_WRITE is set")):s(t,n,l):s(t,E,a)}function l(t,e,n,r,i,o,s){function a(t){t?s(t):s(null,i)}function c(e){e?s(e):t.put(l.id,l,a)}function u(r,a){if(r)s(r);else{h=a;var u=void 0!==o&&null!==o?o:e.position,f=Math.max(h.length,u+i),d=new Uint8Array(f);h&&d.set(h),d.set(n,u),void 0===o&&(e.position+=i),l.size=f,l.mtime=Date.now(),l.version+=1,t.put(l.data,d,c)}}function f(e,n){e?s(e):(l=n,t.get(l.data,u))}var l,h;t.get(e.id,f)}function h(t,e,n,r,i,o,s){function a(t,a){if(t)s(t);else{f=a;var c=void 0!==o&&null!==o?o:e.position;i=c+i>n.length?i-c:i;var u=f.subarray(c,c+i);n.set(u,r),void 0===o&&(e.position+=i),s(null,i)}}function c(e,n){e?s(e):(u=n,t.get(u.data,a))}var u,f;t.get(e.id,c)}function d(t,e,n){function r(t,e){t?n(t):n(null,e)}e=Z(e),Q(e),s(t,e,r)}function p(t,e,n){function r(t,e){t?n(t):n(null,e)}t.get(e.id,r)}function g(t,e,n){function r(e,r){e?n(e):(a=r,t.get(a.data,i))}function i(e,r){e?n(e):(c=r,Y(c).has(u)?t.get(c[u].id,o):n(new ee("a component of the path does not name an existing file")))}function o(t,e){t?n(t):n(null,e)}e=Z(e);var a,c,u=Q(e),f=$(e);ye==u?s(t,e,o):s(t,f,r)}function y(t,e,n,r){function i(e,n){e?r(e):(v=n,v.nlinks+=1,t.put(v.id,v,r))}function o(e){e?r(e):t.get(y[m].id,i)}function a(e,n){e?r(e):(y=n,Y(y).has(m)?r(new J("newpath resolves to an existing file")):(y[m]=p[l],t.put(g.data,y,o)))}function c(e,n){e?r(e):(g=n,t.get(g.data,a))}function u(e,n){e?r(e):(p=n,Y(p).has(l)?s(t,_,c):r(new ee("a component of either path prefix does not exist")))}function f(e,n){e?r(e):(d=n,t.get(d.data,u))}e=Z(e);var l=Q(e),h=$(e);n=Z(n);var d,p,g,y,v,m=Q(n),_=$(n);s(t,h,f)}function v(t,e,n){function r(e){e?n(e):(delete f[h],t.put(u.data,f,n))}function i(e){e?n(e):t.delete(l.data,r)}function o(e,o){e?n(e):(l=o,l.nlinks-=1,1>l.nlinks?t.delete(l.id,i):t.put(l.id,l,r))}function a(e,r){e?n(e):(f=r,Y(f).has(h)?t.get(f[h].id,o):n(new ee("a component of the path does not name an existing file")))}function c(e,r){e?n(e):(u=r,t.get(u.data,a))}e=Z(e);var u,f,l,h=Q(e),d=$(e);s(t,d,c)}function m(t,e,n){function r(t,e){if(t)n(t);else{a=e;var r=Object.keys(a);n(null,r)}}function i(e,i){e?n(e):(o=i,t.get(o.data,r))}e=Z(e),Q(e);var o,a;s(t,e,i)}function _(t,n,r,o){function a(e,n){e?o(e):(l=n,t.get(l.data,c))}function c(t,e){t?o(t):(h=e,Y(h).has(p)?o(new J("the destination path already exists")):u())}function u(){d=new i(void 0,pe),d.nlinks+=1,d.size=n.length,d.data=n,t.put(d.id,d,f)}function f(n){n?o(n):(h[p]=new e(d.id,pe),t.put(l.data,h,o))}r=Z(r);var l,h,d,p=Q(r),g=$(r);ye==p?o(new J("the destination path already exists")):s(t,g,a)}function b(t,e,n){function r(e,r){e?n(e):(a=r,t.get(a.data,i))}function i(e,r){e?n(e):(c=r,Y(c).has(u)?t.get(c[u].id,o):n(new ee("a component of the path does not name an existing file")))}function o(t,e){t?n(t):e.mode!=pe?n(new se("path not a symbolic link")):n(null,e.data)}e=Z(e);var a,c,u=Q(e),f=$(e);s(t,f,r)}function w(t,e,n,r){function i(e,n){e?r(e):n.mode==de?r(new te("the named file is a directory")):(c=n,t.get(c.data,o))}function o(e,i){if(e)r(e);else{var o=new Uint8Array(n);i&&o.set(i.subarray(0,n)),t.put(c.data,o,a)}}function a(e){e?r(e):(c.size=n,c.mtime=Date.now(),c.version+=1,t.put(c.id,c,r))}e=Z(e);var c;0>n?r(new se("length cannot be negative")):s(t,e,i)}function E(t,e,n,r){function i(e,n){e?r(e):n.mode==de?r(new te("the named file is a directory")):(a=n,t.get(a.data,o))}function o(e,i){if(e)r(e);else{var o=new Uint8Array(n);i&&o.set(i.subarray(0,n)),t.put(a.data,o,s)}}function s(e){e?r(e):(a.size=n,a.mtime=Date.now(),a.version+=1,t.put(a.id,a,r))}var a;0>n?r(new se("length cannot be negative")):t.get(e.id,i)}function x(t){return Y(Ae).has(t)?Ae[t]:null}function k(t,e){if(-1!==(""+t).indexOf("\0")){var n=Error("Path must be a string without null bytes.");return e(n),!1}return!0}function S(t){return"function"==typeof t?t:function(t){if(t)throw t}}function B(t,e){function n(){l.forEach(function(t){t.call(this)}.bind(c)),l=null}t=t||{},e=e||G;var r=t.name||fe,i=t.flags,o=t.provider||new Oe.Default(r),s=Y(i).contains(le),c=this;c.readyState=be,c.name=r,c.error=null;var u={},f=1;Object.defineProperty(this,"openFiles",{get:function(){return u}}),this.allocDescriptor=function(t){var e=f++;return u[e]=t,e},this.releaseDescriptor=function(t){delete u[t]};var l=[];this.queueOrRun=function(t){var e;return _e==c.readyState?t.call(c):we==c.readyState?e=new ue("unknown error"):l.push(t),e},o.open(function(t,r){function i(t){c.provider=o,t?c.readyState=we:(c.readyState=_e,n()),e(t)}if(t)return i(t);if(!s&&!r)return i(null);var u=o.getReadWriteContext();u.clear(function(t){return t?(i(t),void 0):(a(u,i),void 0)})})}function A(t,e,r,i,o){function s(e,r){if(e)o(e);else{var s;s=Y(i).contains(Be)?r.size:0;var a=new n(r.id,i,s),c=t.allocDescriptor(a);o(null,c)}}k(r,o)&&(i=x(i),i||o(new se("flags is not valid")),f(e,r,i,s))}function O(t,e,n){Y(t.openFiles).has(e)?(t.releaseDescriptor(e),n(null)):n(new oe("invalid file descriptor"))}function D(t,e,n){function r(t){t?n(t):n(null)}k(e,n)&&c(t,e,r)}function C(t,e,n){function r(t){t?n(t):n(null)}k(e,n)&&u(t,e,r)}function R(t,e,n,r){function i(t,n){if(t)r(t);else{var i=new o(n,e);r(null,i)}}k(n,r)&&d(t,n,i)}function z(t,e,n,r){function i(e,n){if(e)r(e);else{var i=new o(n,t.name);r(null,i)}}var s=t.openFiles[n];s?p(e,s,i):r(new oe("invalid file descriptor"))}function M(t,e,n,r){function i(t){t?r(t):r(null)}k(e,r)&&k(n,r)&&y(t,e,n,i)}function I(t,e,n){function r(t){t?n(t):n(null)}k(e,n)&&v(t,e,r)}function j(t,e,n,r,i,o,s,a){function c(t,e){t?a(t):a(null,e)}i=void 0===i?0:i,o=void 0===o?r.length-i:o;var u=t.openFiles[n];u?Y(u.flags).contains(Ee)?h(e,u,r,i,o,s,c):a(new oe("descriptor does not permit reading")):a(new oe("invalid file descriptor"))}function F(t,e,r,i,s){if(i?"function"==typeof i?i={encoding:null,flag:"r"}:"string"==typeof i&&(i={encoding:i,flag:"r"}):i={encoding:null,flag:"r"},k(r,s)){var a=x(i.flag||"r");a||s(new se("flags is not valid")),f(e,r,a,function(r,c){if(r)return s(r);var u=new n(c.id,a,0),f=t.allocDescriptor(u);p(e,u,function(n,r){if(n)return s(n);var a=new o(r,t.name),c=a.size,l=new Uint8Array(c);h(e,u,l,0,c,0,function(e){if(e)return s(e);t.releaseDescriptor(f);var n;n="utf8"===i.encoding?new TextDecoder("utf-8").decode(l):l,s(null,n)})})})}}function T(t,e,n,r,i,o,s,a){function c(t,e){t?a(t):a(null,e)}i=void 0===i?0:i,o=void 0===o?r.length-i:o;var u=t.openFiles[n];u?Y(u.flags).contains(xe)?o>r.length-i?a(new ae("intput buffer is too small")):l(e,u,r,i,o,s,c):a(new oe("descriptor does not permit writing")):a(new oe("invalid file descriptor"))}function U(t,e,r,i,o,s){if(o?"function"==typeof o?o={encoding:"utf8",flag:"w"}:"string"==typeof o&&(o={encoding:o,flag:"w"}):o={encoding:"utf8",flag:"w"},k(r,s)){var a=x(o.flag||"w");a||s(new se("flags is not valid")),i=i||"","number"==typeof i&&(i=""+i),"string"==typeof i&&"utf8"===o.encoding&&(i=new TextEncoder("utf-8").encode(i)),f(e,r,a,function(r,o){if(r)return s(r);var c=new n(o.id,a,0),u=t.allocDescriptor(c);l(e,c,i,0,i.length,0,function(e){return e?s(e):(t.releaseDescriptor(u),s(null),void 0)})})}}function N(t,e,n,r,i,o){function s(t,e){t?o(t):0>e.size+r?o(new se("resulting file offset would be negative")):(a.position=e.size+r,o(null,a.position))}var a=t.openFiles[n];a||o(new oe("invalid file descriptor")),"SET"===i?0>r?o(new se("resulting file offset would be negative")):(a.position=r,o(null,a.position)):"CUR"===i?0>a.position+r?o(new se("resulting file offset would be negative")):(a.position+=r,o(null,a.position)):"END"===i?p(e,a,s):o(new se("whence argument is not a proper value"))}function L(t,e,n){function r(t,e){t?n(t):n(null,e)}k(e,n)&&m(t,e,r)}function W(t,e,n,r){function i(t){t?r(t):r(null)}function o(n){n?r(n):v(t,e,i)}k(e,r)&&k(n,r)&&y(t,e,n,o)}function P(t,e,n,r){function i(t){t?r(t):r(null)}k(e,r)&&k(n,r)&&_(t,e,n,i)}function H(t,e,n){function r(t,e){t?n(t):n(null,e)}k(e,n)&&b(t,e,r)}function q(t,e,n,r){function i(e,n){if(e)r(e);else{var i=new o(n,t.name);r(null,i)}}k(n,r)&&g(e,n,i)}function X(t,e,n,r){function i(t){t?r(t):r(null)}k(e,r)&&w(t,e,n,i)}function K(t,e,n,r,i){function o(t){t?i(t):i(null)}var s=t.openFiles[n];s?Y(s.flags).contains(xe)?E(e,s,r,o):i(new oe("descriptor does not permit writing")):i(new oe("invalid file descriptor"))}var Y=t("nodash");t("encoding");var Z=t("src/path").normalize,$=t("src/path").dirname,Q=t("src/path").basename,V=t("src/shared").guid;t("src/shared").hash;var G=t("src/shared").nop,J=t("src/error").EExists,te=t("src/error").EIsDirectory,ee=t("src/error").ENoEntry,ne=t("src/error").EBusy,re=t("src/error").ENotEmpty,ie=t("src/error").ENotDirectory,oe=t("src/error").EBadFileDescriptor;t("src/error").ENotImplemented,t("src/error").ENotMounted;var se=t("src/error").EInvalid,ae=t("src/error").EIO,ce=t("src/error").ELoop,ue=t("src/error").EFileSystemError,fe=t("src/constants").FILE_SYSTEM_NAME,le=t("src/constants").FS_FORMAT,he=t("src/constants").MODE_FILE,de=t("src/constants").MODE_DIRECTORY,pe=t("src/constants").MODE_SYMBOLIC_LINK,ge=t("src/constants").MODE_META,ye=t("src/constants").ROOT_DIRECTORY_NAME,ve=t("src/constants").SUPER_NODE_ID,me=t("src/constants").SYMLOOP_MAX,_e=t("src/constants").FS_READY,be=t("src/constants").FS_PENDING,we=t("src/constants").FS_ERROR,Ee=t("src/constants").O_READ,xe=t("src/constants").O_WRITE,ke=t("src/constants").O_CREATE,Se=t("src/constants").O_EXCLUSIVE;t("src/constants").O_TRUNCATE;var Be=t("src/constants").O_APPEND,Ae=t("src/constants").O_FLAGS,Oe=t("src/providers/providers"),De=t("src/adapters/adapters");return B.providers=Oe,B.adapters=De,B.prototype.open=function(t,e,n,r){r=S(arguments[arguments.length-1]);var i=this,o=i.queueOrRun(function(){var n=i.provider.getReadWriteContext();A(i,n,t,e,r)});o&&r(o)},B.prototype.close=function(t,e){O(this,t,S(e))},B.prototype.mkdir=function(t,e,n){"function"==typeof e&&(n=e),n=S(n);var r=this,i=r.queueOrRun(function(){var e=r.provider.getReadWriteContext();D(e,t,n)});i&&n(i)},B.prototype.rmdir=function(t,e){e=S(e);var n=this,r=n.queueOrRun(function(){var r=n.provider.getReadWriteContext();C(r,t,e)});r&&e(r)},B.prototype.stat=function(t,e){e=S(e);var n=this,r=n.queueOrRun(function(){var r=n.provider.getReadWriteContext();R(r,n.name,t,e)});r&&e(r)},B.prototype.fstat=function(t,e){e=S(e);var n=this,r=n.queueOrRun(function(){var r=n.provider.getReadWriteContext();z(n,r,t,e)});r&&e(r)},B.prototype.link=function(t,e,n){n=S(n);var r=this,i=r.queueOrRun(function(){var i=r.provider.getReadWriteContext();M(i,t,e,n)});i&&n(i)},B.prototype.unlink=function(t,e){e=S(e);var n=this,r=n.queueOrRun(function(){var r=n.provider.getReadWriteContext();I(r,t,e)});r&&e(r)},B.prototype.read=function(t,e,n,r,i,o){function s(t,n){o(t,n||0,e)}o=S(o);var a=this,c=a.queueOrRun(function(){var o=a.provider.getReadWriteContext();j(a,o,t,e,n,r,i,s)});c&&o(c)},B.prototype.readFile=function(t,e){var n=S(arguments[arguments.length-1]),r=this,i=r.queueOrRun(function(){var i=r.provider.getReadWriteContext();F(r,i,t,e,n)});i&&n(i)},B.prototype.write=function(t,e,n,r,i,o){o=S(o);var s=this,a=s.queueOrRun(function(){var a=s.provider.getReadWriteContext();T(s,a,t,e,n,r,i,o)});a&&o(a)},B.prototype.writeFile=function(t,e,n){var r=S(arguments[arguments.length-1]),i=this,o=i.queueOrRun(function(){var o=i.provider.getReadWriteContext();U(i,o,t,e,n,r)});o&&r(o)},B.prototype.lseek=function(t,e,n,r){r=S(r);var i=this,o=i.queueOrRun(function(){var o=i.provider.getReadWriteContext();N(i,o,t,e,n,r)});o&&r(o)},B.prototype.readdir=function(t,e){e=S(e);var n=this,r=n.queueOrRun(function(){var r=n.provider.getReadWriteContext();L(r,t,e)});r&&e(r)},B.prototype.rename=function(t,e,n){n=S(n);var r=this,i=r.queueOrRun(function(){var i=r.provider.getReadWriteContext();W(i,t,e,n)});i&&n(i)},B.prototype.readlink=function(t,e){e=S(e);var n=this,r=n.queueOrRun(function(){var r=n.provider.getReadWriteContext();H(r,t,e)});r&&e(r)},B.prototype.symlink=function(t,e){var n=S(arguments[arguments.length-1]),r=this,i=r.queueOrRun(function(){var i=r.provider.getReadWriteContext();P(i,t,e,n)});i&&n(i)},B.prototype.lstat=function(t,e){e=S(e);var n=this,r=n.queueOrRun(function(){var r=n.provider.getReadWriteContext();q(n,r,t,e)});r&&e(r)},B.prototype.truncate=function(t,e,n){n=S(n);var r=this,i=r.queueOrRun(function(){var i=r.provider.getReadWriteContext();X(i,t,e,n)});i&&n(i)},B.prototype.ftruncate=function(t,e,n){n=S(n);var r=this,i=r.queueOrRun(function(){var i=r.provider.getReadWriteContext();K(r,i,t,e,n)});i&&n(i)},B}),n("src/index",["require","src/fs","src/fs","src/path"],function(t){return t("src/fs"),{FileSystem:t("src/fs"),Path:t("src/path")}});var i=e("src/index");return i}); \ No newline at end of file diff --git a/tests/spec/fs.xattr.spec.js b/tests/spec/fs.xattr.spec.js index 737e8d3..579a1be 100644 --- a/tests/spec/fs.xattr.spec.js +++ b/tests/spec/fs.xattr.spec.js @@ -15,6 +15,17 @@ define(["IDBFS"], function(IDBFS) { }); it('should be a function', function () { + + that = this; + + that.fs.writeFile('/testfile/this/is/a/dir/tmp', function (error) { + if (error) throw error; + + that.fs.setxattr('/testfile/this/is/a/dir/tmp', 'test', 'value', function (error) { + + }); + }); + expect(typeof this.fs.setxattr).toEqual('function'); expect(typeof this.fs.getxattr).toEqual('function'); }); @@ -240,12 +251,12 @@ define(["IDBFS"], function(IDBFS) { }); it('should error when file descriptor is invalid', function (error) { - var completeSet, completeGet; - var _errorSet, _errorGet; + var completeSet, completeGet, completeRemove; + var _errorSet, _errorGet, _errorRemove; var that = this; var _value; - completeSet = completeGet = false; + completeSet = completeGet = completeRemove = false; that.fs.fsetxattr(1, 'test', 'value', function (error) { _errorSet = error; @@ -258,8 +269,13 @@ define(["IDBFS"], function(IDBFS) { completeGet = true; }); + that.fs.fremovexattr(1, 'test', function (error, value) { + _errorRemove = error; + completeRemove = true; + }); + waitsFor(function () { - return completeSet && completeGet; + return completeSet && completeGet && completeRemove; }, 'test to complete', DEFAULT_TIMEOUT); runs(function () { @@ -268,6 +284,8 @@ define(["IDBFS"], function(IDBFS) { expect(_errorSet.name).toEqual('EBadFileDescriptor'); expect(_errorGet).toBeDefined(); expect(_errorGet.name).toEqual('EBadFileDescriptor'); + expect(_errorRemove).toBeDefined(); + expect(_errorRemove.name).toEqual('EBadFileDescriptor'); }); }); @@ -555,7 +573,49 @@ define(["IDBFS"], function(IDBFS) { expect(_value).toEqual('somevalue'); expect(_error.name).toEqual('ENoAttr'); }); + }); + it('should remove an extended attribute from a valid file descriptor', function () { + var complete = false; + var _error, _value; + var that = this; + var ofd; + + that.fs.open('/testfile', 'w', function (error, result) { + if (error) throw error; + + var ofd = result; + + that.fs.fsetxattr(ofd, 'test', 'somevalue', function (error) { + if (error) throw error; + + that.fs.fgetxattr(ofd, 'test', function (error, value) { + if (error) throw error; + + _value = value; + + that.fs.fremovexattr(ofd, 'test', function (error) { + if (error) throw error; + + that.fs.fgetxattr(ofd, 'test', function (error) { + _error = error; + complete = true; + }); + }); + }); + }); + }); + + waitsFor(function () { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function () { + expect(_error).toBeDefined(); + expect(_value).toBeDefined(); + expect(_value).toEqual('somevalue'); + expect(_error.name).toEqual('ENoAttr'); + }); }); }); }); \ No newline at end of file From b08a8d15ddd556b8e306621b21b5522f82875845 Mon Sep 17 00:00:00 2001 From: Barry Tulchinsky Date: Sun, 5 Jan 2014 12:22:57 -0500 Subject: [PATCH 10/11] fixed null value and refactored setxattr --- src/fs.js | 81 +++++++++++++++++-------------------- tests/spec/fs.xattr.spec.js | 67 ++++++++++++++++-------------- 2 files changed, 73 insertions(+), 75 deletions(-) diff --git a/src/fs.js b/src/fs.js index ba6e357..440a3ab 100644 --- a/src/fs.js +++ b/src/fs.js @@ -222,6 +222,41 @@ define(function(require) { } } + + /* + * set extended attribute (refactor) + */ + + function set_extended_attribute (context, path, name, value, flag, callback) { + function set_xattr (error, node) { + var xattr = (node ? node.xattrs[name] : null); + + if (error) { + callback(error); + } + else if (flag === XATTR_CREATE && node.xattrs.hasOwnProperty(name)) { + callback(new EExists('attribute already exists')); + } + else if (flag === XATTR_REPLACE && !node.xattrs.hasOwnProperty(name)) { + callback(new ENoAttr('attribute does not exist')); + } + else { + node.xattrs[name] = value; + context.put(node.id, node, callback); + } + } + + if (typeof path == 'string') { + find_node(context, path, set_xattr); + } + else if (typeof path.id == 'string') { + context.get(path.id, set_xattr); + } + else { + callback(new EInvalid('path or file descriptor of wrong type')); + } + } + /* * make_root_directory */ @@ -1124,77 +1159,35 @@ define(function(require) { function setxattr_file (context, path, name, value, flag, callback) { path = normalize(path); - function set_xattr (error, node) { - var xattr = (node ? node.xattrs[name] : null); - - if (error) { - callback (error); - } - else if (flag == XATTR_CREATE && node.xattrs.hasOwnProperty(name)) { - callback(new EExists('attribute already exists')); - } - else if (flag === XATTR_REPLACE && !node.xattrs.hasOwnProperty(name)) { - callback(new ENoAttr('attribute does not exist')); - } - else { - node.xattrs[name] = value; - context.put(node.id, node, callback); - } - } - if (typeof name != 'string') { callback(new EInvalid('attribute name must be a string')); } else if (!name) { callback(new EInvalid('attribute name cannot be an empty string')); } - else if (value == null) { - callback(new EInvalid('value must be defined')); - } else if (flag != null && flag !== XATTR_CREATE && flag !== XATTR_REPLACE) { callback(new EInvalid('invalid flag, must be null, XATTR_CREATE or XATTR_REPLACE')); } else { - find_node (context, path, set_xattr); + set_extended_attribute(context, path, name, value, flag, callback); } } function fsetxattr_file (context, ofd, name, value, flag, callback) { - function set_xattr (error, node) { - var xattr = (node ? node.xattrs[name] : null); - - if (error) { - callback(error); - } - else if (flag === XATTR_CREATE && node.xattrs.hasOwnProperty(name)) { - callback(new EExists('attribute already exists')); - } - else if (flag === XATTR_REPLACE && !node.xattrs.hasOwnProperty(name)) { - callback(new ENoAttr('attribute does not exist')); - } - else { - node.xattrs[name] = value; - context.put(node.id, node, callback); - } - } - if (typeof name != 'string') { callback(new EInvalid('attribute name must be a string')); } else if (!name) { callback(new EInvalid('attribute name cannot be an empty string')); } - else if (value == null) { - callback(new EInvalid('value must be defined')); - } else if (flag != null && flag !== XATTR_CREATE && flag !== XATTR_REPLACE) { callback(new EInvalid('invalid flag, must be null, XATTR_CREATE or XATTR_REPLACE')); } else { - context.get(ofd.id, set_xattr); + set_extended_attribute(context, ofd, name, value, flag, callback); } } diff --git a/tests/spec/fs.xattr.spec.js b/tests/spec/fs.xattr.spec.js index 579a1be..1dfc793 100644 --- a/tests/spec/fs.xattr.spec.js +++ b/tests/spec/fs.xattr.spec.js @@ -15,16 +15,15 @@ define(["IDBFS"], function(IDBFS) { }); it('should be a function', function () { + // that = this; - that = this; + // that.fs.writeFile('/testfile/this/is/a/dir/tmp', function (error) { + // if (error) throw error; - that.fs.writeFile('/testfile/this/is/a/dir/tmp', function (error) { - if (error) throw error; + // that.fs.setxattr('/testfile/this/is/a/dir/tmp', 'test', 'value', function (error) { - that.fs.setxattr('/testfile/this/is/a/dir/tmp', 'test', 'value', function (error) { - - }); - }); + // }); + // }); expect(typeof this.fs.setxattr).toEqual('function'); expect(typeof this.fs.getxattr).toEqual('function'); @@ -78,30 +77,6 @@ define(["IDBFS"], function(IDBFS) { }); }); - it('should error when setting with a null value', function () { - var complete = false; - var _error; - var that = this; - - that.fs.writeFile('/testfile', '', function (error) { - if (error) throw error; - - that.fs.setxattr('/testfile', 'test', null, function (error) { - _error = error; - complete = true; - }); - }); - - waitsFor(function () { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); - - runs(function () { - expect(_error).toBeDefined(); - expect(_error.name).toEqual('EInvalid'); - }); - }); - it('should error when setting with an invalid flag', function () { var complete = false; var _error; @@ -617,5 +592,35 @@ define(["IDBFS"], function(IDBFS) { expect(_error.name).toEqual('ENoAttr'); }); }); + + it('should allow setting with a null value', function () { + var complete = false; + var _error; + var _value; + var that = this; + + that.fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + that.fs.setxattr('/testfile', 'test', null, function (error) { + if (error) throw error; + + that.fs.getxattr('/testfile', 'test', function (error, value) { + _error = error; + _value = value; + complete = true; + }); + }); + }); + + waitsFor(function () { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function () { + expect(_error).toEqual(null); + expect(_value).toEqual(null); + }); + }); }); }); \ No newline at end of file From d31d33651c91fa78f9326c3adbf3c09be34a1ef7 Mon Sep 17 00:00:00 2001 From: Barry Tulchinsky Date: Mon, 13 Jan 2014 20:03:54 -0500 Subject: [PATCH 11/11] removed comments and patched parameter name and potential undefined error --- src/fs.js | 10 +++++----- tests/spec/fs.xattr.spec.js | 13 +++---------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/fs.js b/src/fs.js index 440a3ab..8506327 100644 --- a/src/fs.js +++ b/src/fs.js @@ -227,7 +227,7 @@ define(function(require) { * set extended attribute (refactor) */ - function set_extended_attribute (context, path, name, value, flag, callback) { + function set_extended_attribute (context, path_or_fd, name, value, flag, callback) { function set_xattr (error, node) { var xattr = (node ? node.xattrs[name] : null); @@ -246,11 +246,11 @@ define(function(require) { } } - if (typeof path == 'string') { - find_node(context, path, set_xattr); + if (typeof path_or_fd == 'string') { + find_node(context, path_or_fd, set_xattr); } - else if (typeof path.id == 'string') { - context.get(path.id, set_xattr); + else if (typeof path_or_fd == 'object' && typeof path_or_fd.id == 'string') { + context.get(path_or_fd.id, set_xattr); } else { callback(new EInvalid('path or file descriptor of wrong type')); diff --git a/tests/spec/fs.xattr.spec.js b/tests/spec/fs.xattr.spec.js index 1dfc793..e9e3db3 100644 --- a/tests/spec/fs.xattr.spec.js +++ b/tests/spec/fs.xattr.spec.js @@ -15,18 +15,11 @@ define(["IDBFS"], function(IDBFS) { }); it('should be a function', function () { - // that = this; - - // that.fs.writeFile('/testfile/this/is/a/dir/tmp', function (error) { - // if (error) throw error; - - // that.fs.setxattr('/testfile/this/is/a/dir/tmp', 'test', 'value', function (error) { - - // }); - // }); - expect(typeof this.fs.setxattr).toEqual('function'); expect(typeof this.fs.getxattr).toEqual('function'); + expect(typeof this.fs.removexattr).toEqual('function'); + expect(typeof this.fs.fsetxattr).toEqual('function'); + expect(typeof this.fs.fgetxattr).toEqual('function'); }); it('should error when setting with a name that is not a string', function () {