@powersync/web 1.31.0 → 1.32.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/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapp-89f0ba.index.umd.js +1867 -0
- package/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapp-89f0ba.index.umd.js.map +1 -0
- package/dist/_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapps_wa-sqlite_src_example-2530150.index.umd.js +555 -0
- package/dist/_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapps_wa-sqlite_src_example-2530150.index.umd.js.map +1 -0
- package/dist/_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapps_wa-sqlite_src_example-2530151.index.umd.js +555 -0
- package/dist/_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapps_wa-sqlite_src_example-2530151.index.umd.js.map +1 -0
- package/dist/index.umd.js +4575 -43416
- package/dist/index.umd.js.map +1 -1
- package/dist/worker/SharedSyncImplementation.umd.js +402 -2053
- package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
- package/dist/worker/WASQLiteDB.umd.js +449 -2104
- package/dist/worker/WASQLiteDB.umd.js.map +1 -1
- package/dist/worker/{node_modules_bson_lib_bson_mjs.umd.js → node_modules_pnpm_bson_6_10_4_node_modules_bson_lib_bson_mjs.umd.js} +6 -6
- package/dist/worker/node_modules_pnpm_bson_6_10_4_node_modules_bson_lib_bson_mjs.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-3a94cf.umd.js +44 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-3a94cf.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-868779.umd.js +44 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-868779.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-f60d0d.umd.js +44 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-f60d0d.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js +44 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js.map +1 -0
- package/dist/worker/{node_modules_journeyapps_wa-sqlite_src_examples_IDBBatchAtomicVFS_js.umd.js → node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_src_examples-0d2437.umd.js} +24 -24
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_src_examples-0d2437.umd.js.map +1 -0
- package/dist/worker/{node_modules_journeyapps_wa-sqlite_src_examples_OPFSCoopSyncVFS_js.umd.js → node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_src_examples-1d4e74.umd.js} +18 -18
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_src_examples-1d4e74.umd.js.map +1 -0
- package/dist/worker/{node_modules_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js.umd.js → node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_src_examples-3622cf.umd.js} +18 -18
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_src_examples-3622cf.umd.js.map +1 -0
- package/lib/package.json +26 -22
- package/lib/src/db/NavigatorTriggerClaimManager.d.ts +6 -0
- package/lib/src/db/NavigatorTriggerClaimManager.js +20 -0
- package/lib/src/db/PowerSyncDatabase.d.ts +5 -2
- package/lib/src/db/PowerSyncDatabase.js +46 -8
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.d.ts +1 -1
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js +1 -1
- package/lib/src/db/adapters/AbstractWebSQLOpenFactory.d.ts +2 -2
- package/lib/src/db/adapters/AbstractWebSQLOpenFactory.js +2 -2
- package/lib/src/db/adapters/AsyncDatabaseConnection.d.ts +1 -1
- package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.d.ts +4 -4
- package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.js +8 -4
- package/lib/src/db/adapters/WebDBAdapter.d.ts +5 -2
- package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.d.ts +2 -2
- package/lib/src/db/adapters/wa-sqlite/InternalWASQLiteDBAdapter.d.ts +12 -0
- package/lib/src/db/adapters/wa-sqlite/InternalWASQLiteDBAdapter.js +19 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLiteConnection.d.ts +2 -2
- package/lib/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.d.ts +4 -4
- package/lib/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.js +6 -6
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +4 -4
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +7 -7
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.d.ts +1 -1
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js +3 -3
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.d.ts +5 -5
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js +5 -5
- package/lib/src/db/sync/WebRemote.js +1 -1
- package/lib/src/db/sync/WebStreamingSyncImplementation.d.ts +1 -1
- package/lib/src/db/sync/WebStreamingSyncImplementation.js +1 -1
- package/lib/src/index.d.ts +12 -12
- package/lib/src/index.js +12 -12
- package/lib/src/worker/db/SharedWASQLiteConnection.d.ts +2 -2
- package/lib/src/worker/db/WASQLiteDB.worker.js +3 -3
- package/lib/src/worker/db/WorkerWASQLiteConnection.d.ts +2 -2
- package/lib/src/worker/db/WorkerWASQLiteConnection.js +1 -1
- package/lib/src/worker/db/open-worker-database.d.ts +2 -2
- package/lib/src/worker/db/open-worker-database.js +1 -1
- package/lib/src/worker/sync/BroadcastLogger.d.ts +1 -1
- package/lib/src/worker/sync/SharedSyncImplementation.d.ts +4 -4
- package/lib/src/worker/sync/SharedSyncImplementation.js +5 -5
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js +2 -2
- package/lib/src/worker/sync/WorkerClient.d.ts +1 -1
- package/lib/src/worker/sync/WorkerClient.js +2 -2
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -17
- package/src/db/NavigatorTriggerClaimManager.ts +23 -0
- package/src/db/PowerSyncDatabase.ts +53 -9
- package/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.ts +1 -1
- package/src/db/adapters/AbstractWebSQLOpenFactory.ts +3 -3
- package/src/db/adapters/AsyncDatabaseConnection.ts +1 -1
- package/src/db/adapters/LockedAsyncDatabaseAdapter.ts +13 -9
- package/src/db/adapters/WebDBAdapter.ts +6 -2
- package/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.ts +2 -2
- package/src/db/adapters/wa-sqlite/InternalWASQLiteDBAdapter.ts +23 -0
- package/src/db/adapters/wa-sqlite/WASQLiteConnection.ts +2 -2
- package/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.ts +8 -8
- package/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.ts +8 -8
- package/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.ts +3 -3
- package/src/db/sync/SharedWebStreamingSyncImplementation.ts +7 -7
- package/src/db/sync/WebRemote.ts +1 -1
- package/src/db/sync/WebStreamingSyncImplementation.ts +2 -2
- package/src/index.ts +12 -12
- package/src/worker/db/SharedWASQLiteConnection.ts +2 -2
- package/src/worker/db/WASQLiteDB.worker.ts +5 -5
- package/src/worker/db/WorkerWASQLiteConnection.ts +2 -2
- package/src/worker/db/open-worker-database.ts +2 -2
- package/src/worker/sync/BroadcastLogger.ts +1 -1
- package/src/worker/sync/SharedSyncImplementation.ts +9 -9
- package/src/worker/sync/SharedSyncImplementation.worker.ts +2 -2
- package/src/worker/sync/WorkerClient.ts +2 -2
- package/dist/worker/node_modules_bson_lib_bson_mjs.umd.js.map +0 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite-async_mjs.umd.js +0 -44
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite-async_mjs.umd.js.map +0 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite_mjs.umd.js +0 -44
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite_mjs.umd.js.map +0 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite-async_mjs.umd.js +0 -44
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite-async_mjs.umd.js.map +0 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js +0 -44
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js.map +0 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js.umd.js.map +0 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_IDBBatchAtomicVFS_js.umd.js.map +0 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_OPFSCoopSyncVFS_js.umd.js.map +0 -1
- /package/bin/{powersync.js → powersync.cjs} +0 -0
|
@@ -3,10 +3,10 @@ var sdk_web;
|
|
|
3
3
|
/******/ "use strict";
|
|
4
4
|
/******/ var __webpack_modules__ = ({
|
|
5
5
|
|
|
6
|
-
/***/ "../../node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js"
|
|
7
|
-
|
|
8
|
-
!*** ../../node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js ***!
|
|
9
|
-
|
|
6
|
+
/***/ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.4.1/node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js"
|
|
7
|
+
/*!*******************************************************************************************************************!*\
|
|
8
|
+
!*** ../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.4.1/node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js ***!
|
|
9
|
+
\*******************************************************************************************************************/
|
|
10
10
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
11
11
|
|
|
12
12
|
__webpack_require__.r(__webpack_exports__);
|
|
@@ -246,7 +246,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
246
246
|
/* harmony export */ SQLITE_WARNING: () => (/* reexport safe */ _sqlite_constants_js__WEBPACK_IMPORTED_MODULE_0__.SQLITE_WARNING),
|
|
247
247
|
/* harmony export */ SQLiteError: () => (/* binding */ SQLiteError)
|
|
248
248
|
/* harmony export */ });
|
|
249
|
-
/* harmony import */ var _sqlite_constants_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./sqlite-constants.js */ "../../node_modules/@journeyapps/wa-sqlite/src/sqlite-constants.js");
|
|
249
|
+
/* harmony import */ var _sqlite_constants_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./sqlite-constants.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.4.1/node_modules/@journeyapps/wa-sqlite/src/sqlite-constants.js");
|
|
250
250
|
// Copyright 2021 Roy T. Hashimoto. All Rights Reserved.
|
|
251
251
|
|
|
252
252
|
|
|
@@ -1198,10 +1198,10 @@ function decl(s) {
|
|
|
1198
1198
|
|
|
1199
1199
|
/***/ },
|
|
1200
1200
|
|
|
1201
|
-
/***/ "../../node_modules/@journeyapps/wa-sqlite/src/sqlite-constants.js"
|
|
1202
|
-
|
|
1203
|
-
!*** ../../node_modules/@journeyapps/wa-sqlite/src/sqlite-constants.js ***!
|
|
1204
|
-
|
|
1201
|
+
/***/ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.4.1/node_modules/@journeyapps/wa-sqlite/src/sqlite-constants.js"
|
|
1202
|
+
/*!*************************************************************************************************************************!*\
|
|
1203
|
+
!*** ../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.4.1/node_modules/@journeyapps/wa-sqlite/src/sqlite-constants.js ***!
|
|
1204
|
+
\*************************************************************************************************************************/
|
|
1205
1205
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
1206
1206
|
|
|
1207
1207
|
__webpack_require__.r(__webpack_exports__);
|
|
@@ -1717,10 +1717,10 @@ const SQLITE_PREPARE_NO_VTAB = 0x04;
|
|
|
1717
1717
|
|
|
1718
1718
|
/***/ },
|
|
1719
1719
|
|
|
1720
|
-
/***/ "../../node_modules/async-mutex/index.mjs"
|
|
1721
|
-
|
|
1722
|
-
!*** ../../node_modules/async-mutex/index.mjs ***!
|
|
1723
|
-
|
|
1720
|
+
/***/ "../../node_modules/.pnpm/async-mutex@0.5.0/node_modules/async-mutex/index.mjs"
|
|
1721
|
+
/*!*************************************************************************************!*\
|
|
1722
|
+
!*** ../../node_modules/.pnpm/async-mutex@0.5.0/node_modules/async-mutex/index.mjs ***!
|
|
1723
|
+
\*************************************************************************************/
|
|
1724
1724
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
1725
1725
|
|
|
1726
1726
|
__webpack_require__.r(__webpack_exports__);
|
|
@@ -2028,10 +2028,10 @@ function tryAcquire(sync, alreadyAcquiredError = E_ALREADY_LOCKED) {
|
|
|
2028
2028
|
|
|
2029
2029
|
/***/ },
|
|
2030
2030
|
|
|
2031
|
-
/***/ "../../node_modules/comlink/dist/esm/comlink.mjs"
|
|
2032
|
-
|
|
2033
|
-
!*** ../../node_modules/comlink/dist/esm/comlink.mjs ***!
|
|
2034
|
-
|
|
2031
|
+
/***/ "../../node_modules/.pnpm/comlink@4.4.2/node_modules/comlink/dist/esm/comlink.mjs"
|
|
2032
|
+
/*!****************************************************************************************!*\
|
|
2033
|
+
!*** ../../node_modules/.pnpm/comlink@4.4.2/node_modules/comlink/dist/esm/comlink.mjs ***!
|
|
2034
|
+
\****************************************************************************************/
|
|
2035
2035
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
2036
2036
|
|
|
2037
2037
|
__webpack_require__.r(__webpack_exports__);
|
|
@@ -2466,12 +2466,14 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2466
2466
|
/* harmony export */ LogLevel: () => (/* binding */ LogLevel),
|
|
2467
2467
|
/* harmony export */ MAX_AMOUNT_OF_COLUMNS: () => (/* binding */ MAX_AMOUNT_OF_COLUMNS),
|
|
2468
2468
|
/* harmony export */ MAX_OP_ID: () => (/* binding */ MAX_OP_ID),
|
|
2469
|
+
/* harmony export */ MEMORY_TRIGGER_CLAIM_MANAGER: () => (/* binding */ MEMORY_TRIGGER_CLAIM_MANAGER),
|
|
2469
2470
|
/* harmony export */ OnChangeQueryProcessor: () => (/* binding */ OnChangeQueryProcessor),
|
|
2470
2471
|
/* harmony export */ OpType: () => (/* binding */ OpType),
|
|
2471
2472
|
/* harmony export */ OpTypeEnum: () => (/* binding */ OpTypeEnum),
|
|
2472
2473
|
/* harmony export */ OplogEntry: () => (/* binding */ OplogEntry),
|
|
2473
2474
|
/* harmony export */ PSInternalTable: () => (/* binding */ PSInternalTable),
|
|
2474
2475
|
/* harmony export */ PowerSyncControlCommand: () => (/* binding */ PowerSyncControlCommand),
|
|
2476
|
+
/* harmony export */ RawTable: () => (/* binding */ RawTable),
|
|
2475
2477
|
/* harmony export */ RowUpdateType: () => (/* binding */ RowUpdateType),
|
|
2476
2478
|
/* harmony export */ Schema: () => (/* binding */ Schema),
|
|
2477
2479
|
/* harmony export */ SqliteBucketStorage: () => (/* binding */ SqliteBucketStorage),
|
|
@@ -2483,6 +2485,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2483
2485
|
/* harmony export */ SyncStreamConnectionMethod: () => (/* binding */ SyncStreamConnectionMethod),
|
|
2484
2486
|
/* harmony export */ Table: () => (/* binding */ Table),
|
|
2485
2487
|
/* harmony export */ TableV2: () => (/* binding */ TableV2),
|
|
2488
|
+
/* harmony export */ TriggerManagerImpl: () => (/* binding */ TriggerManagerImpl),
|
|
2486
2489
|
/* harmony export */ UpdateType: () => (/* binding */ UpdateType),
|
|
2487
2490
|
/* harmony export */ UploadQueueStats: () => (/* binding */ UploadQueueStats),
|
|
2488
2491
|
/* harmony export */ WatchedQueryListenerEvent: () => (/* binding */ WatchedQueryListenerEvent),
|
|
@@ -2509,7 +2512,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2509
2512
|
/* harmony export */ sanitizeSQL: () => (/* binding */ sanitizeSQL),
|
|
2510
2513
|
/* harmony export */ sanitizeUUID: () => (/* binding */ sanitizeUUID)
|
|
2511
2514
|
/* harmony export */ });
|
|
2512
|
-
/* harmony import */ var async_mutex__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! async-mutex */ "../../node_modules/async-mutex/index.mjs");
|
|
2515
|
+
/* harmony import */ var async_mutex__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! async-mutex */ "../../node_modules/.pnpm/async-mutex@0.5.0/node_modules/async-mutex/index.mjs");
|
|
2513
2516
|
|
|
2514
2517
|
|
|
2515
2518
|
function getDefaultExportFromCjs (x) {
|
|
@@ -4599,7 +4602,7 @@ class SyncDataBucket {
|
|
|
4599
4602
|
}
|
|
4600
4603
|
}
|
|
4601
4604
|
|
|
4602
|
-
var buffer
|
|
4605
|
+
var buffer = {};
|
|
4603
4606
|
|
|
4604
4607
|
var base64Js = {};
|
|
4605
4608
|
|
|
@@ -4863,11 +4866,11 @@ function requireIeee754 () {
|
|
|
4863
4866
|
* @license MIT
|
|
4864
4867
|
*/
|
|
4865
4868
|
|
|
4866
|
-
var hasRequiredBuffer
|
|
4869
|
+
var hasRequiredBuffer;
|
|
4867
4870
|
|
|
4868
|
-
function requireBuffer
|
|
4869
|
-
if (hasRequiredBuffer
|
|
4870
|
-
hasRequiredBuffer
|
|
4871
|
+
function requireBuffer () {
|
|
4872
|
+
if (hasRequiredBuffer) return buffer;
|
|
4873
|
+
hasRequiredBuffer = 1;
|
|
4871
4874
|
(function (exports$1) {
|
|
4872
4875
|
|
|
4873
4876
|
const base64 = requireBase64Js();
|
|
@@ -6645,1982 +6648,10 @@ function requireBuffer$1 () {
|
|
|
6645
6648
|
this[i] = val;
|
|
6646
6649
|
}
|
|
6647
6650
|
} else {
|
|
6648
|
-
const bytes = Buffer.isBuffer(val)
|
|
6649
|
-
? val
|
|
6650
|
-
: Buffer.from(val, encoding);
|
|
6651
|
-
const len = bytes.length;
|
|
6652
|
-
if (len === 0) {
|
|
6653
|
-
throw new TypeError('The value "' + val +
|
|
6654
|
-
'" is invalid for argument "value"')
|
|
6655
|
-
}
|
|
6656
|
-
for (i = 0; i < end - start; ++i) {
|
|
6657
|
-
this[i + start] = bytes[i % len];
|
|
6658
|
-
}
|
|
6659
|
-
}
|
|
6660
|
-
|
|
6661
|
-
return this
|
|
6662
|
-
};
|
|
6663
|
-
|
|
6664
|
-
// CUSTOM ERRORS
|
|
6665
|
-
// =============
|
|
6666
|
-
|
|
6667
|
-
// Simplified versions from Node, changed for Buffer-only usage
|
|
6668
|
-
const errors = {};
|
|
6669
|
-
function E (sym, getMessage, Base) {
|
|
6670
|
-
errors[sym] = class NodeError extends Base {
|
|
6671
|
-
constructor () {
|
|
6672
|
-
super();
|
|
6673
|
-
|
|
6674
|
-
Object.defineProperty(this, 'message', {
|
|
6675
|
-
value: getMessage.apply(this, arguments),
|
|
6676
|
-
writable: true,
|
|
6677
|
-
configurable: true
|
|
6678
|
-
});
|
|
6679
|
-
|
|
6680
|
-
// Add the error code to the name to include it in the stack trace.
|
|
6681
|
-
this.name = `${this.name} [${sym}]`;
|
|
6682
|
-
// Access the stack to generate the error message including the error code
|
|
6683
|
-
// from the name.
|
|
6684
|
-
this.stack; // eslint-disable-line no-unused-expressions
|
|
6685
|
-
// Reset the name to the actual name.
|
|
6686
|
-
delete this.name;
|
|
6687
|
-
}
|
|
6688
|
-
|
|
6689
|
-
get code () {
|
|
6690
|
-
return sym
|
|
6691
|
-
}
|
|
6692
|
-
|
|
6693
|
-
set code (value) {
|
|
6694
|
-
Object.defineProperty(this, 'code', {
|
|
6695
|
-
configurable: true,
|
|
6696
|
-
enumerable: true,
|
|
6697
|
-
value,
|
|
6698
|
-
writable: true
|
|
6699
|
-
});
|
|
6700
|
-
}
|
|
6701
|
-
|
|
6702
|
-
toString () {
|
|
6703
|
-
return `${this.name} [${sym}]: ${this.message}`
|
|
6704
|
-
}
|
|
6705
|
-
};
|
|
6706
|
-
}
|
|
6707
|
-
|
|
6708
|
-
E('ERR_BUFFER_OUT_OF_BOUNDS',
|
|
6709
|
-
function (name) {
|
|
6710
|
-
if (name) {
|
|
6711
|
-
return `${name} is outside of buffer bounds`
|
|
6712
|
-
}
|
|
6713
|
-
|
|
6714
|
-
return 'Attempt to access memory outside buffer bounds'
|
|
6715
|
-
}, RangeError);
|
|
6716
|
-
E('ERR_INVALID_ARG_TYPE',
|
|
6717
|
-
function (name, actual) {
|
|
6718
|
-
return `The "${name}" argument must be of type number. Received type ${typeof actual}`
|
|
6719
|
-
}, TypeError);
|
|
6720
|
-
E('ERR_OUT_OF_RANGE',
|
|
6721
|
-
function (str, range, input) {
|
|
6722
|
-
let msg = `The value of "${str}" is out of range.`;
|
|
6723
|
-
let received = input;
|
|
6724
|
-
if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
|
|
6725
|
-
received = addNumericalSeparator(String(input));
|
|
6726
|
-
} else if (typeof input === 'bigint') {
|
|
6727
|
-
received = String(input);
|
|
6728
|
-
if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
|
|
6729
|
-
received = addNumericalSeparator(received);
|
|
6730
|
-
}
|
|
6731
|
-
received += 'n';
|
|
6732
|
-
}
|
|
6733
|
-
msg += ` It must be ${range}. Received ${received}`;
|
|
6734
|
-
return msg
|
|
6735
|
-
}, RangeError);
|
|
6736
|
-
|
|
6737
|
-
function addNumericalSeparator (val) {
|
|
6738
|
-
let res = '';
|
|
6739
|
-
let i = val.length;
|
|
6740
|
-
const start = val[0] === '-' ? 1 : 0;
|
|
6741
|
-
for (; i >= start + 4; i -= 3) {
|
|
6742
|
-
res = `_${val.slice(i - 3, i)}${res}`;
|
|
6743
|
-
}
|
|
6744
|
-
return `${val.slice(0, i)}${res}`
|
|
6745
|
-
}
|
|
6746
|
-
|
|
6747
|
-
// CHECK FUNCTIONS
|
|
6748
|
-
// ===============
|
|
6749
|
-
|
|
6750
|
-
function checkBounds (buf, offset, byteLength) {
|
|
6751
|
-
validateNumber(offset, 'offset');
|
|
6752
|
-
if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
|
|
6753
|
-
boundsError(offset, buf.length - (byteLength + 1));
|
|
6754
|
-
}
|
|
6755
|
-
}
|
|
6756
|
-
|
|
6757
|
-
function checkIntBI (value, min, max, buf, offset, byteLength) {
|
|
6758
|
-
if (value > max || value < min) {
|
|
6759
|
-
const n = typeof min === 'bigint' ? 'n' : '';
|
|
6760
|
-
let range;
|
|
6761
|
-
{
|
|
6762
|
-
if (min === 0 || min === BigInt(0)) {
|
|
6763
|
-
range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;
|
|
6764
|
-
} else {
|
|
6765
|
-
range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
|
|
6766
|
-
`${(byteLength + 1) * 8 - 1}${n}`;
|
|
6767
|
-
}
|
|
6768
|
-
}
|
|
6769
|
-
throw new errors.ERR_OUT_OF_RANGE('value', range, value)
|
|
6770
|
-
}
|
|
6771
|
-
checkBounds(buf, offset, byteLength);
|
|
6772
|
-
}
|
|
6773
|
-
|
|
6774
|
-
function validateNumber (value, name) {
|
|
6775
|
-
if (typeof value !== 'number') {
|
|
6776
|
-
throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
|
|
6777
|
-
}
|
|
6778
|
-
}
|
|
6779
|
-
|
|
6780
|
-
function boundsError (value, length, type) {
|
|
6781
|
-
if (Math.floor(value) !== value) {
|
|
6782
|
-
validateNumber(value, type);
|
|
6783
|
-
throw new errors.ERR_OUT_OF_RANGE('offset', 'an integer', value)
|
|
6784
|
-
}
|
|
6785
|
-
|
|
6786
|
-
if (length < 0) {
|
|
6787
|
-
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
|
|
6788
|
-
}
|
|
6789
|
-
|
|
6790
|
-
throw new errors.ERR_OUT_OF_RANGE('offset',
|
|
6791
|
-
`>= ${0} and <= ${length}`,
|
|
6792
|
-
value)
|
|
6793
|
-
}
|
|
6794
|
-
|
|
6795
|
-
// HELPER FUNCTIONS
|
|
6796
|
-
// ================
|
|
6797
|
-
|
|
6798
|
-
const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
|
6799
|
-
|
|
6800
|
-
function base64clean (str) {
|
|
6801
|
-
// Node takes equal signs as end of the Base64 encoding
|
|
6802
|
-
str = str.split('=')[0];
|
|
6803
|
-
// Node strips out invalid characters like \n and \t from the string, base64-js does not
|
|
6804
|
-
str = str.trim().replace(INVALID_BASE64_RE, '');
|
|
6805
|
-
// Node converts strings with length < 2 to ''
|
|
6806
|
-
if (str.length < 2) return ''
|
|
6807
|
-
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
|
|
6808
|
-
while (str.length % 4 !== 0) {
|
|
6809
|
-
str = str + '=';
|
|
6810
|
-
}
|
|
6811
|
-
return str
|
|
6812
|
-
}
|
|
6813
|
-
|
|
6814
|
-
function utf8ToBytes (string, units) {
|
|
6815
|
-
units = units || Infinity;
|
|
6816
|
-
let codePoint;
|
|
6817
|
-
const length = string.length;
|
|
6818
|
-
let leadSurrogate = null;
|
|
6819
|
-
const bytes = [];
|
|
6820
|
-
|
|
6821
|
-
for (let i = 0; i < length; ++i) {
|
|
6822
|
-
codePoint = string.charCodeAt(i);
|
|
6823
|
-
|
|
6824
|
-
// is surrogate component
|
|
6825
|
-
if (codePoint > 0xD7FF && codePoint < 0xE000) {
|
|
6826
|
-
// last char was a lead
|
|
6827
|
-
if (!leadSurrogate) {
|
|
6828
|
-
// no lead yet
|
|
6829
|
-
if (codePoint > 0xDBFF) {
|
|
6830
|
-
// unexpected trail
|
|
6831
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
6832
|
-
continue
|
|
6833
|
-
} else if (i + 1 === length) {
|
|
6834
|
-
// unpaired lead
|
|
6835
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
6836
|
-
continue
|
|
6837
|
-
}
|
|
6838
|
-
|
|
6839
|
-
// valid lead
|
|
6840
|
-
leadSurrogate = codePoint;
|
|
6841
|
-
|
|
6842
|
-
continue
|
|
6843
|
-
}
|
|
6844
|
-
|
|
6845
|
-
// 2 leads in a row
|
|
6846
|
-
if (codePoint < 0xDC00) {
|
|
6847
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
6848
|
-
leadSurrogate = codePoint;
|
|
6849
|
-
continue
|
|
6850
|
-
}
|
|
6851
|
-
|
|
6852
|
-
// valid surrogate pair
|
|
6853
|
-
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
|
|
6854
|
-
} else if (leadSurrogate) {
|
|
6855
|
-
// valid bmp char, but last char was a lead
|
|
6856
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
6857
|
-
}
|
|
6858
|
-
|
|
6859
|
-
leadSurrogate = null;
|
|
6860
|
-
|
|
6861
|
-
// encode utf8
|
|
6862
|
-
if (codePoint < 0x80) {
|
|
6863
|
-
if ((units -= 1) < 0) break
|
|
6864
|
-
bytes.push(codePoint);
|
|
6865
|
-
} else if (codePoint < 0x800) {
|
|
6866
|
-
if ((units -= 2) < 0) break
|
|
6867
|
-
bytes.push(
|
|
6868
|
-
codePoint >> 0x6 | 0xC0,
|
|
6869
|
-
codePoint & 0x3F | 0x80
|
|
6870
|
-
);
|
|
6871
|
-
} else if (codePoint < 0x10000) {
|
|
6872
|
-
if ((units -= 3) < 0) break
|
|
6873
|
-
bytes.push(
|
|
6874
|
-
codePoint >> 0xC | 0xE0,
|
|
6875
|
-
codePoint >> 0x6 & 0x3F | 0x80,
|
|
6876
|
-
codePoint & 0x3F | 0x80
|
|
6877
|
-
);
|
|
6878
|
-
} else if (codePoint < 0x110000) {
|
|
6879
|
-
if ((units -= 4) < 0) break
|
|
6880
|
-
bytes.push(
|
|
6881
|
-
codePoint >> 0x12 | 0xF0,
|
|
6882
|
-
codePoint >> 0xC & 0x3F | 0x80,
|
|
6883
|
-
codePoint >> 0x6 & 0x3F | 0x80,
|
|
6884
|
-
codePoint & 0x3F | 0x80
|
|
6885
|
-
);
|
|
6886
|
-
} else {
|
|
6887
|
-
throw new Error('Invalid code point')
|
|
6888
|
-
}
|
|
6889
|
-
}
|
|
6890
|
-
|
|
6891
|
-
return bytes
|
|
6892
|
-
}
|
|
6893
|
-
|
|
6894
|
-
function asciiToBytes (str) {
|
|
6895
|
-
const byteArray = [];
|
|
6896
|
-
for (let i = 0; i < str.length; ++i) {
|
|
6897
|
-
// Node's code seems to be doing this and not & 0x7F..
|
|
6898
|
-
byteArray.push(str.charCodeAt(i) & 0xFF);
|
|
6899
|
-
}
|
|
6900
|
-
return byteArray
|
|
6901
|
-
}
|
|
6902
|
-
|
|
6903
|
-
function utf16leToBytes (str, units) {
|
|
6904
|
-
let c, hi, lo;
|
|
6905
|
-
const byteArray = [];
|
|
6906
|
-
for (let i = 0; i < str.length; ++i) {
|
|
6907
|
-
if ((units -= 2) < 0) break
|
|
6908
|
-
|
|
6909
|
-
c = str.charCodeAt(i);
|
|
6910
|
-
hi = c >> 8;
|
|
6911
|
-
lo = c % 256;
|
|
6912
|
-
byteArray.push(lo);
|
|
6913
|
-
byteArray.push(hi);
|
|
6914
|
-
}
|
|
6915
|
-
|
|
6916
|
-
return byteArray
|
|
6917
|
-
}
|
|
6918
|
-
|
|
6919
|
-
function base64ToBytes (str) {
|
|
6920
|
-
return base64.toByteArray(base64clean(str))
|
|
6921
|
-
}
|
|
6922
|
-
|
|
6923
|
-
function blitBuffer (src, dst, offset, length) {
|
|
6924
|
-
let i;
|
|
6925
|
-
for (i = 0; i < length; ++i) {
|
|
6926
|
-
if ((i + offset >= dst.length) || (i >= src.length)) break
|
|
6927
|
-
dst[i + offset] = src[i];
|
|
6928
|
-
}
|
|
6929
|
-
return i
|
|
6930
|
-
}
|
|
6931
|
-
|
|
6932
|
-
// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
|
|
6933
|
-
// the `instanceof` check but they should be treated as of that type.
|
|
6934
|
-
// See: https://github.com/feross/buffer/issues/166
|
|
6935
|
-
function isInstance (obj, type) {
|
|
6936
|
-
return obj instanceof type ||
|
|
6937
|
-
(obj != null && obj.constructor != null && obj.constructor.name != null &&
|
|
6938
|
-
obj.constructor.name === type.name)
|
|
6939
|
-
}
|
|
6940
|
-
function numberIsNaN (obj) {
|
|
6941
|
-
// For IE11 support
|
|
6942
|
-
return obj !== obj // eslint-disable-line no-self-compare
|
|
6943
|
-
}
|
|
6944
|
-
|
|
6945
|
-
// Create lookup table for `toString('hex')`
|
|
6946
|
-
// See: https://github.com/feross/buffer/issues/219
|
|
6947
|
-
const hexSliceLookupTable = (function () {
|
|
6948
|
-
const alphabet = '0123456789abcdef';
|
|
6949
|
-
const table = new Array(256);
|
|
6950
|
-
for (let i = 0; i < 16; ++i) {
|
|
6951
|
-
const i16 = i * 16;
|
|
6952
|
-
for (let j = 0; j < 16; ++j) {
|
|
6953
|
-
table[i16 + j] = alphabet[i] + alphabet[j];
|
|
6954
|
-
}
|
|
6955
|
-
}
|
|
6956
|
-
return table
|
|
6957
|
-
})();
|
|
6958
|
-
|
|
6959
|
-
// Return not function with Error if BigInt not supported
|
|
6960
|
-
function defineBigIntMethod (fn) {
|
|
6961
|
-
return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
|
|
6962
|
-
}
|
|
6963
|
-
|
|
6964
|
-
function BufferBigIntNotDefined () {
|
|
6965
|
-
throw new Error('BigInt not supported')
|
|
6966
|
-
}
|
|
6967
|
-
} (buffer$1));
|
|
6968
|
-
return buffer$1;
|
|
6969
|
-
}
|
|
6970
|
-
|
|
6971
|
-
var bufferExports$1 = requireBuffer$1();
|
|
6972
|
-
|
|
6973
|
-
var dist = {};
|
|
6974
|
-
|
|
6975
|
-
var buffer = {};
|
|
6976
|
-
|
|
6977
|
-
/*!
|
|
6978
|
-
* The buffer module from node.js, for the browser.
|
|
6979
|
-
*
|
|
6980
|
-
* @author Feross Aboukhadijeh <https://feross.org>
|
|
6981
|
-
* @license MIT
|
|
6982
|
-
*/
|
|
6983
|
-
|
|
6984
|
-
var hasRequiredBuffer;
|
|
6985
|
-
|
|
6986
|
-
function requireBuffer () {
|
|
6987
|
-
if (hasRequiredBuffer) return buffer;
|
|
6988
|
-
hasRequiredBuffer = 1;
|
|
6989
|
-
(function (exports$1) {
|
|
6990
|
-
|
|
6991
|
-
var base64 = requireBase64Js();
|
|
6992
|
-
var ieee754 = requireIeee754();
|
|
6993
|
-
var customInspectSymbol =
|
|
6994
|
-
(typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
|
|
6995
|
-
? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
|
|
6996
|
-
: null;
|
|
6997
|
-
|
|
6998
|
-
exports$1.Buffer = Buffer;
|
|
6999
|
-
exports$1.SlowBuffer = SlowBuffer;
|
|
7000
|
-
exports$1.INSPECT_MAX_BYTES = 50;
|
|
7001
|
-
|
|
7002
|
-
var K_MAX_LENGTH = 0x7fffffff;
|
|
7003
|
-
exports$1.kMaxLength = K_MAX_LENGTH;
|
|
7004
|
-
|
|
7005
|
-
/**
|
|
7006
|
-
* If `Buffer.TYPED_ARRAY_SUPPORT`:
|
|
7007
|
-
* === true Use Uint8Array implementation (fastest)
|
|
7008
|
-
* === false Print warning and recommend using `buffer` v4.x which has an Object
|
|
7009
|
-
* implementation (most compatible, even IE6)
|
|
7010
|
-
*
|
|
7011
|
-
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
|
|
7012
|
-
* Opera 11.6+, iOS 4.2+.
|
|
7013
|
-
*
|
|
7014
|
-
* We report that the browser does not support typed arrays if the are not subclassable
|
|
7015
|
-
* using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
|
|
7016
|
-
* (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
|
|
7017
|
-
* for __proto__ and has a buggy typed array implementation.
|
|
7018
|
-
*/
|
|
7019
|
-
Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
|
|
7020
|
-
|
|
7021
|
-
if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
|
|
7022
|
-
typeof console.error === 'function') {
|
|
7023
|
-
console.error(
|
|
7024
|
-
'This browser lacks typed array (Uint8Array) support which is required by ' +
|
|
7025
|
-
'`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
|
|
7026
|
-
);
|
|
7027
|
-
}
|
|
7028
|
-
|
|
7029
|
-
function typedArraySupport () {
|
|
7030
|
-
// Can typed array instances can be augmented?
|
|
7031
|
-
try {
|
|
7032
|
-
var arr = new Uint8Array(1);
|
|
7033
|
-
var proto = { foo: function () { return 42 } };
|
|
7034
|
-
Object.setPrototypeOf(proto, Uint8Array.prototype);
|
|
7035
|
-
Object.setPrototypeOf(arr, proto);
|
|
7036
|
-
return arr.foo() === 42
|
|
7037
|
-
} catch (e) {
|
|
7038
|
-
return false
|
|
7039
|
-
}
|
|
7040
|
-
}
|
|
7041
|
-
|
|
7042
|
-
Object.defineProperty(Buffer.prototype, 'parent', {
|
|
7043
|
-
enumerable: true,
|
|
7044
|
-
get: function () {
|
|
7045
|
-
if (!Buffer.isBuffer(this)) return undefined
|
|
7046
|
-
return this.buffer
|
|
7047
|
-
}
|
|
7048
|
-
});
|
|
7049
|
-
|
|
7050
|
-
Object.defineProperty(Buffer.prototype, 'offset', {
|
|
7051
|
-
enumerable: true,
|
|
7052
|
-
get: function () {
|
|
7053
|
-
if (!Buffer.isBuffer(this)) return undefined
|
|
7054
|
-
return this.byteOffset
|
|
7055
|
-
}
|
|
7056
|
-
});
|
|
7057
|
-
|
|
7058
|
-
function createBuffer (length) {
|
|
7059
|
-
if (length > K_MAX_LENGTH) {
|
|
7060
|
-
throw new RangeError('The value "' + length + '" is invalid for option "size"')
|
|
7061
|
-
}
|
|
7062
|
-
// Return an augmented `Uint8Array` instance
|
|
7063
|
-
var buf = new Uint8Array(length);
|
|
7064
|
-
Object.setPrototypeOf(buf, Buffer.prototype);
|
|
7065
|
-
return buf
|
|
7066
|
-
}
|
|
7067
|
-
|
|
7068
|
-
/**
|
|
7069
|
-
* The Buffer constructor returns instances of `Uint8Array` that have their
|
|
7070
|
-
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
|
|
7071
|
-
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
|
|
7072
|
-
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
|
|
7073
|
-
* returns a single octet.
|
|
7074
|
-
*
|
|
7075
|
-
* The `Uint8Array` prototype remains unmodified.
|
|
7076
|
-
*/
|
|
7077
|
-
|
|
7078
|
-
function Buffer (arg, encodingOrOffset, length) {
|
|
7079
|
-
// Common case.
|
|
7080
|
-
if (typeof arg === 'number') {
|
|
7081
|
-
if (typeof encodingOrOffset === 'string') {
|
|
7082
|
-
throw new TypeError(
|
|
7083
|
-
'The "string" argument must be of type string. Received type number'
|
|
7084
|
-
)
|
|
7085
|
-
}
|
|
7086
|
-
return allocUnsafe(arg)
|
|
7087
|
-
}
|
|
7088
|
-
return from(arg, encodingOrOffset, length)
|
|
7089
|
-
}
|
|
7090
|
-
|
|
7091
|
-
Buffer.poolSize = 8192; // not used by this implementation
|
|
7092
|
-
|
|
7093
|
-
function from (value, encodingOrOffset, length) {
|
|
7094
|
-
if (typeof value === 'string') {
|
|
7095
|
-
return fromString(value, encodingOrOffset)
|
|
7096
|
-
}
|
|
7097
|
-
|
|
7098
|
-
if (ArrayBuffer.isView(value)) {
|
|
7099
|
-
return fromArrayView(value)
|
|
7100
|
-
}
|
|
7101
|
-
|
|
7102
|
-
if (value == null) {
|
|
7103
|
-
throw new TypeError(
|
|
7104
|
-
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
|
7105
|
-
'or Array-like Object. Received type ' + (typeof value)
|
|
7106
|
-
)
|
|
7107
|
-
}
|
|
7108
|
-
|
|
7109
|
-
if (isInstance(value, ArrayBuffer) ||
|
|
7110
|
-
(value && isInstance(value.buffer, ArrayBuffer))) {
|
|
7111
|
-
return fromArrayBuffer(value, encodingOrOffset, length)
|
|
7112
|
-
}
|
|
7113
|
-
|
|
7114
|
-
if (typeof SharedArrayBuffer !== 'undefined' &&
|
|
7115
|
-
(isInstance(value, SharedArrayBuffer) ||
|
|
7116
|
-
(value && isInstance(value.buffer, SharedArrayBuffer)))) {
|
|
7117
|
-
return fromArrayBuffer(value, encodingOrOffset, length)
|
|
7118
|
-
}
|
|
7119
|
-
|
|
7120
|
-
if (typeof value === 'number') {
|
|
7121
|
-
throw new TypeError(
|
|
7122
|
-
'The "value" argument must not be of type number. Received type number'
|
|
7123
|
-
)
|
|
7124
|
-
}
|
|
7125
|
-
|
|
7126
|
-
var valueOf = value.valueOf && value.valueOf();
|
|
7127
|
-
if (valueOf != null && valueOf !== value) {
|
|
7128
|
-
return Buffer.from(valueOf, encodingOrOffset, length)
|
|
7129
|
-
}
|
|
7130
|
-
|
|
7131
|
-
var b = fromObject(value);
|
|
7132
|
-
if (b) return b
|
|
7133
|
-
|
|
7134
|
-
if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
|
|
7135
|
-
typeof value[Symbol.toPrimitive] === 'function') {
|
|
7136
|
-
return Buffer.from(
|
|
7137
|
-
value[Symbol.toPrimitive]('string'), encodingOrOffset, length
|
|
7138
|
-
)
|
|
7139
|
-
}
|
|
7140
|
-
|
|
7141
|
-
throw new TypeError(
|
|
7142
|
-
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
|
7143
|
-
'or Array-like Object. Received type ' + (typeof value)
|
|
7144
|
-
)
|
|
7145
|
-
}
|
|
7146
|
-
|
|
7147
|
-
/**
|
|
7148
|
-
* Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
|
|
7149
|
-
* if value is a number.
|
|
7150
|
-
* Buffer.from(str[, encoding])
|
|
7151
|
-
* Buffer.from(array)
|
|
7152
|
-
* Buffer.from(buffer)
|
|
7153
|
-
* Buffer.from(arrayBuffer[, byteOffset[, length]])
|
|
7154
|
-
**/
|
|
7155
|
-
Buffer.from = function (value, encodingOrOffset, length) {
|
|
7156
|
-
return from(value, encodingOrOffset, length)
|
|
7157
|
-
};
|
|
7158
|
-
|
|
7159
|
-
// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
|
|
7160
|
-
// https://github.com/feross/buffer/pull/148
|
|
7161
|
-
Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
|
|
7162
|
-
Object.setPrototypeOf(Buffer, Uint8Array);
|
|
7163
|
-
|
|
7164
|
-
function assertSize (size) {
|
|
7165
|
-
if (typeof size !== 'number') {
|
|
7166
|
-
throw new TypeError('"size" argument must be of type number')
|
|
7167
|
-
} else if (size < 0) {
|
|
7168
|
-
throw new RangeError('The value "' + size + '" is invalid for option "size"')
|
|
7169
|
-
}
|
|
7170
|
-
}
|
|
7171
|
-
|
|
7172
|
-
function alloc (size, fill, encoding) {
|
|
7173
|
-
assertSize(size);
|
|
7174
|
-
if (size <= 0) {
|
|
7175
|
-
return createBuffer(size)
|
|
7176
|
-
}
|
|
7177
|
-
if (fill !== undefined) {
|
|
7178
|
-
// Only pay attention to encoding if it's a string. This
|
|
7179
|
-
// prevents accidentally sending in a number that would
|
|
7180
|
-
// be interpreted as a start offset.
|
|
7181
|
-
return typeof encoding === 'string'
|
|
7182
|
-
? createBuffer(size).fill(fill, encoding)
|
|
7183
|
-
: createBuffer(size).fill(fill)
|
|
7184
|
-
}
|
|
7185
|
-
return createBuffer(size)
|
|
7186
|
-
}
|
|
7187
|
-
|
|
7188
|
-
/**
|
|
7189
|
-
* Creates a new filled Buffer instance.
|
|
7190
|
-
* alloc(size[, fill[, encoding]])
|
|
7191
|
-
**/
|
|
7192
|
-
Buffer.alloc = function (size, fill, encoding) {
|
|
7193
|
-
return alloc(size, fill, encoding)
|
|
7194
|
-
};
|
|
7195
|
-
|
|
7196
|
-
function allocUnsafe (size) {
|
|
7197
|
-
assertSize(size);
|
|
7198
|
-
return createBuffer(size < 0 ? 0 : checked(size) | 0)
|
|
7199
|
-
}
|
|
7200
|
-
|
|
7201
|
-
/**
|
|
7202
|
-
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
|
|
7203
|
-
* */
|
|
7204
|
-
Buffer.allocUnsafe = function (size) {
|
|
7205
|
-
return allocUnsafe(size)
|
|
7206
|
-
};
|
|
7207
|
-
/**
|
|
7208
|
-
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
|
7209
|
-
*/
|
|
7210
|
-
Buffer.allocUnsafeSlow = function (size) {
|
|
7211
|
-
return allocUnsafe(size)
|
|
7212
|
-
};
|
|
7213
|
-
|
|
7214
|
-
function fromString (string, encoding) {
|
|
7215
|
-
if (typeof encoding !== 'string' || encoding === '') {
|
|
7216
|
-
encoding = 'utf8';
|
|
7217
|
-
}
|
|
7218
|
-
|
|
7219
|
-
if (!Buffer.isEncoding(encoding)) {
|
|
7220
|
-
throw new TypeError('Unknown encoding: ' + encoding)
|
|
7221
|
-
}
|
|
7222
|
-
|
|
7223
|
-
var length = byteLength(string, encoding) | 0;
|
|
7224
|
-
var buf = createBuffer(length);
|
|
7225
|
-
|
|
7226
|
-
var actual = buf.write(string, encoding);
|
|
7227
|
-
|
|
7228
|
-
if (actual !== length) {
|
|
7229
|
-
// Writing a hex string, for example, that contains invalid characters will
|
|
7230
|
-
// cause everything after the first invalid character to be ignored. (e.g.
|
|
7231
|
-
// 'abxxcd' will be treated as 'ab')
|
|
7232
|
-
buf = buf.slice(0, actual);
|
|
7233
|
-
}
|
|
7234
|
-
|
|
7235
|
-
return buf
|
|
7236
|
-
}
|
|
7237
|
-
|
|
7238
|
-
function fromArrayLike (array) {
|
|
7239
|
-
var length = array.length < 0 ? 0 : checked(array.length) | 0;
|
|
7240
|
-
var buf = createBuffer(length);
|
|
7241
|
-
for (var i = 0; i < length; i += 1) {
|
|
7242
|
-
buf[i] = array[i] & 255;
|
|
7243
|
-
}
|
|
7244
|
-
return buf
|
|
7245
|
-
}
|
|
7246
|
-
|
|
7247
|
-
function fromArrayView (arrayView) {
|
|
7248
|
-
if (isInstance(arrayView, Uint8Array)) {
|
|
7249
|
-
var copy = new Uint8Array(arrayView);
|
|
7250
|
-
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
|
|
7251
|
-
}
|
|
7252
|
-
return fromArrayLike(arrayView)
|
|
7253
|
-
}
|
|
7254
|
-
|
|
7255
|
-
function fromArrayBuffer (array, byteOffset, length) {
|
|
7256
|
-
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
7257
|
-
throw new RangeError('"offset" is outside of buffer bounds')
|
|
7258
|
-
}
|
|
7259
|
-
|
|
7260
|
-
if (array.byteLength < byteOffset + (length || 0)) {
|
|
7261
|
-
throw new RangeError('"length" is outside of buffer bounds')
|
|
7262
|
-
}
|
|
7263
|
-
|
|
7264
|
-
var buf;
|
|
7265
|
-
if (byteOffset === undefined && length === undefined) {
|
|
7266
|
-
buf = new Uint8Array(array);
|
|
7267
|
-
} else if (length === undefined) {
|
|
7268
|
-
buf = new Uint8Array(array, byteOffset);
|
|
7269
|
-
} else {
|
|
7270
|
-
buf = new Uint8Array(array, byteOffset, length);
|
|
7271
|
-
}
|
|
7272
|
-
|
|
7273
|
-
// Return an augmented `Uint8Array` instance
|
|
7274
|
-
Object.setPrototypeOf(buf, Buffer.prototype);
|
|
7275
|
-
|
|
7276
|
-
return buf
|
|
7277
|
-
}
|
|
7278
|
-
|
|
7279
|
-
function fromObject (obj) {
|
|
7280
|
-
if (Buffer.isBuffer(obj)) {
|
|
7281
|
-
var len = checked(obj.length) | 0;
|
|
7282
|
-
var buf = createBuffer(len);
|
|
7283
|
-
|
|
7284
|
-
if (buf.length === 0) {
|
|
7285
|
-
return buf
|
|
7286
|
-
}
|
|
7287
|
-
|
|
7288
|
-
obj.copy(buf, 0, 0, len);
|
|
7289
|
-
return buf
|
|
7290
|
-
}
|
|
7291
|
-
|
|
7292
|
-
if (obj.length !== undefined) {
|
|
7293
|
-
if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
|
|
7294
|
-
return createBuffer(0)
|
|
7295
|
-
}
|
|
7296
|
-
return fromArrayLike(obj)
|
|
7297
|
-
}
|
|
7298
|
-
|
|
7299
|
-
if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
|
|
7300
|
-
return fromArrayLike(obj.data)
|
|
7301
|
-
}
|
|
7302
|
-
}
|
|
7303
|
-
|
|
7304
|
-
function checked (length) {
|
|
7305
|
-
// Note: cannot use `length < K_MAX_LENGTH` here because that fails when
|
|
7306
|
-
// length is NaN (which is otherwise coerced to zero.)
|
|
7307
|
-
if (length >= K_MAX_LENGTH) {
|
|
7308
|
-
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
|
|
7309
|
-
'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
|
|
7310
|
-
}
|
|
7311
|
-
return length | 0
|
|
7312
|
-
}
|
|
7313
|
-
|
|
7314
|
-
function SlowBuffer (length) {
|
|
7315
|
-
if (+length != length) { // eslint-disable-line eqeqeq
|
|
7316
|
-
length = 0;
|
|
7317
|
-
}
|
|
7318
|
-
return Buffer.alloc(+length)
|
|
7319
|
-
}
|
|
7320
|
-
|
|
7321
|
-
Buffer.isBuffer = function isBuffer (b) {
|
|
7322
|
-
return b != null && b._isBuffer === true &&
|
|
7323
|
-
b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
|
|
7324
|
-
};
|
|
7325
|
-
|
|
7326
|
-
Buffer.compare = function compare (a, b) {
|
|
7327
|
-
if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
|
|
7328
|
-
if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
|
|
7329
|
-
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
|
|
7330
|
-
throw new TypeError(
|
|
7331
|
-
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
|
|
7332
|
-
)
|
|
7333
|
-
}
|
|
7334
|
-
|
|
7335
|
-
if (a === b) return 0
|
|
7336
|
-
|
|
7337
|
-
var x = a.length;
|
|
7338
|
-
var y = b.length;
|
|
7339
|
-
|
|
7340
|
-
for (var i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
7341
|
-
if (a[i] !== b[i]) {
|
|
7342
|
-
x = a[i];
|
|
7343
|
-
y = b[i];
|
|
7344
|
-
break
|
|
7345
|
-
}
|
|
7346
|
-
}
|
|
7347
|
-
|
|
7348
|
-
if (x < y) return -1
|
|
7349
|
-
if (y < x) return 1
|
|
7350
|
-
return 0
|
|
7351
|
-
};
|
|
7352
|
-
|
|
7353
|
-
Buffer.isEncoding = function isEncoding (encoding) {
|
|
7354
|
-
switch (String(encoding).toLowerCase()) {
|
|
7355
|
-
case 'hex':
|
|
7356
|
-
case 'utf8':
|
|
7357
|
-
case 'utf-8':
|
|
7358
|
-
case 'ascii':
|
|
7359
|
-
case 'latin1':
|
|
7360
|
-
case 'binary':
|
|
7361
|
-
case 'base64':
|
|
7362
|
-
case 'ucs2':
|
|
7363
|
-
case 'ucs-2':
|
|
7364
|
-
case 'utf16le':
|
|
7365
|
-
case 'utf-16le':
|
|
7366
|
-
return true
|
|
7367
|
-
default:
|
|
7368
|
-
return false
|
|
7369
|
-
}
|
|
7370
|
-
};
|
|
7371
|
-
|
|
7372
|
-
Buffer.concat = function concat (list, length) {
|
|
7373
|
-
if (!Array.isArray(list)) {
|
|
7374
|
-
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
7375
|
-
}
|
|
7376
|
-
|
|
7377
|
-
if (list.length === 0) {
|
|
7378
|
-
return Buffer.alloc(0)
|
|
7379
|
-
}
|
|
7380
|
-
|
|
7381
|
-
var i;
|
|
7382
|
-
if (length === undefined) {
|
|
7383
|
-
length = 0;
|
|
7384
|
-
for (i = 0; i < list.length; ++i) {
|
|
7385
|
-
length += list[i].length;
|
|
7386
|
-
}
|
|
7387
|
-
}
|
|
7388
|
-
|
|
7389
|
-
var buffer = Buffer.allocUnsafe(length);
|
|
7390
|
-
var pos = 0;
|
|
7391
|
-
for (i = 0; i < list.length; ++i) {
|
|
7392
|
-
var buf = list[i];
|
|
7393
|
-
if (isInstance(buf, Uint8Array)) {
|
|
7394
|
-
if (pos + buf.length > buffer.length) {
|
|
7395
|
-
Buffer.from(buf).copy(buffer, pos);
|
|
7396
|
-
} else {
|
|
7397
|
-
Uint8Array.prototype.set.call(
|
|
7398
|
-
buffer,
|
|
7399
|
-
buf,
|
|
7400
|
-
pos
|
|
7401
|
-
);
|
|
7402
|
-
}
|
|
7403
|
-
} else if (!Buffer.isBuffer(buf)) {
|
|
7404
|
-
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
7405
|
-
} else {
|
|
7406
|
-
buf.copy(buffer, pos);
|
|
7407
|
-
}
|
|
7408
|
-
pos += buf.length;
|
|
7409
|
-
}
|
|
7410
|
-
return buffer
|
|
7411
|
-
};
|
|
7412
|
-
|
|
7413
|
-
function byteLength (string, encoding) {
|
|
7414
|
-
if (Buffer.isBuffer(string)) {
|
|
7415
|
-
return string.length
|
|
7416
|
-
}
|
|
7417
|
-
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
|
|
7418
|
-
return string.byteLength
|
|
7419
|
-
}
|
|
7420
|
-
if (typeof string !== 'string') {
|
|
7421
|
-
throw new TypeError(
|
|
7422
|
-
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
|
|
7423
|
-
'Received type ' + typeof string
|
|
7424
|
-
)
|
|
7425
|
-
}
|
|
7426
|
-
|
|
7427
|
-
var len = string.length;
|
|
7428
|
-
var mustMatch = (arguments.length > 2 && arguments[2] === true);
|
|
7429
|
-
if (!mustMatch && len === 0) return 0
|
|
7430
|
-
|
|
7431
|
-
// Use a for loop to avoid recursion
|
|
7432
|
-
var loweredCase = false;
|
|
7433
|
-
for (;;) {
|
|
7434
|
-
switch (encoding) {
|
|
7435
|
-
case 'ascii':
|
|
7436
|
-
case 'latin1':
|
|
7437
|
-
case 'binary':
|
|
7438
|
-
return len
|
|
7439
|
-
case 'utf8':
|
|
7440
|
-
case 'utf-8':
|
|
7441
|
-
return utf8ToBytes(string).length
|
|
7442
|
-
case 'ucs2':
|
|
7443
|
-
case 'ucs-2':
|
|
7444
|
-
case 'utf16le':
|
|
7445
|
-
case 'utf-16le':
|
|
7446
|
-
return len * 2
|
|
7447
|
-
case 'hex':
|
|
7448
|
-
return len >>> 1
|
|
7449
|
-
case 'base64':
|
|
7450
|
-
return base64ToBytes(string).length
|
|
7451
|
-
default:
|
|
7452
|
-
if (loweredCase) {
|
|
7453
|
-
return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
|
|
7454
|
-
}
|
|
7455
|
-
encoding = ('' + encoding).toLowerCase();
|
|
7456
|
-
loweredCase = true;
|
|
7457
|
-
}
|
|
7458
|
-
}
|
|
7459
|
-
}
|
|
7460
|
-
Buffer.byteLength = byteLength;
|
|
7461
|
-
|
|
7462
|
-
function slowToString (encoding, start, end) {
|
|
7463
|
-
var loweredCase = false;
|
|
7464
|
-
|
|
7465
|
-
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
|
|
7466
|
-
// property of a typed array.
|
|
7467
|
-
|
|
7468
|
-
// This behaves neither like String nor Uint8Array in that we set start/end
|
|
7469
|
-
// to their upper/lower bounds if the value passed is out of range.
|
|
7470
|
-
// undefined is handled specially as per ECMA-262 6th Edition,
|
|
7471
|
-
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
|
|
7472
|
-
if (start === undefined || start < 0) {
|
|
7473
|
-
start = 0;
|
|
7474
|
-
}
|
|
7475
|
-
// Return early if start > this.length. Done here to prevent potential uint32
|
|
7476
|
-
// coercion fail below.
|
|
7477
|
-
if (start > this.length) {
|
|
7478
|
-
return ''
|
|
7479
|
-
}
|
|
7480
|
-
|
|
7481
|
-
if (end === undefined || end > this.length) {
|
|
7482
|
-
end = this.length;
|
|
7483
|
-
}
|
|
7484
|
-
|
|
7485
|
-
if (end <= 0) {
|
|
7486
|
-
return ''
|
|
7487
|
-
}
|
|
7488
|
-
|
|
7489
|
-
// Force coercion to uint32. This will also coerce falsey/NaN values to 0.
|
|
7490
|
-
end >>>= 0;
|
|
7491
|
-
start >>>= 0;
|
|
7492
|
-
|
|
7493
|
-
if (end <= start) {
|
|
7494
|
-
return ''
|
|
7495
|
-
}
|
|
7496
|
-
|
|
7497
|
-
if (!encoding) encoding = 'utf8';
|
|
7498
|
-
|
|
7499
|
-
while (true) {
|
|
7500
|
-
switch (encoding) {
|
|
7501
|
-
case 'hex':
|
|
7502
|
-
return hexSlice(this, start, end)
|
|
7503
|
-
|
|
7504
|
-
case 'utf8':
|
|
7505
|
-
case 'utf-8':
|
|
7506
|
-
return utf8Slice(this, start, end)
|
|
7507
|
-
|
|
7508
|
-
case 'ascii':
|
|
7509
|
-
return asciiSlice(this, start, end)
|
|
7510
|
-
|
|
7511
|
-
case 'latin1':
|
|
7512
|
-
case 'binary':
|
|
7513
|
-
return latin1Slice(this, start, end)
|
|
7514
|
-
|
|
7515
|
-
case 'base64':
|
|
7516
|
-
return base64Slice(this, start, end)
|
|
7517
|
-
|
|
7518
|
-
case 'ucs2':
|
|
7519
|
-
case 'ucs-2':
|
|
7520
|
-
case 'utf16le':
|
|
7521
|
-
case 'utf-16le':
|
|
7522
|
-
return utf16leSlice(this, start, end)
|
|
7523
|
-
|
|
7524
|
-
default:
|
|
7525
|
-
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
7526
|
-
encoding = (encoding + '').toLowerCase();
|
|
7527
|
-
loweredCase = true;
|
|
7528
|
-
}
|
|
7529
|
-
}
|
|
7530
|
-
}
|
|
7531
|
-
|
|
7532
|
-
// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
|
|
7533
|
-
// to detect a Buffer instance. It's not possible to use `instanceof Buffer`
|
|
7534
|
-
// reliably in a browserify context because there could be multiple different
|
|
7535
|
-
// copies of the 'buffer' package in use. This method works even for Buffer
|
|
7536
|
-
// instances that were created from another copy of the `buffer` package.
|
|
7537
|
-
// See: https://github.com/feross/buffer/issues/154
|
|
7538
|
-
Buffer.prototype._isBuffer = true;
|
|
7539
|
-
|
|
7540
|
-
function swap (b, n, m) {
|
|
7541
|
-
var i = b[n];
|
|
7542
|
-
b[n] = b[m];
|
|
7543
|
-
b[m] = i;
|
|
7544
|
-
}
|
|
7545
|
-
|
|
7546
|
-
Buffer.prototype.swap16 = function swap16 () {
|
|
7547
|
-
var len = this.length;
|
|
7548
|
-
if (len % 2 !== 0) {
|
|
7549
|
-
throw new RangeError('Buffer size must be a multiple of 16-bits')
|
|
7550
|
-
}
|
|
7551
|
-
for (var i = 0; i < len; i += 2) {
|
|
7552
|
-
swap(this, i, i + 1);
|
|
7553
|
-
}
|
|
7554
|
-
return this
|
|
7555
|
-
};
|
|
7556
|
-
|
|
7557
|
-
Buffer.prototype.swap32 = function swap32 () {
|
|
7558
|
-
var len = this.length;
|
|
7559
|
-
if (len % 4 !== 0) {
|
|
7560
|
-
throw new RangeError('Buffer size must be a multiple of 32-bits')
|
|
7561
|
-
}
|
|
7562
|
-
for (var i = 0; i < len; i += 4) {
|
|
7563
|
-
swap(this, i, i + 3);
|
|
7564
|
-
swap(this, i + 1, i + 2);
|
|
7565
|
-
}
|
|
7566
|
-
return this
|
|
7567
|
-
};
|
|
7568
|
-
|
|
7569
|
-
Buffer.prototype.swap64 = function swap64 () {
|
|
7570
|
-
var len = this.length;
|
|
7571
|
-
if (len % 8 !== 0) {
|
|
7572
|
-
throw new RangeError('Buffer size must be a multiple of 64-bits')
|
|
7573
|
-
}
|
|
7574
|
-
for (var i = 0; i < len; i += 8) {
|
|
7575
|
-
swap(this, i, i + 7);
|
|
7576
|
-
swap(this, i + 1, i + 6);
|
|
7577
|
-
swap(this, i + 2, i + 5);
|
|
7578
|
-
swap(this, i + 3, i + 4);
|
|
7579
|
-
}
|
|
7580
|
-
return this
|
|
7581
|
-
};
|
|
7582
|
-
|
|
7583
|
-
Buffer.prototype.toString = function toString () {
|
|
7584
|
-
var length = this.length;
|
|
7585
|
-
if (length === 0) return ''
|
|
7586
|
-
if (arguments.length === 0) return utf8Slice(this, 0, length)
|
|
7587
|
-
return slowToString.apply(this, arguments)
|
|
7588
|
-
};
|
|
7589
|
-
|
|
7590
|
-
Buffer.prototype.toLocaleString = Buffer.prototype.toString;
|
|
7591
|
-
|
|
7592
|
-
Buffer.prototype.equals = function equals (b) {
|
|
7593
|
-
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
|
|
7594
|
-
if (this === b) return true
|
|
7595
|
-
return Buffer.compare(this, b) === 0
|
|
7596
|
-
};
|
|
7597
|
-
|
|
7598
|
-
Buffer.prototype.inspect = function inspect () {
|
|
7599
|
-
var str = '';
|
|
7600
|
-
var max = exports$1.INSPECT_MAX_BYTES;
|
|
7601
|
-
str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
|
|
7602
|
-
if (this.length > max) str += ' ... ';
|
|
7603
|
-
return '<Buffer ' + str + '>'
|
|
7604
|
-
};
|
|
7605
|
-
if (customInspectSymbol) {
|
|
7606
|
-
Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
|
|
7607
|
-
}
|
|
7608
|
-
|
|
7609
|
-
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
|
|
7610
|
-
if (isInstance(target, Uint8Array)) {
|
|
7611
|
-
target = Buffer.from(target, target.offset, target.byteLength);
|
|
7612
|
-
}
|
|
7613
|
-
if (!Buffer.isBuffer(target)) {
|
|
7614
|
-
throw new TypeError(
|
|
7615
|
-
'The "target" argument must be one of type Buffer or Uint8Array. ' +
|
|
7616
|
-
'Received type ' + (typeof target)
|
|
7617
|
-
)
|
|
7618
|
-
}
|
|
7619
|
-
|
|
7620
|
-
if (start === undefined) {
|
|
7621
|
-
start = 0;
|
|
7622
|
-
}
|
|
7623
|
-
if (end === undefined) {
|
|
7624
|
-
end = target ? target.length : 0;
|
|
7625
|
-
}
|
|
7626
|
-
if (thisStart === undefined) {
|
|
7627
|
-
thisStart = 0;
|
|
7628
|
-
}
|
|
7629
|
-
if (thisEnd === undefined) {
|
|
7630
|
-
thisEnd = this.length;
|
|
7631
|
-
}
|
|
7632
|
-
|
|
7633
|
-
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
7634
|
-
throw new RangeError('out of range index')
|
|
7635
|
-
}
|
|
7636
|
-
|
|
7637
|
-
if (thisStart >= thisEnd && start >= end) {
|
|
7638
|
-
return 0
|
|
7639
|
-
}
|
|
7640
|
-
if (thisStart >= thisEnd) {
|
|
7641
|
-
return -1
|
|
7642
|
-
}
|
|
7643
|
-
if (start >= end) {
|
|
7644
|
-
return 1
|
|
7645
|
-
}
|
|
7646
|
-
|
|
7647
|
-
start >>>= 0;
|
|
7648
|
-
end >>>= 0;
|
|
7649
|
-
thisStart >>>= 0;
|
|
7650
|
-
thisEnd >>>= 0;
|
|
7651
|
-
|
|
7652
|
-
if (this === target) return 0
|
|
7653
|
-
|
|
7654
|
-
var x = thisEnd - thisStart;
|
|
7655
|
-
var y = end - start;
|
|
7656
|
-
var len = Math.min(x, y);
|
|
7657
|
-
|
|
7658
|
-
var thisCopy = this.slice(thisStart, thisEnd);
|
|
7659
|
-
var targetCopy = target.slice(start, end);
|
|
7660
|
-
|
|
7661
|
-
for (var i = 0; i < len; ++i) {
|
|
7662
|
-
if (thisCopy[i] !== targetCopy[i]) {
|
|
7663
|
-
x = thisCopy[i];
|
|
7664
|
-
y = targetCopy[i];
|
|
7665
|
-
break
|
|
7666
|
-
}
|
|
7667
|
-
}
|
|
7668
|
-
|
|
7669
|
-
if (x < y) return -1
|
|
7670
|
-
if (y < x) return 1
|
|
7671
|
-
return 0
|
|
7672
|
-
};
|
|
7673
|
-
|
|
7674
|
-
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
|
|
7675
|
-
// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
|
|
7676
|
-
//
|
|
7677
|
-
// Arguments:
|
|
7678
|
-
// - buffer - a Buffer to search
|
|
7679
|
-
// - val - a string, Buffer, or number
|
|
7680
|
-
// - byteOffset - an index into `buffer`; will be clamped to an int32
|
|
7681
|
-
// - encoding - an optional encoding, relevant is val is a string
|
|
7682
|
-
// - dir - true for indexOf, false for lastIndexOf
|
|
7683
|
-
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
|
7684
|
-
// Empty buffer means no match
|
|
7685
|
-
if (buffer.length === 0) return -1
|
|
7686
|
-
|
|
7687
|
-
// Normalize byteOffset
|
|
7688
|
-
if (typeof byteOffset === 'string') {
|
|
7689
|
-
encoding = byteOffset;
|
|
7690
|
-
byteOffset = 0;
|
|
7691
|
-
} else if (byteOffset > 0x7fffffff) {
|
|
7692
|
-
byteOffset = 0x7fffffff;
|
|
7693
|
-
} else if (byteOffset < -2147483648) {
|
|
7694
|
-
byteOffset = -2147483648;
|
|
7695
|
-
}
|
|
7696
|
-
byteOffset = +byteOffset; // Coerce to Number.
|
|
7697
|
-
if (numberIsNaN(byteOffset)) {
|
|
7698
|
-
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
|
|
7699
|
-
byteOffset = dir ? 0 : (buffer.length - 1);
|
|
7700
|
-
}
|
|
7701
|
-
|
|
7702
|
-
// Normalize byteOffset: negative offsets start from the end of the buffer
|
|
7703
|
-
if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
|
|
7704
|
-
if (byteOffset >= buffer.length) {
|
|
7705
|
-
if (dir) return -1
|
|
7706
|
-
else byteOffset = buffer.length - 1;
|
|
7707
|
-
} else if (byteOffset < 0) {
|
|
7708
|
-
if (dir) byteOffset = 0;
|
|
7709
|
-
else return -1
|
|
7710
|
-
}
|
|
7711
|
-
|
|
7712
|
-
// Normalize val
|
|
7713
|
-
if (typeof val === 'string') {
|
|
7714
|
-
val = Buffer.from(val, encoding);
|
|
7715
|
-
}
|
|
7716
|
-
|
|
7717
|
-
// Finally, search either indexOf (if dir is true) or lastIndexOf
|
|
7718
|
-
if (Buffer.isBuffer(val)) {
|
|
7719
|
-
// Special case: looking for empty string/buffer always fails
|
|
7720
|
-
if (val.length === 0) {
|
|
7721
|
-
return -1
|
|
7722
|
-
}
|
|
7723
|
-
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
|
|
7724
|
-
} else if (typeof val === 'number') {
|
|
7725
|
-
val = val & 0xFF; // Search for a byte value [0-255]
|
|
7726
|
-
if (typeof Uint8Array.prototype.indexOf === 'function') {
|
|
7727
|
-
if (dir) {
|
|
7728
|
-
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
|
|
7729
|
-
} else {
|
|
7730
|
-
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
|
|
7731
|
-
}
|
|
7732
|
-
}
|
|
7733
|
-
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
|
|
7734
|
-
}
|
|
7735
|
-
|
|
7736
|
-
throw new TypeError('val must be string, number or Buffer')
|
|
7737
|
-
}
|
|
7738
|
-
|
|
7739
|
-
function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
|
|
7740
|
-
var indexSize = 1;
|
|
7741
|
-
var arrLength = arr.length;
|
|
7742
|
-
var valLength = val.length;
|
|
7743
|
-
|
|
7744
|
-
if (encoding !== undefined) {
|
|
7745
|
-
encoding = String(encoding).toLowerCase();
|
|
7746
|
-
if (encoding === 'ucs2' || encoding === 'ucs-2' ||
|
|
7747
|
-
encoding === 'utf16le' || encoding === 'utf-16le') {
|
|
7748
|
-
if (arr.length < 2 || val.length < 2) {
|
|
7749
|
-
return -1
|
|
7750
|
-
}
|
|
7751
|
-
indexSize = 2;
|
|
7752
|
-
arrLength /= 2;
|
|
7753
|
-
valLength /= 2;
|
|
7754
|
-
byteOffset /= 2;
|
|
7755
|
-
}
|
|
7756
|
-
}
|
|
7757
|
-
|
|
7758
|
-
function read (buf, i) {
|
|
7759
|
-
if (indexSize === 1) {
|
|
7760
|
-
return buf[i]
|
|
7761
|
-
} else {
|
|
7762
|
-
return buf.readUInt16BE(i * indexSize)
|
|
7763
|
-
}
|
|
7764
|
-
}
|
|
7765
|
-
|
|
7766
|
-
var i;
|
|
7767
|
-
if (dir) {
|
|
7768
|
-
var foundIndex = -1;
|
|
7769
|
-
for (i = byteOffset; i < arrLength; i++) {
|
|
7770
|
-
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
7771
|
-
if (foundIndex === -1) foundIndex = i;
|
|
7772
|
-
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
|
|
7773
|
-
} else {
|
|
7774
|
-
if (foundIndex !== -1) i -= i - foundIndex;
|
|
7775
|
-
foundIndex = -1;
|
|
7776
|
-
}
|
|
7777
|
-
}
|
|
7778
|
-
} else {
|
|
7779
|
-
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
|
|
7780
|
-
for (i = byteOffset; i >= 0; i--) {
|
|
7781
|
-
var found = true;
|
|
7782
|
-
for (var j = 0; j < valLength; j++) {
|
|
7783
|
-
if (read(arr, i + j) !== read(val, j)) {
|
|
7784
|
-
found = false;
|
|
7785
|
-
break
|
|
7786
|
-
}
|
|
7787
|
-
}
|
|
7788
|
-
if (found) return i
|
|
7789
|
-
}
|
|
7790
|
-
}
|
|
7791
|
-
|
|
7792
|
-
return -1
|
|
7793
|
-
}
|
|
7794
|
-
|
|
7795
|
-
Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
|
|
7796
|
-
return this.indexOf(val, byteOffset, encoding) !== -1
|
|
7797
|
-
};
|
|
7798
|
-
|
|
7799
|
-
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
|
|
7800
|
-
return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
|
|
7801
|
-
};
|
|
7802
|
-
|
|
7803
|
-
Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
|
|
7804
|
-
return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
|
|
7805
|
-
};
|
|
7806
|
-
|
|
7807
|
-
function hexWrite (buf, string, offset, length) {
|
|
7808
|
-
offset = Number(offset) || 0;
|
|
7809
|
-
var remaining = buf.length - offset;
|
|
7810
|
-
if (!length) {
|
|
7811
|
-
length = remaining;
|
|
7812
|
-
} else {
|
|
7813
|
-
length = Number(length);
|
|
7814
|
-
if (length > remaining) {
|
|
7815
|
-
length = remaining;
|
|
7816
|
-
}
|
|
7817
|
-
}
|
|
7818
|
-
|
|
7819
|
-
var strLen = string.length;
|
|
7820
|
-
|
|
7821
|
-
if (length > strLen / 2) {
|
|
7822
|
-
length = strLen / 2;
|
|
7823
|
-
}
|
|
7824
|
-
for (var i = 0; i < length; ++i) {
|
|
7825
|
-
var parsed = parseInt(string.substr(i * 2, 2), 16);
|
|
7826
|
-
if (numberIsNaN(parsed)) return i
|
|
7827
|
-
buf[offset + i] = parsed;
|
|
7828
|
-
}
|
|
7829
|
-
return i
|
|
7830
|
-
}
|
|
7831
|
-
|
|
7832
|
-
function utf8Write (buf, string, offset, length) {
|
|
7833
|
-
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
|
|
7834
|
-
}
|
|
7835
|
-
|
|
7836
|
-
function asciiWrite (buf, string, offset, length) {
|
|
7837
|
-
return blitBuffer(asciiToBytes(string), buf, offset, length)
|
|
7838
|
-
}
|
|
7839
|
-
|
|
7840
|
-
function base64Write (buf, string, offset, length) {
|
|
7841
|
-
return blitBuffer(base64ToBytes(string), buf, offset, length)
|
|
7842
|
-
}
|
|
7843
|
-
|
|
7844
|
-
function ucs2Write (buf, string, offset, length) {
|
|
7845
|
-
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
|
|
7846
|
-
}
|
|
7847
|
-
|
|
7848
|
-
Buffer.prototype.write = function write (string, offset, length, encoding) {
|
|
7849
|
-
// Buffer#write(string)
|
|
7850
|
-
if (offset === undefined) {
|
|
7851
|
-
encoding = 'utf8';
|
|
7852
|
-
length = this.length;
|
|
7853
|
-
offset = 0;
|
|
7854
|
-
// Buffer#write(string, encoding)
|
|
7855
|
-
} else if (length === undefined && typeof offset === 'string') {
|
|
7856
|
-
encoding = offset;
|
|
7857
|
-
length = this.length;
|
|
7858
|
-
offset = 0;
|
|
7859
|
-
// Buffer#write(string, offset[, length][, encoding])
|
|
7860
|
-
} else if (isFinite(offset)) {
|
|
7861
|
-
offset = offset >>> 0;
|
|
7862
|
-
if (isFinite(length)) {
|
|
7863
|
-
length = length >>> 0;
|
|
7864
|
-
if (encoding === undefined) encoding = 'utf8';
|
|
7865
|
-
} else {
|
|
7866
|
-
encoding = length;
|
|
7867
|
-
length = undefined;
|
|
7868
|
-
}
|
|
7869
|
-
} else {
|
|
7870
|
-
throw new Error(
|
|
7871
|
-
'Buffer.write(string, encoding, offset[, length]) is no longer supported'
|
|
7872
|
-
)
|
|
7873
|
-
}
|
|
7874
|
-
|
|
7875
|
-
var remaining = this.length - offset;
|
|
7876
|
-
if (length === undefined || length > remaining) length = remaining;
|
|
7877
|
-
|
|
7878
|
-
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
|
|
7879
|
-
throw new RangeError('Attempt to write outside buffer bounds')
|
|
7880
|
-
}
|
|
7881
|
-
|
|
7882
|
-
if (!encoding) encoding = 'utf8';
|
|
7883
|
-
|
|
7884
|
-
var loweredCase = false;
|
|
7885
|
-
for (;;) {
|
|
7886
|
-
switch (encoding) {
|
|
7887
|
-
case 'hex':
|
|
7888
|
-
return hexWrite(this, string, offset, length)
|
|
7889
|
-
|
|
7890
|
-
case 'utf8':
|
|
7891
|
-
case 'utf-8':
|
|
7892
|
-
return utf8Write(this, string, offset, length)
|
|
7893
|
-
|
|
7894
|
-
case 'ascii':
|
|
7895
|
-
case 'latin1':
|
|
7896
|
-
case 'binary':
|
|
7897
|
-
return asciiWrite(this, string, offset, length)
|
|
7898
|
-
|
|
7899
|
-
case 'base64':
|
|
7900
|
-
// Warning: maxLength not taken into account in base64Write
|
|
7901
|
-
return base64Write(this, string, offset, length)
|
|
7902
|
-
|
|
7903
|
-
case 'ucs2':
|
|
7904
|
-
case 'ucs-2':
|
|
7905
|
-
case 'utf16le':
|
|
7906
|
-
case 'utf-16le':
|
|
7907
|
-
return ucs2Write(this, string, offset, length)
|
|
7908
|
-
|
|
7909
|
-
default:
|
|
7910
|
-
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
7911
|
-
encoding = ('' + encoding).toLowerCase();
|
|
7912
|
-
loweredCase = true;
|
|
7913
|
-
}
|
|
7914
|
-
}
|
|
7915
|
-
};
|
|
7916
|
-
|
|
7917
|
-
Buffer.prototype.toJSON = function toJSON () {
|
|
7918
|
-
return {
|
|
7919
|
-
type: 'Buffer',
|
|
7920
|
-
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
7921
|
-
}
|
|
7922
|
-
};
|
|
7923
|
-
|
|
7924
|
-
function base64Slice (buf, start, end) {
|
|
7925
|
-
if (start === 0 && end === buf.length) {
|
|
7926
|
-
return base64.fromByteArray(buf)
|
|
7927
|
-
} else {
|
|
7928
|
-
return base64.fromByteArray(buf.slice(start, end))
|
|
7929
|
-
}
|
|
7930
|
-
}
|
|
7931
|
-
|
|
7932
|
-
function utf8Slice (buf, start, end) {
|
|
7933
|
-
end = Math.min(buf.length, end);
|
|
7934
|
-
var res = [];
|
|
7935
|
-
|
|
7936
|
-
var i = start;
|
|
7937
|
-
while (i < end) {
|
|
7938
|
-
var firstByte = buf[i];
|
|
7939
|
-
var codePoint = null;
|
|
7940
|
-
var bytesPerSequence = (firstByte > 0xEF)
|
|
7941
|
-
? 4
|
|
7942
|
-
: (firstByte > 0xDF)
|
|
7943
|
-
? 3
|
|
7944
|
-
: (firstByte > 0xBF)
|
|
7945
|
-
? 2
|
|
7946
|
-
: 1;
|
|
7947
|
-
|
|
7948
|
-
if (i + bytesPerSequence <= end) {
|
|
7949
|
-
var secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
7950
|
-
|
|
7951
|
-
switch (bytesPerSequence) {
|
|
7952
|
-
case 1:
|
|
7953
|
-
if (firstByte < 0x80) {
|
|
7954
|
-
codePoint = firstByte;
|
|
7955
|
-
}
|
|
7956
|
-
break
|
|
7957
|
-
case 2:
|
|
7958
|
-
secondByte = buf[i + 1];
|
|
7959
|
-
if ((secondByte & 0xC0) === 0x80) {
|
|
7960
|
-
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
|
|
7961
|
-
if (tempCodePoint > 0x7F) {
|
|
7962
|
-
codePoint = tempCodePoint;
|
|
7963
|
-
}
|
|
7964
|
-
}
|
|
7965
|
-
break
|
|
7966
|
-
case 3:
|
|
7967
|
-
secondByte = buf[i + 1];
|
|
7968
|
-
thirdByte = buf[i + 2];
|
|
7969
|
-
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
|
|
7970
|
-
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
|
|
7971
|
-
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
|
|
7972
|
-
codePoint = tempCodePoint;
|
|
7973
|
-
}
|
|
7974
|
-
}
|
|
7975
|
-
break
|
|
7976
|
-
case 4:
|
|
7977
|
-
secondByte = buf[i + 1];
|
|
7978
|
-
thirdByte = buf[i + 2];
|
|
7979
|
-
fourthByte = buf[i + 3];
|
|
7980
|
-
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
|
|
7981
|
-
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
|
|
7982
|
-
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
|
|
7983
|
-
codePoint = tempCodePoint;
|
|
7984
|
-
}
|
|
7985
|
-
}
|
|
7986
|
-
}
|
|
7987
|
-
}
|
|
7988
|
-
|
|
7989
|
-
if (codePoint === null) {
|
|
7990
|
-
// we did not generate a valid codePoint so insert a
|
|
7991
|
-
// replacement char (U+FFFD) and advance only 1 byte
|
|
7992
|
-
codePoint = 0xFFFD;
|
|
7993
|
-
bytesPerSequence = 1;
|
|
7994
|
-
} else if (codePoint > 0xFFFF) {
|
|
7995
|
-
// encode to utf16 (surrogate pair dance)
|
|
7996
|
-
codePoint -= 0x10000;
|
|
7997
|
-
res.push(codePoint >>> 10 & 0x3FF | 0xD800);
|
|
7998
|
-
codePoint = 0xDC00 | codePoint & 0x3FF;
|
|
7999
|
-
}
|
|
8000
|
-
|
|
8001
|
-
res.push(codePoint);
|
|
8002
|
-
i += bytesPerSequence;
|
|
8003
|
-
}
|
|
8004
|
-
|
|
8005
|
-
return decodeCodePointsArray(res)
|
|
8006
|
-
}
|
|
8007
|
-
|
|
8008
|
-
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
|
|
8009
|
-
// the lowest limit is Chrome, with 0x10000 args.
|
|
8010
|
-
// We go 1 magnitude less, for safety
|
|
8011
|
-
var MAX_ARGUMENTS_LENGTH = 0x1000;
|
|
8012
|
-
|
|
8013
|
-
function decodeCodePointsArray (codePoints) {
|
|
8014
|
-
var len = codePoints.length;
|
|
8015
|
-
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
8016
|
-
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
|
|
8017
|
-
}
|
|
8018
|
-
|
|
8019
|
-
// Decode in chunks to avoid "call stack size exceeded".
|
|
8020
|
-
var res = '';
|
|
8021
|
-
var i = 0;
|
|
8022
|
-
while (i < len) {
|
|
8023
|
-
res += String.fromCharCode.apply(
|
|
8024
|
-
String,
|
|
8025
|
-
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
8026
|
-
);
|
|
8027
|
-
}
|
|
8028
|
-
return res
|
|
8029
|
-
}
|
|
8030
|
-
|
|
8031
|
-
function asciiSlice (buf, start, end) {
|
|
8032
|
-
var ret = '';
|
|
8033
|
-
end = Math.min(buf.length, end);
|
|
8034
|
-
|
|
8035
|
-
for (var i = start; i < end; ++i) {
|
|
8036
|
-
ret += String.fromCharCode(buf[i] & 0x7F);
|
|
8037
|
-
}
|
|
8038
|
-
return ret
|
|
8039
|
-
}
|
|
8040
|
-
|
|
8041
|
-
function latin1Slice (buf, start, end) {
|
|
8042
|
-
var ret = '';
|
|
8043
|
-
end = Math.min(buf.length, end);
|
|
8044
|
-
|
|
8045
|
-
for (var i = start; i < end; ++i) {
|
|
8046
|
-
ret += String.fromCharCode(buf[i]);
|
|
8047
|
-
}
|
|
8048
|
-
return ret
|
|
8049
|
-
}
|
|
8050
|
-
|
|
8051
|
-
function hexSlice (buf, start, end) {
|
|
8052
|
-
var len = buf.length;
|
|
8053
|
-
|
|
8054
|
-
if (!start || start < 0) start = 0;
|
|
8055
|
-
if (!end || end < 0 || end > len) end = len;
|
|
8056
|
-
|
|
8057
|
-
var out = '';
|
|
8058
|
-
for (var i = start; i < end; ++i) {
|
|
8059
|
-
out += hexSliceLookupTable[buf[i]];
|
|
8060
|
-
}
|
|
8061
|
-
return out
|
|
8062
|
-
}
|
|
8063
|
-
|
|
8064
|
-
function utf16leSlice (buf, start, end) {
|
|
8065
|
-
var bytes = buf.slice(start, end);
|
|
8066
|
-
var res = '';
|
|
8067
|
-
// If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
|
|
8068
|
-
for (var i = 0; i < bytes.length - 1; i += 2) {
|
|
8069
|
-
res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256));
|
|
8070
|
-
}
|
|
8071
|
-
return res
|
|
8072
|
-
}
|
|
8073
|
-
|
|
8074
|
-
Buffer.prototype.slice = function slice (start, end) {
|
|
8075
|
-
var len = this.length;
|
|
8076
|
-
start = ~~start;
|
|
8077
|
-
end = end === undefined ? len : ~~end;
|
|
8078
|
-
|
|
8079
|
-
if (start < 0) {
|
|
8080
|
-
start += len;
|
|
8081
|
-
if (start < 0) start = 0;
|
|
8082
|
-
} else if (start > len) {
|
|
8083
|
-
start = len;
|
|
8084
|
-
}
|
|
8085
|
-
|
|
8086
|
-
if (end < 0) {
|
|
8087
|
-
end += len;
|
|
8088
|
-
if (end < 0) end = 0;
|
|
8089
|
-
} else if (end > len) {
|
|
8090
|
-
end = len;
|
|
8091
|
-
}
|
|
8092
|
-
|
|
8093
|
-
if (end < start) end = start;
|
|
8094
|
-
|
|
8095
|
-
var newBuf = this.subarray(start, end);
|
|
8096
|
-
// Return an augmented `Uint8Array` instance
|
|
8097
|
-
Object.setPrototypeOf(newBuf, Buffer.prototype);
|
|
8098
|
-
|
|
8099
|
-
return newBuf
|
|
8100
|
-
};
|
|
8101
|
-
|
|
8102
|
-
/*
|
|
8103
|
-
* Need to make sure that buffer isn't trying to write out of bounds.
|
|
8104
|
-
*/
|
|
8105
|
-
function checkOffset (offset, ext, length) {
|
|
8106
|
-
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
|
|
8107
|
-
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
|
|
8108
|
-
}
|
|
8109
|
-
|
|
8110
|
-
Buffer.prototype.readUintLE =
|
|
8111
|
-
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
|
|
8112
|
-
offset = offset >>> 0;
|
|
8113
|
-
byteLength = byteLength >>> 0;
|
|
8114
|
-
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
8115
|
-
|
|
8116
|
-
var val = this[offset];
|
|
8117
|
-
var mul = 1;
|
|
8118
|
-
var i = 0;
|
|
8119
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
|
8120
|
-
val += this[offset + i] * mul;
|
|
8121
|
-
}
|
|
8122
|
-
|
|
8123
|
-
return val
|
|
8124
|
-
};
|
|
8125
|
-
|
|
8126
|
-
Buffer.prototype.readUintBE =
|
|
8127
|
-
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
|
|
8128
|
-
offset = offset >>> 0;
|
|
8129
|
-
byteLength = byteLength >>> 0;
|
|
8130
|
-
if (!noAssert) {
|
|
8131
|
-
checkOffset(offset, byteLength, this.length);
|
|
8132
|
-
}
|
|
8133
|
-
|
|
8134
|
-
var val = this[offset + --byteLength];
|
|
8135
|
-
var mul = 1;
|
|
8136
|
-
while (byteLength > 0 && (mul *= 0x100)) {
|
|
8137
|
-
val += this[offset + --byteLength] * mul;
|
|
8138
|
-
}
|
|
8139
|
-
|
|
8140
|
-
return val
|
|
8141
|
-
};
|
|
8142
|
-
|
|
8143
|
-
Buffer.prototype.readUint8 =
|
|
8144
|
-
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
|
|
8145
|
-
offset = offset >>> 0;
|
|
8146
|
-
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
8147
|
-
return this[offset]
|
|
8148
|
-
};
|
|
8149
|
-
|
|
8150
|
-
Buffer.prototype.readUint16LE =
|
|
8151
|
-
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
|
|
8152
|
-
offset = offset >>> 0;
|
|
8153
|
-
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
8154
|
-
return this[offset] | (this[offset + 1] << 8)
|
|
8155
|
-
};
|
|
8156
|
-
|
|
8157
|
-
Buffer.prototype.readUint16BE =
|
|
8158
|
-
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
|
|
8159
|
-
offset = offset >>> 0;
|
|
8160
|
-
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
8161
|
-
return (this[offset] << 8) | this[offset + 1]
|
|
8162
|
-
};
|
|
8163
|
-
|
|
8164
|
-
Buffer.prototype.readUint32LE =
|
|
8165
|
-
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
|
|
8166
|
-
offset = offset >>> 0;
|
|
8167
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
8168
|
-
|
|
8169
|
-
return ((this[offset]) |
|
|
8170
|
-
(this[offset + 1] << 8) |
|
|
8171
|
-
(this[offset + 2] << 16)) +
|
|
8172
|
-
(this[offset + 3] * 0x1000000)
|
|
8173
|
-
};
|
|
8174
|
-
|
|
8175
|
-
Buffer.prototype.readUint32BE =
|
|
8176
|
-
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
|
|
8177
|
-
offset = offset >>> 0;
|
|
8178
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
8179
|
-
|
|
8180
|
-
return (this[offset] * 0x1000000) +
|
|
8181
|
-
((this[offset + 1] << 16) |
|
|
8182
|
-
(this[offset + 2] << 8) |
|
|
8183
|
-
this[offset + 3])
|
|
8184
|
-
};
|
|
8185
|
-
|
|
8186
|
-
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
|
|
8187
|
-
offset = offset >>> 0;
|
|
8188
|
-
byteLength = byteLength >>> 0;
|
|
8189
|
-
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
8190
|
-
|
|
8191
|
-
var val = this[offset];
|
|
8192
|
-
var mul = 1;
|
|
8193
|
-
var i = 0;
|
|
8194
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
|
8195
|
-
val += this[offset + i] * mul;
|
|
8196
|
-
}
|
|
8197
|
-
mul *= 0x80;
|
|
8198
|
-
|
|
8199
|
-
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
|
|
8200
|
-
|
|
8201
|
-
return val
|
|
8202
|
-
};
|
|
8203
|
-
|
|
8204
|
-
Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
|
|
8205
|
-
offset = offset >>> 0;
|
|
8206
|
-
byteLength = byteLength >>> 0;
|
|
8207
|
-
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
8208
|
-
|
|
8209
|
-
var i = byteLength;
|
|
8210
|
-
var mul = 1;
|
|
8211
|
-
var val = this[offset + --i];
|
|
8212
|
-
while (i > 0 && (mul *= 0x100)) {
|
|
8213
|
-
val += this[offset + --i] * mul;
|
|
8214
|
-
}
|
|
8215
|
-
mul *= 0x80;
|
|
8216
|
-
|
|
8217
|
-
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
|
|
8218
|
-
|
|
8219
|
-
return val
|
|
8220
|
-
};
|
|
8221
|
-
|
|
8222
|
-
Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
|
|
8223
|
-
offset = offset >>> 0;
|
|
8224
|
-
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
8225
|
-
if (!(this[offset] & 0x80)) return (this[offset])
|
|
8226
|
-
return ((0xff - this[offset] + 1) * -1)
|
|
8227
|
-
};
|
|
8228
|
-
|
|
8229
|
-
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
|
|
8230
|
-
offset = offset >>> 0;
|
|
8231
|
-
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
8232
|
-
var val = this[offset] | (this[offset + 1] << 8);
|
|
8233
|
-
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
8234
|
-
};
|
|
8235
|
-
|
|
8236
|
-
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
|
|
8237
|
-
offset = offset >>> 0;
|
|
8238
|
-
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
8239
|
-
var val = this[offset + 1] | (this[offset] << 8);
|
|
8240
|
-
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
8241
|
-
};
|
|
8242
|
-
|
|
8243
|
-
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
|
|
8244
|
-
offset = offset >>> 0;
|
|
8245
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
8246
|
-
|
|
8247
|
-
return (this[offset]) |
|
|
8248
|
-
(this[offset + 1] << 8) |
|
|
8249
|
-
(this[offset + 2] << 16) |
|
|
8250
|
-
(this[offset + 3] << 24)
|
|
8251
|
-
};
|
|
8252
|
-
|
|
8253
|
-
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
|
|
8254
|
-
offset = offset >>> 0;
|
|
8255
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
8256
|
-
|
|
8257
|
-
return (this[offset] << 24) |
|
|
8258
|
-
(this[offset + 1] << 16) |
|
|
8259
|
-
(this[offset + 2] << 8) |
|
|
8260
|
-
(this[offset + 3])
|
|
8261
|
-
};
|
|
8262
|
-
|
|
8263
|
-
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
|
|
8264
|
-
offset = offset >>> 0;
|
|
8265
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
8266
|
-
return ieee754.read(this, offset, true, 23, 4)
|
|
8267
|
-
};
|
|
8268
|
-
|
|
8269
|
-
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
|
|
8270
|
-
offset = offset >>> 0;
|
|
8271
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
8272
|
-
return ieee754.read(this, offset, false, 23, 4)
|
|
8273
|
-
};
|
|
8274
|
-
|
|
8275
|
-
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
|
|
8276
|
-
offset = offset >>> 0;
|
|
8277
|
-
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
8278
|
-
return ieee754.read(this, offset, true, 52, 8)
|
|
8279
|
-
};
|
|
8280
|
-
|
|
8281
|
-
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
|
|
8282
|
-
offset = offset >>> 0;
|
|
8283
|
-
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
8284
|
-
return ieee754.read(this, offset, false, 52, 8)
|
|
8285
|
-
};
|
|
8286
|
-
|
|
8287
|
-
function checkInt (buf, value, offset, ext, max, min) {
|
|
8288
|
-
if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
|
|
8289
|
-
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
|
|
8290
|
-
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
8291
|
-
}
|
|
8292
|
-
|
|
8293
|
-
Buffer.prototype.writeUintLE =
|
|
8294
|
-
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
|
|
8295
|
-
value = +value;
|
|
8296
|
-
offset = offset >>> 0;
|
|
8297
|
-
byteLength = byteLength >>> 0;
|
|
8298
|
-
if (!noAssert) {
|
|
8299
|
-
var maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
8300
|
-
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
8301
|
-
}
|
|
8302
|
-
|
|
8303
|
-
var mul = 1;
|
|
8304
|
-
var i = 0;
|
|
8305
|
-
this[offset] = value & 0xFF;
|
|
8306
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
|
8307
|
-
this[offset + i] = (value / mul) & 0xFF;
|
|
8308
|
-
}
|
|
8309
|
-
|
|
8310
|
-
return offset + byteLength
|
|
8311
|
-
};
|
|
8312
|
-
|
|
8313
|
-
Buffer.prototype.writeUintBE =
|
|
8314
|
-
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
|
|
8315
|
-
value = +value;
|
|
8316
|
-
offset = offset >>> 0;
|
|
8317
|
-
byteLength = byteLength >>> 0;
|
|
8318
|
-
if (!noAssert) {
|
|
8319
|
-
var maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
8320
|
-
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
8321
|
-
}
|
|
8322
|
-
|
|
8323
|
-
var i = byteLength - 1;
|
|
8324
|
-
var mul = 1;
|
|
8325
|
-
this[offset + i] = value & 0xFF;
|
|
8326
|
-
while (--i >= 0 && (mul *= 0x100)) {
|
|
8327
|
-
this[offset + i] = (value / mul) & 0xFF;
|
|
8328
|
-
}
|
|
8329
|
-
|
|
8330
|
-
return offset + byteLength
|
|
8331
|
-
};
|
|
8332
|
-
|
|
8333
|
-
Buffer.prototype.writeUint8 =
|
|
8334
|
-
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
|
|
8335
|
-
value = +value;
|
|
8336
|
-
offset = offset >>> 0;
|
|
8337
|
-
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
|
|
8338
|
-
this[offset] = (value & 0xff);
|
|
8339
|
-
return offset + 1
|
|
8340
|
-
};
|
|
8341
|
-
|
|
8342
|
-
Buffer.prototype.writeUint16LE =
|
|
8343
|
-
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
|
|
8344
|
-
value = +value;
|
|
8345
|
-
offset = offset >>> 0;
|
|
8346
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
|
8347
|
-
this[offset] = (value & 0xff);
|
|
8348
|
-
this[offset + 1] = (value >>> 8);
|
|
8349
|
-
return offset + 2
|
|
8350
|
-
};
|
|
8351
|
-
|
|
8352
|
-
Buffer.prototype.writeUint16BE =
|
|
8353
|
-
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
|
|
8354
|
-
value = +value;
|
|
8355
|
-
offset = offset >>> 0;
|
|
8356
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
|
8357
|
-
this[offset] = (value >>> 8);
|
|
8358
|
-
this[offset + 1] = (value & 0xff);
|
|
8359
|
-
return offset + 2
|
|
8360
|
-
};
|
|
8361
|
-
|
|
8362
|
-
Buffer.prototype.writeUint32LE =
|
|
8363
|
-
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
|
|
8364
|
-
value = +value;
|
|
8365
|
-
offset = offset >>> 0;
|
|
8366
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
8367
|
-
this[offset + 3] = (value >>> 24);
|
|
8368
|
-
this[offset + 2] = (value >>> 16);
|
|
8369
|
-
this[offset + 1] = (value >>> 8);
|
|
8370
|
-
this[offset] = (value & 0xff);
|
|
8371
|
-
return offset + 4
|
|
8372
|
-
};
|
|
8373
|
-
|
|
8374
|
-
Buffer.prototype.writeUint32BE =
|
|
8375
|
-
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
|
|
8376
|
-
value = +value;
|
|
8377
|
-
offset = offset >>> 0;
|
|
8378
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
8379
|
-
this[offset] = (value >>> 24);
|
|
8380
|
-
this[offset + 1] = (value >>> 16);
|
|
8381
|
-
this[offset + 2] = (value >>> 8);
|
|
8382
|
-
this[offset + 3] = (value & 0xff);
|
|
8383
|
-
return offset + 4
|
|
8384
|
-
};
|
|
8385
|
-
|
|
8386
|
-
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
|
|
8387
|
-
value = +value;
|
|
8388
|
-
offset = offset >>> 0;
|
|
8389
|
-
if (!noAssert) {
|
|
8390
|
-
var limit = Math.pow(2, (8 * byteLength) - 1);
|
|
8391
|
-
|
|
8392
|
-
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
8393
|
-
}
|
|
8394
|
-
|
|
8395
|
-
var i = 0;
|
|
8396
|
-
var mul = 1;
|
|
8397
|
-
var sub = 0;
|
|
8398
|
-
this[offset] = value & 0xFF;
|
|
8399
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
|
8400
|
-
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
8401
|
-
sub = 1;
|
|
8402
|
-
}
|
|
8403
|
-
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
|
|
8404
|
-
}
|
|
8405
|
-
|
|
8406
|
-
return offset + byteLength
|
|
8407
|
-
};
|
|
8408
|
-
|
|
8409
|
-
Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
|
|
8410
|
-
value = +value;
|
|
8411
|
-
offset = offset >>> 0;
|
|
8412
|
-
if (!noAssert) {
|
|
8413
|
-
var limit = Math.pow(2, (8 * byteLength) - 1);
|
|
8414
|
-
|
|
8415
|
-
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
8416
|
-
}
|
|
8417
|
-
|
|
8418
|
-
var i = byteLength - 1;
|
|
8419
|
-
var mul = 1;
|
|
8420
|
-
var sub = 0;
|
|
8421
|
-
this[offset + i] = value & 0xFF;
|
|
8422
|
-
while (--i >= 0 && (mul *= 0x100)) {
|
|
8423
|
-
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
8424
|
-
sub = 1;
|
|
8425
|
-
}
|
|
8426
|
-
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
|
|
8427
|
-
}
|
|
8428
|
-
|
|
8429
|
-
return offset + byteLength
|
|
8430
|
-
};
|
|
8431
|
-
|
|
8432
|
-
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
|
|
8433
|
-
value = +value;
|
|
8434
|
-
offset = offset >>> 0;
|
|
8435
|
-
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
|
|
8436
|
-
if (value < 0) value = 0xff + value + 1;
|
|
8437
|
-
this[offset] = (value & 0xff);
|
|
8438
|
-
return offset + 1
|
|
8439
|
-
};
|
|
8440
|
-
|
|
8441
|
-
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
|
|
8442
|
-
value = +value;
|
|
8443
|
-
offset = offset >>> 0;
|
|
8444
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
|
|
8445
|
-
this[offset] = (value & 0xff);
|
|
8446
|
-
this[offset + 1] = (value >>> 8);
|
|
8447
|
-
return offset + 2
|
|
8448
|
-
};
|
|
8449
|
-
|
|
8450
|
-
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
|
|
8451
|
-
value = +value;
|
|
8452
|
-
offset = offset >>> 0;
|
|
8453
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
|
|
8454
|
-
this[offset] = (value >>> 8);
|
|
8455
|
-
this[offset + 1] = (value & 0xff);
|
|
8456
|
-
return offset + 2
|
|
8457
|
-
};
|
|
8458
|
-
|
|
8459
|
-
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
|
|
8460
|
-
value = +value;
|
|
8461
|
-
offset = offset >>> 0;
|
|
8462
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
|
|
8463
|
-
this[offset] = (value & 0xff);
|
|
8464
|
-
this[offset + 1] = (value >>> 8);
|
|
8465
|
-
this[offset + 2] = (value >>> 16);
|
|
8466
|
-
this[offset + 3] = (value >>> 24);
|
|
8467
|
-
return offset + 4
|
|
8468
|
-
};
|
|
8469
|
-
|
|
8470
|
-
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
|
|
8471
|
-
value = +value;
|
|
8472
|
-
offset = offset >>> 0;
|
|
8473
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
|
|
8474
|
-
if (value < 0) value = 0xffffffff + value + 1;
|
|
8475
|
-
this[offset] = (value >>> 24);
|
|
8476
|
-
this[offset + 1] = (value >>> 16);
|
|
8477
|
-
this[offset + 2] = (value >>> 8);
|
|
8478
|
-
this[offset + 3] = (value & 0xff);
|
|
8479
|
-
return offset + 4
|
|
8480
|
-
};
|
|
8481
|
-
|
|
8482
|
-
function checkIEEE754 (buf, value, offset, ext, max, min) {
|
|
8483
|
-
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
8484
|
-
if (offset < 0) throw new RangeError('Index out of range')
|
|
8485
|
-
}
|
|
8486
|
-
|
|
8487
|
-
function writeFloat (buf, value, offset, littleEndian, noAssert) {
|
|
8488
|
-
value = +value;
|
|
8489
|
-
offset = offset >>> 0;
|
|
8490
|
-
if (!noAssert) {
|
|
8491
|
-
checkIEEE754(buf, value, offset, 4);
|
|
8492
|
-
}
|
|
8493
|
-
ieee754.write(buf, value, offset, littleEndian, 23, 4);
|
|
8494
|
-
return offset + 4
|
|
8495
|
-
}
|
|
8496
|
-
|
|
8497
|
-
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
|
|
8498
|
-
return writeFloat(this, value, offset, true, noAssert)
|
|
8499
|
-
};
|
|
8500
|
-
|
|
8501
|
-
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
|
|
8502
|
-
return writeFloat(this, value, offset, false, noAssert)
|
|
8503
|
-
};
|
|
8504
|
-
|
|
8505
|
-
function writeDouble (buf, value, offset, littleEndian, noAssert) {
|
|
8506
|
-
value = +value;
|
|
8507
|
-
offset = offset >>> 0;
|
|
8508
|
-
if (!noAssert) {
|
|
8509
|
-
checkIEEE754(buf, value, offset, 8);
|
|
8510
|
-
}
|
|
8511
|
-
ieee754.write(buf, value, offset, littleEndian, 52, 8);
|
|
8512
|
-
return offset + 8
|
|
8513
|
-
}
|
|
8514
|
-
|
|
8515
|
-
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
|
|
8516
|
-
return writeDouble(this, value, offset, true, noAssert)
|
|
8517
|
-
};
|
|
8518
|
-
|
|
8519
|
-
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
|
|
8520
|
-
return writeDouble(this, value, offset, false, noAssert)
|
|
8521
|
-
};
|
|
8522
|
-
|
|
8523
|
-
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
|
|
8524
|
-
Buffer.prototype.copy = function copy (target, targetStart, start, end) {
|
|
8525
|
-
if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
|
|
8526
|
-
if (!start) start = 0;
|
|
8527
|
-
if (!end && end !== 0) end = this.length;
|
|
8528
|
-
if (targetStart >= target.length) targetStart = target.length;
|
|
8529
|
-
if (!targetStart) targetStart = 0;
|
|
8530
|
-
if (end > 0 && end < start) end = start;
|
|
8531
|
-
|
|
8532
|
-
// Copy 0 bytes; we're done
|
|
8533
|
-
if (end === start) return 0
|
|
8534
|
-
if (target.length === 0 || this.length === 0) return 0
|
|
8535
|
-
|
|
8536
|
-
// Fatal error conditions
|
|
8537
|
-
if (targetStart < 0) {
|
|
8538
|
-
throw new RangeError('targetStart out of bounds')
|
|
8539
|
-
}
|
|
8540
|
-
if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
|
|
8541
|
-
if (end < 0) throw new RangeError('sourceEnd out of bounds')
|
|
8542
|
-
|
|
8543
|
-
// Are we oob?
|
|
8544
|
-
if (end > this.length) end = this.length;
|
|
8545
|
-
if (target.length - targetStart < end - start) {
|
|
8546
|
-
end = target.length - targetStart + start;
|
|
8547
|
-
}
|
|
8548
|
-
|
|
8549
|
-
var len = end - start;
|
|
8550
|
-
|
|
8551
|
-
if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
|
|
8552
|
-
// Use built-in when available, missing from IE11
|
|
8553
|
-
this.copyWithin(targetStart, start, end);
|
|
8554
|
-
} else {
|
|
8555
|
-
Uint8Array.prototype.set.call(
|
|
8556
|
-
target,
|
|
8557
|
-
this.subarray(start, end),
|
|
8558
|
-
targetStart
|
|
8559
|
-
);
|
|
8560
|
-
}
|
|
8561
|
-
|
|
8562
|
-
return len
|
|
8563
|
-
};
|
|
8564
|
-
|
|
8565
|
-
// Usage:
|
|
8566
|
-
// buffer.fill(number[, offset[, end]])
|
|
8567
|
-
// buffer.fill(buffer[, offset[, end]])
|
|
8568
|
-
// buffer.fill(string[, offset[, end]][, encoding])
|
|
8569
|
-
Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
|
8570
|
-
// Handle string cases:
|
|
8571
|
-
if (typeof val === 'string') {
|
|
8572
|
-
if (typeof start === 'string') {
|
|
8573
|
-
encoding = start;
|
|
8574
|
-
start = 0;
|
|
8575
|
-
end = this.length;
|
|
8576
|
-
} else if (typeof end === 'string') {
|
|
8577
|
-
encoding = end;
|
|
8578
|
-
end = this.length;
|
|
8579
|
-
}
|
|
8580
|
-
if (encoding !== undefined && typeof encoding !== 'string') {
|
|
8581
|
-
throw new TypeError('encoding must be a string')
|
|
8582
|
-
}
|
|
8583
|
-
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
|
8584
|
-
throw new TypeError('Unknown encoding: ' + encoding)
|
|
8585
|
-
}
|
|
8586
|
-
if (val.length === 1) {
|
|
8587
|
-
var code = val.charCodeAt(0);
|
|
8588
|
-
if ((encoding === 'utf8' && code < 128) ||
|
|
8589
|
-
encoding === 'latin1') {
|
|
8590
|
-
// Fast path: If `val` fits into a single byte, use that numeric value.
|
|
8591
|
-
val = code;
|
|
8592
|
-
}
|
|
8593
|
-
}
|
|
8594
|
-
} else if (typeof val === 'number') {
|
|
8595
|
-
val = val & 255;
|
|
8596
|
-
} else if (typeof val === 'boolean') {
|
|
8597
|
-
val = Number(val);
|
|
8598
|
-
}
|
|
8599
|
-
|
|
8600
|
-
// Invalid ranges are not set to a default, so can range check early.
|
|
8601
|
-
if (start < 0 || this.length < start || this.length < end) {
|
|
8602
|
-
throw new RangeError('Out of range index')
|
|
8603
|
-
}
|
|
8604
|
-
|
|
8605
|
-
if (end <= start) {
|
|
8606
|
-
return this
|
|
8607
|
-
}
|
|
8608
|
-
|
|
8609
|
-
start = start >>> 0;
|
|
8610
|
-
end = end === undefined ? this.length : end >>> 0;
|
|
8611
|
-
|
|
8612
|
-
if (!val) val = 0;
|
|
8613
|
-
|
|
8614
|
-
var i;
|
|
8615
|
-
if (typeof val === 'number') {
|
|
8616
|
-
for (i = start; i < end; ++i) {
|
|
8617
|
-
this[i] = val;
|
|
8618
|
-
}
|
|
8619
|
-
} else {
|
|
8620
|
-
var bytes = Buffer.isBuffer(val)
|
|
6651
|
+
const bytes = Buffer.isBuffer(val)
|
|
8621
6652
|
? val
|
|
8622
6653
|
: Buffer.from(val, encoding);
|
|
8623
|
-
|
|
6654
|
+
const len = bytes.length;
|
|
8624
6655
|
if (len === 0) {
|
|
8625
6656
|
throw new TypeError('The value "' + val +
|
|
8626
6657
|
'" is invalid for argument "value"')
|
|
@@ -8633,10 +6664,141 @@ function requireBuffer () {
|
|
|
8633
6664
|
return this
|
|
8634
6665
|
};
|
|
8635
6666
|
|
|
6667
|
+
// CUSTOM ERRORS
|
|
6668
|
+
// =============
|
|
6669
|
+
|
|
6670
|
+
// Simplified versions from Node, changed for Buffer-only usage
|
|
6671
|
+
const errors = {};
|
|
6672
|
+
function E (sym, getMessage, Base) {
|
|
6673
|
+
errors[sym] = class NodeError extends Base {
|
|
6674
|
+
constructor () {
|
|
6675
|
+
super();
|
|
6676
|
+
|
|
6677
|
+
Object.defineProperty(this, 'message', {
|
|
6678
|
+
value: getMessage.apply(this, arguments),
|
|
6679
|
+
writable: true,
|
|
6680
|
+
configurable: true
|
|
6681
|
+
});
|
|
6682
|
+
|
|
6683
|
+
// Add the error code to the name to include it in the stack trace.
|
|
6684
|
+
this.name = `${this.name} [${sym}]`;
|
|
6685
|
+
// Access the stack to generate the error message including the error code
|
|
6686
|
+
// from the name.
|
|
6687
|
+
this.stack; // eslint-disable-line no-unused-expressions
|
|
6688
|
+
// Reset the name to the actual name.
|
|
6689
|
+
delete this.name;
|
|
6690
|
+
}
|
|
6691
|
+
|
|
6692
|
+
get code () {
|
|
6693
|
+
return sym
|
|
6694
|
+
}
|
|
6695
|
+
|
|
6696
|
+
set code (value) {
|
|
6697
|
+
Object.defineProperty(this, 'code', {
|
|
6698
|
+
configurable: true,
|
|
6699
|
+
enumerable: true,
|
|
6700
|
+
value,
|
|
6701
|
+
writable: true
|
|
6702
|
+
});
|
|
6703
|
+
}
|
|
6704
|
+
|
|
6705
|
+
toString () {
|
|
6706
|
+
return `${this.name} [${sym}]: ${this.message}`
|
|
6707
|
+
}
|
|
6708
|
+
};
|
|
6709
|
+
}
|
|
6710
|
+
|
|
6711
|
+
E('ERR_BUFFER_OUT_OF_BOUNDS',
|
|
6712
|
+
function (name) {
|
|
6713
|
+
if (name) {
|
|
6714
|
+
return `${name} is outside of buffer bounds`
|
|
6715
|
+
}
|
|
6716
|
+
|
|
6717
|
+
return 'Attempt to access memory outside buffer bounds'
|
|
6718
|
+
}, RangeError);
|
|
6719
|
+
E('ERR_INVALID_ARG_TYPE',
|
|
6720
|
+
function (name, actual) {
|
|
6721
|
+
return `The "${name}" argument must be of type number. Received type ${typeof actual}`
|
|
6722
|
+
}, TypeError);
|
|
6723
|
+
E('ERR_OUT_OF_RANGE',
|
|
6724
|
+
function (str, range, input) {
|
|
6725
|
+
let msg = `The value of "${str}" is out of range.`;
|
|
6726
|
+
let received = input;
|
|
6727
|
+
if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
|
|
6728
|
+
received = addNumericalSeparator(String(input));
|
|
6729
|
+
} else if (typeof input === 'bigint') {
|
|
6730
|
+
received = String(input);
|
|
6731
|
+
if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
|
|
6732
|
+
received = addNumericalSeparator(received);
|
|
6733
|
+
}
|
|
6734
|
+
received += 'n';
|
|
6735
|
+
}
|
|
6736
|
+
msg += ` It must be ${range}. Received ${received}`;
|
|
6737
|
+
return msg
|
|
6738
|
+
}, RangeError);
|
|
6739
|
+
|
|
6740
|
+
function addNumericalSeparator (val) {
|
|
6741
|
+
let res = '';
|
|
6742
|
+
let i = val.length;
|
|
6743
|
+
const start = val[0] === '-' ? 1 : 0;
|
|
6744
|
+
for (; i >= start + 4; i -= 3) {
|
|
6745
|
+
res = `_${val.slice(i - 3, i)}${res}`;
|
|
6746
|
+
}
|
|
6747
|
+
return `${val.slice(0, i)}${res}`
|
|
6748
|
+
}
|
|
6749
|
+
|
|
6750
|
+
// CHECK FUNCTIONS
|
|
6751
|
+
// ===============
|
|
6752
|
+
|
|
6753
|
+
function checkBounds (buf, offset, byteLength) {
|
|
6754
|
+
validateNumber(offset, 'offset');
|
|
6755
|
+
if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
|
|
6756
|
+
boundsError(offset, buf.length - (byteLength + 1));
|
|
6757
|
+
}
|
|
6758
|
+
}
|
|
6759
|
+
|
|
6760
|
+
function checkIntBI (value, min, max, buf, offset, byteLength) {
|
|
6761
|
+
if (value > max || value < min) {
|
|
6762
|
+
const n = typeof min === 'bigint' ? 'n' : '';
|
|
6763
|
+
let range;
|
|
6764
|
+
{
|
|
6765
|
+
if (min === 0 || min === BigInt(0)) {
|
|
6766
|
+
range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;
|
|
6767
|
+
} else {
|
|
6768
|
+
range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
|
|
6769
|
+
`${(byteLength + 1) * 8 - 1}${n}`;
|
|
6770
|
+
}
|
|
6771
|
+
}
|
|
6772
|
+
throw new errors.ERR_OUT_OF_RANGE('value', range, value)
|
|
6773
|
+
}
|
|
6774
|
+
checkBounds(buf, offset, byteLength);
|
|
6775
|
+
}
|
|
6776
|
+
|
|
6777
|
+
function validateNumber (value, name) {
|
|
6778
|
+
if (typeof value !== 'number') {
|
|
6779
|
+
throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
|
|
6780
|
+
}
|
|
6781
|
+
}
|
|
6782
|
+
|
|
6783
|
+
function boundsError (value, length, type) {
|
|
6784
|
+
if (Math.floor(value) !== value) {
|
|
6785
|
+
validateNumber(value, type);
|
|
6786
|
+
throw new errors.ERR_OUT_OF_RANGE('offset', 'an integer', value)
|
|
6787
|
+
}
|
|
6788
|
+
|
|
6789
|
+
if (length < 0) {
|
|
6790
|
+
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
|
|
6791
|
+
}
|
|
6792
|
+
|
|
6793
|
+
throw new errors.ERR_OUT_OF_RANGE('offset',
|
|
6794
|
+
`>= ${0} and <= ${length}`,
|
|
6795
|
+
value)
|
|
6796
|
+
}
|
|
6797
|
+
|
|
8636
6798
|
// HELPER FUNCTIONS
|
|
8637
6799
|
// ================
|
|
8638
6800
|
|
|
8639
|
-
|
|
6801
|
+
const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
|
8640
6802
|
|
|
8641
6803
|
function base64clean (str) {
|
|
8642
6804
|
// Node takes equal signs as end of the Base64 encoding
|
|
@@ -8654,12 +6816,12 @@ function requireBuffer () {
|
|
|
8654
6816
|
|
|
8655
6817
|
function utf8ToBytes (string, units) {
|
|
8656
6818
|
units = units || Infinity;
|
|
8657
|
-
|
|
8658
|
-
|
|
8659
|
-
|
|
8660
|
-
|
|
6819
|
+
let codePoint;
|
|
6820
|
+
const length = string.length;
|
|
6821
|
+
let leadSurrogate = null;
|
|
6822
|
+
const bytes = [];
|
|
8661
6823
|
|
|
8662
|
-
for (
|
|
6824
|
+
for (let i = 0; i < length; ++i) {
|
|
8663
6825
|
codePoint = string.charCodeAt(i);
|
|
8664
6826
|
|
|
8665
6827
|
// is surrogate component
|
|
@@ -8733,8 +6895,8 @@ function requireBuffer () {
|
|
|
8733
6895
|
}
|
|
8734
6896
|
|
|
8735
6897
|
function asciiToBytes (str) {
|
|
8736
|
-
|
|
8737
|
-
for (
|
|
6898
|
+
const byteArray = [];
|
|
6899
|
+
for (let i = 0; i < str.length; ++i) {
|
|
8738
6900
|
// Node's code seems to be doing this and not & 0x7F..
|
|
8739
6901
|
byteArray.push(str.charCodeAt(i) & 0xFF);
|
|
8740
6902
|
}
|
|
@@ -8742,9 +6904,9 @@ function requireBuffer () {
|
|
|
8742
6904
|
}
|
|
8743
6905
|
|
|
8744
6906
|
function utf16leToBytes (str, units) {
|
|
8745
|
-
|
|
8746
|
-
|
|
8747
|
-
for (
|
|
6907
|
+
let c, hi, lo;
|
|
6908
|
+
const byteArray = [];
|
|
6909
|
+
for (let i = 0; i < str.length; ++i) {
|
|
8748
6910
|
if ((units -= 2) < 0) break
|
|
8749
6911
|
|
|
8750
6912
|
c = str.charCodeAt(i);
|
|
@@ -8762,7 +6924,8 @@ function requireBuffer () {
|
|
|
8762
6924
|
}
|
|
8763
6925
|
|
|
8764
6926
|
function blitBuffer (src, dst, offset, length) {
|
|
8765
|
-
|
|
6927
|
+
let i;
|
|
6928
|
+
for (i = 0; i < length; ++i) {
|
|
8766
6929
|
if ((i + offset >= dst.length) || (i >= src.length)) break
|
|
8767
6930
|
dst[i + offset] = src[i];
|
|
8768
6931
|
}
|
|
@@ -8784,23 +6947,34 @@ function requireBuffer () {
|
|
|
8784
6947
|
|
|
8785
6948
|
// Create lookup table for `toString('hex')`
|
|
8786
6949
|
// See: https://github.com/feross/buffer/issues/219
|
|
8787
|
-
|
|
8788
|
-
|
|
8789
|
-
|
|
8790
|
-
for (
|
|
8791
|
-
|
|
8792
|
-
for (
|
|
6950
|
+
const hexSliceLookupTable = (function () {
|
|
6951
|
+
const alphabet = '0123456789abcdef';
|
|
6952
|
+
const table = new Array(256);
|
|
6953
|
+
for (let i = 0; i < 16; ++i) {
|
|
6954
|
+
const i16 = i * 16;
|
|
6955
|
+
for (let j = 0; j < 16; ++j) {
|
|
8793
6956
|
table[i16 + j] = alphabet[i] + alphabet[j];
|
|
8794
6957
|
}
|
|
8795
6958
|
}
|
|
8796
6959
|
return table
|
|
8797
|
-
})();
|
|
6960
|
+
})();
|
|
6961
|
+
|
|
6962
|
+
// Return not function with Error if BigInt not supported
|
|
6963
|
+
function defineBigIntMethod (fn) {
|
|
6964
|
+
return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
|
|
6965
|
+
}
|
|
6966
|
+
|
|
6967
|
+
function BufferBigIntNotDefined () {
|
|
6968
|
+
throw new Error('BigInt not supported')
|
|
6969
|
+
}
|
|
8798
6970
|
} (buffer));
|
|
8799
6971
|
return buffer;
|
|
8800
6972
|
}
|
|
8801
6973
|
|
|
8802
6974
|
var bufferExports = requireBuffer();
|
|
8803
6975
|
|
|
6976
|
+
var dist = {};
|
|
6977
|
+
|
|
8804
6978
|
var Codecs = {};
|
|
8805
6979
|
|
|
8806
6980
|
var Frames = {};
|
|
@@ -13583,7 +11757,7 @@ function requireDist () {
|
|
|
13583
11757
|
|
|
13584
11758
|
var distExports = requireDist();
|
|
13585
11759
|
|
|
13586
|
-
var version = "1.
|
|
11760
|
+
var version = "1.46.0";
|
|
13587
11761
|
var PACKAGE = {
|
|
13588
11762
|
version: version};
|
|
13589
11763
|
|
|
@@ -13654,6 +11828,16 @@ class DataStream extends BaseObserver {
|
|
|
13654
11828
|
* @returns a Data payload or Null if the stream closed.
|
|
13655
11829
|
*/
|
|
13656
11830
|
async read() {
|
|
11831
|
+
if (this.closed) {
|
|
11832
|
+
return null;
|
|
11833
|
+
}
|
|
11834
|
+
// Wait for any pending processing to complete first.
|
|
11835
|
+
// This ensures we register our listener before calling processQueue(),
|
|
11836
|
+
// avoiding a race where processQueue() sees no reader and returns early.
|
|
11837
|
+
if (this.processingPromise) {
|
|
11838
|
+
await this.processingPromise;
|
|
11839
|
+
}
|
|
11840
|
+
// Re-check after await - stream may have closed while we were waiting
|
|
13657
11841
|
if (this.closed) {
|
|
13658
11842
|
return null;
|
|
13659
11843
|
}
|
|
@@ -13693,7 +11877,7 @@ class DataStream extends BaseObserver {
|
|
|
13693
11877
|
}
|
|
13694
11878
|
const promise = (this.processingPromise = this._processQueue());
|
|
13695
11879
|
promise.finally(() => {
|
|
13696
|
-
|
|
11880
|
+
this.processingPromise = null;
|
|
13697
11881
|
});
|
|
13698
11882
|
return promise;
|
|
13699
11883
|
}
|
|
@@ -13725,7 +11909,6 @@ class DataStream extends BaseObserver {
|
|
|
13725
11909
|
this.notifyDataAdded = null;
|
|
13726
11910
|
}
|
|
13727
11911
|
if (this.dataQueue.length > 0) {
|
|
13728
|
-
// Next tick
|
|
13729
11912
|
setTimeout(() => this.processQueue());
|
|
13730
11913
|
}
|
|
13731
11914
|
}
|
|
@@ -14105,7 +12288,7 @@ class AbstractRemote {
|
|
|
14105
12288
|
else {
|
|
14106
12289
|
contents = JSON.stringify(js);
|
|
14107
12290
|
}
|
|
14108
|
-
return bufferExports
|
|
12291
|
+
return bufferExports.Buffer.from(contents);
|
|
14109
12292
|
}
|
|
14110
12293
|
const syncQueueRequestSize = fetchStrategy == FetchStrategy.Buffered ? 10 : 1;
|
|
14111
12294
|
const request = await this.buildRequest(path);
|
|
@@ -14345,7 +12528,11 @@ class AbstractRemote {
|
|
|
14345
12528
|
};
|
|
14346
12529
|
const stream = new DataStream({
|
|
14347
12530
|
logger: this.logger,
|
|
14348
|
-
mapLine: mapLine
|
|
12531
|
+
mapLine: mapLine,
|
|
12532
|
+
pressure: {
|
|
12533
|
+
highWaterMark: 20,
|
|
12534
|
+
lowWaterMark: 10
|
|
12535
|
+
}
|
|
14349
12536
|
});
|
|
14350
12537
|
abortSignal?.addEventListener('abort', () => {
|
|
14351
12538
|
closeReader();
|
|
@@ -14353,42 +12540,47 @@ class AbstractRemote {
|
|
|
14353
12540
|
});
|
|
14354
12541
|
const decoder = this.createTextDecoder();
|
|
14355
12542
|
let buffer = '';
|
|
14356
|
-
const
|
|
14357
|
-
|
|
14358
|
-
|
|
12543
|
+
const consumeStream = async () => {
|
|
12544
|
+
while (!stream.closed && !abortSignal?.aborted && !readerReleased) {
|
|
12545
|
+
const { done, value } = await reader.read();
|
|
12546
|
+
if (done) {
|
|
12547
|
+
const remaining = buffer.trim();
|
|
12548
|
+
if (remaining.length != 0) {
|
|
12549
|
+
stream.enqueueData(remaining);
|
|
12550
|
+
}
|
|
12551
|
+
stream.close();
|
|
12552
|
+
await closeReader();
|
|
14359
12553
|
return;
|
|
14360
12554
|
}
|
|
14361
|
-
|
|
14362
|
-
|
|
14363
|
-
|
|
14364
|
-
|
|
14365
|
-
|
|
14366
|
-
|
|
14367
|
-
|
|
14368
|
-
stream.enqueueData(remaining);
|
|
14369
|
-
}
|
|
14370
|
-
stream.close();
|
|
14371
|
-
await closeReader();
|
|
14372
|
-
return;
|
|
14373
|
-
}
|
|
14374
|
-
const data = decoder.decode(value, { stream: true });
|
|
14375
|
-
buffer += data;
|
|
14376
|
-
const lines = buffer.split('\n');
|
|
14377
|
-
for (var i = 0; i < lines.length - 1; i++) {
|
|
14378
|
-
var l = lines[i].trim();
|
|
14379
|
-
if (l.length > 0) {
|
|
14380
|
-
stream.enqueueData(l);
|
|
14381
|
-
didCompleteLine = true;
|
|
14382
|
-
}
|
|
14383
|
-
}
|
|
14384
|
-
buffer = lines[lines.length - 1];
|
|
12555
|
+
const data = decoder.decode(value, { stream: true });
|
|
12556
|
+
buffer += data;
|
|
12557
|
+
const lines = buffer.split('\n');
|
|
12558
|
+
for (var i = 0; i < lines.length - 1; i++) {
|
|
12559
|
+
var l = lines[i].trim();
|
|
12560
|
+
if (l.length > 0) {
|
|
12561
|
+
stream.enqueueData(l);
|
|
14385
12562
|
}
|
|
14386
12563
|
}
|
|
14387
|
-
|
|
14388
|
-
|
|
14389
|
-
|
|
12564
|
+
buffer = lines[lines.length - 1];
|
|
12565
|
+
// Implement backpressure by waiting for the low water mark to be reached
|
|
12566
|
+
if (stream.dataQueue.length > stream.highWatermark) {
|
|
12567
|
+
await new Promise((resolve) => {
|
|
12568
|
+
const dispose = stream.registerListener({
|
|
12569
|
+
lowWater: async () => {
|
|
12570
|
+
resolve();
|
|
12571
|
+
dispose();
|
|
12572
|
+
},
|
|
12573
|
+
closed: () => {
|
|
12574
|
+
resolve();
|
|
12575
|
+
dispose();
|
|
12576
|
+
}
|
|
12577
|
+
});
|
|
12578
|
+
});
|
|
14390
12579
|
}
|
|
14391
|
-
}
|
|
12580
|
+
}
|
|
12581
|
+
};
|
|
12582
|
+
consumeStream().catch(ex => this.logger.error('Error consuming stream', ex));
|
|
12583
|
+
const l = stream.registerListener({
|
|
14392
12584
|
closed: () => {
|
|
14393
12585
|
closeReader();
|
|
14394
12586
|
l?.();
|
|
@@ -14467,18 +12659,17 @@ var SyncClientImplementation;
|
|
|
14467
12659
|
*
|
|
14468
12660
|
* This is the default option.
|
|
14469
12661
|
*
|
|
14470
|
-
* @deprecated
|
|
14471
|
-
*
|
|
14472
|
-
*
|
|
12662
|
+
* @deprecated We recommend the {@link RUST} client implementation for all apps. If you have issues with
|
|
12663
|
+
* the Rust client, please file an issue or reach out to us. The JavaScript client will be removed in a future
|
|
12664
|
+
* version of the PowerSync SDK.
|
|
14473
12665
|
*/
|
|
14474
12666
|
SyncClientImplementation["JAVASCRIPT"] = "js";
|
|
14475
12667
|
/**
|
|
14476
12668
|
* This implementation offloads the sync line decoding and handling into the PowerSync
|
|
14477
12669
|
* core extension.
|
|
14478
12670
|
*
|
|
14479
|
-
* @
|
|
14480
|
-
*
|
|
14481
|
-
* it has seen less real-world testing and is marked as __experimental__ at the moment.
|
|
12671
|
+
* This option is more performant than the {@link JAVASCRIPT} client, enabled by default and the
|
|
12672
|
+
* recommended client implementation for all apps.
|
|
14482
12673
|
*
|
|
14483
12674
|
* ## Compatibility warning
|
|
14484
12675
|
*
|
|
@@ -14496,13 +12687,9 @@ var SyncClientImplementation;
|
|
|
14496
12687
|
SyncClientImplementation["RUST"] = "rust";
|
|
14497
12688
|
})(SyncClientImplementation || (SyncClientImplementation = {}));
|
|
14498
12689
|
/**
|
|
14499
|
-
* The default {@link SyncClientImplementation} to use.
|
|
14500
|
-
*
|
|
14501
|
-
* Please use this field instead of {@link SyncClientImplementation.JAVASCRIPT} directly. A future version
|
|
14502
|
-
* of the PowerSync SDK will enable {@link SyncClientImplementation.RUST} by default and remove the JavaScript
|
|
14503
|
-
* option.
|
|
12690
|
+
* The default {@link SyncClientImplementation} to use, {@link SyncClientImplementation.RUST}.
|
|
14504
12691
|
*/
|
|
14505
|
-
const DEFAULT_SYNC_CLIENT_IMPLEMENTATION = SyncClientImplementation.
|
|
12692
|
+
const DEFAULT_SYNC_CLIENT_IMPLEMENTATION = SyncClientImplementation.RUST;
|
|
14506
12693
|
const DEFAULT_CRUD_UPLOAD_THROTTLE_MS = 1000;
|
|
14507
12694
|
const DEFAULT_RETRY_DELAY_MS = 5000;
|
|
14508
12695
|
const DEFAULT_STREAMING_SYNC_OPTIONS = {
|
|
@@ -14912,6 +13099,9 @@ The next upload iteration will be delayed.`);
|
|
|
14912
13099
|
if (rawTables != null && rawTables.length) {
|
|
14913
13100
|
this.logger.warn('Raw tables require the Rust-based sync client. The JS client will ignore them.');
|
|
14914
13101
|
}
|
|
13102
|
+
if (this.activeStreams.length) {
|
|
13103
|
+
this.logger.error('Sync streams require `clientImplementation: SyncClientImplementation.RUST` when connecting.');
|
|
13104
|
+
}
|
|
14915
13105
|
this.logger.debug('Streaming sync iteration started');
|
|
14916
13106
|
this.options.adapter.startSession();
|
|
14917
13107
|
let [req, bucketMap] = await this.collectLocalBucketState();
|
|
@@ -15427,6 +13617,27 @@ The next upload iteration will be delayed.`);
|
|
|
15427
13617
|
}
|
|
15428
13618
|
}
|
|
15429
13619
|
|
|
13620
|
+
const CLAIM_STORE = new Map();
|
|
13621
|
+
/**
|
|
13622
|
+
* @internal
|
|
13623
|
+
* @experimental
|
|
13624
|
+
*/
|
|
13625
|
+
const MEMORY_TRIGGER_CLAIM_MANAGER = {
|
|
13626
|
+
async obtainClaim(identifier) {
|
|
13627
|
+
if (CLAIM_STORE.has(identifier)) {
|
|
13628
|
+
throw new Error(`A claim is already present for ${identifier}`);
|
|
13629
|
+
}
|
|
13630
|
+
const release = async () => {
|
|
13631
|
+
CLAIM_STORE.delete(identifier);
|
|
13632
|
+
};
|
|
13633
|
+
CLAIM_STORE.set(identifier, release);
|
|
13634
|
+
return release;
|
|
13635
|
+
},
|
|
13636
|
+
async checkClaim(identifier) {
|
|
13637
|
+
return CLAIM_STORE.has(identifier);
|
|
13638
|
+
}
|
|
13639
|
+
};
|
|
13640
|
+
|
|
15430
13641
|
/**
|
|
15431
13642
|
* SQLite operations to track changes for with {@link TriggerManager}
|
|
15432
13643
|
* @experimental
|
|
@@ -15438,9 +13649,20 @@ var DiffTriggerOperation;
|
|
|
15438
13649
|
DiffTriggerOperation["DELETE"] = "DELETE";
|
|
15439
13650
|
})(DiffTriggerOperation || (DiffTriggerOperation = {}));
|
|
15440
13651
|
|
|
13652
|
+
const DEFAULT_TRIGGER_MANAGER_CONFIGURATION = {
|
|
13653
|
+
useStorageByDefault: false
|
|
13654
|
+
};
|
|
13655
|
+
const TRIGGER_CLEANUP_INTERVAL_MS = 120_000; // 2 minutes
|
|
13656
|
+
/**
|
|
13657
|
+
* @internal
|
|
13658
|
+
* @experimental
|
|
13659
|
+
*/
|
|
15441
13660
|
class TriggerManagerImpl {
|
|
15442
13661
|
options;
|
|
15443
13662
|
schema;
|
|
13663
|
+
defaultConfig;
|
|
13664
|
+
cleanupTimeout;
|
|
13665
|
+
isDisposed;
|
|
15444
13666
|
constructor(options) {
|
|
15445
13667
|
this.options = options;
|
|
15446
13668
|
this.schema = options.schema;
|
|
@@ -15449,6 +13671,33 @@ class TriggerManagerImpl {
|
|
|
15449
13671
|
this.schema = schema;
|
|
15450
13672
|
}
|
|
15451
13673
|
});
|
|
13674
|
+
this.isDisposed = false;
|
|
13675
|
+
/**
|
|
13676
|
+
* Configure a cleanup to run on an interval.
|
|
13677
|
+
* The interval is configured using setTimeout to take the async
|
|
13678
|
+
* execution time of the callback into account.
|
|
13679
|
+
*/
|
|
13680
|
+
this.defaultConfig = DEFAULT_TRIGGER_MANAGER_CONFIGURATION;
|
|
13681
|
+
const cleanupCallback = async () => {
|
|
13682
|
+
this.cleanupTimeout = null;
|
|
13683
|
+
if (this.isDisposed) {
|
|
13684
|
+
return;
|
|
13685
|
+
}
|
|
13686
|
+
try {
|
|
13687
|
+
await this.cleanupResources();
|
|
13688
|
+
}
|
|
13689
|
+
catch (ex) {
|
|
13690
|
+
this.db.logger.error(`Caught error while attempting to cleanup triggers`, ex);
|
|
13691
|
+
}
|
|
13692
|
+
finally {
|
|
13693
|
+
// if not closed, set another timeout
|
|
13694
|
+
if (this.isDisposed) {
|
|
13695
|
+
return;
|
|
13696
|
+
}
|
|
13697
|
+
this.cleanupTimeout = setTimeout(cleanupCallback, TRIGGER_CLEANUP_INTERVAL_MS);
|
|
13698
|
+
}
|
|
13699
|
+
};
|
|
13700
|
+
this.cleanupTimeout = setTimeout(cleanupCallback, TRIGGER_CLEANUP_INTERVAL_MS);
|
|
15452
13701
|
}
|
|
15453
13702
|
get db() {
|
|
15454
13703
|
return this.options.db;
|
|
@@ -15466,13 +13715,95 @@ class TriggerManagerImpl {
|
|
|
15466
13715
|
await tx.execute(/* sql */ `DROP TRIGGER IF EXISTS ${triggerId}; `);
|
|
15467
13716
|
}
|
|
15468
13717
|
}
|
|
13718
|
+
dispose() {
|
|
13719
|
+
this.isDisposed = true;
|
|
13720
|
+
if (this.cleanupTimeout) {
|
|
13721
|
+
clearTimeout(this.cleanupTimeout);
|
|
13722
|
+
}
|
|
13723
|
+
}
|
|
13724
|
+
/**
|
|
13725
|
+
* Updates default config settings for platform specific use-cases.
|
|
13726
|
+
*/
|
|
13727
|
+
updateDefaults(config) {
|
|
13728
|
+
this.defaultConfig = {
|
|
13729
|
+
...this.defaultConfig,
|
|
13730
|
+
...config
|
|
13731
|
+
};
|
|
13732
|
+
}
|
|
13733
|
+
generateTriggerName(operation, destinationTable, triggerId) {
|
|
13734
|
+
return `__ps_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
|
|
13735
|
+
}
|
|
13736
|
+
/**
|
|
13737
|
+
* Cleanup any SQLite triggers or tables that are no longer in use.
|
|
13738
|
+
*/
|
|
13739
|
+
async cleanupResources() {
|
|
13740
|
+
// we use the database here since cleanupResources is called during the PowerSyncDatabase initialization
|
|
13741
|
+
await this.db.database.writeLock(async (ctx) => {
|
|
13742
|
+
/**
|
|
13743
|
+
* Note: We only cleanup persisted triggers. These are tracked in the sqlite_master table.
|
|
13744
|
+
* temporary triggers will not be affected by this.
|
|
13745
|
+
* Query all triggers that match our naming pattern
|
|
13746
|
+
*/
|
|
13747
|
+
const triggers = await ctx.getAll(/* sql */ `
|
|
13748
|
+
SELECT
|
|
13749
|
+
name
|
|
13750
|
+
FROM
|
|
13751
|
+
sqlite_master
|
|
13752
|
+
WHERE
|
|
13753
|
+
type = 'trigger'
|
|
13754
|
+
AND name LIKE '__ps_temp_trigger_%'
|
|
13755
|
+
`);
|
|
13756
|
+
/** Use regex to extract table names and IDs from trigger names
|
|
13757
|
+
* Trigger naming convention: __ps_temp_trigger_<operation>__<destination_table>__<id>
|
|
13758
|
+
*/
|
|
13759
|
+
const triggerPattern = /^__ps_temp_trigger_(?:insert|update|delete)__(.+)__([a-f0-9_]{36})$/i;
|
|
13760
|
+
const trackedItems = new Map();
|
|
13761
|
+
for (const trigger of triggers) {
|
|
13762
|
+
const match = trigger.name.match(triggerPattern);
|
|
13763
|
+
if (match) {
|
|
13764
|
+
const [, table, id] = match;
|
|
13765
|
+
// Collect all trigger names for each id combo
|
|
13766
|
+
const existing = trackedItems.get(id);
|
|
13767
|
+
if (existing) {
|
|
13768
|
+
existing.triggerNames.push(trigger.name);
|
|
13769
|
+
}
|
|
13770
|
+
else {
|
|
13771
|
+
trackedItems.set(id, { table, id, triggerNames: [trigger.name] });
|
|
13772
|
+
}
|
|
13773
|
+
}
|
|
13774
|
+
}
|
|
13775
|
+
for (const trackedItem of trackedItems.values()) {
|
|
13776
|
+
// check if there is anything holding on to this item
|
|
13777
|
+
const hasClaim = await this.options.claimManager.checkClaim(trackedItem.id);
|
|
13778
|
+
if (hasClaim) {
|
|
13779
|
+
// This does not require cleanup
|
|
13780
|
+
continue;
|
|
13781
|
+
}
|
|
13782
|
+
this.db.logger.debug(`Clearing resources for trigger ${trackedItem.id} with table ${trackedItem.table}`);
|
|
13783
|
+
// We need to delete the triggers and table
|
|
13784
|
+
for (const triggerName of trackedItem.triggerNames) {
|
|
13785
|
+
await ctx.execute(`DROP TRIGGER IF EXISTS ${triggerName}`);
|
|
13786
|
+
}
|
|
13787
|
+
await ctx.execute(`DROP TABLE IF EXISTS ${trackedItem.table}`);
|
|
13788
|
+
}
|
|
13789
|
+
});
|
|
13790
|
+
}
|
|
15469
13791
|
async createDiffTrigger(options) {
|
|
15470
13792
|
await this.db.waitForReady();
|
|
15471
|
-
const { source, destination, columns, when, hooks
|
|
13793
|
+
const { source, destination, columns, when, hooks,
|
|
13794
|
+
// Fall back to the provided default if not given on this level
|
|
13795
|
+
useStorage = this.defaultConfig.useStorageByDefault } = options;
|
|
15472
13796
|
const operations = Object.keys(when);
|
|
15473
13797
|
if (operations.length == 0) {
|
|
15474
13798
|
throw new Error('At least one WHEN operation must be specified for the trigger.');
|
|
15475
13799
|
}
|
|
13800
|
+
/**
|
|
13801
|
+
* The clause to use when executing
|
|
13802
|
+
* CREATE ${tableTriggerTypeClause} TABLE
|
|
13803
|
+
* OR
|
|
13804
|
+
* CREATE ${tableTriggerTypeClause} TRIGGER
|
|
13805
|
+
*/
|
|
13806
|
+
const tableTriggerTypeClause = !useStorage ? 'TEMP' : '';
|
|
15476
13807
|
const whenClauses = Object.fromEntries(Object.entries(when).map(([operation, filter]) => [operation, `WHEN ${filter}`]));
|
|
15477
13808
|
/**
|
|
15478
13809
|
* Allow specifying the View name as the source.
|
|
@@ -15486,6 +13817,7 @@ class TriggerManagerImpl {
|
|
|
15486
13817
|
const internalSource = sourceDefinition.internalName;
|
|
15487
13818
|
const triggerIds = [];
|
|
15488
13819
|
const id = await this.getUUID();
|
|
13820
|
+
const releaseStorageClaim = useStorage ? await this.options.claimManager.obtainClaim(id) : null;
|
|
15489
13821
|
/**
|
|
15490
13822
|
* We default to replicating all columns if no columns array is provided.
|
|
15491
13823
|
*/
|
|
@@ -15518,26 +13850,27 @@ class TriggerManagerImpl {
|
|
|
15518
13850
|
return this.db.writeLock(async (tx) => {
|
|
15519
13851
|
await this.removeTriggers(tx, triggerIds);
|
|
15520
13852
|
await tx.execute(/* sql */ `DROP TABLE IF EXISTS ${destination};`);
|
|
13853
|
+
await releaseStorageClaim?.();
|
|
15521
13854
|
});
|
|
15522
13855
|
};
|
|
15523
13856
|
const setup = async (tx) => {
|
|
15524
13857
|
// Allow user code to execute in this lock context before the trigger is created.
|
|
15525
13858
|
await hooks?.beforeCreate?.(tx);
|
|
15526
13859
|
await tx.execute(/* sql */ `
|
|
15527
|
-
CREATE
|
|
13860
|
+
CREATE ${tableTriggerTypeClause} TABLE ${destination} (
|
|
15528
13861
|
operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
15529
13862
|
id TEXT,
|
|
15530
13863
|
operation TEXT,
|
|
15531
13864
|
timestamp TEXT,
|
|
15532
13865
|
value TEXT,
|
|
15533
13866
|
previous_value TEXT
|
|
15534
|
-
)
|
|
13867
|
+
)
|
|
15535
13868
|
`);
|
|
15536
13869
|
if (operations.includes(DiffTriggerOperation.INSERT)) {
|
|
15537
|
-
const insertTriggerId =
|
|
13870
|
+
const insertTriggerId = this.generateTriggerName(DiffTriggerOperation.INSERT, destination, id);
|
|
15538
13871
|
triggerIds.push(insertTriggerId);
|
|
15539
13872
|
await tx.execute(/* sql */ `
|
|
15540
|
-
CREATE
|
|
13873
|
+
CREATE ${tableTriggerTypeClause} TRIGGER ${insertTriggerId} AFTER INSERT ON ${internalSource} ${whenClauses[DiffTriggerOperation.INSERT]} BEGIN
|
|
15541
13874
|
INSERT INTO
|
|
15542
13875
|
${destination} (id, operation, timestamp, value)
|
|
15543
13876
|
VALUES
|
|
@@ -15548,14 +13881,14 @@ class TriggerManagerImpl {
|
|
|
15548
13881
|
${jsonFragment('NEW')}
|
|
15549
13882
|
);
|
|
15550
13883
|
|
|
15551
|
-
END
|
|
13884
|
+
END
|
|
15552
13885
|
`);
|
|
15553
13886
|
}
|
|
15554
13887
|
if (operations.includes(DiffTriggerOperation.UPDATE)) {
|
|
15555
|
-
const updateTriggerId =
|
|
13888
|
+
const updateTriggerId = this.generateTriggerName(DiffTriggerOperation.UPDATE, destination, id);
|
|
15556
13889
|
triggerIds.push(updateTriggerId);
|
|
15557
13890
|
await tx.execute(/* sql */ `
|
|
15558
|
-
CREATE
|
|
13891
|
+
CREATE ${tableTriggerTypeClause} TRIGGER ${updateTriggerId} AFTER
|
|
15559
13892
|
UPDATE ON ${internalSource} ${whenClauses[DiffTriggerOperation.UPDATE]} BEGIN
|
|
15560
13893
|
INSERT INTO
|
|
15561
13894
|
${destination} (id, operation, timestamp, value, previous_value)
|
|
@@ -15572,11 +13905,11 @@ class TriggerManagerImpl {
|
|
|
15572
13905
|
`);
|
|
15573
13906
|
}
|
|
15574
13907
|
if (operations.includes(DiffTriggerOperation.DELETE)) {
|
|
15575
|
-
const deleteTriggerId =
|
|
13908
|
+
const deleteTriggerId = this.generateTriggerName(DiffTriggerOperation.DELETE, destination, id);
|
|
15576
13909
|
triggerIds.push(deleteTriggerId);
|
|
15577
13910
|
// Create delete trigger for basic JSON
|
|
15578
13911
|
await tx.execute(/* sql */ `
|
|
15579
|
-
CREATE
|
|
13912
|
+
CREATE ${tableTriggerTypeClause} TRIGGER ${deleteTriggerId} AFTER DELETE ON ${internalSource} ${whenClauses[DiffTriggerOperation.DELETE]} BEGIN
|
|
15580
13913
|
INSERT INTO
|
|
15581
13914
|
${destination} (id, operation, timestamp, value)
|
|
15582
13915
|
VALUES
|
|
@@ -15620,7 +13953,7 @@ class TriggerManagerImpl {
|
|
|
15620
13953
|
// If no array is provided, we use all columns from the source table.
|
|
15621
13954
|
const contextColumns = columns ?? sourceDefinition.columns.map((col) => col.name);
|
|
15622
13955
|
const id = await this.getUUID();
|
|
15623
|
-
const destination = `
|
|
13956
|
+
const destination = `__ps_temp_track_${source}_${id}`;
|
|
15624
13957
|
// register an onChange before the trigger is created
|
|
15625
13958
|
const abortController = new AbortController();
|
|
15626
13959
|
const abortOnChange = () => abortController.abort();
|
|
@@ -15775,6 +14108,7 @@ class AbstractPowerSyncDatabase extends BaseObserver {
|
|
|
15775
14108
|
* Allows creating SQLite triggers which can be used to track various operations on SQLite tables.
|
|
15776
14109
|
*/
|
|
15777
14110
|
triggers;
|
|
14111
|
+
triggersImpl;
|
|
15778
14112
|
logger;
|
|
15779
14113
|
constructor(options) {
|
|
15780
14114
|
super();
|
|
@@ -15838,9 +14172,10 @@ class AbstractPowerSyncDatabase extends BaseObserver {
|
|
|
15838
14172
|
logger: this.logger
|
|
15839
14173
|
});
|
|
15840
14174
|
this._isReadyPromise = this.initialize();
|
|
15841
|
-
this.triggers = new TriggerManagerImpl({
|
|
14175
|
+
this.triggers = this.triggersImpl = new TriggerManagerImpl({
|
|
15842
14176
|
db: this,
|
|
15843
|
-
schema: this.schema
|
|
14177
|
+
schema: this.schema,
|
|
14178
|
+
...this.generateTriggerManagerConfig()
|
|
15844
14179
|
});
|
|
15845
14180
|
}
|
|
15846
14181
|
/**
|
|
@@ -15866,6 +14201,15 @@ class AbstractPowerSyncDatabase extends BaseObserver {
|
|
|
15866
14201
|
get connecting() {
|
|
15867
14202
|
return this.currentStatus?.connecting || false;
|
|
15868
14203
|
}
|
|
14204
|
+
/**
|
|
14205
|
+
* Generates a base configuration for {@link TriggerManagerImpl}.
|
|
14206
|
+
* Implementations should override this if necessary.
|
|
14207
|
+
*/
|
|
14208
|
+
generateTriggerManagerConfig() {
|
|
14209
|
+
return {
|
|
14210
|
+
claimManager: MEMORY_TRIGGER_CLAIM_MANAGER
|
|
14211
|
+
};
|
|
14212
|
+
}
|
|
15869
14213
|
/**
|
|
15870
14214
|
* @returns A promise which will resolve once initialization is completed.
|
|
15871
14215
|
*/
|
|
@@ -15926,14 +14270,15 @@ class AbstractPowerSyncDatabase extends BaseObserver {
|
|
|
15926
14270
|
async initialize() {
|
|
15927
14271
|
await this._initialize();
|
|
15928
14272
|
await this.bucketStorageAdapter.init();
|
|
15929
|
-
await this.
|
|
14273
|
+
await this.loadVersion();
|
|
15930
14274
|
await this.updateSchema(this.options.schema);
|
|
15931
14275
|
await this.resolveOfflineSyncStatus();
|
|
15932
14276
|
await this.database.execute('PRAGMA RECURSIVE_TRIGGERS=TRUE');
|
|
14277
|
+
await this.triggersImpl.cleanupResources();
|
|
15933
14278
|
this.ready = true;
|
|
15934
14279
|
this.iterateListeners((cb) => cb.initialized?.());
|
|
15935
14280
|
}
|
|
15936
|
-
async
|
|
14281
|
+
async loadVersion() {
|
|
15937
14282
|
try {
|
|
15938
14283
|
const { version } = await this.database.get('SELECT powersync_rs_version() as version');
|
|
15939
14284
|
this.sdkVersion = version;
|
|
@@ -16049,7 +14394,6 @@ class AbstractPowerSyncDatabase extends BaseObserver {
|
|
|
16049
14394
|
await this.disconnect();
|
|
16050
14395
|
await this.waitForReady();
|
|
16051
14396
|
const { clearLocal } = options;
|
|
16052
|
-
// TODO DB name, verify this is necessary with extension
|
|
16053
14397
|
await this.database.writeTransaction(async (tx) => {
|
|
16054
14398
|
await tx.execute('SELECT powersync_clear(?)', [clearLocal ? 1 : 0]);
|
|
16055
14399
|
});
|
|
@@ -16081,6 +14425,7 @@ class AbstractPowerSyncDatabase extends BaseObserver {
|
|
|
16081
14425
|
if (this.closed) {
|
|
16082
14426
|
return;
|
|
16083
14427
|
}
|
|
14428
|
+
this.triggersImpl.dispose();
|
|
16084
14429
|
await this.iterateAsyncListeners(async (cb) => cb.closing?.());
|
|
16085
14430
|
const { disconnect } = options;
|
|
16086
14431
|
if (disconnect) {
|
|
@@ -17657,7 +16002,7 @@ const parseQuery = (query, parameters) => {
|
|
|
17657
16002
|
/*!*************************************************************!*\
|
|
17658
16003
|
!*** ./lib/src/db/adapters/wa-sqlite/WASQLiteConnection.js ***!
|
|
17659
16004
|
\*************************************************************/
|
|
17660
|
-
(
|
|
16005
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
17661
16006
|
|
|
17662
16007
|
__webpack_require__.r(__webpack_exports__);
|
|
17663
16008
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
@@ -17669,9 +16014,9 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
17669
16014
|
/* harmony export */ WASQLiteVFS: () => (/* binding */ WASQLiteVFS),
|
|
17670
16015
|
/* harmony export */ WASqliteConnection: () => (/* binding */ WASqliteConnection)
|
|
17671
16016
|
/* harmony export */ });
|
|
17672
|
-
/* harmony import */ var _journeyapps_wa_sqlite__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @journeyapps/wa-sqlite */ "../../node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js");
|
|
16017
|
+
/* harmony import */ var _journeyapps_wa_sqlite__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @journeyapps/wa-sqlite */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.4.1/node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js");
|
|
17673
16018
|
/* harmony import */ var _powersync_common__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @powersync/common */ "../common/dist/bundle.mjs");
|
|
17674
|
-
/* harmony import */ var async_mutex__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! async-mutex */ "../../node_modules/async-mutex/index.mjs");
|
|
16019
|
+
/* harmony import */ var async_mutex__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! async-mutex */ "../../node_modules/.pnpm/async-mutex@0.5.0/node_modules/async-mutex/index.mjs");
|
|
17675
16020
|
|
|
17676
16021
|
|
|
17677
16022
|
|
|
@@ -17688,28 +16033,28 @@ var WASQLiteVFS;
|
|
|
17688
16033
|
* @internal
|
|
17689
16034
|
*/
|
|
17690
16035
|
const AsyncWASQLiteModuleFactory = async () => {
|
|
17691
|
-
const { default: factory } = await __webpack_require__.e(/*! import() */ "
|
|
16036
|
+
const { default: factory } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-f60d0d").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/dist/wa-sqlite-async.mjs */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.4.1/node_modules/@journeyapps/wa-sqlite/dist/wa-sqlite-async.mjs"));
|
|
17692
16037
|
return factory();
|
|
17693
16038
|
};
|
|
17694
16039
|
/**
|
|
17695
16040
|
* @internal
|
|
17696
16041
|
*/
|
|
17697
16042
|
const MultiCipherAsyncWASQLiteModuleFactory = async () => {
|
|
17698
|
-
const { default: factory } = await __webpack_require__.e(/*! import() */ "
|
|
16043
|
+
const { default: factory } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-3a94cf").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/dist/mc-wa-sqlite-async.mjs */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.4.1/node_modules/@journeyapps/wa-sqlite/dist/mc-wa-sqlite-async.mjs"));
|
|
17699
16044
|
return factory();
|
|
17700
16045
|
};
|
|
17701
16046
|
/**
|
|
17702
16047
|
* @internal
|
|
17703
16048
|
*/
|
|
17704
16049
|
const SyncWASQLiteModuleFactory = async () => {
|
|
17705
|
-
const { default: factory } = await __webpack_require__.e(/*! import() */ "
|
|
16050
|
+
const { default: factory } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/dist/wa-sqlite.mjs */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.4.1/node_modules/@journeyapps/wa-sqlite/dist/wa-sqlite.mjs"));
|
|
17706
16051
|
return factory();
|
|
17707
16052
|
};
|
|
17708
16053
|
/**
|
|
17709
16054
|
* @internal
|
|
17710
16055
|
*/
|
|
17711
16056
|
const MultiCipherSyncWASQLiteModuleFactory = async () => {
|
|
17712
|
-
const { default: factory } = await __webpack_require__.e(/*! import() */ "
|
|
16057
|
+
const { default: factory } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-868779").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/dist/mc-wa-sqlite.mjs */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.4.1/node_modules/@journeyapps/wa-sqlite/dist/mc-wa-sqlite.mjs"));
|
|
17713
16058
|
return factory();
|
|
17714
16059
|
};
|
|
17715
16060
|
/**
|
|
@@ -17724,7 +16069,7 @@ const DEFAULT_MODULE_FACTORIES = {
|
|
|
17724
16069
|
else {
|
|
17725
16070
|
module = await AsyncWASQLiteModuleFactory();
|
|
17726
16071
|
}
|
|
17727
|
-
const { IDBBatchAtomicVFS } = await __webpack_require__.e(/*! import() */ "
|
|
16072
|
+
const { IDBBatchAtomicVFS } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_src_examples-0d2437").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/src/examples/IDBBatchAtomicVFS.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.4.1/node_modules/@journeyapps/wa-sqlite/src/examples/IDBBatchAtomicVFS.js"));
|
|
17728
16073
|
return {
|
|
17729
16074
|
module,
|
|
17730
16075
|
// @ts-expect-error The types for this static method are missing upstream
|
|
@@ -17740,7 +16085,7 @@ const DEFAULT_MODULE_FACTORIES = {
|
|
|
17740
16085
|
module = await SyncWASQLiteModuleFactory();
|
|
17741
16086
|
}
|
|
17742
16087
|
// @ts-expect-error The types for this static method are missing upstream
|
|
17743
|
-
const { AccessHandlePoolVFS } = await __webpack_require__.e(/*! import() */ "
|
|
16088
|
+
const { AccessHandlePoolVFS } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_src_examples-3622cf").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/src/examples/AccessHandlePoolVFS.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.4.1/node_modules/@journeyapps/wa-sqlite/src/examples/AccessHandlePoolVFS.js"));
|
|
17744
16089
|
return {
|
|
17745
16090
|
module,
|
|
17746
16091
|
vfs: await AccessHandlePoolVFS.create(options.dbFileName, module)
|
|
@@ -17755,7 +16100,7 @@ const DEFAULT_MODULE_FACTORIES = {
|
|
|
17755
16100
|
module = await SyncWASQLiteModuleFactory();
|
|
17756
16101
|
}
|
|
17757
16102
|
// @ts-expect-error The types for this static method are missing upstream
|
|
17758
|
-
const { OPFSCoopSyncVFS } = await __webpack_require__.e(/*! import() */ "
|
|
16103
|
+
const { OPFSCoopSyncVFS } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_src_examples-1d4e74").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.4.1/node_modules/@journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js"));
|
|
17759
16104
|
const vfs = await OPFSCoopSyncVFS.create(options.dbFileName, module);
|
|
17760
16105
|
return {
|
|
17761
16106
|
module,
|
|
@@ -18081,7 +16426,7 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
|
|
|
18081
16426
|
/*!*************************************!*\
|
|
18082
16427
|
!*** ./lib/src/shared/navigator.js ***!
|
|
18083
16428
|
\*************************************/
|
|
18084
|
-
(
|
|
16429
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
18085
16430
|
|
|
18086
16431
|
__webpack_require__.r(__webpack_exports__);
|
|
18087
16432
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
@@ -18101,7 +16446,7 @@ const getNavigatorLocks = () => {
|
|
|
18101
16446
|
/*!*******************************************************!*\
|
|
18102
16447
|
!*** ./lib/src/worker/db/SharedWASQLiteConnection.js ***!
|
|
18103
16448
|
\*******************************************************/
|
|
18104
|
-
(
|
|
16449
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
18105
16450
|
|
|
18106
16451
|
__webpack_require__.r(__webpack_exports__);
|
|
18107
16452
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
@@ -18205,21 +16550,21 @@ class SharedWASQLiteConnection {
|
|
|
18205
16550
|
/*!*******************************************************!*\
|
|
18206
16551
|
!*** ./lib/src/worker/db/WorkerWASQLiteConnection.js ***!
|
|
18207
16552
|
\*******************************************************/
|
|
18208
|
-
(
|
|
16553
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
18209
16554
|
|
|
18210
16555
|
__webpack_require__.r(__webpack_exports__);
|
|
18211
16556
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
18212
16557
|
/* harmony export */ WorkerWASQLiteConnection: () => (/* binding */ WorkerWASQLiteConnection)
|
|
18213
16558
|
/* harmony export */ });
|
|
18214
|
-
/* harmony import */ var comlink__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! comlink */ "../../node_modules/comlink/dist/esm/comlink.mjs");
|
|
18215
|
-
/* harmony import */ var
|
|
16559
|
+
/* harmony import */ var comlink__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! comlink */ "../../node_modules/.pnpm/comlink@4.4.2/node_modules/comlink/dist/esm/comlink.mjs");
|
|
16560
|
+
/* harmony import */ var _db_adapters_wa_sqlite_WASQLiteConnection_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../db/adapters/wa-sqlite/WASQLiteConnection.js */ "./lib/src/db/adapters/wa-sqlite/WASQLiteConnection.js");
|
|
18216
16561
|
|
|
18217
16562
|
|
|
18218
16563
|
/**
|
|
18219
16564
|
* A Small proxy wrapper around the WASqliteConnection.
|
|
18220
16565
|
* This ensures that certain return types are properly proxied.
|
|
18221
16566
|
*/
|
|
18222
|
-
class WorkerWASQLiteConnection extends
|
|
16567
|
+
class WorkerWASQLiteConnection extends _db_adapters_wa_sqlite_WASQLiteConnection_js__WEBPACK_IMPORTED_MODULE_1__.WASqliteConnection {
|
|
18223
16568
|
async registerOnTableChange(callback) {
|
|
18224
16569
|
// Proxy the callback remove function
|
|
18225
16570
|
return comlink__WEBPACK_IMPORTED_MODULE_0__.proxy(await super.registerOnTableChange(callback));
|
|
@@ -18399,12 +16744,12 @@ var __webpack_exports__ = {};
|
|
|
18399
16744
|
!*** ./lib/src/worker/db/WASQLiteDB.worker.js ***!
|
|
18400
16745
|
\************************************************/
|
|
18401
16746
|
__webpack_require__.r(__webpack_exports__);
|
|
18402
|
-
/* harmony import */ var _journeyapps_wa_sqlite__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @journeyapps/wa-sqlite */ "../../node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js");
|
|
16747
|
+
/* harmony import */ var _journeyapps_wa_sqlite__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @journeyapps/wa-sqlite */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.4.1/node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js");
|
|
18403
16748
|
/* harmony import */ var _powersync_common__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @powersync/common */ "../common/dist/bundle.mjs");
|
|
18404
|
-
/* harmony import */ var comlink__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! comlink */ "../../node_modules/comlink/dist/esm/comlink.mjs");
|
|
18405
|
-
/* harmony import */ var
|
|
18406
|
-
/* harmony import */ var
|
|
18407
|
-
/* harmony import */ var
|
|
16749
|
+
/* harmony import */ var comlink__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! comlink */ "../../node_modules/.pnpm/comlink@4.4.2/node_modules/comlink/dist/esm/comlink.mjs");
|
|
16750
|
+
/* harmony import */ var _shared_navigator_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../shared/navigator.js */ "./lib/src/shared/navigator.js");
|
|
16751
|
+
/* harmony import */ var _SharedWASQLiteConnection_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./SharedWASQLiteConnection.js */ "./lib/src/worker/db/SharedWASQLiteConnection.js");
|
|
16752
|
+
/* harmony import */ var _WorkerWASQLiteConnection_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./WorkerWASQLiteConnection.js */ "./lib/src/worker/db/WorkerWASQLiteConnection.js");
|
|
18408
16753
|
/**
|
|
18409
16754
|
* Supports both shared and dedicated workers, based on how the worker is constructed (new SharedWorker vs new Worker()).
|
|
18410
16755
|
*/
|
|
@@ -18422,14 +16767,14 @@ const OPEN_DB_LOCK = 'open-wasqlite-db';
|
|
|
18422
16767
|
let nextClientId = 1;
|
|
18423
16768
|
const openDBShared = async (options) => {
|
|
18424
16769
|
// Prevent multiple simultaneous opens from causing race conditions
|
|
18425
|
-
return (0,
|
|
16770
|
+
return (0,_shared_navigator_js__WEBPACK_IMPORTED_MODULE_3__.getNavigatorLocks)().request(OPEN_DB_LOCK, async () => {
|
|
18426
16771
|
const clientId = nextClientId++;
|
|
18427
16772
|
const { dbFilename, logLevel } = options;
|
|
18428
16773
|
logger.setLevel(logLevel);
|
|
18429
16774
|
if (!DBMap.has(dbFilename)) {
|
|
18430
16775
|
const clientIds = new Set();
|
|
18431
16776
|
// This format returns proxy objects for function callbacks
|
|
18432
|
-
const connection = new
|
|
16777
|
+
const connection = new _WorkerWASQLiteConnection_js__WEBPACK_IMPORTED_MODULE_5__.WorkerWASQLiteConnection(options);
|
|
18433
16778
|
await connection.init();
|
|
18434
16779
|
connection.registerListener({
|
|
18435
16780
|
holdOverwritten: async () => {
|
|
@@ -18447,7 +16792,7 @@ const openDBShared = async (options) => {
|
|
|
18447
16792
|
});
|
|
18448
16793
|
}
|
|
18449
16794
|
// Associates this clientId with the shared connection entry
|
|
18450
|
-
const sharedConnection = new
|
|
16795
|
+
const sharedConnection = new _SharedWASQLiteConnection_js__WEBPACK_IMPORTED_MODULE_4__.SharedWASQLiteConnection({
|
|
18451
16796
|
dbMap: DBMap,
|
|
18452
16797
|
dbFilename,
|
|
18453
16798
|
clientId,
|