@ohos-ports/core 1.0.113-beta.0 → 1.16.33-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +13 -0
- package/README.md +3 -0
- package/lib/api/node.js +176 -0
- package/lib/api/team.js +1889 -0
- package/lib/blocklet/downloader/blocklet-downloader.js +246 -0
- package/lib/blocklet/downloader/bundle-downloader.js +316 -0
- package/lib/blocklet/downloader/constants.js +3 -0
- package/lib/blocklet/downloader/resolve-download.js +187 -0
- package/lib/blocklet/extras.js +177 -0
- package/lib/blocklet/hooks.js +89 -0
- package/lib/blocklet/manager/base.js +49 -0
- package/lib/blocklet/manager/config-synchronizer.js +128 -0
- package/lib/blocklet/manager/disk.js +5170 -0
- package/lib/blocklet/manager/engine.js +124 -0
- package/lib/blocklet/manager/helper/install-application-from-backup.js +285 -0
- package/lib/blocklet/manager/helper/install-application-from-dev.js +72 -0
- package/lib/blocklet/manager/helper/install-application-from-general.js +209 -0
- package/lib/blocklet/manager/helper/install-component-from-dev.js +128 -0
- package/lib/blocklet/manager/helper/install-component-from-upload.js +197 -0
- package/lib/blocklet/manager/helper/install-component-from-url.js +214 -0
- package/lib/blocklet/manager/helper/migrate-application-to-struct-v2.js +557 -0
- package/lib/blocklet/manager/helper/rollback-cache.js +41 -0
- package/lib/blocklet/manager/helper/upgrade-components.js +179 -0
- package/lib/blocklet/manager/pm2-events.js +50 -0
- package/lib/blocklet/migration-dist/migration.cjs +38605 -0
- package/lib/blocklet/migration-dist/run-script.cjs +29 -0
- package/lib/blocklet/migration.js +145 -0
- package/lib/blocklet/project/connect-by-studio.js +91 -0
- package/lib/blocklet/project/connect-to-store.js +64 -0
- package/lib/blocklet/project/create-pack-release.js +293 -0
- package/lib/blocklet/project/disconnect-from-store.js +13 -0
- package/lib/blocklet/project/get-is-multiple-tenant.js +8 -0
- package/lib/blocklet/project/index.js +545 -0
- package/lib/blocklet/project/logo.png +0 -0
- package/lib/blocklet/project/publish-to-store.js +108 -0
- package/lib/blocklet/project/util.js +194 -0
- package/lib/blocklet/security/access-policy.js +131 -0
- package/lib/blocklet/security/index.js +309 -0
- package/lib/blocklet/security/response-header-policy.js +178 -0
- package/lib/blocklet/security/security-rule.js +127 -0
- package/lib/blocklet/security/utils.js +35 -0
- package/lib/blocklet/security/validator.js +40 -0
- package/lib/blocklet/storage/backup/base.js +149 -0
- package/lib/blocklet/storage/backup/blocklet-extras.js +110 -0
- package/lib/blocklet/storage/backup/blocklet.js +159 -0
- package/lib/blocklet/storage/backup/blocklets.js +109 -0
- package/lib/blocklet/storage/backup/data.js +35 -0
- package/lib/blocklet/storage/backup/disk.js +131 -0
- package/lib/blocklet/storage/backup/logs.js +24 -0
- package/lib/blocklet/storage/backup/routing-rule.js +47 -0
- package/lib/blocklet/storage/backup/spaces.js +345 -0
- package/lib/blocklet/storage/restore/base.js +74 -0
- package/lib/blocklet/storage/restore/blocklet-extras.js +89 -0
- package/lib/blocklet/storage/restore/blocklet.js +56 -0
- package/lib/blocklet/storage/restore/blocklets.js +43 -0
- package/lib/blocklet/storage/restore/disk.js +104 -0
- package/lib/blocklet/storage/restore/logs.js +21 -0
- package/lib/blocklet/storage/restore/spaces.js +174 -0
- package/lib/blocklet/storage/utils/disk.js +178 -0
- package/lib/blocklet/storage/utils/hash.js +53 -0
- package/lib/blocklet/storage/utils/zip.js +43 -0
- package/lib/cert.js +221 -0
- package/lib/crons/check-new-version.js +68 -0
- package/lib/crons/monitor-disk-usage.js +46 -0
- package/lib/crons/rotate-pm2-logs/index.js +41 -0
- package/lib/crons/rotate-pm2-logs/script.js +56 -0
- package/lib/event/auto-backup-handler.js +48 -0
- package/lib/event/index.js +520 -0
- package/lib/index.js +768 -364
- package/lib/locales/ar.js +18 -0
- package/lib/locales/de.js +21 -0
- package/lib/locales/en.js +19 -0
- package/lib/locales/es.js +21 -0
- package/lib/locales/fr.js +21 -0
- package/lib/locales/hi.js +18 -0
- package/lib/locales/i18n.db +0 -0
- package/lib/locales/id.js +20 -0
- package/lib/locales/index.js +54 -0
- package/lib/locales/ja.js +19 -0
- package/lib/locales/ko.js +18 -0
- package/lib/locales/pt.js +20 -0
- package/lib/locales/ru.js +21 -0
- package/lib/locales/th.js +18 -0
- package/lib/locales/vi.js +18 -0
- package/lib/locales/zh-tw.js +17 -0
- package/lib/locales/zh.js +17 -0
- package/lib/migrations/1.0.21-update-config.js +34 -0
- package/lib/migrations/1.0.22-max-memory.js +40 -0
- package/lib/migrations/1.0.25.js +36 -0
- package/lib/migrations/1.0.32-update-config.js +30 -0
- package/lib/migrations/1.0.33-blocklets.js +33 -0
- package/lib/migrations/1.0.36-snapshot.js +10 -0
- package/lib/migrations/1.1.10-team.js +26 -0
- package/lib/migrations/1.1.9-snapshot.js +7 -0
- package/lib/migrations/1.16.11-component-status.js +22 -0
- package/lib/migrations/1.16.33-blocklet-security-rule.js +17 -0
- package/lib/migrations/1.16.6-chain-info.js +78 -0
- package/lib/migrations/1.16.8-component-title.js +66 -0
- package/lib/migrations/1.2.11-blocklet-registry.js +10 -0
- package/lib/migrations/1.2.2-blocklet-registry.js +10 -0
- package/lib/migrations/1.3.1-disk-alert-threshold.js +10 -0
- package/lib/migrations/1.4.5-access-key.js +18 -0
- package/lib/migrations/1.5.0-site.js +34 -0
- package/lib/migrations/1.5.15-site.js +184 -0
- package/lib/migrations/1.5.20-registry.js +15 -0
- package/lib/migrations/1.6.17-blocklet-children.js +48 -0
- package/lib/migrations/1.6.21-rename-ip-echo-domain.js +35 -0
- package/lib/migrations/1.6.4-security.js +59 -0
- package/lib/migrations/1.6.5-security.js +60 -0
- package/lib/migrations/1.6.9-update-node-info-and-certificate.js +39 -0
- package/lib/migrations/1.7.1-blocklet-setup.js +18 -0
- package/lib/migrations/1.7.12-blocklet-meta.js +51 -0
- package/lib/migrations/1.7.15-blocklet-bundle-source.js +42 -0
- package/lib/migrations/1.7.20-blocklet-component.js +41 -0
- package/lib/migrations/1.8.33-blocklet-mem-limit.js +20 -0
- package/lib/migrations/README.md +71 -0
- package/lib/migrations/index.js +215 -0
- package/lib/monitor/blocklet-runtime-monitor.js +204 -0
- package/lib/monitor/get-history-list.js +37 -0
- package/lib/monitor/node-monit-sender.js +99 -0
- package/lib/monitor/node-runtime-monitor.js +205 -0
- package/lib/processes/updater.js +186 -0
- package/lib/router/helper.js +1653 -0
- package/lib/router/index.js +341 -0
- package/lib/router/manager.js +806 -0
- package/lib/states/README.md +38 -0
- package/lib/states/access-key.js +124 -0
- package/lib/states/access-policy.js +29 -0
- package/lib/states/audit-log.js +734 -0
- package/lib/states/backup.js +165 -0
- package/lib/states/base.js +25 -0
- package/lib/states/blocklet-extras.js +257 -0
- package/lib/states/blocklet.js +755 -0
- package/lib/states/cache.js +23 -0
- package/lib/states/connect-account.js +8 -0
- package/lib/states/index.js +76 -0
- package/lib/states/job.js +8 -0
- package/lib/states/migration.js +34 -0
- package/lib/states/node.js +324 -0
- package/lib/states/notification.js +81 -0
- package/lib/states/passport.js +8 -0
- package/lib/states/project.js +119 -0
- package/lib/states/release.js +50 -0
- package/lib/states/response-header-policy.js +30 -0
- package/lib/states/routing-snapshot.js +146 -0
- package/lib/states/runtime-insight.js +25 -0
- package/lib/states/security-rule.js +30 -0
- package/lib/states/session.js +53 -0
- package/lib/states/site.js +102 -0
- package/lib/states/tag.js +8 -0
- package/lib/states/traffic-insight.js +25 -0
- package/lib/states/user-session.js +8 -0
- package/lib/states/user.js +717 -0
- package/lib/states/verify-code.js +152 -0
- package/lib/states/webhook.js +66 -0
- package/lib/team/manager.js +508 -0
- package/lib/util/blocklet.js +2182 -0
- package/lib/util/cache.js +63 -0
- package/lib/util/chain.js +29 -0
- package/lib/util/default-node-config.js +46 -0
- package/lib/util/docker/blocklet-custom-dockerfile.js +92 -0
- package/lib/util/docker/check-docker-has-image.js +23 -0
- package/lib/util/docker/check-docker-installed.js +32 -0
- package/lib/util/docker/check-docker-run-history.js +18 -0
- package/lib/util/docker/check-need-run-docker.js +32 -0
- package/lib/util/docker/create-docker-image.js +65 -0
- package/lib/util/docker/debian-dockerfile.js +50 -0
- package/lib/util/docker/docker-container-prune.js +75 -0
- package/lib/util/docker/docker-exec-chown.js +39 -0
- package/lib/util/docker/docker-exec.js +68 -0
- package/lib/util/docker/docker-remove-by-name.js +20 -0
- package/lib/util/docker/get-docker-runtime-info.js +39 -0
- package/lib/util/docker/parse-docker-name.js +10 -0
- package/lib/util/docker/parse-docker-options-from-pm2.js +295 -0
- package/lib/util/docker/shard-network.js +10 -0
- package/lib/util/domain-status.js +118 -0
- package/lib/util/get-accessible-external-node-ip.js +92 -0
- package/lib/util/get-dynamic-components.js +47 -0
- package/lib/util/get-meta-from-url.js +30 -0
- package/lib/util/get-migration-scripts.js +36 -0
- package/lib/util/get-safe-env.js +12 -0
- package/lib/util/index.js +522 -0
- package/lib/util/install-external-dependencies.js +67 -0
- package/lib/util/ip.js +53 -0
- package/lib/util/launcher.js +475 -0
- package/lib/util/log.js +431 -0
- package/lib/util/maintain.js +178 -0
- package/lib/util/promise-debounce.js +29 -0
- package/lib/util/promise-once.js +14 -0
- package/lib/util/promise-spawn.js +93 -0
- package/lib/util/queue.js +44 -0
- package/lib/util/ready.js +89 -0
- package/lib/util/request.js +10 -0
- package/lib/util/requirement.js +61 -0
- package/lib/util/reset-node.js +166 -0
- package/lib/util/rotator.js +194 -0
- package/lib/util/router.js +122 -0
- package/lib/util/rpc.js +78 -0
- package/lib/util/spaces.js +102 -0
- package/lib/util/store.js +184 -0
- package/lib/util/sysinfo.js +46 -0
- package/lib/util/ua.js +54 -0
- package/lib/validators/backup.js +34 -0
- package/lib/validators/blocklet-extra.js +18 -0
- package/lib/validators/node.js +73 -0
- package/lib/validators/permission.js +38 -0
- package/lib/validators/project.js +39 -0
- package/lib/validators/role.js +64 -0
- package/lib/validators/router.js +192 -0
- package/lib/validators/space-gateway.js +33 -0
- package/lib/validators/trusted-factory.js +28 -0
- package/lib/validators/trusted-passport.js +32 -0
- package/lib/validators/user.js +62 -0
- package/lib/validators/util.js +92 -0
- package/lib/validators/webhook.js +42 -0
- package/lib/webhook/index.js +216 -0
- package/lib/webhook/reduce-queue.js +12 -0
- package/lib/webhook/sender/api/index.js +67 -0
- package/lib/webhook/sender/base.js +11 -0
- package/lib/webhook/sender/index.js +44 -0
- package/lib/webhook/sender/slack/index.js +167 -0
- package/lib/webhook/sender/wallet/index.js +62 -0
- package/package.json +107 -34
- package/examples/BatchClient.js +0 -61
- package/examples/compressor/example.js +0 -7
- package/examples/jsonrpcserver/rpcmethod.js +0 -21
- package/examples/jsonrpcserver/rpcrequest.js +0 -20
- package/examples/jsonrpcserver/rpctest.js +0 -6
- package/examples/loader-pipes/test-mc.js +0 -52
- package/examples/loader-pipes/test.js +0 -51
- package/examples/mc-test.js +0 -44
- package/examples/redisdebug.js +0 -80
- package/lib/cache/CFMemcache.js +0 -57
- package/lib/cache/CacheLoader.js +0 -217
- package/lib/cache/Memcache.js +0 -406
- package/lib/class/Class.js +0 -54
- package/lib/client/MemcacheAdapter.js +0 -139
- package/lib/client/Memcached.js +0 -142
- package/lib/client/MemcachedSocket.js +0 -570
- package/lib/client/MySQLPool.js +0 -153
- package/lib/client/PGPool.js +0 -296
- package/lib/client/Redis.js +0 -787
- package/lib/client/S3.js +0 -103
- package/lib/client/S3Client.js +0 -392
- package/lib/client/pg/CursorQueryWorker.js +0 -160
- package/lib/client/rabbitmq/RbmqChannel.js +0 -61
- package/lib/client/rabbitmq/RbmqConfig.js +0 -144
- package/lib/client/rabbitmq/RbmqConnection.js +0 -259
- package/lib/client/rabbitmq/RbmqExchange.js +0 -112
- package/lib/client/rabbitmq/RbmqIncomingMessage.js +0 -53
- package/lib/client/rabbitmq/RbmqMessage.js +0 -120
- package/lib/client/rabbitmq/RbmqOutcomingMessage.js +0 -47
- package/lib/client/rabbitmq/RbmqQueue.js +0 -87
- package/lib/client/rabbitmq/index.js +0 -8
- package/lib/common/Assertions.js +0 -184
- package/lib/common/Merge.js +0 -32
- package/lib/common/Net.js +0 -56
- package/lib/common/Process.js +0 -20
- package/lib/common/Random.js +0 -53
- package/lib/common/Sort.js +0 -19
- package/lib/common/Types.js +0 -163
- package/lib/credentials/CredentialsProvider.js +0 -45
- package/lib/credentials/Manager.js +0 -101
- package/lib/crypto/Crypto.js +0 -66
- package/lib/data/BinaryData.js +0 -363
- package/lib/data/Compressor.js +0 -83
- package/lib/data/FormData.js +0 -144
- package/lib/data/Mime.js +0 -45
- package/lib/event/ErrorEvent.js +0 -71
- package/lib/event/Event.js +0 -20
- package/lib/event/EventDispatcher.js +0 -157
- package/lib/http/ConnectionPool.js +0 -82
- package/lib/http/ExpressServer.js +0 -19
- package/lib/http/Headers.js +0 -165
- package/lib/http/Loader.js +0 -584
- package/lib/http/Message.js +0 -189
- package/lib/http/Request.js +0 -848
- package/lib/http/RequestProcessor.js +0 -150
- package/lib/http/Response.js +0 -850
- package/lib/http/Server.js +0 -267
- package/lib/http/Socket.js +0 -157
- package/lib/http/Url.js +0 -2
- package/lib/jsonrpc/JsonRpcAbstract.js +0 -109
- package/lib/jsonrpc/JsonRpcBatchRequest.js +0 -54
- package/lib/jsonrpc/JsonRpcBatchResponse.js +0 -73
- package/lib/jsonrpc/JsonRpcError.js +0 -191
- package/lib/jsonrpc/JsonRpcMethod.js +0 -67
- package/lib/jsonrpc/JsonRpcRequest.js +0 -224
- package/lib/jsonrpc/JsonRpcRequestProcessor.js +0 -366
- package/lib/jsonrpc/JsonRpcResponse.js +0 -175
- package/lib/jsonrpc/JsonRpcServer.js +0 -81
- package/lib/logger/EmptyLogger.js +0 -15
- package/lib/logger/LoggerFactory.js +0 -20
- package/lib/logger/WildFireLogger.js +0 -267
- package/lib/pattern/Pool.js +0 -187
- package/lib/pattern/decorator/AbstractDecorator.js +0 -49
- package/lib/pattern/decorator/DecoratorChain.js +0 -285
- package/lib/util/DeviceDetector.js +0 -153
- package/lib/yaml/YAML.js +0 -46
- package/patterns.conf +0 -6
- package/tests/cache/CacheLoaderSpec.js +0 -7
- package/tests/class/ClassSpec.js +0 -106
- package/tests/client/MemcachedSocketSpec.js +0 -1228
- package/tests/client/MemcachedSpec.js +0 -77
- package/tests/client/MySQLPoolSpec.js +0 -231
- package/tests/client/PGPoolSpec.js +0 -479
- package/tests/client/RedisSpec.js +0 -471
- package/tests/client/S3ClientSpec.js +0 -26
- package/tests/client/S3Spec.js +0 -129
- package/tests/client/rabbitmq/RbmqConnectionSpec.js +0 -71
- package/tests/common/AssertionsSpec.js +0 -278
- package/tests/common/NetSpec.js +0 -6
- package/tests/common/RandomSpec.js +0 -35
- package/tests/common/TypesSpec.js +0 -7
- package/tests/credentials/CredentialsProviderSpec.js +0 -46
- package/tests/crypto/CryptoSpec.js +0 -33
- package/tests/data/BinaryDataSpec.js +0 -50
- package/tests/data/CompressorSpec.js +0 -7
- package/tests/data/FormDataSpec.js +0 -7
- package/tests/data/MimeSpec.js +0 -7
- package/tests/event/ErrorEventSpec.js +0 -20
- package/tests/event/EventDispatcherSpec.js +0 -319
- package/tests/event/EventSpec.js +0 -17
- package/tests/http/ConnectionPoolSpec.js +0 -7
- package/tests/http/HeadersSpec.js +0 -79
- package/tests/http/LoaderSpec.js +0 -43
- package/tests/http/MessageSpec.js +0 -251
- package/tests/http/RequestProcessorSpec.js +0 -124
- package/tests/http/RequestSpec.js +0 -651
- package/tests/http/ResponseSpec.js +0 -491
- package/tests/http/ServerSpec.js +0 -7
- package/tests/http/SocketSpec.js +0 -7
- package/tests/http/UrlSpec.js +0 -14
- package/tests/jsonrpc/JsonRpcAbstractSpec.js +0 -20
- package/tests/jsonrpc/JsonRpcBatchRequestSpec.js +0 -31
- package/tests/jsonrpc/JsonRpcBatchResponseSpec.js +0 -38
- package/tests/jsonrpc/JsonRpcErrorSpec.js +0 -58
- package/tests/jsonrpc/JsonRpcMethodSpec.js +0 -7
- package/tests/jsonrpc/JsonRpcRequestProcessorSpec.js +0 -271
- package/tests/jsonrpc/JsonRpcRequestSpec.js +0 -70
- package/tests/jsonrpc/JsonRpcResponseSpec.js +0 -63
- package/tests/jsonrpc/JsonRpcServerSpec.js +0 -42
- package/tests/pattern/PoolSpec.js +0 -180
- package/tests/pattern/decorator/AbstractDecoratorSpec.js +0 -7
- package/tests/pattern/decorator/DecoratorChainSpec.js +0 -7
- package/tests/yaml/YAMLSpec.js +0 -132
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var Event = require('../event/Event.js').Event;
|
|
3
|
-
var EventDispatcher = require('../event/EventDispatcher.js').EventDispatcher;
|
|
4
|
-
/**
|
|
5
|
-
* CredentialProvider
|
|
6
|
-
* @class CredentialProvider credentials access object
|
|
7
|
-
* @requires Event
|
|
8
|
-
* @requires EventDispatcher
|
|
9
|
-
*/
|
|
10
|
-
var CredentialsProvider = function () {
|
|
11
|
-
EventDispatcher.call(this);
|
|
12
|
-
this._currentCredentials = null;
|
|
13
|
-
if (arguments.length == 1) {
|
|
14
|
-
this._currentCredentials = arguments[0];
|
|
15
|
-
} else if (arguments.length > 0) {
|
|
16
|
-
this._currentCredentials = arguments;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
CredentialsProvider.prototype = Object.create(EventDispatcher.prototype);
|
|
21
|
-
|
|
22
|
-
CredentialsProvider.prototype.get = function (callback) {
|
|
23
|
-
if (this._currentCredentials) {
|
|
24
|
-
callback(null, this._currentCredentials);
|
|
25
|
-
} else {
|
|
26
|
-
callback(CredentialsProvider.Error.ACCESS_ERROR, null);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
CredentialsProvider.prototype.refresh = function () {
|
|
30
|
-
//abstract
|
|
31
|
-
};
|
|
32
|
-
CredentialsProvider.prototype.destroy = function () {
|
|
33
|
-
//abstract
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
CredentialsProvider.Event = {};
|
|
37
|
-
|
|
38
|
-
CredentialsProvider.Event.LOAD = "Credetials_loaded";
|
|
39
|
-
CredentialsProvider.Event.ERROR = "Credetials_load_error";
|
|
40
|
-
CredentialsProvider.Event.TIMEOUT = "Credetials_load_timeout";
|
|
41
|
-
|
|
42
|
-
CredentialsProvider.Error = {};
|
|
43
|
-
CredentialsProvider.Error.ACCESS_ERROR = "Unable to access credentials";
|
|
44
|
-
|
|
45
|
-
exports.CredentialsProvider = CredentialsProvider;
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
var Assertions = require('../common/Assertions.js').Assertions;
|
|
2
|
-
var Types = require('../common/Types.js').Types;
|
|
3
|
-
|
|
4
|
-
var EventDispatcher = require('../event/EventDispatcher.js').EventDispatcher;
|
|
5
|
-
var Event = require('../event/Event.js').Event;
|
|
6
|
-
var ErrorEvent = require('../event/ErrorEvent.js').ErrorEvent;
|
|
7
|
-
|
|
8
|
-
var Loader = require('../http/Loader.js').Loader;
|
|
9
|
-
|
|
10
|
-
var SingletonEnforcer = function(){};
|
|
11
|
-
|
|
12
|
-
var CredentialsManager = function (enforcer, appName) {
|
|
13
|
-
EventDispatcher.call(this);
|
|
14
|
-
|
|
15
|
-
this._credentials = {};
|
|
16
|
-
this._jobs = {};
|
|
17
|
-
Assertions.isInstanceOf(enforcer, SingletonEnforcer, CredentialsManager.Exception.SINGLETON);
|
|
18
|
-
this._applicationName = appName;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
CredentialsManager.prototype = Object.create(EventDispatcher.prototype);
|
|
22
|
-
|
|
23
|
-
CredentialsManager.prototype.addEventListener = function (eventName, key, callback, context) {
|
|
24
|
-
return EventDispatcher.prototype.addEventListener.call(this, eventName + key, callback, context);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
CredentialsManager.prototype.removeEventListener = function (eventName, key, callback) {
|
|
28
|
-
return EventDispatcher.prototype.removeEventListener.call(this, eventName + key, callback);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
CredentialsManager.prototype.getCredential = function (key) {
|
|
32
|
-
if (this._credentials.hasOwnProperty(key)) {
|
|
33
|
-
this.dispatchEvent(new Event(CredentialsManager.Event.LOADED + key, this._credentials[key]));
|
|
34
|
-
} else {
|
|
35
|
-
this.renewCredential(key);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
CredentialsManager.prototype.renewCredential = function (key) {
|
|
40
|
-
var self = this;
|
|
41
|
-
|
|
42
|
-
if (this._jobs.hasOwnProperty(key)) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
this._jobs[key] = true;
|
|
47
|
-
var OpalRequest = require('dl').opal.OpalRequest;
|
|
48
|
-
var OpalLoader = require('dl').opal.OpalLoader;
|
|
49
|
-
|
|
50
|
-
(new OpalLoader(new OpalRequest({
|
|
51
|
-
"url": "router.opaladmin.onetapi.pl",
|
|
52
|
-
"method": "get_credentials",
|
|
53
|
-
"params": {
|
|
54
|
-
"ds_alias": key
|
|
55
|
-
},
|
|
56
|
-
"application": this._applicationName
|
|
57
|
-
}))).addEventListener(OpalLoader.Event.JSON_RESPONSE, function(data){
|
|
58
|
-
var rpc = data.data.getBody();
|
|
59
|
-
|
|
60
|
-
if (rpc.isError()) {
|
|
61
|
-
delete self._jobs[key];
|
|
62
|
-
self.dispatchEvent(new ErrorEvent(CredentialsManager.Event.ERROR + key, rpc.getError()));
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
self._credentials[key] = rpc.getResult();
|
|
67
|
-
delete self._jobs[key];
|
|
68
|
-
self.dispatchEvent(new Event(CredentialsManager.Event.LOADED + key, self._credentials[key]));
|
|
69
|
-
}).addEventListener(Loader.Event.ERROR, function(data){
|
|
70
|
-
delete self._jobs[key];
|
|
71
|
-
self.dispatchEvent(new ErrorEvent(CredentialsManager.Event.ERROR + key, data));
|
|
72
|
-
}).load();
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
var factoryInstances = {};
|
|
76
|
-
|
|
77
|
-
CredentialsManager.factory = function (appName) {
|
|
78
|
-
if (!Types.isString(appName)) {
|
|
79
|
-
if (process.env['OPAL_IDENTITY']) {
|
|
80
|
-
appName = process.env['OPAL_IDENTITY'];
|
|
81
|
-
} else {
|
|
82
|
-
appName = "edgeserver.edgeserver.onetapi.pl";
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (factoryInstances.hasOwnProperty(appName)) {
|
|
87
|
-
return factoryInstances[appName];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
factoryInstances[appName] = new CredentialsManager(new SingletonEnforcer(), appName);
|
|
91
|
-
return factoryInstances[appName];
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
CredentialsManager.Event = {};
|
|
95
|
-
CredentialsManager.Event.LOADED = 'CredentialsManager_LOADED_';
|
|
96
|
-
CredentialsManager.Event.ERROR = 'CredentialsManager_ERROR_';
|
|
97
|
-
|
|
98
|
-
CredentialsManager.Exception = {};
|
|
99
|
-
CredentialsManager.Exception.SINGLETON = "Singleton class, use factory() instead.";
|
|
100
|
-
|
|
101
|
-
exports.CredentialsManager = CredentialsManager;
|
package/lib/crypto/Crypto.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @overview Crypto
|
|
3
|
-
* @copyright Dreamlab Onet.pl sp. z. o o 2012
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
var crypto = require('crypto');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @class Crypto
|
|
10
|
-
*/
|
|
11
|
-
var Crypto = {};
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Create md5 digest
|
|
15
|
-
* @static
|
|
16
|
-
* @param {String|Buffer} data
|
|
17
|
-
* @param {String} [encoding='binary'] Digest format. Can be 'hex', 'binary' or 'base64'
|
|
18
|
-
* @returns {String}
|
|
19
|
-
*/
|
|
20
|
-
Crypto.md5 = function (data, encoding) {
|
|
21
|
-
encoding = encoding || 'hex';
|
|
22
|
-
var hash = crypto.createHash('md5');
|
|
23
|
-
hash.update(data);
|
|
24
|
-
return hash.digest(encoding);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Create sha1 digest
|
|
29
|
-
* @static
|
|
30
|
-
* @param {String|Buffer} data
|
|
31
|
-
* @param {String} [encoding='binary'] Digest format. Can be 'hex', 'binary' or 'base64'
|
|
32
|
-
* @returns {String}
|
|
33
|
-
*/
|
|
34
|
-
Crypto.sha1 = function (data, encoding) {
|
|
35
|
-
encoding = encoding || 'hex';
|
|
36
|
-
var hash = crypto.createHash('sha1');
|
|
37
|
-
hash.update(data);
|
|
38
|
-
return hash.digest(encoding);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
Crypto.sha256 = function (data, format) {
|
|
42
|
-
format = format || 'hex';
|
|
43
|
-
var hash = crypto.createHash('sha256');
|
|
44
|
-
hash.update(data);
|
|
45
|
-
return hash.digest(format);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
Crypto.convertHexToBase64 = function (hex) {
|
|
49
|
-
var bytesArr = [];
|
|
50
|
-
for (var i = 0, len = hex.length - 1; i < len; i = i + 2) {
|
|
51
|
-
var str = hex[i] + hex[i + 1];
|
|
52
|
-
bytesArr.push(parseInt(str, 16));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return new Buffer(bytesArr).toString('base64');
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
Crypto.unescapeBase64 = function (str) {
|
|
59
|
-
return Buffer(str.replace(/-/g, '+').replace(/_/g, '/'), 'base64').toString();
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
Crypto.escapeBase64 = function (str) {
|
|
63
|
-
return Buffer(str, 'UTF-8').toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
exports.Crypto = Crypto;
|
package/lib/data/BinaryData.js
DELETED
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @overview BinaryData
|
|
3
|
-
* @copyright Dreamlab Onet.pl sp. z. o o 2012
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
var Types = require("../common/Types.js");
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Pure-JS replacement for the native iconv.Iconv addon, built on Node
|
|
10
|
-
* built-ins (TextDecoder / Buffer). Implements only the API subset used by
|
|
11
|
-
* core: `new Iconv(from, to).convert(buffer)`.
|
|
12
|
-
* It is used when the native `iconv` binding cannot be loaded (e.g. on
|
|
13
|
-
* HarmonyOS, where the 2012 pre-NAN addon has no bindings).
|
|
14
|
-
* @private
|
|
15
|
-
* @class IconvShim
|
|
16
|
-
*/
|
|
17
|
-
var IconvShim = function (fromEncoding, toEncoding) {
|
|
18
|
-
this._from = String(fromEncoding).replace(/\s*\/\/.*$/, "");
|
|
19
|
-
this._to = String(toEncoding).replace(/\s*\/\/.*$/, "");
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Cache of reverse byte maps (charCode -> byte) for single-byte encodings.
|
|
24
|
-
* @private
|
|
25
|
-
* @static
|
|
26
|
-
*/
|
|
27
|
-
IconvShim._byteMaps = {};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Builds (and caches) a reverse byte map for a single-byte target encoding
|
|
31
|
-
* by decoding bytes 0x00-0xFF with TextDecoder.
|
|
32
|
-
* @private
|
|
33
|
-
* @static
|
|
34
|
-
* @returns {Object} charCode to byte mapping
|
|
35
|
-
*/
|
|
36
|
-
IconvShim._buildByteMap = function (encoding) {
|
|
37
|
-
if (!IconvShim._byteMaps.hasOwnProperty(encoding)) {
|
|
38
|
-
var bytes = new Uint8Array(256);
|
|
39
|
-
var i;
|
|
40
|
-
for (i = 0; i < 256; i++) {
|
|
41
|
-
bytes[i] = i;
|
|
42
|
-
}
|
|
43
|
-
var decoded = new TextDecoder(encoding).decode(bytes);
|
|
44
|
-
var map = {};
|
|
45
|
-
for (i = 0; i < 256; i++) {
|
|
46
|
-
var code = decoded.charCodeAt(i);
|
|
47
|
-
if (!(code in map)) {
|
|
48
|
-
map[code] = i;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
IconvShim._byteMaps[encoding] = map;
|
|
52
|
-
}
|
|
53
|
-
return IconvShim._byteMaps[encoding];
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Converts a Buffer from one character encoding to another.
|
|
58
|
-
* @param {Buffer} buffer
|
|
59
|
-
* @method
|
|
60
|
-
* @returns {Buffer}
|
|
61
|
-
*/
|
|
62
|
-
IconvShim.prototype.convert = function (buffer) {
|
|
63
|
-
var source = new TextDecoder(this._from).decode(buffer);
|
|
64
|
-
var target = this._to.toLowerCase();
|
|
65
|
-
var i, code, out;
|
|
66
|
-
|
|
67
|
-
if (target === "utf-8" || target === "utf8" || target === "us-ascii" || target === "ascii") {
|
|
68
|
-
return Buffer.from(source, "utf8");
|
|
69
|
-
}
|
|
70
|
-
if (target === "latin1" || target === "iso-8859-1" || target === "l1" || target === "cp28591") {
|
|
71
|
-
return Buffer.from(source, "latin1");
|
|
72
|
-
}
|
|
73
|
-
if (target === "utf-16le" || target === "ucs-2" || target === "utf-16" || target === "utf-16be" || target === "unicode") {
|
|
74
|
-
out = Buffer.from(source, "utf16le");
|
|
75
|
-
if (target !== "utf-16le" && target !== "ucs-2") {
|
|
76
|
-
// iconv's UTF-16 / UCS-2 default byte order is big-endian
|
|
77
|
-
for (i = 0; i < out.length; i += 2) {
|
|
78
|
-
var b = out[i];
|
|
79
|
-
out[i] = out[i + 1];
|
|
80
|
-
out[i + 1] = b;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return out;
|
|
84
|
-
}
|
|
85
|
-
if (target === "utf-32" || target === "utf-32be" || target === "ucs-4" || target === "utf-32le") {
|
|
86
|
-
var littleEndian = (target === "utf-32le");
|
|
87
|
-
out = Buffer.alloc(source.length * 4);
|
|
88
|
-
var offset = 0;
|
|
89
|
-
for (var char in source) {
|
|
90
|
-
code = source.charCodeAt(char);
|
|
91
|
-
if (littleEndian) {
|
|
92
|
-
out.writeUInt32LE(code, offset);
|
|
93
|
-
} else {
|
|
94
|
-
out.writeUInt32BE(code, offset);
|
|
95
|
-
}
|
|
96
|
-
offset += 4;
|
|
97
|
-
}
|
|
98
|
-
return out.slice(0, offset);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// any other single-byte target encoding: reverse byte map
|
|
102
|
-
var map = IconvShim._buildByteMap(this._to);
|
|
103
|
-
out = Buffer.alloc(source.length);
|
|
104
|
-
for (i = 0; i < source.length; i++) {
|
|
105
|
-
code = source.charCodeAt(i);
|
|
106
|
-
if (!(code in map)) {
|
|
107
|
-
throw new Error("Iconv: character U+" + code.toString(16) +
|
|
108
|
-
" could not be converted to " + this._to);
|
|
109
|
-
}
|
|
110
|
-
out[i] = map[code];
|
|
111
|
-
}
|
|
112
|
-
return out;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Lazily resolves the Iconv constructor. Tries the native `iconv` addon
|
|
117
|
-
* first and falls back to the pure-JS IconvShim when it cannot be loaded.
|
|
118
|
-
* @private
|
|
119
|
-
* @returns {Function} Iconv constructor
|
|
120
|
-
*/
|
|
121
|
-
var loadIconv = function () {
|
|
122
|
-
if (loadIconv._ctor === undefined) {
|
|
123
|
-
var NativeIconv = null;
|
|
124
|
-
try {
|
|
125
|
-
NativeIconv = require('iconv').Iconv;
|
|
126
|
-
} catch (ex) {
|
|
127
|
-
NativeIconv = null;
|
|
128
|
-
}
|
|
129
|
-
loadIconv._ctor = NativeIconv || IconvShim;
|
|
130
|
-
}
|
|
131
|
-
return loadIconv._ctor;
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Data
|
|
136
|
-
* @private
|
|
137
|
-
* @class Data Private helper class.
|
|
138
|
-
*/
|
|
139
|
-
var Data = function (data, encoding, characterEncoding) {
|
|
140
|
-
this.encoding = encoding;
|
|
141
|
-
this.characterEncoding = characterEncoding;
|
|
142
|
-
this.data = data;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Converts data to encoding and characterEncoding
|
|
147
|
-
*
|
|
148
|
-
* @method
|
|
149
|
-
* @returns {}
|
|
150
|
-
*/
|
|
151
|
-
Data.prototype.convertTo = function (encoding, characterEncoding) {
|
|
152
|
-
if (this.encoding != encoding || this.characterEncoding != characterEncoding) {
|
|
153
|
-
//jesli aktualnie mamy base64 musimy to odczynic na chwile
|
|
154
|
-
if (this.encoding == BinaryData.Encoding.BASE64) {
|
|
155
|
-
this.data = new Buffer(this.data, 'base64');
|
|
156
|
-
this.encoding = BinaryData.Encoding.BINARY;
|
|
157
|
-
}
|
|
158
|
-
//jesli zmieniamy kodowanie znaków
|
|
159
|
-
if (characterEncoding && this.characterEncoding != characterEncoding) {
|
|
160
|
-
this.data = (new (loadIconv())(this.characterEncoding, characterEncoding)).convert(this.data);
|
|
161
|
-
this.characterEncoding = characterEncoding;
|
|
162
|
-
this.encoding = BinaryData.Encoding.BINARY;
|
|
163
|
-
}
|
|
164
|
-
//ustalamy ostateczny encoding
|
|
165
|
-
if (this.encoding != encoding) {
|
|
166
|
-
//jesli ma byc base64
|
|
167
|
-
if (encoding == BinaryData.Encoding.BASE64) {
|
|
168
|
-
this.data = this.data.toString('base64');
|
|
169
|
-
this.encoding = BinaryData.Encoding.BASE64;
|
|
170
|
-
}
|
|
171
|
-
//jesli powinien byc TEXT
|
|
172
|
-
else if (encoding == BinaryData.Encoding.TEXT) {
|
|
173
|
-
//tylko jesli kodowanie jest UTF8
|
|
174
|
-
if (this.characterEncoding == BinaryData.CharacterEncoding.UTF8) {
|
|
175
|
-
this.encoding = BinaryData.Encoding.TEXT;
|
|
176
|
-
//this.data = this.data.toString();
|
|
177
|
-
}
|
|
178
|
-
//jesli nie jest to mamy problem
|
|
179
|
-
else {
|
|
180
|
-
throw BinaryData.Exception.CONVERTION_ERROR;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* BinaryData
|
|
190
|
-
* @class BinaryData
|
|
191
|
-
* @classdoc represents and holds binary data type. Allows to convert to and form diferent representations such as Base64 String or Buffer, also can conver String character encoding.
|
|
192
|
-
* @requires Types
|
|
193
|
-
* @requires iconv
|
|
194
|
-
* @requires base64
|
|
195
|
-
* @param {String|Buffer} data
|
|
196
|
-
* @param {String} encoding Determine what kind of output encoding will be expected, after calling toString, toBuffer methods
|
|
197
|
-
* @param {String} characterEncoding Determine what kind of output character encoding will be expected, after calling toString, toBuffer methods
|
|
198
|
-
*/
|
|
199
|
-
var BinaryData = function (data, encoding, characterEncoding) {
|
|
200
|
-
this._encoding = encoding;
|
|
201
|
-
this._characterEncoding = characterEncoding;
|
|
202
|
-
this._data = null;
|
|
203
|
-
this.setData(data, encoding, characterEncoding);
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Allows to set data in deferent representation (encoding and character encoding)
|
|
208
|
-
* @public
|
|
209
|
-
* @param {String|Buffer} data
|
|
210
|
-
* @param {String} encoding {@see BinaryData.Encoding} current data encoding
|
|
211
|
-
* @param {String} characterEncoding {@see BinaryData.CharacterEncoding} current data character encoding
|
|
212
|
-
*/
|
|
213
|
-
BinaryData.prototype.setData = function (data, encoding, characterEncoding) {
|
|
214
|
-
this._data = new Data(data, encoding, characterEncoding);
|
|
215
|
-
};
|
|
216
|
-
/**
|
|
217
|
-
* Returns current data byte length
|
|
218
|
-
* @public
|
|
219
|
-
* @returns {Number} byte length
|
|
220
|
-
*/
|
|
221
|
-
BinaryData.prototype.length = function () {
|
|
222
|
-
if (this._data) {
|
|
223
|
-
//Potential problem maker if given buffer will have more space than content
|
|
224
|
-
return this.toBuffer().length;
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
/**
|
|
228
|
-
* Returns expected character encoding
|
|
229
|
-
* @public
|
|
230
|
-
* @returns {String} {@see BinaryData.CharacterEncoding}
|
|
231
|
-
*/
|
|
232
|
-
BinaryData.prototype.getCharacterEncoding = function () {
|
|
233
|
-
return this._characterEncoding;
|
|
234
|
-
};
|
|
235
|
-
/**
|
|
236
|
-
* Returns expected encoding
|
|
237
|
-
* @public
|
|
238
|
-
* @returns {String} {@see BinaryData.Encoding}
|
|
239
|
-
*/
|
|
240
|
-
BinaryData.prototype.getEncoding = function () {
|
|
241
|
-
return this._encoding;
|
|
242
|
-
};
|
|
243
|
-
/**
|
|
244
|
-
* Returns data convertet to UTF8 string
|
|
245
|
-
* @public
|
|
246
|
-
* @returns {String} UTF8 string
|
|
247
|
-
*/
|
|
248
|
-
BinaryData.prototype.toUTF8String = function () {
|
|
249
|
-
//TODO make not permanent convertion
|
|
250
|
-
this._data.convertTo(BinaryData.Encoding.TEXT, BinaryData.CharacterEncoding.UTF8);
|
|
251
|
-
return this._data.data.toString();
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Retuns data convertet to safe string representation. If current data is Buffer which cannot be easly transformed to UTF8 representations, then data will be converted to Base64 representation. It works similar with deferent character encodings if desired encoding is ISO then returned string will be UTF8 Base64 converted string witch after decoding will be binary representation of ISO string.
|
|
255
|
-
* @returns {String}
|
|
256
|
-
*/
|
|
257
|
-
BinaryData.prototype.toString = function () {
|
|
258
|
-
var encoding = BinaryData.Encoding.TEXT;
|
|
259
|
-
if (this.getEncoding() != BinaryData.Encoding.TEXT) {
|
|
260
|
-
encoding = BinaryData.Encoding.BASE64;
|
|
261
|
-
}
|
|
262
|
-
this._data.convertTo(encoding, this.getCharacterEncoding())
|
|
263
|
-
return this._data.data.toString();
|
|
264
|
-
};
|
|
265
|
-
/**
|
|
266
|
-
* Returns data in Buffor representation. Character encoding will be converted if desired character encoding is deferent than seted data character encoding.
|
|
267
|
-
* @returns {Buffer}
|
|
268
|
-
*/
|
|
269
|
-
BinaryData.prototype.toBuffer = function () {
|
|
270
|
-
this._data.convertTo(this.getEncoding(), this.getCharacterEncoding());
|
|
271
|
-
if (Buffer.isBuffer(this._data.data)) {
|
|
272
|
-
return this._data.data;
|
|
273
|
-
} else {
|
|
274
|
-
return new Buffer(this._data.data, this.getEncoding());
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Namespace for exeptions messages.
|
|
281
|
-
* @static
|
|
282
|
-
* @constant
|
|
283
|
-
* @namespace
|
|
284
|
-
*/
|
|
285
|
-
BinaryData.Exception = {};
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* @constant
|
|
289
|
-
* @static
|
|
290
|
-
* @type {String}
|
|
291
|
-
* @default
|
|
292
|
-
*/
|
|
293
|
-
BinaryData.Exception.CONVERTION_ERROR = "CONVERTION_ERROR";
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Namespace for encoding types.
|
|
298
|
-
* @static
|
|
299
|
-
* @constant
|
|
300
|
-
* @namespace
|
|
301
|
-
*/
|
|
302
|
-
BinaryData.Encoding = {};
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* @constant
|
|
306
|
-
* @static
|
|
307
|
-
* @type {String}
|
|
308
|
-
* @default
|
|
309
|
-
*/
|
|
310
|
-
BinaryData.Encoding.BINARY = "binary";
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* @constant
|
|
314
|
-
* @static
|
|
315
|
-
* @type {String}
|
|
316
|
-
* @default
|
|
317
|
-
*/
|
|
318
|
-
BinaryData.Encoding.BASE64 = "base64";
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* @constant
|
|
322
|
-
* @static
|
|
323
|
-
* @type {String}
|
|
324
|
-
* @default
|
|
325
|
-
*/
|
|
326
|
-
BinaryData.Encoding.TEXT = "utf8";
|
|
327
|
-
// BinaryData.Encoding.ASCII = "ascii";
|
|
328
|
-
// BinaryData.Encoding.UCS2 = "ucs2";
|
|
329
|
-
// BinaryData.Encoding.HEX = "hex";
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* Namespace for character encoding types.
|
|
333
|
-
* @static
|
|
334
|
-
* @constant
|
|
335
|
-
* @namespace
|
|
336
|
-
*/
|
|
337
|
-
BinaryData.CharacterEncoding = {};
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* @constant
|
|
341
|
-
* @static
|
|
342
|
-
* @type {String}
|
|
343
|
-
* @default
|
|
344
|
-
*/
|
|
345
|
-
BinaryData.CharacterEncoding.UTF8 = "UTF-8";
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* @constant
|
|
349
|
-
* @static
|
|
350
|
-
* @type {String}
|
|
351
|
-
* @default
|
|
352
|
-
*/
|
|
353
|
-
BinaryData.CharacterEncoding.ISO_8859_1 = "ISO-8859-1";
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* @constant
|
|
357
|
-
* @static
|
|
358
|
-
* @type {String}
|
|
359
|
-
* @default
|
|
360
|
-
*/
|
|
361
|
-
BinaryData.CharacterEncoding.ISO_8859_2 = "ISO-8859-2";
|
|
362
|
-
|
|
363
|
-
exports.BinaryData = BinaryData;
|
package/lib/data/Compressor.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @overview Compressor
|
|
3
|
-
* @copyright Dreamlab Onet.pl sp. z. o o 2012
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
var Types = require("../common/Types.js");
|
|
7
|
-
var zlib = require('zlib');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Compressor
|
|
11
|
-
* @class Compressor
|
|
12
|
-
* @classdesc Compressor
|
|
13
|
-
*
|
|
14
|
-
* @requires Types
|
|
15
|
-
* @requires compress-buffer
|
|
16
|
-
*
|
|
17
|
-
* @param {Object} configuration
|
|
18
|
-
* @return {Compressor}
|
|
19
|
-
*/
|
|
20
|
-
var Compressor = function(configuration){
|
|
21
|
-
this._configuration = configuration;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Compress data
|
|
26
|
-
* @param {Buffer} data
|
|
27
|
-
* @param {Function} callback
|
|
28
|
-
* @param {Number} compressLevel
|
|
29
|
-
*
|
|
30
|
-
* @method
|
|
31
|
-
* @return {undefined}
|
|
32
|
-
*/
|
|
33
|
-
Compressor.prototype.compress = function(data, callback, compressLevel){
|
|
34
|
-
compressLevel = compressLevel || 6;
|
|
35
|
-
// compress-buffer level semantics: invalid level (<= 0 or > 9) falls back to default compression
|
|
36
|
-
var level = (compressLevel >= 1 && compressLevel <= 9) ? compressLevel : zlib.constants.Z_DEFAULT_COMPRESSION;
|
|
37
|
-
// compress-buffer wraps zlib compress2() which emits the standard zlib format,
|
|
38
|
-
// byte-compatible with Node's built-in zlib.deflateSync()
|
|
39
|
-
var compressedData = zlib.deflateSync(data, { level: level });
|
|
40
|
-
callback(
|
|
41
|
-
compressedData,
|
|
42
|
-
this._getCompressionRate(data.length, compressedData.length)
|
|
43
|
-
);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Uncompress data
|
|
48
|
-
* @param {Buffer} data
|
|
49
|
-
* @param {Function} callback
|
|
50
|
-
*
|
|
51
|
-
* @method
|
|
52
|
-
* @return {undefined}
|
|
53
|
-
*/
|
|
54
|
-
Compressor.prototype.uncompress = function(data, callback){
|
|
55
|
-
// compress-buffer wraps zlib uncompress() which consumes the standard zlib
|
|
56
|
-
// format, byte-compatible with Node's built-in zlib.inflateSync()
|
|
57
|
-
var compressedData = zlib.inflateSync(data);
|
|
58
|
-
callback(
|
|
59
|
-
compressedData,
|
|
60
|
-
this._getCompressionRate(data.length, compressedData.length)
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Uncompress data
|
|
66
|
-
* @param {Number} unCompressedLength
|
|
67
|
-
* @param {Number} compressedLength
|
|
68
|
-
*
|
|
69
|
-
* @method
|
|
70
|
-
* @return {Object} in format: {times:Number, percentage:Number, compressedLength:Number, unCompressedLength:Number}
|
|
71
|
-
* @private
|
|
72
|
-
*/
|
|
73
|
-
Compressor.prototype._getCompressionRate = function(unCompressedLength, compressedLength){
|
|
74
|
-
return {
|
|
75
|
-
times: Math.round(unCompressedLength/compressedLength),
|
|
76
|
-
percentage: Math.round((100-(100*(compressedLength/unCompressedLength)))),
|
|
77
|
-
compressedLength: compressedLength,
|
|
78
|
-
unCompressedLength: unCompressedLength
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
exports.Compressor = Compressor;
|