@powersync/common 0.0.0-dev-20251209082930 → 0.0.0-dev-20260120150240
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/bundle.cjs +366 -2142
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.mjs +365 -2143
- package/dist/bundle.mjs.map +1 -1
- package/dist/bundle.node.cjs +153 -100
- package/dist/bundle.node.cjs.map +1 -1
- package/dist/bundle.node.mjs +152 -101
- package/dist/bundle.node.mjs.map +1 -1
- package/dist/index.d.cts +26 -3
- package/lib/client/AbstractPowerSyncDatabase.d.ts +1 -1
- package/lib/client/AbstractPowerSyncDatabase.js +2 -2
- package/lib/client/AbstractPowerSyncDatabase.js.map +1 -1
- package/lib/client/sync/stream/AbstractRemote.js +41 -32
- package/lib/client/sync/stream/AbstractRemote.js.map +1 -1
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +4 -0
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +8 -0
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -1
- package/lib/client/sync/stream/streaming-sync-types.d.ts +4 -0
- package/lib/client/sync/stream/streaming-sync-types.js.map +1 -1
- package/lib/db/ConnectionClosedError.d.ts +10 -0
- package/lib/db/ConnectionClosedError.js +21 -0
- package/lib/db/ConnectionClosedError.js.map +1 -0
- package/lib/db/crud/SyncStatus.d.ts +4 -0
- package/lib/db/crud/SyncStatus.js +4 -0
- package/lib/db/crud/SyncStatus.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/utils/DataStream.js +11 -2
- package/lib/utils/DataStream.js.map +1 -1
- package/package.json +4 -3
- package/src/client/AbstractPowerSyncDatabase.ts +2 -2
- package/src/client/sync/stream/AbstractRemote.ts +47 -35
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +19 -2
- package/src/client/sync/stream/streaming-sync-types.ts +5 -0
- package/src/db/ConnectionClosedError.ts +23 -0
- package/src/db/crud/SyncStatus.ts +4 -0
- package/src/index.ts +2 -0
- package/src/utils/DataStream.ts +13 -2
package/dist/bundle.cjs
CHANGED
|
@@ -732,6 +732,10 @@ class SyncStatus {
|
|
|
732
732
|
priorityStatusEntries: this.priorityStatusEntries
|
|
733
733
|
};
|
|
734
734
|
}
|
|
735
|
+
/**
|
|
736
|
+
* Not all errors are serializable over a MessagePort. E.g. some `DomExceptions` fail to be passed across workers.
|
|
737
|
+
* This explicitly serializes errors in the SyncStatus.
|
|
738
|
+
*/
|
|
735
739
|
serializeError(error) {
|
|
736
740
|
if (typeof error == 'undefined') {
|
|
737
741
|
return undefined;
|
|
@@ -2085,7 +2089,7 @@ class SyncDataBucket {
|
|
|
2085
2089
|
}
|
|
2086
2090
|
}
|
|
2087
2091
|
|
|
2088
|
-
var buffer
|
|
2092
|
+
var buffer = {};
|
|
2089
2093
|
|
|
2090
2094
|
var base64Js = {};
|
|
2091
2095
|
|
|
@@ -2349,12 +2353,12 @@ function requireIeee754 () {
|
|
|
2349
2353
|
* @license MIT
|
|
2350
2354
|
*/
|
|
2351
2355
|
|
|
2352
|
-
var hasRequiredBuffer
|
|
2356
|
+
var hasRequiredBuffer;
|
|
2353
2357
|
|
|
2354
|
-
function requireBuffer
|
|
2355
|
-
if (hasRequiredBuffer
|
|
2356
|
-
hasRequiredBuffer
|
|
2357
|
-
(function (exports) {
|
|
2358
|
+
function requireBuffer () {
|
|
2359
|
+
if (hasRequiredBuffer) return buffer;
|
|
2360
|
+
hasRequiredBuffer = 1;
|
|
2361
|
+
(function (exports$1) {
|
|
2358
2362
|
|
|
2359
2363
|
const base64 = requireBase64Js();
|
|
2360
2364
|
const ieee754 = requireIeee754();
|
|
@@ -2363,12 +2367,12 @@ function requireBuffer$1 () {
|
|
|
2363
2367
|
? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
|
|
2364
2368
|
: null;
|
|
2365
2369
|
|
|
2366
|
-
exports.Buffer = Buffer;
|
|
2367
|
-
exports.SlowBuffer = SlowBuffer;
|
|
2368
|
-
exports.INSPECT_MAX_BYTES = 50;
|
|
2370
|
+
exports$1.Buffer = Buffer;
|
|
2371
|
+
exports$1.SlowBuffer = SlowBuffer;
|
|
2372
|
+
exports$1.INSPECT_MAX_BYTES = 50;
|
|
2369
2373
|
|
|
2370
2374
|
const K_MAX_LENGTH = 0x7fffffff;
|
|
2371
|
-
exports.kMaxLength = K_MAX_LENGTH;
|
|
2375
|
+
exports$1.kMaxLength = K_MAX_LENGTH;
|
|
2372
2376
|
|
|
2373
2377
|
/**
|
|
2374
2378
|
* If `Buffer.TYPED_ARRAY_SUPPORT`:
|
|
@@ -2964,7 +2968,7 @@ function requireBuffer$1 () {
|
|
|
2964
2968
|
|
|
2965
2969
|
Buffer.prototype.inspect = function inspect () {
|
|
2966
2970
|
let str = '';
|
|
2967
|
-
const max = exports.INSPECT_MAX_BYTES;
|
|
2971
|
+
const max = exports$1.INSPECT_MAX_BYTES;
|
|
2968
2972
|
str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
|
|
2969
2973
|
if (this.length > max) str += ' ... ';
|
|
2970
2974
|
return '<Buffer ' + str + '>'
|
|
@@ -3868,2019 +3872,39 @@ function requireBuffer$1 () {
|
|
|
3868
3872
|
buf[offset + 6] = lo;
|
|
3869
3873
|
lo = lo >> 8;
|
|
3870
3874
|
buf[offset + 5] = lo;
|
|
3871
|
-
lo = lo >> 8;
|
|
3872
|
-
buf[offset + 4] = lo;
|
|
3873
|
-
let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
|
|
3874
|
-
buf[offset + 3] = hi;
|
|
3875
|
-
hi = hi >> 8;
|
|
3876
|
-
buf[offset + 2] = hi;
|
|
3877
|
-
hi = hi >> 8;
|
|
3878
|
-
buf[offset + 1] = hi;
|
|
3879
|
-
hi = hi >> 8;
|
|
3880
|
-
buf[offset] = hi;
|
|
3881
|
-
return offset + 8
|
|
3882
|
-
}
|
|
3883
|
-
|
|
3884
|
-
Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) {
|
|
3885
|
-
return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
|
|
3886
|
-
});
|
|
3887
|
-
|
|
3888
|
-
Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) {
|
|
3889
|
-
return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
|
|
3890
|
-
});
|
|
3891
|
-
|
|
3892
|
-
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
|
|
3893
|
-
value = +value;
|
|
3894
|
-
offset = offset >>> 0;
|
|
3895
|
-
if (!noAssert) {
|
|
3896
|
-
const limit = Math.pow(2, (8 * byteLength) - 1);
|
|
3897
|
-
|
|
3898
|
-
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
3899
|
-
}
|
|
3900
|
-
|
|
3901
|
-
let i = 0;
|
|
3902
|
-
let mul = 1;
|
|
3903
|
-
let sub = 0;
|
|
3904
|
-
this[offset] = value & 0xFF;
|
|
3905
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
|
3906
|
-
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
3907
|
-
sub = 1;
|
|
3908
|
-
}
|
|
3909
|
-
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
|
|
3910
|
-
}
|
|
3911
|
-
|
|
3912
|
-
return offset + byteLength
|
|
3913
|
-
};
|
|
3914
|
-
|
|
3915
|
-
Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
|
|
3916
|
-
value = +value;
|
|
3917
|
-
offset = offset >>> 0;
|
|
3918
|
-
if (!noAssert) {
|
|
3919
|
-
const limit = Math.pow(2, (8 * byteLength) - 1);
|
|
3920
|
-
|
|
3921
|
-
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
3922
|
-
}
|
|
3923
|
-
|
|
3924
|
-
let i = byteLength - 1;
|
|
3925
|
-
let mul = 1;
|
|
3926
|
-
let sub = 0;
|
|
3927
|
-
this[offset + i] = value & 0xFF;
|
|
3928
|
-
while (--i >= 0 && (mul *= 0x100)) {
|
|
3929
|
-
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
3930
|
-
sub = 1;
|
|
3931
|
-
}
|
|
3932
|
-
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
|
|
3933
|
-
}
|
|
3934
|
-
|
|
3935
|
-
return offset + byteLength
|
|
3936
|
-
};
|
|
3937
|
-
|
|
3938
|
-
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
|
|
3939
|
-
value = +value;
|
|
3940
|
-
offset = offset >>> 0;
|
|
3941
|
-
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
|
|
3942
|
-
if (value < 0) value = 0xff + value + 1;
|
|
3943
|
-
this[offset] = (value & 0xff);
|
|
3944
|
-
return offset + 1
|
|
3945
|
-
};
|
|
3946
|
-
|
|
3947
|
-
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
|
|
3948
|
-
value = +value;
|
|
3949
|
-
offset = offset >>> 0;
|
|
3950
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
|
|
3951
|
-
this[offset] = (value & 0xff);
|
|
3952
|
-
this[offset + 1] = (value >>> 8);
|
|
3953
|
-
return offset + 2
|
|
3954
|
-
};
|
|
3955
|
-
|
|
3956
|
-
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
|
|
3957
|
-
value = +value;
|
|
3958
|
-
offset = offset >>> 0;
|
|
3959
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
|
|
3960
|
-
this[offset] = (value >>> 8);
|
|
3961
|
-
this[offset + 1] = (value & 0xff);
|
|
3962
|
-
return offset + 2
|
|
3963
|
-
};
|
|
3964
|
-
|
|
3965
|
-
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
|
|
3966
|
-
value = +value;
|
|
3967
|
-
offset = offset >>> 0;
|
|
3968
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
|
|
3969
|
-
this[offset] = (value & 0xff);
|
|
3970
|
-
this[offset + 1] = (value >>> 8);
|
|
3971
|
-
this[offset + 2] = (value >>> 16);
|
|
3972
|
-
this[offset + 3] = (value >>> 24);
|
|
3973
|
-
return offset + 4
|
|
3974
|
-
};
|
|
3975
|
-
|
|
3976
|
-
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
|
|
3977
|
-
value = +value;
|
|
3978
|
-
offset = offset >>> 0;
|
|
3979
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
|
|
3980
|
-
if (value < 0) value = 0xffffffff + value + 1;
|
|
3981
|
-
this[offset] = (value >>> 24);
|
|
3982
|
-
this[offset + 1] = (value >>> 16);
|
|
3983
|
-
this[offset + 2] = (value >>> 8);
|
|
3984
|
-
this[offset + 3] = (value & 0xff);
|
|
3985
|
-
return offset + 4
|
|
3986
|
-
};
|
|
3987
|
-
|
|
3988
|
-
Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) {
|
|
3989
|
-
return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
|
|
3990
|
-
});
|
|
3991
|
-
|
|
3992
|
-
Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) {
|
|
3993
|
-
return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
|
|
3994
|
-
});
|
|
3995
|
-
|
|
3996
|
-
function checkIEEE754 (buf, value, offset, ext, max, min) {
|
|
3997
|
-
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
3998
|
-
if (offset < 0) throw new RangeError('Index out of range')
|
|
3999
|
-
}
|
|
4000
|
-
|
|
4001
|
-
function writeFloat (buf, value, offset, littleEndian, noAssert) {
|
|
4002
|
-
value = +value;
|
|
4003
|
-
offset = offset >>> 0;
|
|
4004
|
-
if (!noAssert) {
|
|
4005
|
-
checkIEEE754(buf, value, offset, 4);
|
|
4006
|
-
}
|
|
4007
|
-
ieee754.write(buf, value, offset, littleEndian, 23, 4);
|
|
4008
|
-
return offset + 4
|
|
4009
|
-
}
|
|
4010
|
-
|
|
4011
|
-
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
|
|
4012
|
-
return writeFloat(this, value, offset, true, noAssert)
|
|
4013
|
-
};
|
|
4014
|
-
|
|
4015
|
-
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
|
|
4016
|
-
return writeFloat(this, value, offset, false, noAssert)
|
|
4017
|
-
};
|
|
4018
|
-
|
|
4019
|
-
function writeDouble (buf, value, offset, littleEndian, noAssert) {
|
|
4020
|
-
value = +value;
|
|
4021
|
-
offset = offset >>> 0;
|
|
4022
|
-
if (!noAssert) {
|
|
4023
|
-
checkIEEE754(buf, value, offset, 8);
|
|
4024
|
-
}
|
|
4025
|
-
ieee754.write(buf, value, offset, littleEndian, 52, 8);
|
|
4026
|
-
return offset + 8
|
|
4027
|
-
}
|
|
4028
|
-
|
|
4029
|
-
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
|
|
4030
|
-
return writeDouble(this, value, offset, true, noAssert)
|
|
4031
|
-
};
|
|
4032
|
-
|
|
4033
|
-
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
|
|
4034
|
-
return writeDouble(this, value, offset, false, noAssert)
|
|
4035
|
-
};
|
|
4036
|
-
|
|
4037
|
-
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
|
|
4038
|
-
Buffer.prototype.copy = function copy (target, targetStart, start, end) {
|
|
4039
|
-
if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
|
|
4040
|
-
if (!start) start = 0;
|
|
4041
|
-
if (!end && end !== 0) end = this.length;
|
|
4042
|
-
if (targetStart >= target.length) targetStart = target.length;
|
|
4043
|
-
if (!targetStart) targetStart = 0;
|
|
4044
|
-
if (end > 0 && end < start) end = start;
|
|
4045
|
-
|
|
4046
|
-
// Copy 0 bytes; we're done
|
|
4047
|
-
if (end === start) return 0
|
|
4048
|
-
if (target.length === 0 || this.length === 0) return 0
|
|
4049
|
-
|
|
4050
|
-
// Fatal error conditions
|
|
4051
|
-
if (targetStart < 0) {
|
|
4052
|
-
throw new RangeError('targetStart out of bounds')
|
|
4053
|
-
}
|
|
4054
|
-
if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
|
|
4055
|
-
if (end < 0) throw new RangeError('sourceEnd out of bounds')
|
|
4056
|
-
|
|
4057
|
-
// Are we oob?
|
|
4058
|
-
if (end > this.length) end = this.length;
|
|
4059
|
-
if (target.length - targetStart < end - start) {
|
|
4060
|
-
end = target.length - targetStart + start;
|
|
4061
|
-
}
|
|
4062
|
-
|
|
4063
|
-
const len = end - start;
|
|
4064
|
-
|
|
4065
|
-
if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
|
|
4066
|
-
// Use built-in when available, missing from IE11
|
|
4067
|
-
this.copyWithin(targetStart, start, end);
|
|
4068
|
-
} else {
|
|
4069
|
-
Uint8Array.prototype.set.call(
|
|
4070
|
-
target,
|
|
4071
|
-
this.subarray(start, end),
|
|
4072
|
-
targetStart
|
|
4073
|
-
);
|
|
4074
|
-
}
|
|
4075
|
-
|
|
4076
|
-
return len
|
|
4077
|
-
};
|
|
4078
|
-
|
|
4079
|
-
// Usage:
|
|
4080
|
-
// buffer.fill(number[, offset[, end]])
|
|
4081
|
-
// buffer.fill(buffer[, offset[, end]])
|
|
4082
|
-
// buffer.fill(string[, offset[, end]][, encoding])
|
|
4083
|
-
Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
|
4084
|
-
// Handle string cases:
|
|
4085
|
-
if (typeof val === 'string') {
|
|
4086
|
-
if (typeof start === 'string') {
|
|
4087
|
-
encoding = start;
|
|
4088
|
-
start = 0;
|
|
4089
|
-
end = this.length;
|
|
4090
|
-
} else if (typeof end === 'string') {
|
|
4091
|
-
encoding = end;
|
|
4092
|
-
end = this.length;
|
|
4093
|
-
}
|
|
4094
|
-
if (encoding !== undefined && typeof encoding !== 'string') {
|
|
4095
|
-
throw new TypeError('encoding must be a string')
|
|
4096
|
-
}
|
|
4097
|
-
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
|
4098
|
-
throw new TypeError('Unknown encoding: ' + encoding)
|
|
4099
|
-
}
|
|
4100
|
-
if (val.length === 1) {
|
|
4101
|
-
const code = val.charCodeAt(0);
|
|
4102
|
-
if ((encoding === 'utf8' && code < 128) ||
|
|
4103
|
-
encoding === 'latin1') {
|
|
4104
|
-
// Fast path: If `val` fits into a single byte, use that numeric value.
|
|
4105
|
-
val = code;
|
|
4106
|
-
}
|
|
4107
|
-
}
|
|
4108
|
-
} else if (typeof val === 'number') {
|
|
4109
|
-
val = val & 255;
|
|
4110
|
-
} else if (typeof val === 'boolean') {
|
|
4111
|
-
val = Number(val);
|
|
4112
|
-
}
|
|
4113
|
-
|
|
4114
|
-
// Invalid ranges are not set to a default, so can range check early.
|
|
4115
|
-
if (start < 0 || this.length < start || this.length < end) {
|
|
4116
|
-
throw new RangeError('Out of range index')
|
|
4117
|
-
}
|
|
4118
|
-
|
|
4119
|
-
if (end <= start) {
|
|
4120
|
-
return this
|
|
4121
|
-
}
|
|
4122
|
-
|
|
4123
|
-
start = start >>> 0;
|
|
4124
|
-
end = end === undefined ? this.length : end >>> 0;
|
|
4125
|
-
|
|
4126
|
-
if (!val) val = 0;
|
|
4127
|
-
|
|
4128
|
-
let i;
|
|
4129
|
-
if (typeof val === 'number') {
|
|
4130
|
-
for (i = start; i < end; ++i) {
|
|
4131
|
-
this[i] = val;
|
|
4132
|
-
}
|
|
4133
|
-
} else {
|
|
4134
|
-
const bytes = Buffer.isBuffer(val)
|
|
4135
|
-
? val
|
|
4136
|
-
: Buffer.from(val, encoding);
|
|
4137
|
-
const len = bytes.length;
|
|
4138
|
-
if (len === 0) {
|
|
4139
|
-
throw new TypeError('The value "' + val +
|
|
4140
|
-
'" is invalid for argument "value"')
|
|
4141
|
-
}
|
|
4142
|
-
for (i = 0; i < end - start; ++i) {
|
|
4143
|
-
this[i + start] = bytes[i % len];
|
|
4144
|
-
}
|
|
4145
|
-
}
|
|
4146
|
-
|
|
4147
|
-
return this
|
|
4148
|
-
};
|
|
4149
|
-
|
|
4150
|
-
// CUSTOM ERRORS
|
|
4151
|
-
// =============
|
|
4152
|
-
|
|
4153
|
-
// Simplified versions from Node, changed for Buffer-only usage
|
|
4154
|
-
const errors = {};
|
|
4155
|
-
function E (sym, getMessage, Base) {
|
|
4156
|
-
errors[sym] = class NodeError extends Base {
|
|
4157
|
-
constructor () {
|
|
4158
|
-
super();
|
|
4159
|
-
|
|
4160
|
-
Object.defineProperty(this, 'message', {
|
|
4161
|
-
value: getMessage.apply(this, arguments),
|
|
4162
|
-
writable: true,
|
|
4163
|
-
configurable: true
|
|
4164
|
-
});
|
|
4165
|
-
|
|
4166
|
-
// Add the error code to the name to include it in the stack trace.
|
|
4167
|
-
this.name = `${this.name} [${sym}]`;
|
|
4168
|
-
// Access the stack to generate the error message including the error code
|
|
4169
|
-
// from the name.
|
|
4170
|
-
this.stack; // eslint-disable-line no-unused-expressions
|
|
4171
|
-
// Reset the name to the actual name.
|
|
4172
|
-
delete this.name;
|
|
4173
|
-
}
|
|
4174
|
-
|
|
4175
|
-
get code () {
|
|
4176
|
-
return sym
|
|
4177
|
-
}
|
|
4178
|
-
|
|
4179
|
-
set code (value) {
|
|
4180
|
-
Object.defineProperty(this, 'code', {
|
|
4181
|
-
configurable: true,
|
|
4182
|
-
enumerable: true,
|
|
4183
|
-
value,
|
|
4184
|
-
writable: true
|
|
4185
|
-
});
|
|
4186
|
-
}
|
|
4187
|
-
|
|
4188
|
-
toString () {
|
|
4189
|
-
return `${this.name} [${sym}]: ${this.message}`
|
|
4190
|
-
}
|
|
4191
|
-
};
|
|
4192
|
-
}
|
|
4193
|
-
|
|
4194
|
-
E('ERR_BUFFER_OUT_OF_BOUNDS',
|
|
4195
|
-
function (name) {
|
|
4196
|
-
if (name) {
|
|
4197
|
-
return `${name} is outside of buffer bounds`
|
|
4198
|
-
}
|
|
4199
|
-
|
|
4200
|
-
return 'Attempt to access memory outside buffer bounds'
|
|
4201
|
-
}, RangeError);
|
|
4202
|
-
E('ERR_INVALID_ARG_TYPE',
|
|
4203
|
-
function (name, actual) {
|
|
4204
|
-
return `The "${name}" argument must be of type number. Received type ${typeof actual}`
|
|
4205
|
-
}, TypeError);
|
|
4206
|
-
E('ERR_OUT_OF_RANGE',
|
|
4207
|
-
function (str, range, input) {
|
|
4208
|
-
let msg = `The value of "${str}" is out of range.`;
|
|
4209
|
-
let received = input;
|
|
4210
|
-
if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
|
|
4211
|
-
received = addNumericalSeparator(String(input));
|
|
4212
|
-
} else if (typeof input === 'bigint') {
|
|
4213
|
-
received = String(input);
|
|
4214
|
-
if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
|
|
4215
|
-
received = addNumericalSeparator(received);
|
|
4216
|
-
}
|
|
4217
|
-
received += 'n';
|
|
4218
|
-
}
|
|
4219
|
-
msg += ` It must be ${range}. Received ${received}`;
|
|
4220
|
-
return msg
|
|
4221
|
-
}, RangeError);
|
|
4222
|
-
|
|
4223
|
-
function addNumericalSeparator (val) {
|
|
4224
|
-
let res = '';
|
|
4225
|
-
let i = val.length;
|
|
4226
|
-
const start = val[0] === '-' ? 1 : 0;
|
|
4227
|
-
for (; i >= start + 4; i -= 3) {
|
|
4228
|
-
res = `_${val.slice(i - 3, i)}${res}`;
|
|
4229
|
-
}
|
|
4230
|
-
return `${val.slice(0, i)}${res}`
|
|
4231
|
-
}
|
|
4232
|
-
|
|
4233
|
-
// CHECK FUNCTIONS
|
|
4234
|
-
// ===============
|
|
4235
|
-
|
|
4236
|
-
function checkBounds (buf, offset, byteLength) {
|
|
4237
|
-
validateNumber(offset, 'offset');
|
|
4238
|
-
if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
|
|
4239
|
-
boundsError(offset, buf.length - (byteLength + 1));
|
|
4240
|
-
}
|
|
4241
|
-
}
|
|
4242
|
-
|
|
4243
|
-
function checkIntBI (value, min, max, buf, offset, byteLength) {
|
|
4244
|
-
if (value > max || value < min) {
|
|
4245
|
-
const n = typeof min === 'bigint' ? 'n' : '';
|
|
4246
|
-
let range;
|
|
4247
|
-
{
|
|
4248
|
-
if (min === 0 || min === BigInt(0)) {
|
|
4249
|
-
range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;
|
|
4250
|
-
} else {
|
|
4251
|
-
range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
|
|
4252
|
-
`${(byteLength + 1) * 8 - 1}${n}`;
|
|
4253
|
-
}
|
|
4254
|
-
}
|
|
4255
|
-
throw new errors.ERR_OUT_OF_RANGE('value', range, value)
|
|
4256
|
-
}
|
|
4257
|
-
checkBounds(buf, offset, byteLength);
|
|
4258
|
-
}
|
|
4259
|
-
|
|
4260
|
-
function validateNumber (value, name) {
|
|
4261
|
-
if (typeof value !== 'number') {
|
|
4262
|
-
throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
|
|
4263
|
-
}
|
|
4264
|
-
}
|
|
4265
|
-
|
|
4266
|
-
function boundsError (value, length, type) {
|
|
4267
|
-
if (Math.floor(value) !== value) {
|
|
4268
|
-
validateNumber(value, type);
|
|
4269
|
-
throw new errors.ERR_OUT_OF_RANGE('offset', 'an integer', value)
|
|
4270
|
-
}
|
|
4271
|
-
|
|
4272
|
-
if (length < 0) {
|
|
4273
|
-
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
|
|
4274
|
-
}
|
|
4275
|
-
|
|
4276
|
-
throw new errors.ERR_OUT_OF_RANGE('offset',
|
|
4277
|
-
`>= ${0} and <= ${length}`,
|
|
4278
|
-
value)
|
|
4279
|
-
}
|
|
4280
|
-
|
|
4281
|
-
// HELPER FUNCTIONS
|
|
4282
|
-
// ================
|
|
4283
|
-
|
|
4284
|
-
const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
|
4285
|
-
|
|
4286
|
-
function base64clean (str) {
|
|
4287
|
-
// Node takes equal signs as end of the Base64 encoding
|
|
4288
|
-
str = str.split('=')[0];
|
|
4289
|
-
// Node strips out invalid characters like \n and \t from the string, base64-js does not
|
|
4290
|
-
str = str.trim().replace(INVALID_BASE64_RE, '');
|
|
4291
|
-
// Node converts strings with length < 2 to ''
|
|
4292
|
-
if (str.length < 2) return ''
|
|
4293
|
-
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
|
|
4294
|
-
while (str.length % 4 !== 0) {
|
|
4295
|
-
str = str + '=';
|
|
4296
|
-
}
|
|
4297
|
-
return str
|
|
4298
|
-
}
|
|
4299
|
-
|
|
4300
|
-
function utf8ToBytes (string, units) {
|
|
4301
|
-
units = units || Infinity;
|
|
4302
|
-
let codePoint;
|
|
4303
|
-
const length = string.length;
|
|
4304
|
-
let leadSurrogate = null;
|
|
4305
|
-
const bytes = [];
|
|
4306
|
-
|
|
4307
|
-
for (let i = 0; i < length; ++i) {
|
|
4308
|
-
codePoint = string.charCodeAt(i);
|
|
4309
|
-
|
|
4310
|
-
// is surrogate component
|
|
4311
|
-
if (codePoint > 0xD7FF && codePoint < 0xE000) {
|
|
4312
|
-
// last char was a lead
|
|
4313
|
-
if (!leadSurrogate) {
|
|
4314
|
-
// no lead yet
|
|
4315
|
-
if (codePoint > 0xDBFF) {
|
|
4316
|
-
// unexpected trail
|
|
4317
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
4318
|
-
continue
|
|
4319
|
-
} else if (i + 1 === length) {
|
|
4320
|
-
// unpaired lead
|
|
4321
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
4322
|
-
continue
|
|
4323
|
-
}
|
|
4324
|
-
|
|
4325
|
-
// valid lead
|
|
4326
|
-
leadSurrogate = codePoint;
|
|
4327
|
-
|
|
4328
|
-
continue
|
|
4329
|
-
}
|
|
4330
|
-
|
|
4331
|
-
// 2 leads in a row
|
|
4332
|
-
if (codePoint < 0xDC00) {
|
|
4333
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
4334
|
-
leadSurrogate = codePoint;
|
|
4335
|
-
continue
|
|
4336
|
-
}
|
|
4337
|
-
|
|
4338
|
-
// valid surrogate pair
|
|
4339
|
-
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
|
|
4340
|
-
} else if (leadSurrogate) {
|
|
4341
|
-
// valid bmp char, but last char was a lead
|
|
4342
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
4343
|
-
}
|
|
4344
|
-
|
|
4345
|
-
leadSurrogate = null;
|
|
4346
|
-
|
|
4347
|
-
// encode utf8
|
|
4348
|
-
if (codePoint < 0x80) {
|
|
4349
|
-
if ((units -= 1) < 0) break
|
|
4350
|
-
bytes.push(codePoint);
|
|
4351
|
-
} else if (codePoint < 0x800) {
|
|
4352
|
-
if ((units -= 2) < 0) break
|
|
4353
|
-
bytes.push(
|
|
4354
|
-
codePoint >> 0x6 | 0xC0,
|
|
4355
|
-
codePoint & 0x3F | 0x80
|
|
4356
|
-
);
|
|
4357
|
-
} else if (codePoint < 0x10000) {
|
|
4358
|
-
if ((units -= 3) < 0) break
|
|
4359
|
-
bytes.push(
|
|
4360
|
-
codePoint >> 0xC | 0xE0,
|
|
4361
|
-
codePoint >> 0x6 & 0x3F | 0x80,
|
|
4362
|
-
codePoint & 0x3F | 0x80
|
|
4363
|
-
);
|
|
4364
|
-
} else if (codePoint < 0x110000) {
|
|
4365
|
-
if ((units -= 4) < 0) break
|
|
4366
|
-
bytes.push(
|
|
4367
|
-
codePoint >> 0x12 | 0xF0,
|
|
4368
|
-
codePoint >> 0xC & 0x3F | 0x80,
|
|
4369
|
-
codePoint >> 0x6 & 0x3F | 0x80,
|
|
4370
|
-
codePoint & 0x3F | 0x80
|
|
4371
|
-
);
|
|
4372
|
-
} else {
|
|
4373
|
-
throw new Error('Invalid code point')
|
|
4374
|
-
}
|
|
4375
|
-
}
|
|
4376
|
-
|
|
4377
|
-
return bytes
|
|
4378
|
-
}
|
|
4379
|
-
|
|
4380
|
-
function asciiToBytes (str) {
|
|
4381
|
-
const byteArray = [];
|
|
4382
|
-
for (let i = 0; i < str.length; ++i) {
|
|
4383
|
-
// Node's code seems to be doing this and not & 0x7F..
|
|
4384
|
-
byteArray.push(str.charCodeAt(i) & 0xFF);
|
|
4385
|
-
}
|
|
4386
|
-
return byteArray
|
|
4387
|
-
}
|
|
4388
|
-
|
|
4389
|
-
function utf16leToBytes (str, units) {
|
|
4390
|
-
let c, hi, lo;
|
|
4391
|
-
const byteArray = [];
|
|
4392
|
-
for (let i = 0; i < str.length; ++i) {
|
|
4393
|
-
if ((units -= 2) < 0) break
|
|
4394
|
-
|
|
4395
|
-
c = str.charCodeAt(i);
|
|
4396
|
-
hi = c >> 8;
|
|
4397
|
-
lo = c % 256;
|
|
4398
|
-
byteArray.push(lo);
|
|
4399
|
-
byteArray.push(hi);
|
|
4400
|
-
}
|
|
4401
|
-
|
|
4402
|
-
return byteArray
|
|
4403
|
-
}
|
|
4404
|
-
|
|
4405
|
-
function base64ToBytes (str) {
|
|
4406
|
-
return base64.toByteArray(base64clean(str))
|
|
4407
|
-
}
|
|
4408
|
-
|
|
4409
|
-
function blitBuffer (src, dst, offset, length) {
|
|
4410
|
-
let i;
|
|
4411
|
-
for (i = 0; i < length; ++i) {
|
|
4412
|
-
if ((i + offset >= dst.length) || (i >= src.length)) break
|
|
4413
|
-
dst[i + offset] = src[i];
|
|
4414
|
-
}
|
|
4415
|
-
return i
|
|
4416
|
-
}
|
|
4417
|
-
|
|
4418
|
-
// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
|
|
4419
|
-
// the `instanceof` check but they should be treated as of that type.
|
|
4420
|
-
// See: https://github.com/feross/buffer/issues/166
|
|
4421
|
-
function isInstance (obj, type) {
|
|
4422
|
-
return obj instanceof type ||
|
|
4423
|
-
(obj != null && obj.constructor != null && obj.constructor.name != null &&
|
|
4424
|
-
obj.constructor.name === type.name)
|
|
4425
|
-
}
|
|
4426
|
-
function numberIsNaN (obj) {
|
|
4427
|
-
// For IE11 support
|
|
4428
|
-
return obj !== obj // eslint-disable-line no-self-compare
|
|
4429
|
-
}
|
|
4430
|
-
|
|
4431
|
-
// Create lookup table for `toString('hex')`
|
|
4432
|
-
// See: https://github.com/feross/buffer/issues/219
|
|
4433
|
-
const hexSliceLookupTable = (function () {
|
|
4434
|
-
const alphabet = '0123456789abcdef';
|
|
4435
|
-
const table = new Array(256);
|
|
4436
|
-
for (let i = 0; i < 16; ++i) {
|
|
4437
|
-
const i16 = i * 16;
|
|
4438
|
-
for (let j = 0; j < 16; ++j) {
|
|
4439
|
-
table[i16 + j] = alphabet[i] + alphabet[j];
|
|
4440
|
-
}
|
|
4441
|
-
}
|
|
4442
|
-
return table
|
|
4443
|
-
})();
|
|
4444
|
-
|
|
4445
|
-
// Return not function with Error if BigInt not supported
|
|
4446
|
-
function defineBigIntMethod (fn) {
|
|
4447
|
-
return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
|
|
4448
|
-
}
|
|
4449
|
-
|
|
4450
|
-
function BufferBigIntNotDefined () {
|
|
4451
|
-
throw new Error('BigInt not supported')
|
|
4452
|
-
}
|
|
4453
|
-
} (buffer$1));
|
|
4454
|
-
return buffer$1;
|
|
4455
|
-
}
|
|
4456
|
-
|
|
4457
|
-
var bufferExports$1 = requireBuffer$1();
|
|
4458
|
-
|
|
4459
|
-
var dist = {};
|
|
4460
|
-
|
|
4461
|
-
var buffer = {};
|
|
4462
|
-
|
|
4463
|
-
/*!
|
|
4464
|
-
* The buffer module from node.js, for the browser.
|
|
4465
|
-
*
|
|
4466
|
-
* @author Feross Aboukhadijeh <https://feross.org>
|
|
4467
|
-
* @license MIT
|
|
4468
|
-
*/
|
|
4469
|
-
|
|
4470
|
-
var hasRequiredBuffer;
|
|
4471
|
-
|
|
4472
|
-
function requireBuffer () {
|
|
4473
|
-
if (hasRequiredBuffer) return buffer;
|
|
4474
|
-
hasRequiredBuffer = 1;
|
|
4475
|
-
(function (exports) {
|
|
4476
|
-
|
|
4477
|
-
var base64 = requireBase64Js();
|
|
4478
|
-
var ieee754 = requireIeee754();
|
|
4479
|
-
var customInspectSymbol =
|
|
4480
|
-
(typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
|
|
4481
|
-
? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
|
|
4482
|
-
: null;
|
|
4483
|
-
|
|
4484
|
-
exports.Buffer = Buffer;
|
|
4485
|
-
exports.SlowBuffer = SlowBuffer;
|
|
4486
|
-
exports.INSPECT_MAX_BYTES = 50;
|
|
4487
|
-
|
|
4488
|
-
var K_MAX_LENGTH = 0x7fffffff;
|
|
4489
|
-
exports.kMaxLength = K_MAX_LENGTH;
|
|
4490
|
-
|
|
4491
|
-
/**
|
|
4492
|
-
* If `Buffer.TYPED_ARRAY_SUPPORT`:
|
|
4493
|
-
* === true Use Uint8Array implementation (fastest)
|
|
4494
|
-
* === false Print warning and recommend using `buffer` v4.x which has an Object
|
|
4495
|
-
* implementation (most compatible, even IE6)
|
|
4496
|
-
*
|
|
4497
|
-
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
|
|
4498
|
-
* Opera 11.6+, iOS 4.2+.
|
|
4499
|
-
*
|
|
4500
|
-
* We report that the browser does not support typed arrays if the are not subclassable
|
|
4501
|
-
* using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
|
|
4502
|
-
* (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
|
|
4503
|
-
* for __proto__ and has a buggy typed array implementation.
|
|
4504
|
-
*/
|
|
4505
|
-
Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
|
|
4506
|
-
|
|
4507
|
-
if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
|
|
4508
|
-
typeof console.error === 'function') {
|
|
4509
|
-
console.error(
|
|
4510
|
-
'This browser lacks typed array (Uint8Array) support which is required by ' +
|
|
4511
|
-
'`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
|
|
4512
|
-
);
|
|
4513
|
-
}
|
|
4514
|
-
|
|
4515
|
-
function typedArraySupport () {
|
|
4516
|
-
// Can typed array instances can be augmented?
|
|
4517
|
-
try {
|
|
4518
|
-
var arr = new Uint8Array(1);
|
|
4519
|
-
var proto = { foo: function () { return 42 } };
|
|
4520
|
-
Object.setPrototypeOf(proto, Uint8Array.prototype);
|
|
4521
|
-
Object.setPrototypeOf(arr, proto);
|
|
4522
|
-
return arr.foo() === 42
|
|
4523
|
-
} catch (e) {
|
|
4524
|
-
return false
|
|
4525
|
-
}
|
|
4526
|
-
}
|
|
4527
|
-
|
|
4528
|
-
Object.defineProperty(Buffer.prototype, 'parent', {
|
|
4529
|
-
enumerable: true,
|
|
4530
|
-
get: function () {
|
|
4531
|
-
if (!Buffer.isBuffer(this)) return undefined
|
|
4532
|
-
return this.buffer
|
|
4533
|
-
}
|
|
4534
|
-
});
|
|
4535
|
-
|
|
4536
|
-
Object.defineProperty(Buffer.prototype, 'offset', {
|
|
4537
|
-
enumerable: true,
|
|
4538
|
-
get: function () {
|
|
4539
|
-
if (!Buffer.isBuffer(this)) return undefined
|
|
4540
|
-
return this.byteOffset
|
|
4541
|
-
}
|
|
4542
|
-
});
|
|
4543
|
-
|
|
4544
|
-
function createBuffer (length) {
|
|
4545
|
-
if (length > K_MAX_LENGTH) {
|
|
4546
|
-
throw new RangeError('The value "' + length + '" is invalid for option "size"')
|
|
4547
|
-
}
|
|
4548
|
-
// Return an augmented `Uint8Array` instance
|
|
4549
|
-
var buf = new Uint8Array(length);
|
|
4550
|
-
Object.setPrototypeOf(buf, Buffer.prototype);
|
|
4551
|
-
return buf
|
|
4552
|
-
}
|
|
4553
|
-
|
|
4554
|
-
/**
|
|
4555
|
-
* The Buffer constructor returns instances of `Uint8Array` that have their
|
|
4556
|
-
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
|
|
4557
|
-
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
|
|
4558
|
-
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
|
|
4559
|
-
* returns a single octet.
|
|
4560
|
-
*
|
|
4561
|
-
* The `Uint8Array` prototype remains unmodified.
|
|
4562
|
-
*/
|
|
4563
|
-
|
|
4564
|
-
function Buffer (arg, encodingOrOffset, length) {
|
|
4565
|
-
// Common case.
|
|
4566
|
-
if (typeof arg === 'number') {
|
|
4567
|
-
if (typeof encodingOrOffset === 'string') {
|
|
4568
|
-
throw new TypeError(
|
|
4569
|
-
'The "string" argument must be of type string. Received type number'
|
|
4570
|
-
)
|
|
4571
|
-
}
|
|
4572
|
-
return allocUnsafe(arg)
|
|
4573
|
-
}
|
|
4574
|
-
return from(arg, encodingOrOffset, length)
|
|
4575
|
-
}
|
|
4576
|
-
|
|
4577
|
-
Buffer.poolSize = 8192; // not used by this implementation
|
|
4578
|
-
|
|
4579
|
-
function from (value, encodingOrOffset, length) {
|
|
4580
|
-
if (typeof value === 'string') {
|
|
4581
|
-
return fromString(value, encodingOrOffset)
|
|
4582
|
-
}
|
|
4583
|
-
|
|
4584
|
-
if (ArrayBuffer.isView(value)) {
|
|
4585
|
-
return fromArrayView(value)
|
|
4586
|
-
}
|
|
4587
|
-
|
|
4588
|
-
if (value == null) {
|
|
4589
|
-
throw new TypeError(
|
|
4590
|
-
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
|
4591
|
-
'or Array-like Object. Received type ' + (typeof value)
|
|
4592
|
-
)
|
|
4593
|
-
}
|
|
4594
|
-
|
|
4595
|
-
if (isInstance(value, ArrayBuffer) ||
|
|
4596
|
-
(value && isInstance(value.buffer, ArrayBuffer))) {
|
|
4597
|
-
return fromArrayBuffer(value, encodingOrOffset, length)
|
|
4598
|
-
}
|
|
4599
|
-
|
|
4600
|
-
if (typeof SharedArrayBuffer !== 'undefined' &&
|
|
4601
|
-
(isInstance(value, SharedArrayBuffer) ||
|
|
4602
|
-
(value && isInstance(value.buffer, SharedArrayBuffer)))) {
|
|
4603
|
-
return fromArrayBuffer(value, encodingOrOffset, length)
|
|
4604
|
-
}
|
|
4605
|
-
|
|
4606
|
-
if (typeof value === 'number') {
|
|
4607
|
-
throw new TypeError(
|
|
4608
|
-
'The "value" argument must not be of type number. Received type number'
|
|
4609
|
-
)
|
|
4610
|
-
}
|
|
4611
|
-
|
|
4612
|
-
var valueOf = value.valueOf && value.valueOf();
|
|
4613
|
-
if (valueOf != null && valueOf !== value) {
|
|
4614
|
-
return Buffer.from(valueOf, encodingOrOffset, length)
|
|
4615
|
-
}
|
|
4616
|
-
|
|
4617
|
-
var b = fromObject(value);
|
|
4618
|
-
if (b) return b
|
|
4619
|
-
|
|
4620
|
-
if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
|
|
4621
|
-
typeof value[Symbol.toPrimitive] === 'function') {
|
|
4622
|
-
return Buffer.from(
|
|
4623
|
-
value[Symbol.toPrimitive]('string'), encodingOrOffset, length
|
|
4624
|
-
)
|
|
4625
|
-
}
|
|
4626
|
-
|
|
4627
|
-
throw new TypeError(
|
|
4628
|
-
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
|
4629
|
-
'or Array-like Object. Received type ' + (typeof value)
|
|
4630
|
-
)
|
|
4631
|
-
}
|
|
4632
|
-
|
|
4633
|
-
/**
|
|
4634
|
-
* Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
|
|
4635
|
-
* if value is a number.
|
|
4636
|
-
* Buffer.from(str[, encoding])
|
|
4637
|
-
* Buffer.from(array)
|
|
4638
|
-
* Buffer.from(buffer)
|
|
4639
|
-
* Buffer.from(arrayBuffer[, byteOffset[, length]])
|
|
4640
|
-
**/
|
|
4641
|
-
Buffer.from = function (value, encodingOrOffset, length) {
|
|
4642
|
-
return from(value, encodingOrOffset, length)
|
|
4643
|
-
};
|
|
4644
|
-
|
|
4645
|
-
// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
|
|
4646
|
-
// https://github.com/feross/buffer/pull/148
|
|
4647
|
-
Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
|
|
4648
|
-
Object.setPrototypeOf(Buffer, Uint8Array);
|
|
4649
|
-
|
|
4650
|
-
function assertSize (size) {
|
|
4651
|
-
if (typeof size !== 'number') {
|
|
4652
|
-
throw new TypeError('"size" argument must be of type number')
|
|
4653
|
-
} else if (size < 0) {
|
|
4654
|
-
throw new RangeError('The value "' + size + '" is invalid for option "size"')
|
|
4655
|
-
}
|
|
4656
|
-
}
|
|
4657
|
-
|
|
4658
|
-
function alloc (size, fill, encoding) {
|
|
4659
|
-
assertSize(size);
|
|
4660
|
-
if (size <= 0) {
|
|
4661
|
-
return createBuffer(size)
|
|
4662
|
-
}
|
|
4663
|
-
if (fill !== undefined) {
|
|
4664
|
-
// Only pay attention to encoding if it's a string. This
|
|
4665
|
-
// prevents accidentally sending in a number that would
|
|
4666
|
-
// be interpreted as a start offset.
|
|
4667
|
-
return typeof encoding === 'string'
|
|
4668
|
-
? createBuffer(size).fill(fill, encoding)
|
|
4669
|
-
: createBuffer(size).fill(fill)
|
|
4670
|
-
}
|
|
4671
|
-
return createBuffer(size)
|
|
4672
|
-
}
|
|
4673
|
-
|
|
4674
|
-
/**
|
|
4675
|
-
* Creates a new filled Buffer instance.
|
|
4676
|
-
* alloc(size[, fill[, encoding]])
|
|
4677
|
-
**/
|
|
4678
|
-
Buffer.alloc = function (size, fill, encoding) {
|
|
4679
|
-
return alloc(size, fill, encoding)
|
|
4680
|
-
};
|
|
4681
|
-
|
|
4682
|
-
function allocUnsafe (size) {
|
|
4683
|
-
assertSize(size);
|
|
4684
|
-
return createBuffer(size < 0 ? 0 : checked(size) | 0)
|
|
4685
|
-
}
|
|
4686
|
-
|
|
4687
|
-
/**
|
|
4688
|
-
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
|
|
4689
|
-
* */
|
|
4690
|
-
Buffer.allocUnsafe = function (size) {
|
|
4691
|
-
return allocUnsafe(size)
|
|
4692
|
-
};
|
|
4693
|
-
/**
|
|
4694
|
-
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
|
4695
|
-
*/
|
|
4696
|
-
Buffer.allocUnsafeSlow = function (size) {
|
|
4697
|
-
return allocUnsafe(size)
|
|
4698
|
-
};
|
|
4699
|
-
|
|
4700
|
-
function fromString (string, encoding) {
|
|
4701
|
-
if (typeof encoding !== 'string' || encoding === '') {
|
|
4702
|
-
encoding = 'utf8';
|
|
4703
|
-
}
|
|
4704
|
-
|
|
4705
|
-
if (!Buffer.isEncoding(encoding)) {
|
|
4706
|
-
throw new TypeError('Unknown encoding: ' + encoding)
|
|
4707
|
-
}
|
|
4708
|
-
|
|
4709
|
-
var length = byteLength(string, encoding) | 0;
|
|
4710
|
-
var buf = createBuffer(length);
|
|
4711
|
-
|
|
4712
|
-
var actual = buf.write(string, encoding);
|
|
4713
|
-
|
|
4714
|
-
if (actual !== length) {
|
|
4715
|
-
// Writing a hex string, for example, that contains invalid characters will
|
|
4716
|
-
// cause everything after the first invalid character to be ignored. (e.g.
|
|
4717
|
-
// 'abxxcd' will be treated as 'ab')
|
|
4718
|
-
buf = buf.slice(0, actual);
|
|
4719
|
-
}
|
|
4720
|
-
|
|
4721
|
-
return buf
|
|
4722
|
-
}
|
|
4723
|
-
|
|
4724
|
-
function fromArrayLike (array) {
|
|
4725
|
-
var length = array.length < 0 ? 0 : checked(array.length) | 0;
|
|
4726
|
-
var buf = createBuffer(length);
|
|
4727
|
-
for (var i = 0; i < length; i += 1) {
|
|
4728
|
-
buf[i] = array[i] & 255;
|
|
4729
|
-
}
|
|
4730
|
-
return buf
|
|
4731
|
-
}
|
|
4732
|
-
|
|
4733
|
-
function fromArrayView (arrayView) {
|
|
4734
|
-
if (isInstance(arrayView, Uint8Array)) {
|
|
4735
|
-
var copy = new Uint8Array(arrayView);
|
|
4736
|
-
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
|
|
4737
|
-
}
|
|
4738
|
-
return fromArrayLike(arrayView)
|
|
4739
|
-
}
|
|
4740
|
-
|
|
4741
|
-
function fromArrayBuffer (array, byteOffset, length) {
|
|
4742
|
-
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
4743
|
-
throw new RangeError('"offset" is outside of buffer bounds')
|
|
4744
|
-
}
|
|
4745
|
-
|
|
4746
|
-
if (array.byteLength < byteOffset + (length || 0)) {
|
|
4747
|
-
throw new RangeError('"length" is outside of buffer bounds')
|
|
4748
|
-
}
|
|
4749
|
-
|
|
4750
|
-
var buf;
|
|
4751
|
-
if (byteOffset === undefined && length === undefined) {
|
|
4752
|
-
buf = new Uint8Array(array);
|
|
4753
|
-
} else if (length === undefined) {
|
|
4754
|
-
buf = new Uint8Array(array, byteOffset);
|
|
4755
|
-
} else {
|
|
4756
|
-
buf = new Uint8Array(array, byteOffset, length);
|
|
4757
|
-
}
|
|
4758
|
-
|
|
4759
|
-
// Return an augmented `Uint8Array` instance
|
|
4760
|
-
Object.setPrototypeOf(buf, Buffer.prototype);
|
|
4761
|
-
|
|
4762
|
-
return buf
|
|
4763
|
-
}
|
|
4764
|
-
|
|
4765
|
-
function fromObject (obj) {
|
|
4766
|
-
if (Buffer.isBuffer(obj)) {
|
|
4767
|
-
var len = checked(obj.length) | 0;
|
|
4768
|
-
var buf = createBuffer(len);
|
|
4769
|
-
|
|
4770
|
-
if (buf.length === 0) {
|
|
4771
|
-
return buf
|
|
4772
|
-
}
|
|
4773
|
-
|
|
4774
|
-
obj.copy(buf, 0, 0, len);
|
|
4775
|
-
return buf
|
|
4776
|
-
}
|
|
4777
|
-
|
|
4778
|
-
if (obj.length !== undefined) {
|
|
4779
|
-
if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
|
|
4780
|
-
return createBuffer(0)
|
|
4781
|
-
}
|
|
4782
|
-
return fromArrayLike(obj)
|
|
4783
|
-
}
|
|
4784
|
-
|
|
4785
|
-
if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
|
|
4786
|
-
return fromArrayLike(obj.data)
|
|
4787
|
-
}
|
|
4788
|
-
}
|
|
4789
|
-
|
|
4790
|
-
function checked (length) {
|
|
4791
|
-
// Note: cannot use `length < K_MAX_LENGTH` here because that fails when
|
|
4792
|
-
// length is NaN (which is otherwise coerced to zero.)
|
|
4793
|
-
if (length >= K_MAX_LENGTH) {
|
|
4794
|
-
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
|
|
4795
|
-
'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
|
|
4796
|
-
}
|
|
4797
|
-
return length | 0
|
|
4798
|
-
}
|
|
4799
|
-
|
|
4800
|
-
function SlowBuffer (length) {
|
|
4801
|
-
if (+length != length) { // eslint-disable-line eqeqeq
|
|
4802
|
-
length = 0;
|
|
4803
|
-
}
|
|
4804
|
-
return Buffer.alloc(+length)
|
|
4805
|
-
}
|
|
4806
|
-
|
|
4807
|
-
Buffer.isBuffer = function isBuffer (b) {
|
|
4808
|
-
return b != null && b._isBuffer === true &&
|
|
4809
|
-
b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
|
|
4810
|
-
};
|
|
4811
|
-
|
|
4812
|
-
Buffer.compare = function compare (a, b) {
|
|
4813
|
-
if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
|
|
4814
|
-
if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
|
|
4815
|
-
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
|
|
4816
|
-
throw new TypeError(
|
|
4817
|
-
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
|
|
4818
|
-
)
|
|
4819
|
-
}
|
|
4820
|
-
|
|
4821
|
-
if (a === b) return 0
|
|
4822
|
-
|
|
4823
|
-
var x = a.length;
|
|
4824
|
-
var y = b.length;
|
|
4825
|
-
|
|
4826
|
-
for (var i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
4827
|
-
if (a[i] !== b[i]) {
|
|
4828
|
-
x = a[i];
|
|
4829
|
-
y = b[i];
|
|
4830
|
-
break
|
|
4831
|
-
}
|
|
4832
|
-
}
|
|
4833
|
-
|
|
4834
|
-
if (x < y) return -1
|
|
4835
|
-
if (y < x) return 1
|
|
4836
|
-
return 0
|
|
4837
|
-
};
|
|
4838
|
-
|
|
4839
|
-
Buffer.isEncoding = function isEncoding (encoding) {
|
|
4840
|
-
switch (String(encoding).toLowerCase()) {
|
|
4841
|
-
case 'hex':
|
|
4842
|
-
case 'utf8':
|
|
4843
|
-
case 'utf-8':
|
|
4844
|
-
case 'ascii':
|
|
4845
|
-
case 'latin1':
|
|
4846
|
-
case 'binary':
|
|
4847
|
-
case 'base64':
|
|
4848
|
-
case 'ucs2':
|
|
4849
|
-
case 'ucs-2':
|
|
4850
|
-
case 'utf16le':
|
|
4851
|
-
case 'utf-16le':
|
|
4852
|
-
return true
|
|
4853
|
-
default:
|
|
4854
|
-
return false
|
|
4855
|
-
}
|
|
4856
|
-
};
|
|
4857
|
-
|
|
4858
|
-
Buffer.concat = function concat (list, length) {
|
|
4859
|
-
if (!Array.isArray(list)) {
|
|
4860
|
-
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
4861
|
-
}
|
|
4862
|
-
|
|
4863
|
-
if (list.length === 0) {
|
|
4864
|
-
return Buffer.alloc(0)
|
|
4865
|
-
}
|
|
4866
|
-
|
|
4867
|
-
var i;
|
|
4868
|
-
if (length === undefined) {
|
|
4869
|
-
length = 0;
|
|
4870
|
-
for (i = 0; i < list.length; ++i) {
|
|
4871
|
-
length += list[i].length;
|
|
4872
|
-
}
|
|
4873
|
-
}
|
|
4874
|
-
|
|
4875
|
-
var buffer = Buffer.allocUnsafe(length);
|
|
4876
|
-
var pos = 0;
|
|
4877
|
-
for (i = 0; i < list.length; ++i) {
|
|
4878
|
-
var buf = list[i];
|
|
4879
|
-
if (isInstance(buf, Uint8Array)) {
|
|
4880
|
-
if (pos + buf.length > buffer.length) {
|
|
4881
|
-
Buffer.from(buf).copy(buffer, pos);
|
|
4882
|
-
} else {
|
|
4883
|
-
Uint8Array.prototype.set.call(
|
|
4884
|
-
buffer,
|
|
4885
|
-
buf,
|
|
4886
|
-
pos
|
|
4887
|
-
);
|
|
4888
|
-
}
|
|
4889
|
-
} else if (!Buffer.isBuffer(buf)) {
|
|
4890
|
-
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
4891
|
-
} else {
|
|
4892
|
-
buf.copy(buffer, pos);
|
|
4893
|
-
}
|
|
4894
|
-
pos += buf.length;
|
|
4895
|
-
}
|
|
4896
|
-
return buffer
|
|
4897
|
-
};
|
|
4898
|
-
|
|
4899
|
-
function byteLength (string, encoding) {
|
|
4900
|
-
if (Buffer.isBuffer(string)) {
|
|
4901
|
-
return string.length
|
|
4902
|
-
}
|
|
4903
|
-
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
|
|
4904
|
-
return string.byteLength
|
|
4905
|
-
}
|
|
4906
|
-
if (typeof string !== 'string') {
|
|
4907
|
-
throw new TypeError(
|
|
4908
|
-
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
|
|
4909
|
-
'Received type ' + typeof string
|
|
4910
|
-
)
|
|
4911
|
-
}
|
|
4912
|
-
|
|
4913
|
-
var len = string.length;
|
|
4914
|
-
var mustMatch = (arguments.length > 2 && arguments[2] === true);
|
|
4915
|
-
if (!mustMatch && len === 0) return 0
|
|
4916
|
-
|
|
4917
|
-
// Use a for loop to avoid recursion
|
|
4918
|
-
var loweredCase = false;
|
|
4919
|
-
for (;;) {
|
|
4920
|
-
switch (encoding) {
|
|
4921
|
-
case 'ascii':
|
|
4922
|
-
case 'latin1':
|
|
4923
|
-
case 'binary':
|
|
4924
|
-
return len
|
|
4925
|
-
case 'utf8':
|
|
4926
|
-
case 'utf-8':
|
|
4927
|
-
return utf8ToBytes(string).length
|
|
4928
|
-
case 'ucs2':
|
|
4929
|
-
case 'ucs-2':
|
|
4930
|
-
case 'utf16le':
|
|
4931
|
-
case 'utf-16le':
|
|
4932
|
-
return len * 2
|
|
4933
|
-
case 'hex':
|
|
4934
|
-
return len >>> 1
|
|
4935
|
-
case 'base64':
|
|
4936
|
-
return base64ToBytes(string).length
|
|
4937
|
-
default:
|
|
4938
|
-
if (loweredCase) {
|
|
4939
|
-
return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
|
|
4940
|
-
}
|
|
4941
|
-
encoding = ('' + encoding).toLowerCase();
|
|
4942
|
-
loweredCase = true;
|
|
4943
|
-
}
|
|
4944
|
-
}
|
|
4945
|
-
}
|
|
4946
|
-
Buffer.byteLength = byteLength;
|
|
4947
|
-
|
|
4948
|
-
function slowToString (encoding, start, end) {
|
|
4949
|
-
var loweredCase = false;
|
|
4950
|
-
|
|
4951
|
-
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
|
|
4952
|
-
// property of a typed array.
|
|
4953
|
-
|
|
4954
|
-
// This behaves neither like String nor Uint8Array in that we set start/end
|
|
4955
|
-
// to their upper/lower bounds if the value passed is out of range.
|
|
4956
|
-
// undefined is handled specially as per ECMA-262 6th Edition,
|
|
4957
|
-
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
|
|
4958
|
-
if (start === undefined || start < 0) {
|
|
4959
|
-
start = 0;
|
|
4960
|
-
}
|
|
4961
|
-
// Return early if start > this.length. Done here to prevent potential uint32
|
|
4962
|
-
// coercion fail below.
|
|
4963
|
-
if (start > this.length) {
|
|
4964
|
-
return ''
|
|
4965
|
-
}
|
|
4966
|
-
|
|
4967
|
-
if (end === undefined || end > this.length) {
|
|
4968
|
-
end = this.length;
|
|
4969
|
-
}
|
|
4970
|
-
|
|
4971
|
-
if (end <= 0) {
|
|
4972
|
-
return ''
|
|
4973
|
-
}
|
|
4974
|
-
|
|
4975
|
-
// Force coercion to uint32. This will also coerce falsey/NaN values to 0.
|
|
4976
|
-
end >>>= 0;
|
|
4977
|
-
start >>>= 0;
|
|
4978
|
-
|
|
4979
|
-
if (end <= start) {
|
|
4980
|
-
return ''
|
|
4981
|
-
}
|
|
4982
|
-
|
|
4983
|
-
if (!encoding) encoding = 'utf8';
|
|
4984
|
-
|
|
4985
|
-
while (true) {
|
|
4986
|
-
switch (encoding) {
|
|
4987
|
-
case 'hex':
|
|
4988
|
-
return hexSlice(this, start, end)
|
|
4989
|
-
|
|
4990
|
-
case 'utf8':
|
|
4991
|
-
case 'utf-8':
|
|
4992
|
-
return utf8Slice(this, start, end)
|
|
4993
|
-
|
|
4994
|
-
case 'ascii':
|
|
4995
|
-
return asciiSlice(this, start, end)
|
|
4996
|
-
|
|
4997
|
-
case 'latin1':
|
|
4998
|
-
case 'binary':
|
|
4999
|
-
return latin1Slice(this, start, end)
|
|
5000
|
-
|
|
5001
|
-
case 'base64':
|
|
5002
|
-
return base64Slice(this, start, end)
|
|
5003
|
-
|
|
5004
|
-
case 'ucs2':
|
|
5005
|
-
case 'ucs-2':
|
|
5006
|
-
case 'utf16le':
|
|
5007
|
-
case 'utf-16le':
|
|
5008
|
-
return utf16leSlice(this, start, end)
|
|
5009
|
-
|
|
5010
|
-
default:
|
|
5011
|
-
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
5012
|
-
encoding = (encoding + '').toLowerCase();
|
|
5013
|
-
loweredCase = true;
|
|
5014
|
-
}
|
|
5015
|
-
}
|
|
5016
|
-
}
|
|
5017
|
-
|
|
5018
|
-
// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
|
|
5019
|
-
// to detect a Buffer instance. It's not possible to use `instanceof Buffer`
|
|
5020
|
-
// reliably in a browserify context because there could be multiple different
|
|
5021
|
-
// copies of the 'buffer' package in use. This method works even for Buffer
|
|
5022
|
-
// instances that were created from another copy of the `buffer` package.
|
|
5023
|
-
// See: https://github.com/feross/buffer/issues/154
|
|
5024
|
-
Buffer.prototype._isBuffer = true;
|
|
5025
|
-
|
|
5026
|
-
function swap (b, n, m) {
|
|
5027
|
-
var i = b[n];
|
|
5028
|
-
b[n] = b[m];
|
|
5029
|
-
b[m] = i;
|
|
5030
|
-
}
|
|
5031
|
-
|
|
5032
|
-
Buffer.prototype.swap16 = function swap16 () {
|
|
5033
|
-
var len = this.length;
|
|
5034
|
-
if (len % 2 !== 0) {
|
|
5035
|
-
throw new RangeError('Buffer size must be a multiple of 16-bits')
|
|
5036
|
-
}
|
|
5037
|
-
for (var i = 0; i < len; i += 2) {
|
|
5038
|
-
swap(this, i, i + 1);
|
|
5039
|
-
}
|
|
5040
|
-
return this
|
|
5041
|
-
};
|
|
5042
|
-
|
|
5043
|
-
Buffer.prototype.swap32 = function swap32 () {
|
|
5044
|
-
var len = this.length;
|
|
5045
|
-
if (len % 4 !== 0) {
|
|
5046
|
-
throw new RangeError('Buffer size must be a multiple of 32-bits')
|
|
5047
|
-
}
|
|
5048
|
-
for (var i = 0; i < len; i += 4) {
|
|
5049
|
-
swap(this, i, i + 3);
|
|
5050
|
-
swap(this, i + 1, i + 2);
|
|
5051
|
-
}
|
|
5052
|
-
return this
|
|
5053
|
-
};
|
|
5054
|
-
|
|
5055
|
-
Buffer.prototype.swap64 = function swap64 () {
|
|
5056
|
-
var len = this.length;
|
|
5057
|
-
if (len % 8 !== 0) {
|
|
5058
|
-
throw new RangeError('Buffer size must be a multiple of 64-bits')
|
|
5059
|
-
}
|
|
5060
|
-
for (var i = 0; i < len; i += 8) {
|
|
5061
|
-
swap(this, i, i + 7);
|
|
5062
|
-
swap(this, i + 1, i + 6);
|
|
5063
|
-
swap(this, i + 2, i + 5);
|
|
5064
|
-
swap(this, i + 3, i + 4);
|
|
5065
|
-
}
|
|
5066
|
-
return this
|
|
5067
|
-
};
|
|
5068
|
-
|
|
5069
|
-
Buffer.prototype.toString = function toString () {
|
|
5070
|
-
var length = this.length;
|
|
5071
|
-
if (length === 0) return ''
|
|
5072
|
-
if (arguments.length === 0) return utf8Slice(this, 0, length)
|
|
5073
|
-
return slowToString.apply(this, arguments)
|
|
5074
|
-
};
|
|
5075
|
-
|
|
5076
|
-
Buffer.prototype.toLocaleString = Buffer.prototype.toString;
|
|
5077
|
-
|
|
5078
|
-
Buffer.prototype.equals = function equals (b) {
|
|
5079
|
-
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
|
|
5080
|
-
if (this === b) return true
|
|
5081
|
-
return Buffer.compare(this, b) === 0
|
|
5082
|
-
};
|
|
5083
|
-
|
|
5084
|
-
Buffer.prototype.inspect = function inspect () {
|
|
5085
|
-
var str = '';
|
|
5086
|
-
var max = exports.INSPECT_MAX_BYTES;
|
|
5087
|
-
str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
|
|
5088
|
-
if (this.length > max) str += ' ... ';
|
|
5089
|
-
return '<Buffer ' + str + '>'
|
|
5090
|
-
};
|
|
5091
|
-
if (customInspectSymbol) {
|
|
5092
|
-
Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
|
|
5093
|
-
}
|
|
5094
|
-
|
|
5095
|
-
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
|
|
5096
|
-
if (isInstance(target, Uint8Array)) {
|
|
5097
|
-
target = Buffer.from(target, target.offset, target.byteLength);
|
|
5098
|
-
}
|
|
5099
|
-
if (!Buffer.isBuffer(target)) {
|
|
5100
|
-
throw new TypeError(
|
|
5101
|
-
'The "target" argument must be one of type Buffer or Uint8Array. ' +
|
|
5102
|
-
'Received type ' + (typeof target)
|
|
5103
|
-
)
|
|
5104
|
-
}
|
|
5105
|
-
|
|
5106
|
-
if (start === undefined) {
|
|
5107
|
-
start = 0;
|
|
5108
|
-
}
|
|
5109
|
-
if (end === undefined) {
|
|
5110
|
-
end = target ? target.length : 0;
|
|
5111
|
-
}
|
|
5112
|
-
if (thisStart === undefined) {
|
|
5113
|
-
thisStart = 0;
|
|
5114
|
-
}
|
|
5115
|
-
if (thisEnd === undefined) {
|
|
5116
|
-
thisEnd = this.length;
|
|
5117
|
-
}
|
|
5118
|
-
|
|
5119
|
-
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
5120
|
-
throw new RangeError('out of range index')
|
|
5121
|
-
}
|
|
5122
|
-
|
|
5123
|
-
if (thisStart >= thisEnd && start >= end) {
|
|
5124
|
-
return 0
|
|
5125
|
-
}
|
|
5126
|
-
if (thisStart >= thisEnd) {
|
|
5127
|
-
return -1
|
|
5128
|
-
}
|
|
5129
|
-
if (start >= end) {
|
|
5130
|
-
return 1
|
|
5131
|
-
}
|
|
5132
|
-
|
|
5133
|
-
start >>>= 0;
|
|
5134
|
-
end >>>= 0;
|
|
5135
|
-
thisStart >>>= 0;
|
|
5136
|
-
thisEnd >>>= 0;
|
|
5137
|
-
|
|
5138
|
-
if (this === target) return 0
|
|
5139
|
-
|
|
5140
|
-
var x = thisEnd - thisStart;
|
|
5141
|
-
var y = end - start;
|
|
5142
|
-
var len = Math.min(x, y);
|
|
5143
|
-
|
|
5144
|
-
var thisCopy = this.slice(thisStart, thisEnd);
|
|
5145
|
-
var targetCopy = target.slice(start, end);
|
|
5146
|
-
|
|
5147
|
-
for (var i = 0; i < len; ++i) {
|
|
5148
|
-
if (thisCopy[i] !== targetCopy[i]) {
|
|
5149
|
-
x = thisCopy[i];
|
|
5150
|
-
y = targetCopy[i];
|
|
5151
|
-
break
|
|
5152
|
-
}
|
|
5153
|
-
}
|
|
5154
|
-
|
|
5155
|
-
if (x < y) return -1
|
|
5156
|
-
if (y < x) return 1
|
|
5157
|
-
return 0
|
|
5158
|
-
};
|
|
5159
|
-
|
|
5160
|
-
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
|
|
5161
|
-
// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
|
|
5162
|
-
//
|
|
5163
|
-
// Arguments:
|
|
5164
|
-
// - buffer - a Buffer to search
|
|
5165
|
-
// - val - a string, Buffer, or number
|
|
5166
|
-
// - byteOffset - an index into `buffer`; will be clamped to an int32
|
|
5167
|
-
// - encoding - an optional encoding, relevant is val is a string
|
|
5168
|
-
// - dir - true for indexOf, false for lastIndexOf
|
|
5169
|
-
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
|
5170
|
-
// Empty buffer means no match
|
|
5171
|
-
if (buffer.length === 0) return -1
|
|
5172
|
-
|
|
5173
|
-
// Normalize byteOffset
|
|
5174
|
-
if (typeof byteOffset === 'string') {
|
|
5175
|
-
encoding = byteOffset;
|
|
5176
|
-
byteOffset = 0;
|
|
5177
|
-
} else if (byteOffset > 0x7fffffff) {
|
|
5178
|
-
byteOffset = 0x7fffffff;
|
|
5179
|
-
} else if (byteOffset < -2147483648) {
|
|
5180
|
-
byteOffset = -2147483648;
|
|
5181
|
-
}
|
|
5182
|
-
byteOffset = +byteOffset; // Coerce to Number.
|
|
5183
|
-
if (numberIsNaN(byteOffset)) {
|
|
5184
|
-
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
|
|
5185
|
-
byteOffset = dir ? 0 : (buffer.length - 1);
|
|
5186
|
-
}
|
|
5187
|
-
|
|
5188
|
-
// Normalize byteOffset: negative offsets start from the end of the buffer
|
|
5189
|
-
if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
|
|
5190
|
-
if (byteOffset >= buffer.length) {
|
|
5191
|
-
if (dir) return -1
|
|
5192
|
-
else byteOffset = buffer.length - 1;
|
|
5193
|
-
} else if (byteOffset < 0) {
|
|
5194
|
-
if (dir) byteOffset = 0;
|
|
5195
|
-
else return -1
|
|
5196
|
-
}
|
|
5197
|
-
|
|
5198
|
-
// Normalize val
|
|
5199
|
-
if (typeof val === 'string') {
|
|
5200
|
-
val = Buffer.from(val, encoding);
|
|
5201
|
-
}
|
|
5202
|
-
|
|
5203
|
-
// Finally, search either indexOf (if dir is true) or lastIndexOf
|
|
5204
|
-
if (Buffer.isBuffer(val)) {
|
|
5205
|
-
// Special case: looking for empty string/buffer always fails
|
|
5206
|
-
if (val.length === 0) {
|
|
5207
|
-
return -1
|
|
5208
|
-
}
|
|
5209
|
-
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
|
|
5210
|
-
} else if (typeof val === 'number') {
|
|
5211
|
-
val = val & 0xFF; // Search for a byte value [0-255]
|
|
5212
|
-
if (typeof Uint8Array.prototype.indexOf === 'function') {
|
|
5213
|
-
if (dir) {
|
|
5214
|
-
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
|
|
5215
|
-
} else {
|
|
5216
|
-
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
|
|
5217
|
-
}
|
|
5218
|
-
}
|
|
5219
|
-
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
|
|
5220
|
-
}
|
|
5221
|
-
|
|
5222
|
-
throw new TypeError('val must be string, number or Buffer')
|
|
5223
|
-
}
|
|
5224
|
-
|
|
5225
|
-
function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
|
|
5226
|
-
var indexSize = 1;
|
|
5227
|
-
var arrLength = arr.length;
|
|
5228
|
-
var valLength = val.length;
|
|
5229
|
-
|
|
5230
|
-
if (encoding !== undefined) {
|
|
5231
|
-
encoding = String(encoding).toLowerCase();
|
|
5232
|
-
if (encoding === 'ucs2' || encoding === 'ucs-2' ||
|
|
5233
|
-
encoding === 'utf16le' || encoding === 'utf-16le') {
|
|
5234
|
-
if (arr.length < 2 || val.length < 2) {
|
|
5235
|
-
return -1
|
|
5236
|
-
}
|
|
5237
|
-
indexSize = 2;
|
|
5238
|
-
arrLength /= 2;
|
|
5239
|
-
valLength /= 2;
|
|
5240
|
-
byteOffset /= 2;
|
|
5241
|
-
}
|
|
5242
|
-
}
|
|
5243
|
-
|
|
5244
|
-
function read (buf, i) {
|
|
5245
|
-
if (indexSize === 1) {
|
|
5246
|
-
return buf[i]
|
|
5247
|
-
} else {
|
|
5248
|
-
return buf.readUInt16BE(i * indexSize)
|
|
5249
|
-
}
|
|
5250
|
-
}
|
|
5251
|
-
|
|
5252
|
-
var i;
|
|
5253
|
-
if (dir) {
|
|
5254
|
-
var foundIndex = -1;
|
|
5255
|
-
for (i = byteOffset; i < arrLength; i++) {
|
|
5256
|
-
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
5257
|
-
if (foundIndex === -1) foundIndex = i;
|
|
5258
|
-
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
|
|
5259
|
-
} else {
|
|
5260
|
-
if (foundIndex !== -1) i -= i - foundIndex;
|
|
5261
|
-
foundIndex = -1;
|
|
5262
|
-
}
|
|
5263
|
-
}
|
|
5264
|
-
} else {
|
|
5265
|
-
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
|
|
5266
|
-
for (i = byteOffset; i >= 0; i--) {
|
|
5267
|
-
var found = true;
|
|
5268
|
-
for (var j = 0; j < valLength; j++) {
|
|
5269
|
-
if (read(arr, i + j) !== read(val, j)) {
|
|
5270
|
-
found = false;
|
|
5271
|
-
break
|
|
5272
|
-
}
|
|
5273
|
-
}
|
|
5274
|
-
if (found) return i
|
|
5275
|
-
}
|
|
5276
|
-
}
|
|
5277
|
-
|
|
5278
|
-
return -1
|
|
5279
|
-
}
|
|
5280
|
-
|
|
5281
|
-
Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
|
|
5282
|
-
return this.indexOf(val, byteOffset, encoding) !== -1
|
|
5283
|
-
};
|
|
5284
|
-
|
|
5285
|
-
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
|
|
5286
|
-
return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
|
|
5287
|
-
};
|
|
5288
|
-
|
|
5289
|
-
Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
|
|
5290
|
-
return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
|
|
5291
|
-
};
|
|
5292
|
-
|
|
5293
|
-
function hexWrite (buf, string, offset, length) {
|
|
5294
|
-
offset = Number(offset) || 0;
|
|
5295
|
-
var remaining = buf.length - offset;
|
|
5296
|
-
if (!length) {
|
|
5297
|
-
length = remaining;
|
|
5298
|
-
} else {
|
|
5299
|
-
length = Number(length);
|
|
5300
|
-
if (length > remaining) {
|
|
5301
|
-
length = remaining;
|
|
5302
|
-
}
|
|
5303
|
-
}
|
|
5304
|
-
|
|
5305
|
-
var strLen = string.length;
|
|
5306
|
-
|
|
5307
|
-
if (length > strLen / 2) {
|
|
5308
|
-
length = strLen / 2;
|
|
5309
|
-
}
|
|
5310
|
-
for (var i = 0; i < length; ++i) {
|
|
5311
|
-
var parsed = parseInt(string.substr(i * 2, 2), 16);
|
|
5312
|
-
if (numberIsNaN(parsed)) return i
|
|
5313
|
-
buf[offset + i] = parsed;
|
|
5314
|
-
}
|
|
5315
|
-
return i
|
|
5316
|
-
}
|
|
5317
|
-
|
|
5318
|
-
function utf8Write (buf, string, offset, length) {
|
|
5319
|
-
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
|
|
5320
|
-
}
|
|
5321
|
-
|
|
5322
|
-
function asciiWrite (buf, string, offset, length) {
|
|
5323
|
-
return blitBuffer(asciiToBytes(string), buf, offset, length)
|
|
5324
|
-
}
|
|
5325
|
-
|
|
5326
|
-
function base64Write (buf, string, offset, length) {
|
|
5327
|
-
return blitBuffer(base64ToBytes(string), buf, offset, length)
|
|
5328
|
-
}
|
|
5329
|
-
|
|
5330
|
-
function ucs2Write (buf, string, offset, length) {
|
|
5331
|
-
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
|
|
5332
|
-
}
|
|
5333
|
-
|
|
5334
|
-
Buffer.prototype.write = function write (string, offset, length, encoding) {
|
|
5335
|
-
// Buffer#write(string)
|
|
5336
|
-
if (offset === undefined) {
|
|
5337
|
-
encoding = 'utf8';
|
|
5338
|
-
length = this.length;
|
|
5339
|
-
offset = 0;
|
|
5340
|
-
// Buffer#write(string, encoding)
|
|
5341
|
-
} else if (length === undefined && typeof offset === 'string') {
|
|
5342
|
-
encoding = offset;
|
|
5343
|
-
length = this.length;
|
|
5344
|
-
offset = 0;
|
|
5345
|
-
// Buffer#write(string, offset[, length][, encoding])
|
|
5346
|
-
} else if (isFinite(offset)) {
|
|
5347
|
-
offset = offset >>> 0;
|
|
5348
|
-
if (isFinite(length)) {
|
|
5349
|
-
length = length >>> 0;
|
|
5350
|
-
if (encoding === undefined) encoding = 'utf8';
|
|
5351
|
-
} else {
|
|
5352
|
-
encoding = length;
|
|
5353
|
-
length = undefined;
|
|
5354
|
-
}
|
|
5355
|
-
} else {
|
|
5356
|
-
throw new Error(
|
|
5357
|
-
'Buffer.write(string, encoding, offset[, length]) is no longer supported'
|
|
5358
|
-
)
|
|
5359
|
-
}
|
|
5360
|
-
|
|
5361
|
-
var remaining = this.length - offset;
|
|
5362
|
-
if (length === undefined || length > remaining) length = remaining;
|
|
5363
|
-
|
|
5364
|
-
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
|
|
5365
|
-
throw new RangeError('Attempt to write outside buffer bounds')
|
|
5366
|
-
}
|
|
5367
|
-
|
|
5368
|
-
if (!encoding) encoding = 'utf8';
|
|
5369
|
-
|
|
5370
|
-
var loweredCase = false;
|
|
5371
|
-
for (;;) {
|
|
5372
|
-
switch (encoding) {
|
|
5373
|
-
case 'hex':
|
|
5374
|
-
return hexWrite(this, string, offset, length)
|
|
5375
|
-
|
|
5376
|
-
case 'utf8':
|
|
5377
|
-
case 'utf-8':
|
|
5378
|
-
return utf8Write(this, string, offset, length)
|
|
5379
|
-
|
|
5380
|
-
case 'ascii':
|
|
5381
|
-
case 'latin1':
|
|
5382
|
-
case 'binary':
|
|
5383
|
-
return asciiWrite(this, string, offset, length)
|
|
5384
|
-
|
|
5385
|
-
case 'base64':
|
|
5386
|
-
// Warning: maxLength not taken into account in base64Write
|
|
5387
|
-
return base64Write(this, string, offset, length)
|
|
5388
|
-
|
|
5389
|
-
case 'ucs2':
|
|
5390
|
-
case 'ucs-2':
|
|
5391
|
-
case 'utf16le':
|
|
5392
|
-
case 'utf-16le':
|
|
5393
|
-
return ucs2Write(this, string, offset, length)
|
|
5394
|
-
|
|
5395
|
-
default:
|
|
5396
|
-
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
5397
|
-
encoding = ('' + encoding).toLowerCase();
|
|
5398
|
-
loweredCase = true;
|
|
5399
|
-
}
|
|
5400
|
-
}
|
|
5401
|
-
};
|
|
5402
|
-
|
|
5403
|
-
Buffer.prototype.toJSON = function toJSON () {
|
|
5404
|
-
return {
|
|
5405
|
-
type: 'Buffer',
|
|
5406
|
-
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
5407
|
-
}
|
|
5408
|
-
};
|
|
5409
|
-
|
|
5410
|
-
function base64Slice (buf, start, end) {
|
|
5411
|
-
if (start === 0 && end === buf.length) {
|
|
5412
|
-
return base64.fromByteArray(buf)
|
|
5413
|
-
} else {
|
|
5414
|
-
return base64.fromByteArray(buf.slice(start, end))
|
|
5415
|
-
}
|
|
5416
|
-
}
|
|
5417
|
-
|
|
5418
|
-
function utf8Slice (buf, start, end) {
|
|
5419
|
-
end = Math.min(buf.length, end);
|
|
5420
|
-
var res = [];
|
|
5421
|
-
|
|
5422
|
-
var i = start;
|
|
5423
|
-
while (i < end) {
|
|
5424
|
-
var firstByte = buf[i];
|
|
5425
|
-
var codePoint = null;
|
|
5426
|
-
var bytesPerSequence = (firstByte > 0xEF)
|
|
5427
|
-
? 4
|
|
5428
|
-
: (firstByte > 0xDF)
|
|
5429
|
-
? 3
|
|
5430
|
-
: (firstByte > 0xBF)
|
|
5431
|
-
? 2
|
|
5432
|
-
: 1;
|
|
5433
|
-
|
|
5434
|
-
if (i + bytesPerSequence <= end) {
|
|
5435
|
-
var secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
5436
|
-
|
|
5437
|
-
switch (bytesPerSequence) {
|
|
5438
|
-
case 1:
|
|
5439
|
-
if (firstByte < 0x80) {
|
|
5440
|
-
codePoint = firstByte;
|
|
5441
|
-
}
|
|
5442
|
-
break
|
|
5443
|
-
case 2:
|
|
5444
|
-
secondByte = buf[i + 1];
|
|
5445
|
-
if ((secondByte & 0xC0) === 0x80) {
|
|
5446
|
-
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
|
|
5447
|
-
if (tempCodePoint > 0x7F) {
|
|
5448
|
-
codePoint = tempCodePoint;
|
|
5449
|
-
}
|
|
5450
|
-
}
|
|
5451
|
-
break
|
|
5452
|
-
case 3:
|
|
5453
|
-
secondByte = buf[i + 1];
|
|
5454
|
-
thirdByte = buf[i + 2];
|
|
5455
|
-
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
|
|
5456
|
-
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
|
|
5457
|
-
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
|
|
5458
|
-
codePoint = tempCodePoint;
|
|
5459
|
-
}
|
|
5460
|
-
}
|
|
5461
|
-
break
|
|
5462
|
-
case 4:
|
|
5463
|
-
secondByte = buf[i + 1];
|
|
5464
|
-
thirdByte = buf[i + 2];
|
|
5465
|
-
fourthByte = buf[i + 3];
|
|
5466
|
-
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
|
|
5467
|
-
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
|
|
5468
|
-
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
|
|
5469
|
-
codePoint = tempCodePoint;
|
|
5470
|
-
}
|
|
5471
|
-
}
|
|
5472
|
-
}
|
|
5473
|
-
}
|
|
5474
|
-
|
|
5475
|
-
if (codePoint === null) {
|
|
5476
|
-
// we did not generate a valid codePoint so insert a
|
|
5477
|
-
// replacement char (U+FFFD) and advance only 1 byte
|
|
5478
|
-
codePoint = 0xFFFD;
|
|
5479
|
-
bytesPerSequence = 1;
|
|
5480
|
-
} else if (codePoint > 0xFFFF) {
|
|
5481
|
-
// encode to utf16 (surrogate pair dance)
|
|
5482
|
-
codePoint -= 0x10000;
|
|
5483
|
-
res.push(codePoint >>> 10 & 0x3FF | 0xD800);
|
|
5484
|
-
codePoint = 0xDC00 | codePoint & 0x3FF;
|
|
5485
|
-
}
|
|
5486
|
-
|
|
5487
|
-
res.push(codePoint);
|
|
5488
|
-
i += bytesPerSequence;
|
|
5489
|
-
}
|
|
5490
|
-
|
|
5491
|
-
return decodeCodePointsArray(res)
|
|
5492
|
-
}
|
|
5493
|
-
|
|
5494
|
-
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
|
|
5495
|
-
// the lowest limit is Chrome, with 0x10000 args.
|
|
5496
|
-
// We go 1 magnitude less, for safety
|
|
5497
|
-
var MAX_ARGUMENTS_LENGTH = 0x1000;
|
|
5498
|
-
|
|
5499
|
-
function decodeCodePointsArray (codePoints) {
|
|
5500
|
-
var len = codePoints.length;
|
|
5501
|
-
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
5502
|
-
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
|
|
5503
|
-
}
|
|
5504
|
-
|
|
5505
|
-
// Decode in chunks to avoid "call stack size exceeded".
|
|
5506
|
-
var res = '';
|
|
5507
|
-
var i = 0;
|
|
5508
|
-
while (i < len) {
|
|
5509
|
-
res += String.fromCharCode.apply(
|
|
5510
|
-
String,
|
|
5511
|
-
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
5512
|
-
);
|
|
5513
|
-
}
|
|
5514
|
-
return res
|
|
5515
|
-
}
|
|
5516
|
-
|
|
5517
|
-
function asciiSlice (buf, start, end) {
|
|
5518
|
-
var ret = '';
|
|
5519
|
-
end = Math.min(buf.length, end);
|
|
5520
|
-
|
|
5521
|
-
for (var i = start; i < end; ++i) {
|
|
5522
|
-
ret += String.fromCharCode(buf[i] & 0x7F);
|
|
5523
|
-
}
|
|
5524
|
-
return ret
|
|
5525
|
-
}
|
|
5526
|
-
|
|
5527
|
-
function latin1Slice (buf, start, end) {
|
|
5528
|
-
var ret = '';
|
|
5529
|
-
end = Math.min(buf.length, end);
|
|
5530
|
-
|
|
5531
|
-
for (var i = start; i < end; ++i) {
|
|
5532
|
-
ret += String.fromCharCode(buf[i]);
|
|
5533
|
-
}
|
|
5534
|
-
return ret
|
|
5535
|
-
}
|
|
5536
|
-
|
|
5537
|
-
function hexSlice (buf, start, end) {
|
|
5538
|
-
var len = buf.length;
|
|
5539
|
-
|
|
5540
|
-
if (!start || start < 0) start = 0;
|
|
5541
|
-
if (!end || end < 0 || end > len) end = len;
|
|
5542
|
-
|
|
5543
|
-
var out = '';
|
|
5544
|
-
for (var i = start; i < end; ++i) {
|
|
5545
|
-
out += hexSliceLookupTable[buf[i]];
|
|
5546
|
-
}
|
|
5547
|
-
return out
|
|
5548
|
-
}
|
|
5549
|
-
|
|
5550
|
-
function utf16leSlice (buf, start, end) {
|
|
5551
|
-
var bytes = buf.slice(start, end);
|
|
5552
|
-
var res = '';
|
|
5553
|
-
// If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
|
|
5554
|
-
for (var i = 0; i < bytes.length - 1; i += 2) {
|
|
5555
|
-
res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256));
|
|
5556
|
-
}
|
|
5557
|
-
return res
|
|
5558
|
-
}
|
|
5559
|
-
|
|
5560
|
-
Buffer.prototype.slice = function slice (start, end) {
|
|
5561
|
-
var len = this.length;
|
|
5562
|
-
start = ~~start;
|
|
5563
|
-
end = end === undefined ? len : ~~end;
|
|
5564
|
-
|
|
5565
|
-
if (start < 0) {
|
|
5566
|
-
start += len;
|
|
5567
|
-
if (start < 0) start = 0;
|
|
5568
|
-
} else if (start > len) {
|
|
5569
|
-
start = len;
|
|
5570
|
-
}
|
|
5571
|
-
|
|
5572
|
-
if (end < 0) {
|
|
5573
|
-
end += len;
|
|
5574
|
-
if (end < 0) end = 0;
|
|
5575
|
-
} else if (end > len) {
|
|
5576
|
-
end = len;
|
|
5577
|
-
}
|
|
5578
|
-
|
|
5579
|
-
if (end < start) end = start;
|
|
5580
|
-
|
|
5581
|
-
var newBuf = this.subarray(start, end);
|
|
5582
|
-
// Return an augmented `Uint8Array` instance
|
|
5583
|
-
Object.setPrototypeOf(newBuf, Buffer.prototype);
|
|
5584
|
-
|
|
5585
|
-
return newBuf
|
|
5586
|
-
};
|
|
5587
|
-
|
|
5588
|
-
/*
|
|
5589
|
-
* Need to make sure that buffer isn't trying to write out of bounds.
|
|
5590
|
-
*/
|
|
5591
|
-
function checkOffset (offset, ext, length) {
|
|
5592
|
-
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
|
|
5593
|
-
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
|
|
5594
|
-
}
|
|
5595
|
-
|
|
5596
|
-
Buffer.prototype.readUintLE =
|
|
5597
|
-
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
|
|
5598
|
-
offset = offset >>> 0;
|
|
5599
|
-
byteLength = byteLength >>> 0;
|
|
5600
|
-
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
5601
|
-
|
|
5602
|
-
var val = this[offset];
|
|
5603
|
-
var mul = 1;
|
|
5604
|
-
var i = 0;
|
|
5605
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
|
5606
|
-
val += this[offset + i] * mul;
|
|
5607
|
-
}
|
|
5608
|
-
|
|
5609
|
-
return val
|
|
5610
|
-
};
|
|
5611
|
-
|
|
5612
|
-
Buffer.prototype.readUintBE =
|
|
5613
|
-
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
|
|
5614
|
-
offset = offset >>> 0;
|
|
5615
|
-
byteLength = byteLength >>> 0;
|
|
5616
|
-
if (!noAssert) {
|
|
5617
|
-
checkOffset(offset, byteLength, this.length);
|
|
5618
|
-
}
|
|
5619
|
-
|
|
5620
|
-
var val = this[offset + --byteLength];
|
|
5621
|
-
var mul = 1;
|
|
5622
|
-
while (byteLength > 0 && (mul *= 0x100)) {
|
|
5623
|
-
val += this[offset + --byteLength] * mul;
|
|
5624
|
-
}
|
|
5625
|
-
|
|
5626
|
-
return val
|
|
5627
|
-
};
|
|
5628
|
-
|
|
5629
|
-
Buffer.prototype.readUint8 =
|
|
5630
|
-
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
|
|
5631
|
-
offset = offset >>> 0;
|
|
5632
|
-
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
5633
|
-
return this[offset]
|
|
5634
|
-
};
|
|
5635
|
-
|
|
5636
|
-
Buffer.prototype.readUint16LE =
|
|
5637
|
-
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
|
|
5638
|
-
offset = offset >>> 0;
|
|
5639
|
-
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
5640
|
-
return this[offset] | (this[offset + 1] << 8)
|
|
5641
|
-
};
|
|
5642
|
-
|
|
5643
|
-
Buffer.prototype.readUint16BE =
|
|
5644
|
-
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
|
|
5645
|
-
offset = offset >>> 0;
|
|
5646
|
-
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
5647
|
-
return (this[offset] << 8) | this[offset + 1]
|
|
5648
|
-
};
|
|
5649
|
-
|
|
5650
|
-
Buffer.prototype.readUint32LE =
|
|
5651
|
-
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
|
|
5652
|
-
offset = offset >>> 0;
|
|
5653
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
5654
|
-
|
|
5655
|
-
return ((this[offset]) |
|
|
5656
|
-
(this[offset + 1] << 8) |
|
|
5657
|
-
(this[offset + 2] << 16)) +
|
|
5658
|
-
(this[offset + 3] * 0x1000000)
|
|
5659
|
-
};
|
|
5660
|
-
|
|
5661
|
-
Buffer.prototype.readUint32BE =
|
|
5662
|
-
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
|
|
5663
|
-
offset = offset >>> 0;
|
|
5664
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
5665
|
-
|
|
5666
|
-
return (this[offset] * 0x1000000) +
|
|
5667
|
-
((this[offset + 1] << 16) |
|
|
5668
|
-
(this[offset + 2] << 8) |
|
|
5669
|
-
this[offset + 3])
|
|
5670
|
-
};
|
|
5671
|
-
|
|
5672
|
-
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
|
|
5673
|
-
offset = offset >>> 0;
|
|
5674
|
-
byteLength = byteLength >>> 0;
|
|
5675
|
-
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
5676
|
-
|
|
5677
|
-
var val = this[offset];
|
|
5678
|
-
var mul = 1;
|
|
5679
|
-
var i = 0;
|
|
5680
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
|
5681
|
-
val += this[offset + i] * mul;
|
|
5682
|
-
}
|
|
5683
|
-
mul *= 0x80;
|
|
5684
|
-
|
|
5685
|
-
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
|
|
5686
|
-
|
|
5687
|
-
return val
|
|
5688
|
-
};
|
|
5689
|
-
|
|
5690
|
-
Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
|
|
5691
|
-
offset = offset >>> 0;
|
|
5692
|
-
byteLength = byteLength >>> 0;
|
|
5693
|
-
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
5694
|
-
|
|
5695
|
-
var i = byteLength;
|
|
5696
|
-
var mul = 1;
|
|
5697
|
-
var val = this[offset + --i];
|
|
5698
|
-
while (i > 0 && (mul *= 0x100)) {
|
|
5699
|
-
val += this[offset + --i] * mul;
|
|
5700
|
-
}
|
|
5701
|
-
mul *= 0x80;
|
|
5702
|
-
|
|
5703
|
-
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
|
|
5704
|
-
|
|
5705
|
-
return val
|
|
5706
|
-
};
|
|
5707
|
-
|
|
5708
|
-
Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
|
|
5709
|
-
offset = offset >>> 0;
|
|
5710
|
-
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
5711
|
-
if (!(this[offset] & 0x80)) return (this[offset])
|
|
5712
|
-
return ((0xff - this[offset] + 1) * -1)
|
|
5713
|
-
};
|
|
5714
|
-
|
|
5715
|
-
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
|
|
5716
|
-
offset = offset >>> 0;
|
|
5717
|
-
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
5718
|
-
var val = this[offset] | (this[offset + 1] << 8);
|
|
5719
|
-
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
5720
|
-
};
|
|
5721
|
-
|
|
5722
|
-
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
|
|
5723
|
-
offset = offset >>> 0;
|
|
5724
|
-
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
5725
|
-
var val = this[offset + 1] | (this[offset] << 8);
|
|
5726
|
-
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
5727
|
-
};
|
|
5728
|
-
|
|
5729
|
-
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
|
|
5730
|
-
offset = offset >>> 0;
|
|
5731
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
5732
|
-
|
|
5733
|
-
return (this[offset]) |
|
|
5734
|
-
(this[offset + 1] << 8) |
|
|
5735
|
-
(this[offset + 2] << 16) |
|
|
5736
|
-
(this[offset + 3] << 24)
|
|
5737
|
-
};
|
|
5738
|
-
|
|
5739
|
-
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
|
|
5740
|
-
offset = offset >>> 0;
|
|
5741
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
5742
|
-
|
|
5743
|
-
return (this[offset] << 24) |
|
|
5744
|
-
(this[offset + 1] << 16) |
|
|
5745
|
-
(this[offset + 2] << 8) |
|
|
5746
|
-
(this[offset + 3])
|
|
5747
|
-
};
|
|
5748
|
-
|
|
5749
|
-
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
|
|
5750
|
-
offset = offset >>> 0;
|
|
5751
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
5752
|
-
return ieee754.read(this, offset, true, 23, 4)
|
|
5753
|
-
};
|
|
5754
|
-
|
|
5755
|
-
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
|
|
5756
|
-
offset = offset >>> 0;
|
|
5757
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
5758
|
-
return ieee754.read(this, offset, false, 23, 4)
|
|
5759
|
-
};
|
|
5760
|
-
|
|
5761
|
-
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
|
|
5762
|
-
offset = offset >>> 0;
|
|
5763
|
-
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
5764
|
-
return ieee754.read(this, offset, true, 52, 8)
|
|
5765
|
-
};
|
|
5766
|
-
|
|
5767
|
-
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
|
|
5768
|
-
offset = offset >>> 0;
|
|
5769
|
-
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
5770
|
-
return ieee754.read(this, offset, false, 52, 8)
|
|
5771
|
-
};
|
|
5772
|
-
|
|
5773
|
-
function checkInt (buf, value, offset, ext, max, min) {
|
|
5774
|
-
if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
|
|
5775
|
-
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
|
|
5776
|
-
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
5777
|
-
}
|
|
5778
|
-
|
|
5779
|
-
Buffer.prototype.writeUintLE =
|
|
5780
|
-
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
|
|
5781
|
-
value = +value;
|
|
5782
|
-
offset = offset >>> 0;
|
|
5783
|
-
byteLength = byteLength >>> 0;
|
|
5784
|
-
if (!noAssert) {
|
|
5785
|
-
var maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
5786
|
-
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
5787
|
-
}
|
|
5788
|
-
|
|
5789
|
-
var mul = 1;
|
|
5790
|
-
var i = 0;
|
|
5791
|
-
this[offset] = value & 0xFF;
|
|
5792
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
|
5793
|
-
this[offset + i] = (value / mul) & 0xFF;
|
|
5794
|
-
}
|
|
5795
|
-
|
|
5796
|
-
return offset + byteLength
|
|
5797
|
-
};
|
|
5798
|
-
|
|
5799
|
-
Buffer.prototype.writeUintBE =
|
|
5800
|
-
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
|
|
5801
|
-
value = +value;
|
|
5802
|
-
offset = offset >>> 0;
|
|
5803
|
-
byteLength = byteLength >>> 0;
|
|
5804
|
-
if (!noAssert) {
|
|
5805
|
-
var maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
5806
|
-
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
5807
|
-
}
|
|
5808
|
-
|
|
5809
|
-
var i = byteLength - 1;
|
|
5810
|
-
var mul = 1;
|
|
5811
|
-
this[offset + i] = value & 0xFF;
|
|
5812
|
-
while (--i >= 0 && (mul *= 0x100)) {
|
|
5813
|
-
this[offset + i] = (value / mul) & 0xFF;
|
|
5814
|
-
}
|
|
5815
|
-
|
|
5816
|
-
return offset + byteLength
|
|
5817
|
-
};
|
|
5818
|
-
|
|
5819
|
-
Buffer.prototype.writeUint8 =
|
|
5820
|
-
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
|
|
5821
|
-
value = +value;
|
|
5822
|
-
offset = offset >>> 0;
|
|
5823
|
-
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
|
|
5824
|
-
this[offset] = (value & 0xff);
|
|
5825
|
-
return offset + 1
|
|
5826
|
-
};
|
|
5827
|
-
|
|
5828
|
-
Buffer.prototype.writeUint16LE =
|
|
5829
|
-
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
|
|
5830
|
-
value = +value;
|
|
5831
|
-
offset = offset >>> 0;
|
|
5832
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
|
5833
|
-
this[offset] = (value & 0xff);
|
|
5834
|
-
this[offset + 1] = (value >>> 8);
|
|
5835
|
-
return offset + 2
|
|
5836
|
-
};
|
|
5837
|
-
|
|
5838
|
-
Buffer.prototype.writeUint16BE =
|
|
5839
|
-
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
|
|
5840
|
-
value = +value;
|
|
5841
|
-
offset = offset >>> 0;
|
|
5842
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
|
5843
|
-
this[offset] = (value >>> 8);
|
|
5844
|
-
this[offset + 1] = (value & 0xff);
|
|
5845
|
-
return offset + 2
|
|
5846
|
-
};
|
|
3875
|
+
lo = lo >> 8;
|
|
3876
|
+
buf[offset + 4] = lo;
|
|
3877
|
+
let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
|
|
3878
|
+
buf[offset + 3] = hi;
|
|
3879
|
+
hi = hi >> 8;
|
|
3880
|
+
buf[offset + 2] = hi;
|
|
3881
|
+
hi = hi >> 8;
|
|
3882
|
+
buf[offset + 1] = hi;
|
|
3883
|
+
hi = hi >> 8;
|
|
3884
|
+
buf[offset] = hi;
|
|
3885
|
+
return offset + 8
|
|
3886
|
+
}
|
|
5847
3887
|
|
|
5848
|
-
Buffer.prototype.
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
offset = offset >>> 0;
|
|
5852
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
5853
|
-
this[offset + 3] = (value >>> 24);
|
|
5854
|
-
this[offset + 2] = (value >>> 16);
|
|
5855
|
-
this[offset + 1] = (value >>> 8);
|
|
5856
|
-
this[offset] = (value & 0xff);
|
|
5857
|
-
return offset + 4
|
|
5858
|
-
};
|
|
3888
|
+
Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) {
|
|
3889
|
+
return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
|
|
3890
|
+
});
|
|
5859
3891
|
|
|
5860
|
-
Buffer.prototype.
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
offset = offset >>> 0;
|
|
5864
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
5865
|
-
this[offset] = (value >>> 24);
|
|
5866
|
-
this[offset + 1] = (value >>> 16);
|
|
5867
|
-
this[offset + 2] = (value >>> 8);
|
|
5868
|
-
this[offset + 3] = (value & 0xff);
|
|
5869
|
-
return offset + 4
|
|
5870
|
-
};
|
|
3892
|
+
Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) {
|
|
3893
|
+
return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
|
|
3894
|
+
});
|
|
5871
3895
|
|
|
5872
3896
|
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
|
|
5873
3897
|
value = +value;
|
|
5874
3898
|
offset = offset >>> 0;
|
|
5875
3899
|
if (!noAssert) {
|
|
5876
|
-
|
|
3900
|
+
const limit = Math.pow(2, (8 * byteLength) - 1);
|
|
5877
3901
|
|
|
5878
3902
|
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
5879
3903
|
}
|
|
5880
3904
|
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
|
|
3905
|
+
let i = 0;
|
|
3906
|
+
let mul = 1;
|
|
3907
|
+
let sub = 0;
|
|
5884
3908
|
this[offset] = value & 0xFF;
|
|
5885
3909
|
while (++i < byteLength && (mul *= 0x100)) {
|
|
5886
3910
|
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
@@ -5896,14 +3920,14 @@ function requireBuffer () {
|
|
|
5896
3920
|
value = +value;
|
|
5897
3921
|
offset = offset >>> 0;
|
|
5898
3922
|
if (!noAssert) {
|
|
5899
|
-
|
|
3923
|
+
const limit = Math.pow(2, (8 * byteLength) - 1);
|
|
5900
3924
|
|
|
5901
3925
|
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
5902
3926
|
}
|
|
5903
3927
|
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
3928
|
+
let i = byteLength - 1;
|
|
3929
|
+
let mul = 1;
|
|
3930
|
+
let sub = 0;
|
|
5907
3931
|
this[offset + i] = value & 0xFF;
|
|
5908
3932
|
while (--i >= 0 && (mul *= 0x100)) {
|
|
5909
3933
|
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
@@ -5965,6 +3989,14 @@ function requireBuffer () {
|
|
|
5965
3989
|
return offset + 4
|
|
5966
3990
|
};
|
|
5967
3991
|
|
|
3992
|
+
Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) {
|
|
3993
|
+
return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
|
|
3994
|
+
});
|
|
3995
|
+
|
|
3996
|
+
Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) {
|
|
3997
|
+
return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
|
|
3998
|
+
});
|
|
3999
|
+
|
|
5968
4000
|
function checkIEEE754 (buf, value, offset, ext, max, min) {
|
|
5969
4001
|
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
5970
4002
|
if (offset < 0) throw new RangeError('Index out of range')
|
|
@@ -6032,7 +4064,7 @@ function requireBuffer () {
|
|
|
6032
4064
|
end = target.length - targetStart + start;
|
|
6033
4065
|
}
|
|
6034
4066
|
|
|
6035
|
-
|
|
4067
|
+
const len = end - start;
|
|
6036
4068
|
|
|
6037
4069
|
if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
|
|
6038
4070
|
// Use built-in when available, missing from IE11
|
|
@@ -6070,7 +4102,7 @@ function requireBuffer () {
|
|
|
6070
4102
|
throw new TypeError('Unknown encoding: ' + encoding)
|
|
6071
4103
|
}
|
|
6072
4104
|
if (val.length === 1) {
|
|
6073
|
-
|
|
4105
|
+
const code = val.charCodeAt(0);
|
|
6074
4106
|
if ((encoding === 'utf8' && code < 128) ||
|
|
6075
4107
|
encoding === 'latin1') {
|
|
6076
4108
|
// Fast path: If `val` fits into a single byte, use that numeric value.
|
|
@@ -6097,16 +4129,16 @@ function requireBuffer () {
|
|
|
6097
4129
|
|
|
6098
4130
|
if (!val) val = 0;
|
|
6099
4131
|
|
|
6100
|
-
|
|
4132
|
+
let i;
|
|
6101
4133
|
if (typeof val === 'number') {
|
|
6102
4134
|
for (i = start; i < end; ++i) {
|
|
6103
4135
|
this[i] = val;
|
|
6104
4136
|
}
|
|
6105
4137
|
} else {
|
|
6106
|
-
|
|
4138
|
+
const bytes = Buffer.isBuffer(val)
|
|
6107
4139
|
? val
|
|
6108
4140
|
: Buffer.from(val, encoding);
|
|
6109
|
-
|
|
4141
|
+
const len = bytes.length;
|
|
6110
4142
|
if (len === 0) {
|
|
6111
4143
|
throw new TypeError('The value "' + val +
|
|
6112
4144
|
'" is invalid for argument "value"')
|
|
@@ -6119,10 +4151,141 @@ function requireBuffer () {
|
|
|
6119
4151
|
return this
|
|
6120
4152
|
};
|
|
6121
4153
|
|
|
4154
|
+
// CUSTOM ERRORS
|
|
4155
|
+
// =============
|
|
4156
|
+
|
|
4157
|
+
// Simplified versions from Node, changed for Buffer-only usage
|
|
4158
|
+
const errors = {};
|
|
4159
|
+
function E (sym, getMessage, Base) {
|
|
4160
|
+
errors[sym] = class NodeError extends Base {
|
|
4161
|
+
constructor () {
|
|
4162
|
+
super();
|
|
4163
|
+
|
|
4164
|
+
Object.defineProperty(this, 'message', {
|
|
4165
|
+
value: getMessage.apply(this, arguments),
|
|
4166
|
+
writable: true,
|
|
4167
|
+
configurable: true
|
|
4168
|
+
});
|
|
4169
|
+
|
|
4170
|
+
// Add the error code to the name to include it in the stack trace.
|
|
4171
|
+
this.name = `${this.name} [${sym}]`;
|
|
4172
|
+
// Access the stack to generate the error message including the error code
|
|
4173
|
+
// from the name.
|
|
4174
|
+
this.stack; // eslint-disable-line no-unused-expressions
|
|
4175
|
+
// Reset the name to the actual name.
|
|
4176
|
+
delete this.name;
|
|
4177
|
+
}
|
|
4178
|
+
|
|
4179
|
+
get code () {
|
|
4180
|
+
return sym
|
|
4181
|
+
}
|
|
4182
|
+
|
|
4183
|
+
set code (value) {
|
|
4184
|
+
Object.defineProperty(this, 'code', {
|
|
4185
|
+
configurable: true,
|
|
4186
|
+
enumerable: true,
|
|
4187
|
+
value,
|
|
4188
|
+
writable: true
|
|
4189
|
+
});
|
|
4190
|
+
}
|
|
4191
|
+
|
|
4192
|
+
toString () {
|
|
4193
|
+
return `${this.name} [${sym}]: ${this.message}`
|
|
4194
|
+
}
|
|
4195
|
+
};
|
|
4196
|
+
}
|
|
4197
|
+
|
|
4198
|
+
E('ERR_BUFFER_OUT_OF_BOUNDS',
|
|
4199
|
+
function (name) {
|
|
4200
|
+
if (name) {
|
|
4201
|
+
return `${name} is outside of buffer bounds`
|
|
4202
|
+
}
|
|
4203
|
+
|
|
4204
|
+
return 'Attempt to access memory outside buffer bounds'
|
|
4205
|
+
}, RangeError);
|
|
4206
|
+
E('ERR_INVALID_ARG_TYPE',
|
|
4207
|
+
function (name, actual) {
|
|
4208
|
+
return `The "${name}" argument must be of type number. Received type ${typeof actual}`
|
|
4209
|
+
}, TypeError);
|
|
4210
|
+
E('ERR_OUT_OF_RANGE',
|
|
4211
|
+
function (str, range, input) {
|
|
4212
|
+
let msg = `The value of "${str}" is out of range.`;
|
|
4213
|
+
let received = input;
|
|
4214
|
+
if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
|
|
4215
|
+
received = addNumericalSeparator(String(input));
|
|
4216
|
+
} else if (typeof input === 'bigint') {
|
|
4217
|
+
received = String(input);
|
|
4218
|
+
if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
|
|
4219
|
+
received = addNumericalSeparator(received);
|
|
4220
|
+
}
|
|
4221
|
+
received += 'n';
|
|
4222
|
+
}
|
|
4223
|
+
msg += ` It must be ${range}. Received ${received}`;
|
|
4224
|
+
return msg
|
|
4225
|
+
}, RangeError);
|
|
4226
|
+
|
|
4227
|
+
function addNumericalSeparator (val) {
|
|
4228
|
+
let res = '';
|
|
4229
|
+
let i = val.length;
|
|
4230
|
+
const start = val[0] === '-' ? 1 : 0;
|
|
4231
|
+
for (; i >= start + 4; i -= 3) {
|
|
4232
|
+
res = `_${val.slice(i - 3, i)}${res}`;
|
|
4233
|
+
}
|
|
4234
|
+
return `${val.slice(0, i)}${res}`
|
|
4235
|
+
}
|
|
4236
|
+
|
|
4237
|
+
// CHECK FUNCTIONS
|
|
4238
|
+
// ===============
|
|
4239
|
+
|
|
4240
|
+
function checkBounds (buf, offset, byteLength) {
|
|
4241
|
+
validateNumber(offset, 'offset');
|
|
4242
|
+
if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
|
|
4243
|
+
boundsError(offset, buf.length - (byteLength + 1));
|
|
4244
|
+
}
|
|
4245
|
+
}
|
|
4246
|
+
|
|
4247
|
+
function checkIntBI (value, min, max, buf, offset, byteLength) {
|
|
4248
|
+
if (value > max || value < min) {
|
|
4249
|
+
const n = typeof min === 'bigint' ? 'n' : '';
|
|
4250
|
+
let range;
|
|
4251
|
+
{
|
|
4252
|
+
if (min === 0 || min === BigInt(0)) {
|
|
4253
|
+
range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;
|
|
4254
|
+
} else {
|
|
4255
|
+
range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
|
|
4256
|
+
`${(byteLength + 1) * 8 - 1}${n}`;
|
|
4257
|
+
}
|
|
4258
|
+
}
|
|
4259
|
+
throw new errors.ERR_OUT_OF_RANGE('value', range, value)
|
|
4260
|
+
}
|
|
4261
|
+
checkBounds(buf, offset, byteLength);
|
|
4262
|
+
}
|
|
4263
|
+
|
|
4264
|
+
function validateNumber (value, name) {
|
|
4265
|
+
if (typeof value !== 'number') {
|
|
4266
|
+
throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
|
|
4267
|
+
}
|
|
4268
|
+
}
|
|
4269
|
+
|
|
4270
|
+
function boundsError (value, length, type) {
|
|
4271
|
+
if (Math.floor(value) !== value) {
|
|
4272
|
+
validateNumber(value, type);
|
|
4273
|
+
throw new errors.ERR_OUT_OF_RANGE('offset', 'an integer', value)
|
|
4274
|
+
}
|
|
4275
|
+
|
|
4276
|
+
if (length < 0) {
|
|
4277
|
+
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
|
|
4278
|
+
}
|
|
4279
|
+
|
|
4280
|
+
throw new errors.ERR_OUT_OF_RANGE('offset',
|
|
4281
|
+
`>= ${0} and <= ${length}`,
|
|
4282
|
+
value)
|
|
4283
|
+
}
|
|
4284
|
+
|
|
6122
4285
|
// HELPER FUNCTIONS
|
|
6123
4286
|
// ================
|
|
6124
4287
|
|
|
6125
|
-
|
|
4288
|
+
const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
|
6126
4289
|
|
|
6127
4290
|
function base64clean (str) {
|
|
6128
4291
|
// Node takes equal signs as end of the Base64 encoding
|
|
@@ -6140,12 +4303,12 @@ function requireBuffer () {
|
|
|
6140
4303
|
|
|
6141
4304
|
function utf8ToBytes (string, units) {
|
|
6142
4305
|
units = units || Infinity;
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
4306
|
+
let codePoint;
|
|
4307
|
+
const length = string.length;
|
|
4308
|
+
let leadSurrogate = null;
|
|
4309
|
+
const bytes = [];
|
|
6147
4310
|
|
|
6148
|
-
for (
|
|
4311
|
+
for (let i = 0; i < length; ++i) {
|
|
6149
4312
|
codePoint = string.charCodeAt(i);
|
|
6150
4313
|
|
|
6151
4314
|
// is surrogate component
|
|
@@ -6219,8 +4382,8 @@ function requireBuffer () {
|
|
|
6219
4382
|
}
|
|
6220
4383
|
|
|
6221
4384
|
function asciiToBytes (str) {
|
|
6222
|
-
|
|
6223
|
-
for (
|
|
4385
|
+
const byteArray = [];
|
|
4386
|
+
for (let i = 0; i < str.length; ++i) {
|
|
6224
4387
|
// Node's code seems to be doing this and not & 0x7F..
|
|
6225
4388
|
byteArray.push(str.charCodeAt(i) & 0xFF);
|
|
6226
4389
|
}
|
|
@@ -6228,9 +4391,9 @@ function requireBuffer () {
|
|
|
6228
4391
|
}
|
|
6229
4392
|
|
|
6230
4393
|
function utf16leToBytes (str, units) {
|
|
6231
|
-
|
|
6232
|
-
|
|
6233
|
-
for (
|
|
4394
|
+
let c, hi, lo;
|
|
4395
|
+
const byteArray = [];
|
|
4396
|
+
for (let i = 0; i < str.length; ++i) {
|
|
6234
4397
|
if ((units -= 2) < 0) break
|
|
6235
4398
|
|
|
6236
4399
|
c = str.charCodeAt(i);
|
|
@@ -6248,7 +4411,8 @@ function requireBuffer () {
|
|
|
6248
4411
|
}
|
|
6249
4412
|
|
|
6250
4413
|
function blitBuffer (src, dst, offset, length) {
|
|
6251
|
-
|
|
4414
|
+
let i;
|
|
4415
|
+
for (i = 0; i < length; ++i) {
|
|
6252
4416
|
if ((i + offset >= dst.length) || (i >= src.length)) break
|
|
6253
4417
|
dst[i + offset] = src[i];
|
|
6254
4418
|
}
|
|
@@ -6270,23 +4434,34 @@ function requireBuffer () {
|
|
|
6270
4434
|
|
|
6271
4435
|
// Create lookup table for `toString('hex')`
|
|
6272
4436
|
// See: https://github.com/feross/buffer/issues/219
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
for (
|
|
6277
|
-
|
|
6278
|
-
for (
|
|
4437
|
+
const hexSliceLookupTable = (function () {
|
|
4438
|
+
const alphabet = '0123456789abcdef';
|
|
4439
|
+
const table = new Array(256);
|
|
4440
|
+
for (let i = 0; i < 16; ++i) {
|
|
4441
|
+
const i16 = i * 16;
|
|
4442
|
+
for (let j = 0; j < 16; ++j) {
|
|
6279
4443
|
table[i16 + j] = alphabet[i] + alphabet[j];
|
|
6280
4444
|
}
|
|
6281
4445
|
}
|
|
6282
4446
|
return table
|
|
6283
|
-
})();
|
|
4447
|
+
})();
|
|
4448
|
+
|
|
4449
|
+
// Return not function with Error if BigInt not supported
|
|
4450
|
+
function defineBigIntMethod (fn) {
|
|
4451
|
+
return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
|
|
4452
|
+
}
|
|
4453
|
+
|
|
4454
|
+
function BufferBigIntNotDefined () {
|
|
4455
|
+
throw new Error('BigInt not supported')
|
|
4456
|
+
}
|
|
6284
4457
|
} (buffer));
|
|
6285
4458
|
return buffer;
|
|
6286
4459
|
}
|
|
6287
4460
|
|
|
6288
4461
|
var bufferExports = requireBuffer();
|
|
6289
4462
|
|
|
4463
|
+
var dist = {};
|
|
4464
|
+
|
|
6290
4465
|
var Codecs = {};
|
|
6291
4466
|
|
|
6292
4467
|
var Frames = {};
|
|
@@ -6296,7 +4471,7 @@ var hasRequiredFrames;
|
|
|
6296
4471
|
function requireFrames () {
|
|
6297
4472
|
if (hasRequiredFrames) return Frames;
|
|
6298
4473
|
hasRequiredFrames = 1;
|
|
6299
|
-
(function (exports) {
|
|
4474
|
+
(function (exports$1) {
|
|
6300
4475
|
/*
|
|
6301
4476
|
* Copyright 2021-2022 the original author or authors.
|
|
6302
4477
|
*
|
|
@@ -6312,8 +4487,8 @@ function requireFrames () {
|
|
|
6312
4487
|
* See the License for the specific language governing permissions and
|
|
6313
4488
|
* limitations under the License.
|
|
6314
4489
|
*/
|
|
6315
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6316
|
-
exports.Frame = exports.Lengths = exports.Flags = exports.FrameTypes = void 0;
|
|
4490
|
+
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
4491
|
+
exports$1.Frame = exports$1.Lengths = exports$1.Flags = exports$1.FrameTypes = void 0;
|
|
6317
4492
|
var FrameTypes;
|
|
6318
4493
|
(function (FrameTypes) {
|
|
6319
4494
|
FrameTypes[FrameTypes["RESERVED"] = 0] = "RESERVED";
|
|
@@ -6332,7 +4507,7 @@ function requireFrames () {
|
|
|
6332
4507
|
FrameTypes[FrameTypes["RESUME"] = 13] = "RESUME";
|
|
6333
4508
|
FrameTypes[FrameTypes["RESUME_OK"] = 14] = "RESUME_OK";
|
|
6334
4509
|
FrameTypes[FrameTypes["EXT"] = 63] = "EXT";
|
|
6335
|
-
})(FrameTypes = exports.FrameTypes || (exports.FrameTypes = {}));
|
|
4510
|
+
})(FrameTypes = exports$1.FrameTypes || (exports$1.FrameTypes = {}));
|
|
6336
4511
|
(function (Flags) {
|
|
6337
4512
|
Flags[Flags["NONE"] = 0] = "NONE";
|
|
6338
4513
|
Flags[Flags["COMPLETE"] = 64] = "COMPLETE";
|
|
@@ -6343,7 +4518,7 @@ function requireFrames () {
|
|
|
6343
4518
|
Flags[Flags["NEXT"] = 32] = "NEXT";
|
|
6344
4519
|
Flags[Flags["RESPOND"] = 128] = "RESPOND";
|
|
6345
4520
|
Flags[Flags["RESUME_ENABLE"] = 128] = "RESUME_ENABLE";
|
|
6346
|
-
})(exports.Flags || (exports.Flags = {}));
|
|
4521
|
+
})(exports$1.Flags || (exports$1.Flags = {}));
|
|
6347
4522
|
(function (Flags) {
|
|
6348
4523
|
function hasMetadata(flags) {
|
|
6349
4524
|
return (flags & Flags.METADATA) === Flags.METADATA;
|
|
@@ -6377,13 +4552,13 @@ function requireFrames () {
|
|
|
6377
4552
|
return (flags & Flags.RESUME_ENABLE) === Flags.RESUME_ENABLE;
|
|
6378
4553
|
}
|
|
6379
4554
|
Flags.hasResume = hasResume;
|
|
6380
|
-
})(exports.Flags || (exports.Flags = {}));
|
|
4555
|
+
})(exports$1.Flags || (exports$1.Flags = {}));
|
|
6381
4556
|
(function (Lengths) {
|
|
6382
4557
|
Lengths[Lengths["FRAME"] = 3] = "FRAME";
|
|
6383
4558
|
Lengths[Lengths["HEADER"] = 6] = "HEADER";
|
|
6384
4559
|
Lengths[Lengths["METADATA"] = 3] = "METADATA";
|
|
6385
4560
|
Lengths[Lengths["REQUEST"] = 3] = "REQUEST";
|
|
6386
|
-
})(exports.Lengths || (exports.Lengths = {}));
|
|
4561
|
+
})(exports$1.Lengths || (exports$1.Lengths = {}));
|
|
6387
4562
|
(function (Frame) {
|
|
6388
4563
|
function isConnection(frame) {
|
|
6389
4564
|
return frame.streamId === 0;
|
|
@@ -6394,7 +4569,7 @@ function requireFrames () {
|
|
|
6394
4569
|
frame.type <= FrameTypes.REQUEST_CHANNEL);
|
|
6395
4570
|
}
|
|
6396
4571
|
Frame.isRequest = isRequest;
|
|
6397
|
-
})(exports.Frame || (exports.Frame = {}));
|
|
4572
|
+
})(exports$1.Frame || (exports$1.Frame = {}));
|
|
6398
4573
|
|
|
6399
4574
|
} (Frames));
|
|
6400
4575
|
return Frames;
|
|
@@ -6405,7 +4580,7 @@ var hasRequiredCodecs;
|
|
|
6405
4580
|
function requireCodecs () {
|
|
6406
4581
|
if (hasRequiredCodecs) return Codecs;
|
|
6407
4582
|
hasRequiredCodecs = 1;
|
|
6408
|
-
(function (exports) {
|
|
4583
|
+
(function (exports$1) {
|
|
6409
4584
|
var __generator = (Codecs && Codecs.__generator) || function (thisArg, body) {
|
|
6410
4585
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
6411
4586
|
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
@@ -6433,22 +4608,22 @@ function requireCodecs () {
|
|
|
6433
4608
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
6434
4609
|
}
|
|
6435
4610
|
};
|
|
6436
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6437
|
-
exports.Deserializer = exports.sizeOfFrame = exports.serializeFrame = exports.deserializeFrame = exports.serializeFrameWithLength = exports.deserializeFrames = exports.deserializeFrameWithLength = exports.writeUInt64BE = exports.readUInt64BE = exports.writeUInt24BE = exports.readUInt24BE = exports.MAX_VERSION = exports.MAX_TTL = exports.MAX_STREAM_ID = exports.MAX_RESUME_LENGTH = exports.MAX_REQUEST_N = exports.MAX_REQUEST_COUNT = exports.MAX_MIME_LENGTH = exports.MAX_METADATA_LENGTH = exports.MAX_LIFETIME = exports.MAX_KEEPALIVE = exports.MAX_CODE = exports.FRAME_TYPE_OFFFSET = exports.FLAGS_MASK = void 0;
|
|
4611
|
+
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
4612
|
+
exports$1.Deserializer = exports$1.sizeOfFrame = exports$1.serializeFrame = exports$1.deserializeFrame = exports$1.serializeFrameWithLength = exports$1.deserializeFrames = exports$1.deserializeFrameWithLength = exports$1.writeUInt64BE = exports$1.readUInt64BE = exports$1.writeUInt24BE = exports$1.readUInt24BE = exports$1.MAX_VERSION = exports$1.MAX_TTL = exports$1.MAX_STREAM_ID = exports$1.MAX_RESUME_LENGTH = exports$1.MAX_REQUEST_N = exports$1.MAX_REQUEST_COUNT = exports$1.MAX_MIME_LENGTH = exports$1.MAX_METADATA_LENGTH = exports$1.MAX_LIFETIME = exports$1.MAX_KEEPALIVE = exports$1.MAX_CODE = exports$1.FRAME_TYPE_OFFFSET = exports$1.FLAGS_MASK = void 0;
|
|
6438
4613
|
var Frames_1 = requireFrames();
|
|
6439
|
-
exports.FLAGS_MASK = 0x3ff; // low 10 bits
|
|
6440
|
-
exports.FRAME_TYPE_OFFFSET = 10; // frame type is offset 10 bytes within the uint16 containing type + flags
|
|
6441
|
-
exports.MAX_CODE = 0x7fffffff; // uint31
|
|
6442
|
-
exports.MAX_KEEPALIVE = 0x7fffffff; // uint31
|
|
6443
|
-
exports.MAX_LIFETIME = 0x7fffffff; // uint31
|
|
6444
|
-
exports.MAX_METADATA_LENGTH = 0xffffff; // uint24
|
|
6445
|
-
exports.MAX_MIME_LENGTH = 0xff; // int8
|
|
6446
|
-
exports.MAX_REQUEST_COUNT = 0x7fffffff; // uint31
|
|
6447
|
-
exports.MAX_REQUEST_N = 0x7fffffff; // uint31
|
|
6448
|
-
exports.MAX_RESUME_LENGTH = 0xffff; // uint16
|
|
6449
|
-
exports.MAX_STREAM_ID = 0x7fffffff; // uint31
|
|
6450
|
-
exports.MAX_TTL = 0x7fffffff; // uint31
|
|
6451
|
-
exports.MAX_VERSION = 0xffff; // uint16
|
|
4614
|
+
exports$1.FLAGS_MASK = 0x3ff; // low 10 bits
|
|
4615
|
+
exports$1.FRAME_TYPE_OFFFSET = 10; // frame type is offset 10 bytes within the uint16 containing type + flags
|
|
4616
|
+
exports$1.MAX_CODE = 0x7fffffff; // uint31
|
|
4617
|
+
exports$1.MAX_KEEPALIVE = 0x7fffffff; // uint31
|
|
4618
|
+
exports$1.MAX_LIFETIME = 0x7fffffff; // uint31
|
|
4619
|
+
exports$1.MAX_METADATA_LENGTH = 0xffffff; // uint24
|
|
4620
|
+
exports$1.MAX_MIME_LENGTH = 0xff; // int8
|
|
4621
|
+
exports$1.MAX_REQUEST_COUNT = 0x7fffffff; // uint31
|
|
4622
|
+
exports$1.MAX_REQUEST_N = 0x7fffffff; // uint31
|
|
4623
|
+
exports$1.MAX_RESUME_LENGTH = 0xffff; // uint16
|
|
4624
|
+
exports$1.MAX_STREAM_ID = 0x7fffffff; // uint31
|
|
4625
|
+
exports$1.MAX_TTL = 0x7fffffff; // uint31
|
|
4626
|
+
exports$1.MAX_VERSION = 0xffff; // uint16
|
|
6452
4627
|
/**
|
|
6453
4628
|
* Mimimum value that would overflow bitwise operators (2^32).
|
|
6454
4629
|
*/
|
|
@@ -6462,7 +4637,7 @@ function requireCodecs () {
|
|
|
6462
4637
|
var val3 = buffer.readUInt8(offset + 2);
|
|
6463
4638
|
return val1 | val2 | val3;
|
|
6464
4639
|
}
|
|
6465
|
-
exports.readUInt24BE = readUInt24BE;
|
|
4640
|
+
exports$1.readUInt24BE = readUInt24BE;
|
|
6466
4641
|
/**
|
|
6467
4642
|
* Writes a uint24 to a buffer starting at the given offset, returning the
|
|
6468
4643
|
* offset of the next byte.
|
|
@@ -6472,7 +4647,7 @@ function requireCodecs () {
|
|
|
6472
4647
|
offset = buffer.writeUInt8((value >>> 8) & 0xff, offset); // 2nd byte
|
|
6473
4648
|
return buffer.writeUInt8(value & 0xff, offset); // 1st byte
|
|
6474
4649
|
}
|
|
6475
|
-
exports.writeUInt24BE = writeUInt24BE;
|
|
4650
|
+
exports$1.writeUInt24BE = writeUInt24BE;
|
|
6476
4651
|
/**
|
|
6477
4652
|
* Read a uint64 (technically supports up to 53 bits per JS number
|
|
6478
4653
|
* representation).
|
|
@@ -6482,7 +4657,7 @@ function requireCodecs () {
|
|
|
6482
4657
|
var low = buffer.readUInt32BE(offset + 4);
|
|
6483
4658
|
return high * BITWISE_OVERFLOW + low;
|
|
6484
4659
|
}
|
|
6485
|
-
exports.readUInt64BE = readUInt64BE;
|
|
4660
|
+
exports$1.readUInt64BE = readUInt64BE;
|
|
6486
4661
|
/**
|
|
6487
4662
|
* Write a uint64 (technically supports up to 53 bits per JS number
|
|
6488
4663
|
* representation).
|
|
@@ -6493,7 +4668,7 @@ function requireCodecs () {
|
|
|
6493
4668
|
offset = buffer.writeUInt32BE(high, offset); // first half of uint64
|
|
6494
4669
|
return buffer.writeUInt32BE(low, offset); // second half of uint64
|
|
6495
4670
|
}
|
|
6496
|
-
exports.writeUInt64BE = writeUInt64BE;
|
|
4671
|
+
exports$1.writeUInt64BE = writeUInt64BE;
|
|
6497
4672
|
/**
|
|
6498
4673
|
* Frame header is:
|
|
6499
4674
|
* - stream id (uint32 = 4)
|
|
@@ -6511,7 +4686,7 @@ function requireCodecs () {
|
|
|
6511
4686
|
var frameLength = readUInt24BE(buffer, 0);
|
|
6512
4687
|
return deserializeFrame(buffer.slice(UINT24_SIZE, UINT24_SIZE + frameLength));
|
|
6513
4688
|
}
|
|
6514
|
-
exports.deserializeFrameWithLength = deserializeFrameWithLength;
|
|
4689
|
+
exports$1.deserializeFrameWithLength = deserializeFrameWithLength;
|
|
6515
4690
|
/**
|
|
6516
4691
|
* Given a buffer that may contain zero or more length-prefixed frames followed
|
|
6517
4692
|
* by zero or more bytes of a (partial) subsequent frame, returns an array of
|
|
@@ -6544,7 +4719,7 @@ function requireCodecs () {
|
|
|
6544
4719
|
}
|
|
6545
4720
|
});
|
|
6546
4721
|
}
|
|
6547
|
-
exports.deserializeFrames = deserializeFrames;
|
|
4722
|
+
exports$1.deserializeFrames = deserializeFrames;
|
|
6548
4723
|
/**
|
|
6549
4724
|
* Writes a frame to a buffer with a length prefix.
|
|
6550
4725
|
*/
|
|
@@ -6555,7 +4730,7 @@ function requireCodecs () {
|
|
|
6555
4730
|
buffer.copy(lengthPrefixed, UINT24_SIZE);
|
|
6556
4731
|
return lengthPrefixed;
|
|
6557
4732
|
}
|
|
6558
|
-
exports.serializeFrameWithLength = serializeFrameWithLength;
|
|
4733
|
+
exports$1.serializeFrameWithLength = serializeFrameWithLength;
|
|
6559
4734
|
/**
|
|
6560
4735
|
* Read a frame from the buffer.
|
|
6561
4736
|
*/
|
|
@@ -6570,8 +4745,8 @@ function requireCodecs () {
|
|
|
6570
4745
|
// );
|
|
6571
4746
|
var typeAndFlags = buffer.readUInt16BE(offset);
|
|
6572
4747
|
offset += 2;
|
|
6573
|
-
var type = typeAndFlags >>> exports.FRAME_TYPE_OFFFSET; // keep highest 6 bits
|
|
6574
|
-
var flags = typeAndFlags & exports.FLAGS_MASK; // keep lowest 10 bits
|
|
4748
|
+
var type = typeAndFlags >>> exports$1.FRAME_TYPE_OFFFSET; // keep highest 6 bits
|
|
4749
|
+
var flags = typeAndFlags & exports$1.FLAGS_MASK; // keep lowest 10 bits
|
|
6575
4750
|
switch (type) {
|
|
6576
4751
|
case Frames_1.FrameTypes.SETUP:
|
|
6577
4752
|
return deserializeSetupFrame(buffer, streamId, flags);
|
|
@@ -6608,7 +4783,7 @@ function requireCodecs () {
|
|
|
6608
4783
|
// );
|
|
6609
4784
|
}
|
|
6610
4785
|
}
|
|
6611
|
-
exports.deserializeFrame = deserializeFrame;
|
|
4786
|
+
exports$1.deserializeFrame = deserializeFrame;
|
|
6612
4787
|
/**
|
|
6613
4788
|
* Convert the frame to a (binary) buffer.
|
|
6614
4789
|
*/
|
|
@@ -6647,7 +4822,7 @@ function requireCodecs () {
|
|
|
6647
4822
|
// );
|
|
6648
4823
|
}
|
|
6649
4824
|
}
|
|
6650
|
-
exports.serializeFrame = serializeFrame;
|
|
4825
|
+
exports$1.serializeFrame = serializeFrame;
|
|
6651
4826
|
/**
|
|
6652
4827
|
* Byte size of frame without size prefix
|
|
6653
4828
|
*/
|
|
@@ -6686,7 +4861,7 @@ function requireCodecs () {
|
|
|
6686
4861
|
// );
|
|
6687
4862
|
}
|
|
6688
4863
|
}
|
|
6689
|
-
exports.sizeOfFrame = sizeOfFrame;
|
|
4864
|
+
exports$1.sizeOfFrame = sizeOfFrame;
|
|
6690
4865
|
/**
|
|
6691
4866
|
* Writes a SETUP frame into a new buffer and returns it.
|
|
6692
4867
|
*
|
|
@@ -7321,7 +5496,7 @@ function requireCodecs () {
|
|
|
7321
5496
|
function writeHeader(frame, buffer) {
|
|
7322
5497
|
var offset = buffer.writeInt32BE(frame.streamId, 0);
|
|
7323
5498
|
// shift frame to high 6 bits, extract lowest 10 bits from flags
|
|
7324
|
-
return buffer.writeUInt16BE((frame.type << exports.FRAME_TYPE_OFFFSET) | (frame.flags & exports.FLAGS_MASK), offset);
|
|
5499
|
+
return buffer.writeUInt16BE((frame.type << exports$1.FRAME_TYPE_OFFFSET) | (frame.flags & exports$1.FLAGS_MASK), offset);
|
|
7325
5500
|
}
|
|
7326
5501
|
/**
|
|
7327
5502
|
* Determine the length of the payload section of a frame. Only applies to
|
|
@@ -7402,7 +5577,7 @@ function requireCodecs () {
|
|
|
7402
5577
|
};
|
|
7403
5578
|
return Deserializer;
|
|
7404
5579
|
}());
|
|
7405
|
-
exports.Deserializer = Deserializer;
|
|
5580
|
+
exports$1.Deserializer = Deserializer;
|
|
7406
5581
|
|
|
7407
5582
|
} (Codecs));
|
|
7408
5583
|
return Codecs;
|
|
@@ -7548,7 +5723,7 @@ var hasRequiredErrors;
|
|
|
7548
5723
|
function requireErrors () {
|
|
7549
5724
|
if (hasRequiredErrors) return Errors;
|
|
7550
5725
|
hasRequiredErrors = 1;
|
|
7551
|
-
(function (exports) {
|
|
5726
|
+
(function (exports$1) {
|
|
7552
5727
|
/*
|
|
7553
5728
|
* Copyright 2021-2022 the original author or authors.
|
|
7554
5729
|
*
|
|
@@ -7579,8 +5754,8 @@ function requireErrors () {
|
|
|
7579
5754
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
7580
5755
|
};
|
|
7581
5756
|
})();
|
|
7582
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7583
|
-
exports.ErrorCodes = exports.RSocketError = void 0;
|
|
5757
|
+
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
5758
|
+
exports$1.ErrorCodes = exports$1.RSocketError = void 0;
|
|
7584
5759
|
var RSocketError = /** @class */ (function (_super) {
|
|
7585
5760
|
__extends(RSocketError, _super);
|
|
7586
5761
|
function RSocketError(code, message) {
|
|
@@ -7590,7 +5765,7 @@ function requireErrors () {
|
|
|
7590
5765
|
}
|
|
7591
5766
|
return RSocketError;
|
|
7592
5767
|
}(Error));
|
|
7593
|
-
exports.RSocketError = RSocketError;
|
|
5768
|
+
exports$1.RSocketError = RSocketError;
|
|
7594
5769
|
(function (ErrorCodes) {
|
|
7595
5770
|
ErrorCodes[ErrorCodes["RESERVED"] = 0] = "RESERVED";
|
|
7596
5771
|
ErrorCodes[ErrorCodes["INVALID_SETUP"] = 1] = "INVALID_SETUP";
|
|
@@ -7604,7 +5779,7 @@ function requireErrors () {
|
|
|
7604
5779
|
ErrorCodes[ErrorCodes["CANCELED"] = 515] = "CANCELED";
|
|
7605
5780
|
ErrorCodes[ErrorCodes["INVALID"] = 516] = "INVALID";
|
|
7606
5781
|
ErrorCodes[ErrorCodes["RESERVED_EXTENSION"] = 4294967295] = "RESERVED_EXTENSION";
|
|
7607
|
-
})(exports.ErrorCodes || (exports.ErrorCodes = {}));
|
|
5782
|
+
})(exports$1.ErrorCodes || (exports$1.ErrorCodes = {}));
|
|
7608
5783
|
|
|
7609
5784
|
} (Errors));
|
|
7610
5785
|
return Errors;
|
|
@@ -7646,7 +5821,7 @@ var hasRequiredClientServerMultiplexerDemultiplexer;
|
|
|
7646
5821
|
function requireClientServerMultiplexerDemultiplexer () {
|
|
7647
5822
|
if (hasRequiredClientServerMultiplexerDemultiplexer) return ClientServerMultiplexerDemultiplexer;
|
|
7648
5823
|
hasRequiredClientServerMultiplexerDemultiplexer = 1;
|
|
7649
|
-
(function (exports) {
|
|
5824
|
+
(function (exports$1) {
|
|
7650
5825
|
/*
|
|
7651
5826
|
* Copyright 2021-2022 the original author or authors.
|
|
7652
5827
|
*
|
|
@@ -7713,8 +5888,8 @@ function requireClientServerMultiplexerDemultiplexer () {
|
|
|
7713
5888
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
7714
5889
|
}
|
|
7715
5890
|
};
|
|
7716
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7717
|
-
exports.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = exports.ResumableClientServerInputMultiplexerDemultiplexer = exports.ClientServerInputMultiplexerDemultiplexer = exports.StreamIdGenerator = void 0;
|
|
5891
|
+
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
5892
|
+
exports$1.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = exports$1.ResumableClientServerInputMultiplexerDemultiplexer = exports$1.ClientServerInputMultiplexerDemultiplexer = exports$1.StreamIdGenerator = void 0;
|
|
7718
5893
|
var _1 = requireDist();
|
|
7719
5894
|
var Deferred_1 = requireDeferred();
|
|
7720
5895
|
var Errors_1 = requireErrors();
|
|
@@ -7737,7 +5912,7 @@ function requireClientServerMultiplexerDemultiplexer () {
|
|
|
7737
5912
|
};
|
|
7738
5913
|
return StreamIdGeneratorImpl;
|
|
7739
5914
|
}());
|
|
7740
|
-
})(exports.StreamIdGenerator || (exports.StreamIdGenerator = {}));
|
|
5915
|
+
})(exports$1.StreamIdGenerator || (exports$1.StreamIdGenerator = {}));
|
|
7741
5916
|
var ClientServerInputMultiplexerDemultiplexer = /** @class */ (function (_super) {
|
|
7742
5917
|
__extends(ClientServerInputMultiplexerDemultiplexer, _super);
|
|
7743
5918
|
function ClientServerInputMultiplexerDemultiplexer(streamIdSupplier, outbound, closeable) {
|
|
@@ -7826,7 +6001,7 @@ function requireClientServerMultiplexerDemultiplexer () {
|
|
|
7826
6001
|
};
|
|
7827
6002
|
return ClientServerInputMultiplexerDemultiplexer;
|
|
7828
6003
|
}(Deferred_1.Deferred));
|
|
7829
|
-
exports.ClientServerInputMultiplexerDemultiplexer = ClientServerInputMultiplexerDemultiplexer;
|
|
6004
|
+
exports$1.ClientServerInputMultiplexerDemultiplexer = ClientServerInputMultiplexerDemultiplexer;
|
|
7830
6005
|
var ResumableClientServerInputMultiplexerDemultiplexer = /** @class */ (function (_super) {
|
|
7831
6006
|
__extends(ResumableClientServerInputMultiplexerDemultiplexer, _super);
|
|
7832
6007
|
function ResumableClientServerInputMultiplexerDemultiplexer(streamIdSupplier, outbound, closeable, frameStore, token, sessionStoreOrReconnector, sessionTimeout) {
|
|
@@ -7983,7 +6158,7 @@ function requireClientServerMultiplexerDemultiplexer () {
|
|
|
7983
6158
|
};
|
|
7984
6159
|
return ResumableClientServerInputMultiplexerDemultiplexer;
|
|
7985
6160
|
}(ClientServerInputMultiplexerDemultiplexer));
|
|
7986
|
-
exports.ResumableClientServerInputMultiplexerDemultiplexer = ResumableClientServerInputMultiplexerDemultiplexer;
|
|
6161
|
+
exports$1.ResumableClientServerInputMultiplexerDemultiplexer = ResumableClientServerInputMultiplexerDemultiplexer;
|
|
7987
6162
|
var ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = /** @class */ (function () {
|
|
7988
6163
|
function ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer(outbound, closeable, delegate) {
|
|
7989
6164
|
this.outbound = outbound;
|
|
@@ -8040,7 +6215,7 @@ function requireClientServerMultiplexerDemultiplexer () {
|
|
|
8040
6215
|
};
|
|
8041
6216
|
return ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer;
|
|
8042
6217
|
}());
|
|
8043
|
-
exports.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer;
|
|
6218
|
+
exports$1.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer;
|
|
8044
6219
|
|
|
8045
6220
|
} (ClientServerMultiplexerDemultiplexer));
|
|
8046
6221
|
return ClientServerMultiplexerDemultiplexer;
|
|
@@ -11026,7 +9201,7 @@ var hasRequiredDist;
|
|
|
11026
9201
|
function requireDist () {
|
|
11027
9202
|
if (hasRequiredDist) return dist;
|
|
11028
9203
|
hasRequiredDist = 1;
|
|
11029
|
-
(function (exports) {
|
|
9204
|
+
(function (exports$1) {
|
|
11030
9205
|
/*
|
|
11031
9206
|
* Copyright 2021-2022 the original author or authors.
|
|
11032
9207
|
*
|
|
@@ -11049,19 +9224,19 @@ function requireDist () {
|
|
|
11049
9224
|
if (k2 === undefined) k2 = k;
|
|
11050
9225
|
o[k2] = m[k];
|
|
11051
9226
|
}));
|
|
11052
|
-
var __exportStar = (dist && dist.__exportStar) || function(m, exports) {
|
|
11053
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
9227
|
+
var __exportStar = (dist && dist.__exportStar) || function(m, exports$1) {
|
|
9228
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports$1, p)) __createBinding(exports$1, m, p);
|
|
11054
9229
|
};
|
|
11055
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11056
|
-
__exportStar(requireCodecs(), exports);
|
|
11057
|
-
__exportStar(requireCommon(), exports);
|
|
11058
|
-
__exportStar(requireDeferred(), exports);
|
|
11059
|
-
__exportStar(requireErrors(), exports);
|
|
11060
|
-
__exportStar(requireFrames(), exports);
|
|
11061
|
-
__exportStar(requireRSocket(), exports);
|
|
11062
|
-
__exportStar(requireRSocketConnector(), exports);
|
|
11063
|
-
__exportStar(requireRSocketServer(), exports);
|
|
11064
|
-
__exportStar(requireTransport(), exports);
|
|
9230
|
+
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
9231
|
+
__exportStar(requireCodecs(), exports$1);
|
|
9232
|
+
__exportStar(requireCommon(), exports$1);
|
|
9233
|
+
__exportStar(requireDeferred(), exports$1);
|
|
9234
|
+
__exportStar(requireErrors(), exports$1);
|
|
9235
|
+
__exportStar(requireFrames(), exports$1);
|
|
9236
|
+
__exportStar(requireRSocket(), exports$1);
|
|
9237
|
+
__exportStar(requireRSocketConnector(), exports$1);
|
|
9238
|
+
__exportStar(requireRSocketServer(), exports$1);
|
|
9239
|
+
__exportStar(requireTransport(), exports$1);
|
|
11065
9240
|
|
|
11066
9241
|
} (dist));
|
|
11067
9242
|
return dist;
|
|
@@ -11069,7 +9244,7 @@ function requireDist () {
|
|
|
11069
9244
|
|
|
11070
9245
|
var distExports = requireDist();
|
|
11071
9246
|
|
|
11072
|
-
var version = "1.
|
|
9247
|
+
var version = "1.45.0";
|
|
11073
9248
|
var PACKAGE = {
|
|
11074
9249
|
version: version};
|
|
11075
9250
|
|
|
@@ -11140,6 +9315,16 @@ class DataStream extends BaseObserver {
|
|
|
11140
9315
|
* @returns a Data payload or Null if the stream closed.
|
|
11141
9316
|
*/
|
|
11142
9317
|
async read() {
|
|
9318
|
+
if (this.closed) {
|
|
9319
|
+
return null;
|
|
9320
|
+
}
|
|
9321
|
+
// Wait for any pending processing to complete first.
|
|
9322
|
+
// This ensures we register our listener before calling processQueue(),
|
|
9323
|
+
// avoiding a race where processQueue() sees no reader and returns early.
|
|
9324
|
+
if (this.processingPromise) {
|
|
9325
|
+
await this.processingPromise;
|
|
9326
|
+
}
|
|
9327
|
+
// Re-check after await - stream may have closed while we were waiting
|
|
11143
9328
|
if (this.closed) {
|
|
11144
9329
|
return null;
|
|
11145
9330
|
}
|
|
@@ -11179,7 +9364,7 @@ class DataStream extends BaseObserver {
|
|
|
11179
9364
|
}
|
|
11180
9365
|
const promise = (this.processingPromise = this._processQueue());
|
|
11181
9366
|
promise.finally(() => {
|
|
11182
|
-
|
|
9367
|
+
this.processingPromise = null;
|
|
11183
9368
|
});
|
|
11184
9369
|
return promise;
|
|
11185
9370
|
}
|
|
@@ -11211,7 +9396,6 @@ class DataStream extends BaseObserver {
|
|
|
11211
9396
|
this.notifyDataAdded = null;
|
|
11212
9397
|
}
|
|
11213
9398
|
if (this.dataQueue.length > 0) {
|
|
11214
|
-
// Next tick
|
|
11215
9399
|
setTimeout(() => this.processQueue());
|
|
11216
9400
|
}
|
|
11217
9401
|
}
|
|
@@ -11591,7 +9775,7 @@ class AbstractRemote {
|
|
|
11591
9775
|
else {
|
|
11592
9776
|
contents = JSON.stringify(js);
|
|
11593
9777
|
}
|
|
11594
|
-
return bufferExports
|
|
9778
|
+
return bufferExports.Buffer.from(contents);
|
|
11595
9779
|
}
|
|
11596
9780
|
const syncQueueRequestSize = fetchStrategy == exports.FetchStrategy.Buffered ? 10 : 1;
|
|
11597
9781
|
const request = await this.buildRequest(path);
|
|
@@ -11831,7 +10015,11 @@ class AbstractRemote {
|
|
|
11831
10015
|
};
|
|
11832
10016
|
const stream = new DataStream({
|
|
11833
10017
|
logger: this.logger,
|
|
11834
|
-
mapLine: mapLine
|
|
10018
|
+
mapLine: mapLine,
|
|
10019
|
+
pressure: {
|
|
10020
|
+
highWaterMark: 20,
|
|
10021
|
+
lowWaterMark: 10
|
|
10022
|
+
}
|
|
11835
10023
|
});
|
|
11836
10024
|
abortSignal?.addEventListener('abort', () => {
|
|
11837
10025
|
closeReader();
|
|
@@ -11839,42 +10027,47 @@ class AbstractRemote {
|
|
|
11839
10027
|
});
|
|
11840
10028
|
const decoder = this.createTextDecoder();
|
|
11841
10029
|
let buffer = '';
|
|
11842
|
-
const
|
|
11843
|
-
|
|
11844
|
-
|
|
10030
|
+
const consumeStream = async () => {
|
|
10031
|
+
while (!stream.closed && !abortSignal?.aborted && !readerReleased) {
|
|
10032
|
+
const { done, value } = await reader.read();
|
|
10033
|
+
if (done) {
|
|
10034
|
+
const remaining = buffer.trim();
|
|
10035
|
+
if (remaining.length != 0) {
|
|
10036
|
+
stream.enqueueData(remaining);
|
|
10037
|
+
}
|
|
10038
|
+
stream.close();
|
|
10039
|
+
await closeReader();
|
|
11845
10040
|
return;
|
|
11846
10041
|
}
|
|
11847
|
-
|
|
11848
|
-
|
|
11849
|
-
|
|
11850
|
-
|
|
11851
|
-
|
|
11852
|
-
|
|
11853
|
-
|
|
11854
|
-
stream.enqueueData(remaining);
|
|
11855
|
-
}
|
|
11856
|
-
stream.close();
|
|
11857
|
-
await closeReader();
|
|
11858
|
-
return;
|
|
11859
|
-
}
|
|
11860
|
-
const data = decoder.decode(value, { stream: true });
|
|
11861
|
-
buffer += data;
|
|
11862
|
-
const lines = buffer.split('\n');
|
|
11863
|
-
for (var i = 0; i < lines.length - 1; i++) {
|
|
11864
|
-
var l = lines[i].trim();
|
|
11865
|
-
if (l.length > 0) {
|
|
11866
|
-
stream.enqueueData(l);
|
|
11867
|
-
didCompleteLine = true;
|
|
11868
|
-
}
|
|
11869
|
-
}
|
|
11870
|
-
buffer = lines[lines.length - 1];
|
|
10042
|
+
const data = decoder.decode(value, { stream: true });
|
|
10043
|
+
buffer += data;
|
|
10044
|
+
const lines = buffer.split('\n');
|
|
10045
|
+
for (var i = 0; i < lines.length - 1; i++) {
|
|
10046
|
+
var l = lines[i].trim();
|
|
10047
|
+
if (l.length > 0) {
|
|
10048
|
+
stream.enqueueData(l);
|
|
11871
10049
|
}
|
|
11872
10050
|
}
|
|
11873
|
-
|
|
11874
|
-
|
|
11875
|
-
|
|
10051
|
+
buffer = lines[lines.length - 1];
|
|
10052
|
+
// Implement backpressure by waiting for the low water mark to be reached
|
|
10053
|
+
if (stream.dataQueue.length > stream.highWatermark) {
|
|
10054
|
+
await new Promise((resolve) => {
|
|
10055
|
+
const dispose = stream.registerListener({
|
|
10056
|
+
lowWater: async () => {
|
|
10057
|
+
resolve();
|
|
10058
|
+
dispose();
|
|
10059
|
+
},
|
|
10060
|
+
closed: () => {
|
|
10061
|
+
resolve();
|
|
10062
|
+
dispose();
|
|
10063
|
+
}
|
|
10064
|
+
});
|
|
10065
|
+
});
|
|
11876
10066
|
}
|
|
11877
|
-
}
|
|
10067
|
+
}
|
|
10068
|
+
};
|
|
10069
|
+
consumeStream().catch(ex => this.logger.error('Error consuming stream', ex));
|
|
10070
|
+
const l = stream.registerListener({
|
|
11878
10071
|
closed: () => {
|
|
11879
10072
|
closeReader();
|
|
11880
10073
|
l?.();
|
|
@@ -11996,6 +10189,7 @@ const DEFAULT_STREAMING_SYNC_OPTIONS = {
|
|
|
11996
10189
|
crudUploadThrottleMs: DEFAULT_CRUD_UPLOAD_THROTTLE_MS
|
|
11997
10190
|
};
|
|
11998
10191
|
const DEFAULT_STREAM_CONNECTION_OPTIONS = {
|
|
10192
|
+
appMetadata: {},
|
|
11999
10193
|
connectionMethod: exports.SyncStreamConnectionMethod.WEB_SOCKET,
|
|
12000
10194
|
clientImplementation: DEFAULT_SYNC_CLIENT_IMPLEMENTATION,
|
|
12001
10195
|
fetchStrategy: exports.FetchStrategy.Buffered,
|
|
@@ -12374,6 +10568,11 @@ The next upload iteration will be delayed.`);
|
|
|
12374
10568
|
...DEFAULT_STREAM_CONNECTION_OPTIONS,
|
|
12375
10569
|
...(options ?? {})
|
|
12376
10570
|
};
|
|
10571
|
+
// Validate app metadata
|
|
10572
|
+
const invalidMetadata = Object.entries(resolvedOptions.appMetadata).filter(([_, value]) => typeof value != 'string');
|
|
10573
|
+
if (invalidMetadata.length > 0) {
|
|
10574
|
+
throw new Error(`Invalid appMetadata provided. Only string values are allowed. Invalid values: ${invalidMetadata.map(([key, value]) => `${key}: ${value}`).join(', ')}`);
|
|
10575
|
+
}
|
|
12377
10576
|
const clientImplementation = resolvedOptions.clientImplementation;
|
|
12378
10577
|
this.updateSyncStatus({ clientImplementation });
|
|
12379
10578
|
if (clientImplementation == exports.SyncClientImplementation.JAVASCRIPT) {
|
|
@@ -12409,6 +10608,7 @@ The next upload iteration will be delayed.`);
|
|
|
12409
10608
|
include_checksum: true,
|
|
12410
10609
|
raw_data: true,
|
|
12411
10610
|
parameters: resolvedOptions.params,
|
|
10611
|
+
app_metadata: resolvedOptions.appMetadata,
|
|
12412
10612
|
client_id: clientId
|
|
12413
10613
|
}
|
|
12414
10614
|
};
|
|
@@ -12768,6 +10968,7 @@ The next upload iteration will be delayed.`);
|
|
|
12768
10968
|
try {
|
|
12769
10969
|
const options = {
|
|
12770
10970
|
parameters: resolvedOptions.params,
|
|
10971
|
+
app_metadata: resolvedOptions.appMetadata,
|
|
12771
10972
|
active_streams: this.activeStreams,
|
|
12772
10973
|
include_defaults: resolvedOptions.includeDefaultStreams
|
|
12773
10974
|
};
|
|
@@ -13404,14 +11605,14 @@ class AbstractPowerSyncDatabase extends BaseObserver {
|
|
|
13404
11605
|
async initialize() {
|
|
13405
11606
|
await this._initialize();
|
|
13406
11607
|
await this.bucketStorageAdapter.init();
|
|
13407
|
-
await this.
|
|
11608
|
+
await this.loadVersion();
|
|
13408
11609
|
await this.updateSchema(this.options.schema);
|
|
13409
11610
|
await this.resolveOfflineSyncStatus();
|
|
13410
11611
|
await this.database.execute('PRAGMA RECURSIVE_TRIGGERS=TRUE');
|
|
13411
11612
|
this.ready = true;
|
|
13412
11613
|
this.iterateListeners((cb) => cb.initialized?.());
|
|
13413
11614
|
}
|
|
13414
|
-
async
|
|
11615
|
+
async loadVersion() {
|
|
13415
11616
|
try {
|
|
13416
11617
|
const { version } = await this.database.get('SELECT powersync_rs_version() as version');
|
|
13417
11618
|
this.sdkVersion = version;
|
|
@@ -14550,6 +12751,27 @@ class SyncDataBatch {
|
|
|
14550
12751
|
}
|
|
14551
12752
|
}
|
|
14552
12753
|
|
|
12754
|
+
/**
|
|
12755
|
+
* Thrown when an underlying database connection is closed.
|
|
12756
|
+
* This is particularly relevant when worker connections are marked as closed while
|
|
12757
|
+
* operations are still in progress.
|
|
12758
|
+
*/
|
|
12759
|
+
class ConnectionClosedError extends Error {
|
|
12760
|
+
static NAME = 'ConnectionClosedError';
|
|
12761
|
+
static MATCHES(input) {
|
|
12762
|
+
/**
|
|
12763
|
+
* If there are weird package issues which cause multiple versions of classes to be present, the instanceof
|
|
12764
|
+
* check might fail. This also performs a failsafe check.
|
|
12765
|
+
* This might also happen if the Error is serialized and parsed over a bridging channel like a MessagePort.
|
|
12766
|
+
*/
|
|
12767
|
+
return (input instanceof ConnectionClosedError || (input instanceof Error && input.name == ConnectionClosedError.NAME));
|
|
12768
|
+
}
|
|
12769
|
+
constructor(message) {
|
|
12770
|
+
super(message);
|
|
12771
|
+
this.name = ConnectionClosedError.NAME;
|
|
12772
|
+
}
|
|
12773
|
+
}
|
|
12774
|
+
|
|
14553
12775
|
// https://www.sqlite.org/lang_expr.html#castexpr
|
|
14554
12776
|
exports.ColumnType = void 0;
|
|
14555
12777
|
(function (ColumnType) {
|
|
@@ -15113,6 +13335,7 @@ exports.AbstractStreamingSyncImplementation = AbstractStreamingSyncImplementatio
|
|
|
15113
13335
|
exports.ArrayComparator = ArrayComparator;
|
|
15114
13336
|
exports.BaseObserver = BaseObserver;
|
|
15115
13337
|
exports.Column = Column;
|
|
13338
|
+
exports.ConnectionClosedError = ConnectionClosedError;
|
|
15116
13339
|
exports.ConnectionManager = ConnectionManager;
|
|
15117
13340
|
exports.ControlledExecutor = ControlledExecutor;
|
|
15118
13341
|
exports.CrudBatch = CrudBatch;
|
|
@@ -15151,6 +13374,7 @@ exports.MAX_OP_ID = MAX_OP_ID;
|
|
|
15151
13374
|
exports.OnChangeQueryProcessor = OnChangeQueryProcessor;
|
|
15152
13375
|
exports.OpType = OpType;
|
|
15153
13376
|
exports.OplogEntry = OplogEntry;
|
|
13377
|
+
exports.RawTable = RawTable;
|
|
15154
13378
|
exports.Schema = Schema;
|
|
15155
13379
|
exports.SqliteBucketStorage = SqliteBucketStorage;
|
|
15156
13380
|
exports.SyncDataBatch = SyncDataBatch;
|