@leofcoin/peernet 1.1.2 → 1.1.4
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/exports/browser/client-111c93a3.js +612 -0
- package/exports/browser/{index-3c5482a7.js → index-3d3f56ca.js} +1 -1
- package/exports/browser/{messages-c9724c0b.js → messages-af41e873.js} +1 -1
- package/exports/browser/{peernet-5b33f983.js → peernet-f349ddaf.js} +8 -4
- package/exports/browser/peernet.js +1 -1
- package/exports/browser/{client-4b8a9fee.js → simple-peer-743c19fe.js} +2880 -655
- package/package.json +2 -1
- package/rollup.config.js +1 -0
|
@@ -1,231 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import require$$0 from 'buffer';
|
|
3
|
-
import require$$0$1 from 'events';
|
|
1
|
+
import { c as commonjsGlobal, r as require$$3$1, i as inherits_browserExports, g as getDefaultExportFromCjs } from './peernet-f349ddaf.js';
|
|
4
2
|
import './value-157ab062.js';
|
|
5
3
|
|
|
6
|
-
var clientApi = _pubsub => {
|
|
7
|
-
|
|
8
|
-
const subscribe = (topic, cb) => {
|
|
9
|
-
_pubsub.subscribe(topic, cb);
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const unsubscribe = (topic, cb) => {
|
|
13
|
-
_pubsub.unsubscribe(topic, cb);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const publish = (topic, value) => {
|
|
17
|
-
_pubsub.publish(topic, value);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const connectionState = (state) => {
|
|
21
|
-
switch (state) {
|
|
22
|
-
case 0:
|
|
23
|
-
return 'connecting'
|
|
24
|
-
case 1:
|
|
25
|
-
return 'open'
|
|
26
|
-
case 2:
|
|
27
|
-
return 'closing'
|
|
28
|
-
case 3:
|
|
29
|
-
return 'closed'
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* @param {string} type
|
|
34
|
-
* @param {string} name
|
|
35
|
-
* @param {object} params
|
|
36
|
-
*/
|
|
37
|
-
const request = (client, request) => {
|
|
38
|
-
return new Promise((resolve, reject) => {
|
|
39
|
-
|
|
40
|
-
const state = connectionState(client.readyState);
|
|
41
|
-
if (state !== 'open') return reject(`coudn't send request to ${client.id}, no open connection found.`)
|
|
42
|
-
|
|
43
|
-
request.id = Math.random().toString(36).slice(-12);
|
|
44
|
-
const handler = result => {
|
|
45
|
-
if (result && result.error) return reject(result.error)
|
|
46
|
-
resolve({result, id: request.id, handler});
|
|
47
|
-
unsubscribe(request.id, handler);
|
|
48
|
-
};
|
|
49
|
-
subscribe(request.id, handler);
|
|
50
|
-
send(client, request);
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const send = async (client, request) => {
|
|
55
|
-
return client.send(JSON.stringify(request))
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const pubsub = client => {
|
|
59
|
-
return {
|
|
60
|
-
publish: (topic = 'pubsub', value) => {
|
|
61
|
-
return send(client, {url: 'pubsub', params: { topic, value }})
|
|
62
|
-
},
|
|
63
|
-
subscribe: (topic = 'pubsub', cb) => {
|
|
64
|
-
subscribe(topic, cb);
|
|
65
|
-
return send(client, {url: 'pubsub', params: { topic, subscribe: true }})
|
|
66
|
-
},
|
|
67
|
-
unsubscribe: (topic = 'pubsub', cb) => {
|
|
68
|
-
unsubscribe(topic, cb);
|
|
69
|
-
return send(client, {url: 'pubsub', params: { topic, unsubscribe: true }})
|
|
70
|
-
},
|
|
71
|
-
subscribers: _pubsub.subscribers
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const server = (client) => {
|
|
76
|
-
return {
|
|
77
|
-
uptime: async () => {
|
|
78
|
-
try {
|
|
79
|
-
const { result, id, handler } = await request(client, {url: 'uptime'});
|
|
80
|
-
unsubscribe(id, handler);
|
|
81
|
-
return result
|
|
82
|
-
} catch (e) {
|
|
83
|
-
throw e
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
ping: async () => {
|
|
87
|
-
try {
|
|
88
|
-
const now = new Date().getTime();
|
|
89
|
-
const { result, id, handler } = await request(client, {url: 'ping'});
|
|
90
|
-
unsubscribe(id, handler);
|
|
91
|
-
return (Number(result) - now)
|
|
92
|
-
} catch (e) {
|
|
93
|
-
throw e
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const peernet = (client) => {
|
|
100
|
-
return {
|
|
101
|
-
join: async (params) => {
|
|
102
|
-
try {
|
|
103
|
-
params.join = true;
|
|
104
|
-
const requested = { url: 'peernet', params };
|
|
105
|
-
const { result, id, handler } = await request(client, requested);
|
|
106
|
-
unsubscribe(id, handler);
|
|
107
|
-
return result
|
|
108
|
-
} catch (e) {
|
|
109
|
-
throw e
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
leave: async (params) => {
|
|
113
|
-
try {
|
|
114
|
-
params.join = false;
|
|
115
|
-
const requested = { url: 'peernet', params };
|
|
116
|
-
const { result, id, handler } = await request(client, requested);
|
|
117
|
-
unsubscribe(id, handler);
|
|
118
|
-
return result
|
|
119
|
-
} catch (e) {
|
|
120
|
-
throw e
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
return { send, request, pubsub, server, subscribe, unsubscribe, publish, peernet, connectionState }
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
if (!globalThis.PubSub) globalThis.PubSub = LittlePubSub;
|
|
130
|
-
if (!globalThis.pubsub) globalThis.pubsub = new LittlePubSub({verbose: false});
|
|
131
|
-
|
|
132
|
-
const socketRequestClient = (url, protocols = 'echo-protocol', options = { retry: true, timeout: 10_000, times: 10 }) => {
|
|
133
|
-
let { retry, timeout, times } = options;
|
|
134
|
-
if (retry === undefined) retry = true;
|
|
135
|
-
if (timeout === undefined) timeout = 10_000;
|
|
136
|
-
if (times === undefined) times = 10;
|
|
137
|
-
|
|
138
|
-
const api = clientApi(pubsub);
|
|
139
|
-
|
|
140
|
-
let tries = 0;
|
|
141
|
-
|
|
142
|
-
const onerror = error => {
|
|
143
|
-
if (pubsub.subscribers['error']) {
|
|
144
|
-
pubsub.publish('error', error);
|
|
145
|
-
} else {
|
|
146
|
-
console.error(error);
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
const onmessage = message => {
|
|
151
|
-
const {value, url, status, id} = JSON.parse(message.data.toString());
|
|
152
|
-
const publisher = id ? id : url;
|
|
153
|
-
if (status === 200) {
|
|
154
|
-
pubsub.publish(publisher, value);
|
|
155
|
-
} else {
|
|
156
|
-
pubsub.publish(publisher, {error: value});
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
const clientConnection = client => {
|
|
161
|
-
const startTime = new Date().getTime();
|
|
162
|
-
return {
|
|
163
|
-
client,
|
|
164
|
-
request: async req => {
|
|
165
|
-
const { result, id, handler } = await api.request(client, req);
|
|
166
|
-
pubsub.unsubscribe(id, handler);
|
|
167
|
-
return result
|
|
168
|
-
},
|
|
169
|
-
send: req => api.send(client, req),
|
|
170
|
-
subscribe: api.subscribe,
|
|
171
|
-
unsubscribe: api.unsubscribe,
|
|
172
|
-
subscribers: api.subscribers,
|
|
173
|
-
publish: api.publish,
|
|
174
|
-
pubsub: api.pubsub(client),
|
|
175
|
-
uptime: () => {
|
|
176
|
-
const now = new Date().getTime();
|
|
177
|
-
return (now - startTime)
|
|
178
|
-
},
|
|
179
|
-
peernet: api.peernet(client),
|
|
180
|
-
server: api.server(client),
|
|
181
|
-
connectionState: () => api.connectionState(client.readyState),
|
|
182
|
-
close: exit => {
|
|
183
|
-
// client.onclose = message => {
|
|
184
|
-
// if (exit) process.exit()
|
|
185
|
-
// }
|
|
186
|
-
client.close();
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
return new Promise(async (resolve, reject) => {
|
|
192
|
-
const init = async () => {
|
|
193
|
-
let ws;
|
|
194
|
-
if (typeof process === 'object' && !globalThis.WebSocket) {
|
|
195
|
-
ws = (await import('./browser-e1cd4e67.js').then(function (n) { return n.b; })).default;
|
|
196
|
-
ws = ws.w3cwebsocket;
|
|
197
|
-
} else {
|
|
198
|
-
ws = WebSocket;
|
|
199
|
-
}
|
|
200
|
-
const client = new ws(url, protocols);
|
|
201
|
-
|
|
202
|
-
client.onmessage = onmessage;
|
|
203
|
-
client.onerror = onerror;
|
|
204
|
-
|
|
205
|
-
client.onopen = () => {
|
|
206
|
-
tries = 0;
|
|
207
|
-
resolve(clientConnection(client));
|
|
208
|
-
};
|
|
209
|
-
client.onclose = message => {
|
|
210
|
-
tries++;
|
|
211
|
-
if (!retry) return reject(options)
|
|
212
|
-
if (tries > times) {
|
|
213
|
-
console.log(`${protocols} Client Closed`);
|
|
214
|
-
console.error(`could not connect to - ${url}/`);
|
|
215
|
-
return resolve(clientConnection(client))
|
|
216
|
-
}
|
|
217
|
-
if (message.code === 1006) {
|
|
218
|
-
console.log(`Retrying in ${timeout} ms`);
|
|
219
|
-
setTimeout(() => {
|
|
220
|
-
return init();
|
|
221
|
-
}, timeout);
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
};
|
|
225
|
-
return init();
|
|
226
|
-
});
|
|
227
|
-
};
|
|
228
|
-
|
|
229
4
|
var browserExports$1 = {};
|
|
230
5
|
var browser$2 = {
|
|
231
6
|
get exports(){ return browserExports$1; },
|
|
@@ -949,40 +724,2391 @@ var common = setup;
|
|
|
949
724
|
};
|
|
950
725
|
} (browser$2, browserExports$1));
|
|
951
726
|
|
|
952
|
-
|
|
727
|
+
var require$$0 = browserExports$1;
|
|
728
|
+
|
|
729
|
+
// originally pulled out of simple-peer
|
|
730
|
+
|
|
731
|
+
var getBrowserRtc = function getBrowserRTC () {
|
|
732
|
+
if (typeof globalThis === 'undefined') return null
|
|
733
|
+
var wrtc = {
|
|
734
|
+
RTCPeerConnection: globalThis.RTCPeerConnection || globalThis.mozRTCPeerConnection ||
|
|
735
|
+
globalThis.webkitRTCPeerConnection,
|
|
736
|
+
RTCSessionDescription: globalThis.RTCSessionDescription ||
|
|
737
|
+
globalThis.mozRTCSessionDescription || globalThis.webkitRTCSessionDescription,
|
|
738
|
+
RTCIceCandidate: globalThis.RTCIceCandidate || globalThis.mozRTCIceCandidate ||
|
|
739
|
+
globalThis.webkitRTCIceCandidate
|
|
740
|
+
};
|
|
741
|
+
if (!wrtc.RTCPeerConnection) return null
|
|
742
|
+
return wrtc
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
var browserExports = {};
|
|
746
|
+
var browser$1 = {
|
|
747
|
+
get exports(){ return browserExports; },
|
|
748
|
+
set exports(v){ browserExports = v; },
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
var safeBufferExports = {};
|
|
752
|
+
var safeBuffer = {
|
|
753
|
+
get exports(){ return safeBufferExports; },
|
|
754
|
+
set exports(v){ safeBufferExports = v; },
|
|
755
|
+
};
|
|
756
|
+
|
|
757
|
+
var buffer = {};
|
|
758
|
+
|
|
759
|
+
var base64Js = {};
|
|
760
|
+
|
|
761
|
+
base64Js.byteLength = byteLength;
|
|
762
|
+
base64Js.toByteArray = toByteArray;
|
|
763
|
+
base64Js.fromByteArray = fromByteArray;
|
|
764
|
+
|
|
765
|
+
var lookup = [];
|
|
766
|
+
var revLookup = [];
|
|
767
|
+
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
|
|
768
|
+
|
|
769
|
+
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
770
|
+
for (var i = 0, len = code.length; i < len; ++i) {
|
|
771
|
+
lookup[i] = code[i];
|
|
772
|
+
revLookup[code.charCodeAt(i)] = i;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
// Support decoding URL-safe base64 strings, as Node.js does.
|
|
776
|
+
// See: https://en.wikipedia.org/wiki/Base64#URL_applications
|
|
777
|
+
revLookup['-'.charCodeAt(0)] = 62;
|
|
778
|
+
revLookup['_'.charCodeAt(0)] = 63;
|
|
779
|
+
|
|
780
|
+
function getLens (b64) {
|
|
781
|
+
var len = b64.length;
|
|
782
|
+
|
|
783
|
+
if (len % 4 > 0) {
|
|
784
|
+
throw new Error('Invalid string. Length must be a multiple of 4')
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// Trim off extra bytes after placeholder bytes are found
|
|
788
|
+
// See: https://github.com/beatgammit/base64-js/issues/42
|
|
789
|
+
var validLen = b64.indexOf('=');
|
|
790
|
+
if (validLen === -1) validLen = len;
|
|
791
|
+
|
|
792
|
+
var placeHoldersLen = validLen === len
|
|
793
|
+
? 0
|
|
794
|
+
: 4 - (validLen % 4);
|
|
795
|
+
|
|
796
|
+
return [validLen, placeHoldersLen]
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// base64 is 4/3 + up to two characters of the original data
|
|
800
|
+
function byteLength (b64) {
|
|
801
|
+
var lens = getLens(b64);
|
|
802
|
+
var validLen = lens[0];
|
|
803
|
+
var placeHoldersLen = lens[1];
|
|
804
|
+
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
function _byteLength (b64, validLen, placeHoldersLen) {
|
|
808
|
+
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
function toByteArray (b64) {
|
|
812
|
+
var tmp;
|
|
813
|
+
var lens = getLens(b64);
|
|
814
|
+
var validLen = lens[0];
|
|
815
|
+
var placeHoldersLen = lens[1];
|
|
816
|
+
|
|
817
|
+
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
818
|
+
|
|
819
|
+
var curByte = 0;
|
|
820
|
+
|
|
821
|
+
// if there are placeholders, only get up to the last complete 4 chars
|
|
822
|
+
var len = placeHoldersLen > 0
|
|
823
|
+
? validLen - 4
|
|
824
|
+
: validLen;
|
|
825
|
+
|
|
826
|
+
var i;
|
|
827
|
+
for (i = 0; i < len; i += 4) {
|
|
828
|
+
tmp =
|
|
829
|
+
(revLookup[b64.charCodeAt(i)] << 18) |
|
|
830
|
+
(revLookup[b64.charCodeAt(i + 1)] << 12) |
|
|
831
|
+
(revLookup[b64.charCodeAt(i + 2)] << 6) |
|
|
832
|
+
revLookup[b64.charCodeAt(i + 3)];
|
|
833
|
+
arr[curByte++] = (tmp >> 16) & 0xFF;
|
|
834
|
+
arr[curByte++] = (tmp >> 8) & 0xFF;
|
|
835
|
+
arr[curByte++] = tmp & 0xFF;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
if (placeHoldersLen === 2) {
|
|
839
|
+
tmp =
|
|
840
|
+
(revLookup[b64.charCodeAt(i)] << 2) |
|
|
841
|
+
(revLookup[b64.charCodeAt(i + 1)] >> 4);
|
|
842
|
+
arr[curByte++] = tmp & 0xFF;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
if (placeHoldersLen === 1) {
|
|
846
|
+
tmp =
|
|
847
|
+
(revLookup[b64.charCodeAt(i)] << 10) |
|
|
848
|
+
(revLookup[b64.charCodeAt(i + 1)] << 4) |
|
|
849
|
+
(revLookup[b64.charCodeAt(i + 2)] >> 2);
|
|
850
|
+
arr[curByte++] = (tmp >> 8) & 0xFF;
|
|
851
|
+
arr[curByte++] = tmp & 0xFF;
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
return arr
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
function tripletToBase64 (num) {
|
|
858
|
+
return lookup[num >> 18 & 0x3F] +
|
|
859
|
+
lookup[num >> 12 & 0x3F] +
|
|
860
|
+
lookup[num >> 6 & 0x3F] +
|
|
861
|
+
lookup[num & 0x3F]
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
function encodeChunk (uint8, start, end) {
|
|
865
|
+
var tmp;
|
|
866
|
+
var output = [];
|
|
867
|
+
for (var i = start; i < end; i += 3) {
|
|
868
|
+
tmp =
|
|
869
|
+
((uint8[i] << 16) & 0xFF0000) +
|
|
870
|
+
((uint8[i + 1] << 8) & 0xFF00) +
|
|
871
|
+
(uint8[i + 2] & 0xFF);
|
|
872
|
+
output.push(tripletToBase64(tmp));
|
|
873
|
+
}
|
|
874
|
+
return output.join('')
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
function fromByteArray (uint8) {
|
|
878
|
+
var tmp;
|
|
879
|
+
var len = uint8.length;
|
|
880
|
+
var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
|
|
881
|
+
var parts = [];
|
|
882
|
+
var maxChunkLength = 16383; // must be multiple of 3
|
|
883
|
+
|
|
884
|
+
// go through the array every three bytes, we'll deal with trailing stuff later
|
|
885
|
+
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
|
|
886
|
+
parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
// pad the end with zeros, but make sure to not forget the extra bytes
|
|
890
|
+
if (extraBytes === 1) {
|
|
891
|
+
tmp = uint8[len - 1];
|
|
892
|
+
parts.push(
|
|
893
|
+
lookup[tmp >> 2] +
|
|
894
|
+
lookup[(tmp << 4) & 0x3F] +
|
|
895
|
+
'=='
|
|
896
|
+
);
|
|
897
|
+
} else if (extraBytes === 2) {
|
|
898
|
+
tmp = (uint8[len - 2] << 8) + uint8[len - 1];
|
|
899
|
+
parts.push(
|
|
900
|
+
lookup[tmp >> 10] +
|
|
901
|
+
lookup[(tmp >> 4) & 0x3F] +
|
|
902
|
+
lookup[(tmp << 2) & 0x3F] +
|
|
903
|
+
'='
|
|
904
|
+
);
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
return parts.join('')
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
var ieee754 = {};
|
|
911
|
+
|
|
912
|
+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
913
|
+
|
|
914
|
+
ieee754.read = function (buffer, offset, isLE, mLen, nBytes) {
|
|
915
|
+
var e, m;
|
|
916
|
+
var eLen = (nBytes * 8) - mLen - 1;
|
|
917
|
+
var eMax = (1 << eLen) - 1;
|
|
918
|
+
var eBias = eMax >> 1;
|
|
919
|
+
var nBits = -7;
|
|
920
|
+
var i = isLE ? (nBytes - 1) : 0;
|
|
921
|
+
var d = isLE ? -1 : 1;
|
|
922
|
+
var s = buffer[offset + i];
|
|
923
|
+
|
|
924
|
+
i += d;
|
|
925
|
+
|
|
926
|
+
e = s & ((1 << (-nBits)) - 1);
|
|
927
|
+
s >>= (-nBits);
|
|
928
|
+
nBits += eLen;
|
|
929
|
+
for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
|
930
|
+
|
|
931
|
+
m = e & ((1 << (-nBits)) - 1);
|
|
932
|
+
e >>= (-nBits);
|
|
933
|
+
nBits += mLen;
|
|
934
|
+
for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
|
935
|
+
|
|
936
|
+
if (e === 0) {
|
|
937
|
+
e = 1 - eBias;
|
|
938
|
+
} else if (e === eMax) {
|
|
939
|
+
return m ? NaN : ((s ? -1 : 1) * Infinity)
|
|
940
|
+
} else {
|
|
941
|
+
m = m + Math.pow(2, mLen);
|
|
942
|
+
e = e - eBias;
|
|
943
|
+
}
|
|
944
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
|
|
945
|
+
};
|
|
946
|
+
|
|
947
|
+
ieee754.write = function (buffer, value, offset, isLE, mLen, nBytes) {
|
|
948
|
+
var e, m, c;
|
|
949
|
+
var eLen = (nBytes * 8) - mLen - 1;
|
|
950
|
+
var eMax = (1 << eLen) - 1;
|
|
951
|
+
var eBias = eMax >> 1;
|
|
952
|
+
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
|
|
953
|
+
var i = isLE ? 0 : (nBytes - 1);
|
|
954
|
+
var d = isLE ? 1 : -1;
|
|
955
|
+
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
|
|
956
|
+
|
|
957
|
+
value = Math.abs(value);
|
|
958
|
+
|
|
959
|
+
if (isNaN(value) || value === Infinity) {
|
|
960
|
+
m = isNaN(value) ? 1 : 0;
|
|
961
|
+
e = eMax;
|
|
962
|
+
} else {
|
|
963
|
+
e = Math.floor(Math.log(value) / Math.LN2);
|
|
964
|
+
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
965
|
+
e--;
|
|
966
|
+
c *= 2;
|
|
967
|
+
}
|
|
968
|
+
if (e + eBias >= 1) {
|
|
969
|
+
value += rt / c;
|
|
970
|
+
} else {
|
|
971
|
+
value += rt * Math.pow(2, 1 - eBias);
|
|
972
|
+
}
|
|
973
|
+
if (value * c >= 2) {
|
|
974
|
+
e++;
|
|
975
|
+
c /= 2;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
if (e + eBias >= eMax) {
|
|
979
|
+
m = 0;
|
|
980
|
+
e = eMax;
|
|
981
|
+
} else if (e + eBias >= 1) {
|
|
982
|
+
m = ((value * c) - 1) * Math.pow(2, mLen);
|
|
983
|
+
e = e + eBias;
|
|
984
|
+
} else {
|
|
985
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
986
|
+
e = 0;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
|
991
|
+
|
|
992
|
+
e = (e << mLen) | m;
|
|
993
|
+
eLen += mLen;
|
|
994
|
+
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
|
995
|
+
|
|
996
|
+
buffer[offset + i - d] |= s * 128;
|
|
997
|
+
};
|
|
998
|
+
|
|
999
|
+
/*!
|
|
1000
|
+
* The buffer module from node.js, for the browser.
|
|
1001
|
+
*
|
|
1002
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
1003
|
+
* @license MIT
|
|
1004
|
+
*/
|
|
1005
|
+
|
|
1006
|
+
(function (exports) {
|
|
1007
|
+
|
|
1008
|
+
const base64 = base64Js;
|
|
1009
|
+
const ieee754$1 = ieee754;
|
|
1010
|
+
const customInspectSymbol =
|
|
1011
|
+
(typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
|
|
1012
|
+
? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
|
|
1013
|
+
: null;
|
|
1014
|
+
|
|
1015
|
+
exports.Buffer = Buffer;
|
|
1016
|
+
exports.SlowBuffer = SlowBuffer;
|
|
1017
|
+
exports.INSPECT_MAX_BYTES = 50;
|
|
1018
|
+
|
|
1019
|
+
const K_MAX_LENGTH = 0x7fffffff;
|
|
1020
|
+
exports.kMaxLength = K_MAX_LENGTH;
|
|
1021
|
+
|
|
1022
|
+
/**
|
|
1023
|
+
* If `Buffer.TYPED_ARRAY_SUPPORT`:
|
|
1024
|
+
* === true Use Uint8Array implementation (fastest)
|
|
1025
|
+
* === false Print warning and recommend using `buffer` v4.x which has an Object
|
|
1026
|
+
* implementation (most compatible, even IE6)
|
|
1027
|
+
*
|
|
1028
|
+
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
|
|
1029
|
+
* Opera 11.6+, iOS 4.2+.
|
|
1030
|
+
*
|
|
1031
|
+
* We report that the browser does not support typed arrays if the are not subclassable
|
|
1032
|
+
* using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
|
|
1033
|
+
* (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
|
|
1034
|
+
* for __proto__ and has a buggy typed array implementation.
|
|
1035
|
+
*/
|
|
1036
|
+
Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
|
|
1037
|
+
|
|
1038
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
|
|
1039
|
+
typeof console.error === 'function') {
|
|
1040
|
+
console.error(
|
|
1041
|
+
'This browser lacks typed array (Uint8Array) support which is required by ' +
|
|
1042
|
+
'`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
|
|
1043
|
+
);
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
function typedArraySupport () {
|
|
1047
|
+
// Can typed array instances can be augmented?
|
|
1048
|
+
try {
|
|
1049
|
+
const arr = new Uint8Array(1);
|
|
1050
|
+
const proto = { foo: function () { return 42 } };
|
|
1051
|
+
Object.setPrototypeOf(proto, Uint8Array.prototype);
|
|
1052
|
+
Object.setPrototypeOf(arr, proto);
|
|
1053
|
+
return arr.foo() === 42
|
|
1054
|
+
} catch (e) {
|
|
1055
|
+
return false
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
Object.defineProperty(Buffer.prototype, 'parent', {
|
|
1060
|
+
enumerable: true,
|
|
1061
|
+
get: function () {
|
|
1062
|
+
if (!Buffer.isBuffer(this)) return undefined
|
|
1063
|
+
return this.buffer
|
|
1064
|
+
}
|
|
1065
|
+
});
|
|
1066
|
+
|
|
1067
|
+
Object.defineProperty(Buffer.prototype, 'offset', {
|
|
1068
|
+
enumerable: true,
|
|
1069
|
+
get: function () {
|
|
1070
|
+
if (!Buffer.isBuffer(this)) return undefined
|
|
1071
|
+
return this.byteOffset
|
|
1072
|
+
}
|
|
1073
|
+
});
|
|
1074
|
+
|
|
1075
|
+
function createBuffer (length) {
|
|
1076
|
+
if (length > K_MAX_LENGTH) {
|
|
1077
|
+
throw new RangeError('The value "' + length + '" is invalid for option "size"')
|
|
1078
|
+
}
|
|
1079
|
+
// Return an augmented `Uint8Array` instance
|
|
1080
|
+
const buf = new Uint8Array(length);
|
|
1081
|
+
Object.setPrototypeOf(buf, Buffer.prototype);
|
|
1082
|
+
return buf
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
/**
|
|
1086
|
+
* The Buffer constructor returns instances of `Uint8Array` that have their
|
|
1087
|
+
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
|
|
1088
|
+
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
|
|
1089
|
+
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
|
|
1090
|
+
* returns a single octet.
|
|
1091
|
+
*
|
|
1092
|
+
* The `Uint8Array` prototype remains unmodified.
|
|
1093
|
+
*/
|
|
1094
|
+
|
|
1095
|
+
function Buffer (arg, encodingOrOffset, length) {
|
|
1096
|
+
// Common case.
|
|
1097
|
+
if (typeof arg === 'number') {
|
|
1098
|
+
if (typeof encodingOrOffset === 'string') {
|
|
1099
|
+
throw new TypeError(
|
|
1100
|
+
'The "string" argument must be of type string. Received type number'
|
|
1101
|
+
)
|
|
1102
|
+
}
|
|
1103
|
+
return allocUnsafe(arg)
|
|
1104
|
+
}
|
|
1105
|
+
return from(arg, encodingOrOffset, length)
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
Buffer.poolSize = 8192; // not used by this implementation
|
|
1109
|
+
|
|
1110
|
+
function from (value, encodingOrOffset, length) {
|
|
1111
|
+
if (typeof value === 'string') {
|
|
1112
|
+
return fromString(value, encodingOrOffset)
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
if (ArrayBuffer.isView(value)) {
|
|
1116
|
+
return fromArrayView(value)
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
if (value == null) {
|
|
1120
|
+
throw new TypeError(
|
|
1121
|
+
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
|
1122
|
+
'or Array-like Object. Received type ' + (typeof value)
|
|
1123
|
+
)
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
if (isInstance(value, ArrayBuffer) ||
|
|
1127
|
+
(value && isInstance(value.buffer, ArrayBuffer))) {
|
|
1128
|
+
return fromArrayBuffer(value, encodingOrOffset, length)
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
if (typeof SharedArrayBuffer !== 'undefined' &&
|
|
1132
|
+
(isInstance(value, SharedArrayBuffer) ||
|
|
1133
|
+
(value && isInstance(value.buffer, SharedArrayBuffer)))) {
|
|
1134
|
+
return fromArrayBuffer(value, encodingOrOffset, length)
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
if (typeof value === 'number') {
|
|
1138
|
+
throw new TypeError(
|
|
1139
|
+
'The "value" argument must not be of type number. Received type number'
|
|
1140
|
+
)
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
const valueOf = value.valueOf && value.valueOf();
|
|
1144
|
+
if (valueOf != null && valueOf !== value) {
|
|
1145
|
+
return Buffer.from(valueOf, encodingOrOffset, length)
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
const b = fromObject(value);
|
|
1149
|
+
if (b) return b
|
|
1150
|
+
|
|
1151
|
+
if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
|
|
1152
|
+
typeof value[Symbol.toPrimitive] === 'function') {
|
|
1153
|
+
return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length)
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
throw new TypeError(
|
|
1157
|
+
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
|
1158
|
+
'or Array-like Object. Received type ' + (typeof value)
|
|
1159
|
+
)
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
/**
|
|
1163
|
+
* Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
|
|
1164
|
+
* if value is a number.
|
|
1165
|
+
* Buffer.from(str[, encoding])
|
|
1166
|
+
* Buffer.from(array)
|
|
1167
|
+
* Buffer.from(buffer)
|
|
1168
|
+
* Buffer.from(arrayBuffer[, byteOffset[, length]])
|
|
1169
|
+
**/
|
|
1170
|
+
Buffer.from = function (value, encodingOrOffset, length) {
|
|
1171
|
+
return from(value, encodingOrOffset, length)
|
|
1172
|
+
};
|
|
1173
|
+
|
|
1174
|
+
// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
|
|
1175
|
+
// https://github.com/feross/buffer/pull/148
|
|
1176
|
+
Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
|
|
1177
|
+
Object.setPrototypeOf(Buffer, Uint8Array);
|
|
1178
|
+
|
|
1179
|
+
function assertSize (size) {
|
|
1180
|
+
if (typeof size !== 'number') {
|
|
1181
|
+
throw new TypeError('"size" argument must be of type number')
|
|
1182
|
+
} else if (size < 0) {
|
|
1183
|
+
throw new RangeError('The value "' + size + '" is invalid for option "size"')
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
function alloc (size, fill, encoding) {
|
|
1188
|
+
assertSize(size);
|
|
1189
|
+
if (size <= 0) {
|
|
1190
|
+
return createBuffer(size)
|
|
1191
|
+
}
|
|
1192
|
+
if (fill !== undefined) {
|
|
1193
|
+
// Only pay attention to encoding if it's a string. This
|
|
1194
|
+
// prevents accidentally sending in a number that would
|
|
1195
|
+
// be interpreted as a start offset.
|
|
1196
|
+
return typeof encoding === 'string'
|
|
1197
|
+
? createBuffer(size).fill(fill, encoding)
|
|
1198
|
+
: createBuffer(size).fill(fill)
|
|
1199
|
+
}
|
|
1200
|
+
return createBuffer(size)
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
/**
|
|
1204
|
+
* Creates a new filled Buffer instance.
|
|
1205
|
+
* alloc(size[, fill[, encoding]])
|
|
1206
|
+
**/
|
|
1207
|
+
Buffer.alloc = function (size, fill, encoding) {
|
|
1208
|
+
return alloc(size, fill, encoding)
|
|
1209
|
+
};
|
|
1210
|
+
|
|
1211
|
+
function allocUnsafe (size) {
|
|
1212
|
+
assertSize(size);
|
|
1213
|
+
return createBuffer(size < 0 ? 0 : checked(size) | 0)
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
/**
|
|
1217
|
+
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
|
|
1218
|
+
* */
|
|
1219
|
+
Buffer.allocUnsafe = function (size) {
|
|
1220
|
+
return allocUnsafe(size)
|
|
1221
|
+
};
|
|
1222
|
+
/**
|
|
1223
|
+
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
|
1224
|
+
*/
|
|
1225
|
+
Buffer.allocUnsafeSlow = function (size) {
|
|
1226
|
+
return allocUnsafe(size)
|
|
1227
|
+
};
|
|
1228
|
+
|
|
1229
|
+
function fromString (string, encoding) {
|
|
1230
|
+
if (typeof encoding !== 'string' || encoding === '') {
|
|
1231
|
+
encoding = 'utf8';
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
if (!Buffer.isEncoding(encoding)) {
|
|
1235
|
+
throw new TypeError('Unknown encoding: ' + encoding)
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
const length = byteLength(string, encoding) | 0;
|
|
1239
|
+
let buf = createBuffer(length);
|
|
1240
|
+
|
|
1241
|
+
const actual = buf.write(string, encoding);
|
|
1242
|
+
|
|
1243
|
+
if (actual !== length) {
|
|
1244
|
+
// Writing a hex string, for example, that contains invalid characters will
|
|
1245
|
+
// cause everything after the first invalid character to be ignored. (e.g.
|
|
1246
|
+
// 'abxxcd' will be treated as 'ab')
|
|
1247
|
+
buf = buf.slice(0, actual);
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
return buf
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
function fromArrayLike (array) {
|
|
1254
|
+
const length = array.length < 0 ? 0 : checked(array.length) | 0;
|
|
1255
|
+
const buf = createBuffer(length);
|
|
1256
|
+
for (let i = 0; i < length; i += 1) {
|
|
1257
|
+
buf[i] = array[i] & 255;
|
|
1258
|
+
}
|
|
1259
|
+
return buf
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
function fromArrayView (arrayView) {
|
|
1263
|
+
if (isInstance(arrayView, Uint8Array)) {
|
|
1264
|
+
const copy = new Uint8Array(arrayView);
|
|
1265
|
+
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
|
|
1266
|
+
}
|
|
1267
|
+
return fromArrayLike(arrayView)
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
function fromArrayBuffer (array, byteOffset, length) {
|
|
1271
|
+
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
1272
|
+
throw new RangeError('"offset" is outside of buffer bounds')
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
if (array.byteLength < byteOffset + (length || 0)) {
|
|
1276
|
+
throw new RangeError('"length" is outside of buffer bounds')
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
let buf;
|
|
1280
|
+
if (byteOffset === undefined && length === undefined) {
|
|
1281
|
+
buf = new Uint8Array(array);
|
|
1282
|
+
} else if (length === undefined) {
|
|
1283
|
+
buf = new Uint8Array(array, byteOffset);
|
|
1284
|
+
} else {
|
|
1285
|
+
buf = new Uint8Array(array, byteOffset, length);
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
// Return an augmented `Uint8Array` instance
|
|
1289
|
+
Object.setPrototypeOf(buf, Buffer.prototype);
|
|
1290
|
+
|
|
1291
|
+
return buf
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
function fromObject (obj) {
|
|
1295
|
+
if (Buffer.isBuffer(obj)) {
|
|
1296
|
+
const len = checked(obj.length) | 0;
|
|
1297
|
+
const buf = createBuffer(len);
|
|
1298
|
+
|
|
1299
|
+
if (buf.length === 0) {
|
|
1300
|
+
return buf
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
obj.copy(buf, 0, 0, len);
|
|
1304
|
+
return buf
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
if (obj.length !== undefined) {
|
|
1308
|
+
if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
|
|
1309
|
+
return createBuffer(0)
|
|
1310
|
+
}
|
|
1311
|
+
return fromArrayLike(obj)
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
|
|
1315
|
+
return fromArrayLike(obj.data)
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
function checked (length) {
|
|
1320
|
+
// Note: cannot use `length < K_MAX_LENGTH` here because that fails when
|
|
1321
|
+
// length is NaN (which is otherwise coerced to zero.)
|
|
1322
|
+
if (length >= K_MAX_LENGTH) {
|
|
1323
|
+
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
|
|
1324
|
+
'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
|
|
1325
|
+
}
|
|
1326
|
+
return length | 0
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
function SlowBuffer (length) {
|
|
1330
|
+
if (+length != length) { // eslint-disable-line eqeqeq
|
|
1331
|
+
length = 0;
|
|
1332
|
+
}
|
|
1333
|
+
return Buffer.alloc(+length)
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
Buffer.isBuffer = function isBuffer (b) {
|
|
1337
|
+
return b != null && b._isBuffer === true &&
|
|
1338
|
+
b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
|
|
1339
|
+
};
|
|
1340
|
+
|
|
1341
|
+
Buffer.compare = function compare (a, b) {
|
|
1342
|
+
if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
|
|
1343
|
+
if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
|
|
1344
|
+
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
|
|
1345
|
+
throw new TypeError(
|
|
1346
|
+
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
|
|
1347
|
+
)
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
if (a === b) return 0
|
|
1351
|
+
|
|
1352
|
+
let x = a.length;
|
|
1353
|
+
let y = b.length;
|
|
1354
|
+
|
|
1355
|
+
for (let i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
1356
|
+
if (a[i] !== b[i]) {
|
|
1357
|
+
x = a[i];
|
|
1358
|
+
y = b[i];
|
|
1359
|
+
break
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
if (x < y) return -1
|
|
1364
|
+
if (y < x) return 1
|
|
1365
|
+
return 0
|
|
1366
|
+
};
|
|
1367
|
+
|
|
1368
|
+
Buffer.isEncoding = function isEncoding (encoding) {
|
|
1369
|
+
switch (String(encoding).toLowerCase()) {
|
|
1370
|
+
case 'hex':
|
|
1371
|
+
case 'utf8':
|
|
1372
|
+
case 'utf-8':
|
|
1373
|
+
case 'ascii':
|
|
1374
|
+
case 'latin1':
|
|
1375
|
+
case 'binary':
|
|
1376
|
+
case 'base64':
|
|
1377
|
+
case 'ucs2':
|
|
1378
|
+
case 'ucs-2':
|
|
1379
|
+
case 'utf16le':
|
|
1380
|
+
case 'utf-16le':
|
|
1381
|
+
return true
|
|
1382
|
+
default:
|
|
1383
|
+
return false
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1386
|
+
|
|
1387
|
+
Buffer.concat = function concat (list, length) {
|
|
1388
|
+
if (!Array.isArray(list)) {
|
|
1389
|
+
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
if (list.length === 0) {
|
|
1393
|
+
return Buffer.alloc(0)
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
let i;
|
|
1397
|
+
if (length === undefined) {
|
|
1398
|
+
length = 0;
|
|
1399
|
+
for (i = 0; i < list.length; ++i) {
|
|
1400
|
+
length += list[i].length;
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
const buffer = Buffer.allocUnsafe(length);
|
|
1405
|
+
let pos = 0;
|
|
1406
|
+
for (i = 0; i < list.length; ++i) {
|
|
1407
|
+
let buf = list[i];
|
|
1408
|
+
if (isInstance(buf, Uint8Array)) {
|
|
1409
|
+
if (pos + buf.length > buffer.length) {
|
|
1410
|
+
if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf);
|
|
1411
|
+
buf.copy(buffer, pos);
|
|
1412
|
+
} else {
|
|
1413
|
+
Uint8Array.prototype.set.call(
|
|
1414
|
+
buffer,
|
|
1415
|
+
buf,
|
|
1416
|
+
pos
|
|
1417
|
+
);
|
|
1418
|
+
}
|
|
1419
|
+
} else if (!Buffer.isBuffer(buf)) {
|
|
1420
|
+
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
1421
|
+
} else {
|
|
1422
|
+
buf.copy(buffer, pos);
|
|
1423
|
+
}
|
|
1424
|
+
pos += buf.length;
|
|
1425
|
+
}
|
|
1426
|
+
return buffer
|
|
1427
|
+
};
|
|
1428
|
+
|
|
1429
|
+
function byteLength (string, encoding) {
|
|
1430
|
+
if (Buffer.isBuffer(string)) {
|
|
1431
|
+
return string.length
|
|
1432
|
+
}
|
|
1433
|
+
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
|
|
1434
|
+
return string.byteLength
|
|
1435
|
+
}
|
|
1436
|
+
if (typeof string !== 'string') {
|
|
1437
|
+
throw new TypeError(
|
|
1438
|
+
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
|
|
1439
|
+
'Received type ' + typeof string
|
|
1440
|
+
)
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
const len = string.length;
|
|
1444
|
+
const mustMatch = (arguments.length > 2 && arguments[2] === true);
|
|
1445
|
+
if (!mustMatch && len === 0) return 0
|
|
1446
|
+
|
|
1447
|
+
// Use a for loop to avoid recursion
|
|
1448
|
+
let loweredCase = false;
|
|
1449
|
+
for (;;) {
|
|
1450
|
+
switch (encoding) {
|
|
1451
|
+
case 'ascii':
|
|
1452
|
+
case 'latin1':
|
|
1453
|
+
case 'binary':
|
|
1454
|
+
return len
|
|
1455
|
+
case 'utf8':
|
|
1456
|
+
case 'utf-8':
|
|
1457
|
+
return utf8ToBytes(string).length
|
|
1458
|
+
case 'ucs2':
|
|
1459
|
+
case 'ucs-2':
|
|
1460
|
+
case 'utf16le':
|
|
1461
|
+
case 'utf-16le':
|
|
1462
|
+
return len * 2
|
|
1463
|
+
case 'hex':
|
|
1464
|
+
return len >>> 1
|
|
1465
|
+
case 'base64':
|
|
1466
|
+
return base64ToBytes(string).length
|
|
1467
|
+
default:
|
|
1468
|
+
if (loweredCase) {
|
|
1469
|
+
return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
|
|
1470
|
+
}
|
|
1471
|
+
encoding = ('' + encoding).toLowerCase();
|
|
1472
|
+
loweredCase = true;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
Buffer.byteLength = byteLength;
|
|
1477
|
+
|
|
1478
|
+
function slowToString (encoding, start, end) {
|
|
1479
|
+
let loweredCase = false;
|
|
1480
|
+
|
|
1481
|
+
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
|
|
1482
|
+
// property of a typed array.
|
|
1483
|
+
|
|
1484
|
+
// This behaves neither like String nor Uint8Array in that we set start/end
|
|
1485
|
+
// to their upper/lower bounds if the value passed is out of range.
|
|
1486
|
+
// undefined is handled specially as per ECMA-262 6th Edition,
|
|
1487
|
+
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
|
|
1488
|
+
if (start === undefined || start < 0) {
|
|
1489
|
+
start = 0;
|
|
1490
|
+
}
|
|
1491
|
+
// Return early if start > this.length. Done here to prevent potential uint32
|
|
1492
|
+
// coercion fail below.
|
|
1493
|
+
if (start > this.length) {
|
|
1494
|
+
return ''
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
if (end === undefined || end > this.length) {
|
|
1498
|
+
end = this.length;
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
if (end <= 0) {
|
|
1502
|
+
return ''
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
// Force coercion to uint32. This will also coerce falsey/NaN values to 0.
|
|
1506
|
+
end >>>= 0;
|
|
1507
|
+
start >>>= 0;
|
|
1508
|
+
|
|
1509
|
+
if (end <= start) {
|
|
1510
|
+
return ''
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
if (!encoding) encoding = 'utf8';
|
|
1514
|
+
|
|
1515
|
+
while (true) {
|
|
1516
|
+
switch (encoding) {
|
|
1517
|
+
case 'hex':
|
|
1518
|
+
return hexSlice(this, start, end)
|
|
1519
|
+
|
|
1520
|
+
case 'utf8':
|
|
1521
|
+
case 'utf-8':
|
|
1522
|
+
return utf8Slice(this, start, end)
|
|
1523
|
+
|
|
1524
|
+
case 'ascii':
|
|
1525
|
+
return asciiSlice(this, start, end)
|
|
1526
|
+
|
|
1527
|
+
case 'latin1':
|
|
1528
|
+
case 'binary':
|
|
1529
|
+
return latin1Slice(this, start, end)
|
|
1530
|
+
|
|
1531
|
+
case 'base64':
|
|
1532
|
+
return base64Slice(this, start, end)
|
|
1533
|
+
|
|
1534
|
+
case 'ucs2':
|
|
1535
|
+
case 'ucs-2':
|
|
1536
|
+
case 'utf16le':
|
|
1537
|
+
case 'utf-16le':
|
|
1538
|
+
return utf16leSlice(this, start, end)
|
|
1539
|
+
|
|
1540
|
+
default:
|
|
1541
|
+
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
1542
|
+
encoding = (encoding + '').toLowerCase();
|
|
1543
|
+
loweredCase = true;
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
|
|
1549
|
+
// to detect a Buffer instance. It's not possible to use `instanceof Buffer`
|
|
1550
|
+
// reliably in a browserify context because there could be multiple different
|
|
1551
|
+
// copies of the 'buffer' package in use. This method works even for Buffer
|
|
1552
|
+
// instances that were created from another copy of the `buffer` package.
|
|
1553
|
+
// See: https://github.com/feross/buffer/issues/154
|
|
1554
|
+
Buffer.prototype._isBuffer = true;
|
|
1555
|
+
|
|
1556
|
+
function swap (b, n, m) {
|
|
1557
|
+
const i = b[n];
|
|
1558
|
+
b[n] = b[m];
|
|
1559
|
+
b[m] = i;
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
Buffer.prototype.swap16 = function swap16 () {
|
|
1563
|
+
const len = this.length;
|
|
1564
|
+
if (len % 2 !== 0) {
|
|
1565
|
+
throw new RangeError('Buffer size must be a multiple of 16-bits')
|
|
1566
|
+
}
|
|
1567
|
+
for (let i = 0; i < len; i += 2) {
|
|
1568
|
+
swap(this, i, i + 1);
|
|
1569
|
+
}
|
|
1570
|
+
return this
|
|
1571
|
+
};
|
|
1572
|
+
|
|
1573
|
+
Buffer.prototype.swap32 = function swap32 () {
|
|
1574
|
+
const len = this.length;
|
|
1575
|
+
if (len % 4 !== 0) {
|
|
1576
|
+
throw new RangeError('Buffer size must be a multiple of 32-bits')
|
|
1577
|
+
}
|
|
1578
|
+
for (let i = 0; i < len; i += 4) {
|
|
1579
|
+
swap(this, i, i + 3);
|
|
1580
|
+
swap(this, i + 1, i + 2);
|
|
1581
|
+
}
|
|
1582
|
+
return this
|
|
1583
|
+
};
|
|
1584
|
+
|
|
1585
|
+
Buffer.prototype.swap64 = function swap64 () {
|
|
1586
|
+
const len = this.length;
|
|
1587
|
+
if (len % 8 !== 0) {
|
|
1588
|
+
throw new RangeError('Buffer size must be a multiple of 64-bits')
|
|
1589
|
+
}
|
|
1590
|
+
for (let i = 0; i < len; i += 8) {
|
|
1591
|
+
swap(this, i, i + 7);
|
|
1592
|
+
swap(this, i + 1, i + 6);
|
|
1593
|
+
swap(this, i + 2, i + 5);
|
|
1594
|
+
swap(this, i + 3, i + 4);
|
|
1595
|
+
}
|
|
1596
|
+
return this
|
|
1597
|
+
};
|
|
1598
|
+
|
|
1599
|
+
Buffer.prototype.toString = function toString () {
|
|
1600
|
+
const length = this.length;
|
|
1601
|
+
if (length === 0) return ''
|
|
1602
|
+
if (arguments.length === 0) return utf8Slice(this, 0, length)
|
|
1603
|
+
return slowToString.apply(this, arguments)
|
|
1604
|
+
};
|
|
1605
|
+
|
|
1606
|
+
Buffer.prototype.toLocaleString = Buffer.prototype.toString;
|
|
1607
|
+
|
|
1608
|
+
Buffer.prototype.equals = function equals (b) {
|
|
1609
|
+
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
|
|
1610
|
+
if (this === b) return true
|
|
1611
|
+
return Buffer.compare(this, b) === 0
|
|
1612
|
+
};
|
|
1613
|
+
|
|
1614
|
+
Buffer.prototype.inspect = function inspect () {
|
|
1615
|
+
let str = '';
|
|
1616
|
+
const max = exports.INSPECT_MAX_BYTES;
|
|
1617
|
+
str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
|
|
1618
|
+
if (this.length > max) str += ' ... ';
|
|
1619
|
+
return '<Buffer ' + str + '>'
|
|
1620
|
+
};
|
|
1621
|
+
if (customInspectSymbol) {
|
|
1622
|
+
Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
|
|
1626
|
+
if (isInstance(target, Uint8Array)) {
|
|
1627
|
+
target = Buffer.from(target, target.offset, target.byteLength);
|
|
1628
|
+
}
|
|
1629
|
+
if (!Buffer.isBuffer(target)) {
|
|
1630
|
+
throw new TypeError(
|
|
1631
|
+
'The "target" argument must be one of type Buffer or Uint8Array. ' +
|
|
1632
|
+
'Received type ' + (typeof target)
|
|
1633
|
+
)
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
if (start === undefined) {
|
|
1637
|
+
start = 0;
|
|
1638
|
+
}
|
|
1639
|
+
if (end === undefined) {
|
|
1640
|
+
end = target ? target.length : 0;
|
|
1641
|
+
}
|
|
1642
|
+
if (thisStart === undefined) {
|
|
1643
|
+
thisStart = 0;
|
|
1644
|
+
}
|
|
1645
|
+
if (thisEnd === undefined) {
|
|
1646
|
+
thisEnd = this.length;
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
1650
|
+
throw new RangeError('out of range index')
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
if (thisStart >= thisEnd && start >= end) {
|
|
1654
|
+
return 0
|
|
1655
|
+
}
|
|
1656
|
+
if (thisStart >= thisEnd) {
|
|
1657
|
+
return -1
|
|
1658
|
+
}
|
|
1659
|
+
if (start >= end) {
|
|
1660
|
+
return 1
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1663
|
+
start >>>= 0;
|
|
1664
|
+
end >>>= 0;
|
|
1665
|
+
thisStart >>>= 0;
|
|
1666
|
+
thisEnd >>>= 0;
|
|
1667
|
+
|
|
1668
|
+
if (this === target) return 0
|
|
1669
|
+
|
|
1670
|
+
let x = thisEnd - thisStart;
|
|
1671
|
+
let y = end - start;
|
|
1672
|
+
const len = Math.min(x, y);
|
|
1673
|
+
|
|
1674
|
+
const thisCopy = this.slice(thisStart, thisEnd);
|
|
1675
|
+
const targetCopy = target.slice(start, end);
|
|
1676
|
+
|
|
1677
|
+
for (let i = 0; i < len; ++i) {
|
|
1678
|
+
if (thisCopy[i] !== targetCopy[i]) {
|
|
1679
|
+
x = thisCopy[i];
|
|
1680
|
+
y = targetCopy[i];
|
|
1681
|
+
break
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
if (x < y) return -1
|
|
1686
|
+
if (y < x) return 1
|
|
1687
|
+
return 0
|
|
1688
|
+
};
|
|
1689
|
+
|
|
1690
|
+
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
|
|
1691
|
+
// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
|
|
1692
|
+
//
|
|
1693
|
+
// Arguments:
|
|
1694
|
+
// - buffer - a Buffer to search
|
|
1695
|
+
// - val - a string, Buffer, or number
|
|
1696
|
+
// - byteOffset - an index into `buffer`; will be clamped to an int32
|
|
1697
|
+
// - encoding - an optional encoding, relevant is val is a string
|
|
1698
|
+
// - dir - true for indexOf, false for lastIndexOf
|
|
1699
|
+
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
|
1700
|
+
// Empty buffer means no match
|
|
1701
|
+
if (buffer.length === 0) return -1
|
|
1702
|
+
|
|
1703
|
+
// Normalize byteOffset
|
|
1704
|
+
if (typeof byteOffset === 'string') {
|
|
1705
|
+
encoding = byteOffset;
|
|
1706
|
+
byteOffset = 0;
|
|
1707
|
+
} else if (byteOffset > 0x7fffffff) {
|
|
1708
|
+
byteOffset = 0x7fffffff;
|
|
1709
|
+
} else if (byteOffset < -0x80000000) {
|
|
1710
|
+
byteOffset = -0x80000000;
|
|
1711
|
+
}
|
|
1712
|
+
byteOffset = +byteOffset; // Coerce to Number.
|
|
1713
|
+
if (numberIsNaN(byteOffset)) {
|
|
1714
|
+
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
|
|
1715
|
+
byteOffset = dir ? 0 : (buffer.length - 1);
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
// Normalize byteOffset: negative offsets start from the end of the buffer
|
|
1719
|
+
if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
|
|
1720
|
+
if (byteOffset >= buffer.length) {
|
|
1721
|
+
if (dir) return -1
|
|
1722
|
+
else byteOffset = buffer.length - 1;
|
|
1723
|
+
} else if (byteOffset < 0) {
|
|
1724
|
+
if (dir) byteOffset = 0;
|
|
1725
|
+
else return -1
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
// Normalize val
|
|
1729
|
+
if (typeof val === 'string') {
|
|
1730
|
+
val = Buffer.from(val, encoding);
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
// Finally, search either indexOf (if dir is true) or lastIndexOf
|
|
1734
|
+
if (Buffer.isBuffer(val)) {
|
|
1735
|
+
// Special case: looking for empty string/buffer always fails
|
|
1736
|
+
if (val.length === 0) {
|
|
1737
|
+
return -1
|
|
1738
|
+
}
|
|
1739
|
+
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
|
|
1740
|
+
} else if (typeof val === 'number') {
|
|
1741
|
+
val = val & 0xFF; // Search for a byte value [0-255]
|
|
1742
|
+
if (typeof Uint8Array.prototype.indexOf === 'function') {
|
|
1743
|
+
if (dir) {
|
|
1744
|
+
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
|
|
1745
|
+
} else {
|
|
1746
|
+
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
throw new TypeError('val must be string, number or Buffer')
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
|
|
1756
|
+
let indexSize = 1;
|
|
1757
|
+
let arrLength = arr.length;
|
|
1758
|
+
let valLength = val.length;
|
|
1759
|
+
|
|
1760
|
+
if (encoding !== undefined) {
|
|
1761
|
+
encoding = String(encoding).toLowerCase();
|
|
1762
|
+
if (encoding === 'ucs2' || encoding === 'ucs-2' ||
|
|
1763
|
+
encoding === 'utf16le' || encoding === 'utf-16le') {
|
|
1764
|
+
if (arr.length < 2 || val.length < 2) {
|
|
1765
|
+
return -1
|
|
1766
|
+
}
|
|
1767
|
+
indexSize = 2;
|
|
1768
|
+
arrLength /= 2;
|
|
1769
|
+
valLength /= 2;
|
|
1770
|
+
byteOffset /= 2;
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1774
|
+
function read (buf, i) {
|
|
1775
|
+
if (indexSize === 1) {
|
|
1776
|
+
return buf[i]
|
|
1777
|
+
} else {
|
|
1778
|
+
return buf.readUInt16BE(i * indexSize)
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
let i;
|
|
1783
|
+
if (dir) {
|
|
1784
|
+
let foundIndex = -1;
|
|
1785
|
+
for (i = byteOffset; i < arrLength; i++) {
|
|
1786
|
+
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
1787
|
+
if (foundIndex === -1) foundIndex = i;
|
|
1788
|
+
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
|
|
1789
|
+
} else {
|
|
1790
|
+
if (foundIndex !== -1) i -= i - foundIndex;
|
|
1791
|
+
foundIndex = -1;
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
} else {
|
|
1795
|
+
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
|
|
1796
|
+
for (i = byteOffset; i >= 0; i--) {
|
|
1797
|
+
let found = true;
|
|
1798
|
+
for (let j = 0; j < valLength; j++) {
|
|
1799
|
+
if (read(arr, i + j) !== read(val, j)) {
|
|
1800
|
+
found = false;
|
|
1801
|
+
break
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
if (found) return i
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
return -1
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
|
|
1812
|
+
return this.indexOf(val, byteOffset, encoding) !== -1
|
|
1813
|
+
};
|
|
1814
|
+
|
|
1815
|
+
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
|
|
1816
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
|
|
1817
|
+
};
|
|
1818
|
+
|
|
1819
|
+
Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
|
|
1820
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
|
|
1821
|
+
};
|
|
1822
|
+
|
|
1823
|
+
function hexWrite (buf, string, offset, length) {
|
|
1824
|
+
offset = Number(offset) || 0;
|
|
1825
|
+
const remaining = buf.length - offset;
|
|
1826
|
+
if (!length) {
|
|
1827
|
+
length = remaining;
|
|
1828
|
+
} else {
|
|
1829
|
+
length = Number(length);
|
|
1830
|
+
if (length > remaining) {
|
|
1831
|
+
length = remaining;
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
const strLen = string.length;
|
|
1836
|
+
|
|
1837
|
+
if (length > strLen / 2) {
|
|
1838
|
+
length = strLen / 2;
|
|
1839
|
+
}
|
|
1840
|
+
let i;
|
|
1841
|
+
for (i = 0; i < length; ++i) {
|
|
1842
|
+
const parsed = parseInt(string.substr(i * 2, 2), 16);
|
|
1843
|
+
if (numberIsNaN(parsed)) return i
|
|
1844
|
+
buf[offset + i] = parsed;
|
|
1845
|
+
}
|
|
1846
|
+
return i
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
function utf8Write (buf, string, offset, length) {
|
|
1850
|
+
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
function asciiWrite (buf, string, offset, length) {
|
|
1854
|
+
return blitBuffer(asciiToBytes(string), buf, offset, length)
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
function base64Write (buf, string, offset, length) {
|
|
1858
|
+
return blitBuffer(base64ToBytes(string), buf, offset, length)
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
function ucs2Write (buf, string, offset, length) {
|
|
1862
|
+
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1865
|
+
Buffer.prototype.write = function write (string, offset, length, encoding) {
|
|
1866
|
+
// Buffer#write(string)
|
|
1867
|
+
if (offset === undefined) {
|
|
1868
|
+
encoding = 'utf8';
|
|
1869
|
+
length = this.length;
|
|
1870
|
+
offset = 0;
|
|
1871
|
+
// Buffer#write(string, encoding)
|
|
1872
|
+
} else if (length === undefined && typeof offset === 'string') {
|
|
1873
|
+
encoding = offset;
|
|
1874
|
+
length = this.length;
|
|
1875
|
+
offset = 0;
|
|
1876
|
+
// Buffer#write(string, offset[, length][, encoding])
|
|
1877
|
+
} else if (isFinite(offset)) {
|
|
1878
|
+
offset = offset >>> 0;
|
|
1879
|
+
if (isFinite(length)) {
|
|
1880
|
+
length = length >>> 0;
|
|
1881
|
+
if (encoding === undefined) encoding = 'utf8';
|
|
1882
|
+
} else {
|
|
1883
|
+
encoding = length;
|
|
1884
|
+
length = undefined;
|
|
1885
|
+
}
|
|
1886
|
+
} else {
|
|
1887
|
+
throw new Error(
|
|
1888
|
+
'Buffer.write(string, encoding, offset[, length]) is no longer supported'
|
|
1889
|
+
)
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
const remaining = this.length - offset;
|
|
1893
|
+
if (length === undefined || length > remaining) length = remaining;
|
|
1894
|
+
|
|
1895
|
+
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
|
|
1896
|
+
throw new RangeError('Attempt to write outside buffer bounds')
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
if (!encoding) encoding = 'utf8';
|
|
1900
|
+
|
|
1901
|
+
let loweredCase = false;
|
|
1902
|
+
for (;;) {
|
|
1903
|
+
switch (encoding) {
|
|
1904
|
+
case 'hex':
|
|
1905
|
+
return hexWrite(this, string, offset, length)
|
|
1906
|
+
|
|
1907
|
+
case 'utf8':
|
|
1908
|
+
case 'utf-8':
|
|
1909
|
+
return utf8Write(this, string, offset, length)
|
|
1910
|
+
|
|
1911
|
+
case 'ascii':
|
|
1912
|
+
case 'latin1':
|
|
1913
|
+
case 'binary':
|
|
1914
|
+
return asciiWrite(this, string, offset, length)
|
|
1915
|
+
|
|
1916
|
+
case 'base64':
|
|
1917
|
+
// Warning: maxLength not taken into account in base64Write
|
|
1918
|
+
return base64Write(this, string, offset, length)
|
|
1919
|
+
|
|
1920
|
+
case 'ucs2':
|
|
1921
|
+
case 'ucs-2':
|
|
1922
|
+
case 'utf16le':
|
|
1923
|
+
case 'utf-16le':
|
|
1924
|
+
return ucs2Write(this, string, offset, length)
|
|
1925
|
+
|
|
1926
|
+
default:
|
|
1927
|
+
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
1928
|
+
encoding = ('' + encoding).toLowerCase();
|
|
1929
|
+
loweredCase = true;
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
};
|
|
1933
|
+
|
|
1934
|
+
Buffer.prototype.toJSON = function toJSON () {
|
|
1935
|
+
return {
|
|
1936
|
+
type: 'Buffer',
|
|
1937
|
+
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
1938
|
+
}
|
|
1939
|
+
};
|
|
1940
|
+
|
|
1941
|
+
function base64Slice (buf, start, end) {
|
|
1942
|
+
if (start === 0 && end === buf.length) {
|
|
1943
|
+
return base64.fromByteArray(buf)
|
|
1944
|
+
} else {
|
|
1945
|
+
return base64.fromByteArray(buf.slice(start, end))
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1949
|
+
function utf8Slice (buf, start, end) {
|
|
1950
|
+
end = Math.min(buf.length, end);
|
|
1951
|
+
const res = [];
|
|
1952
|
+
|
|
1953
|
+
let i = start;
|
|
1954
|
+
while (i < end) {
|
|
1955
|
+
const firstByte = buf[i];
|
|
1956
|
+
let codePoint = null;
|
|
1957
|
+
let bytesPerSequence = (firstByte > 0xEF)
|
|
1958
|
+
? 4
|
|
1959
|
+
: (firstByte > 0xDF)
|
|
1960
|
+
? 3
|
|
1961
|
+
: (firstByte > 0xBF)
|
|
1962
|
+
? 2
|
|
1963
|
+
: 1;
|
|
1964
|
+
|
|
1965
|
+
if (i + bytesPerSequence <= end) {
|
|
1966
|
+
let secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
1967
|
+
|
|
1968
|
+
switch (bytesPerSequence) {
|
|
1969
|
+
case 1:
|
|
1970
|
+
if (firstByte < 0x80) {
|
|
1971
|
+
codePoint = firstByte;
|
|
1972
|
+
}
|
|
1973
|
+
break
|
|
1974
|
+
case 2:
|
|
1975
|
+
secondByte = buf[i + 1];
|
|
1976
|
+
if ((secondByte & 0xC0) === 0x80) {
|
|
1977
|
+
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
|
|
1978
|
+
if (tempCodePoint > 0x7F) {
|
|
1979
|
+
codePoint = tempCodePoint;
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
break
|
|
1983
|
+
case 3:
|
|
1984
|
+
secondByte = buf[i + 1];
|
|
1985
|
+
thirdByte = buf[i + 2];
|
|
1986
|
+
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
|
|
1987
|
+
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
|
|
1988
|
+
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
|
|
1989
|
+
codePoint = tempCodePoint;
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
break
|
|
1993
|
+
case 4:
|
|
1994
|
+
secondByte = buf[i + 1];
|
|
1995
|
+
thirdByte = buf[i + 2];
|
|
1996
|
+
fourthByte = buf[i + 3];
|
|
1997
|
+
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
|
|
1998
|
+
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
|
|
1999
|
+
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
|
|
2000
|
+
codePoint = tempCodePoint;
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
if (codePoint === null) {
|
|
2007
|
+
// we did not generate a valid codePoint so insert a
|
|
2008
|
+
// replacement char (U+FFFD) and advance only 1 byte
|
|
2009
|
+
codePoint = 0xFFFD;
|
|
2010
|
+
bytesPerSequence = 1;
|
|
2011
|
+
} else if (codePoint > 0xFFFF) {
|
|
2012
|
+
// encode to utf16 (surrogate pair dance)
|
|
2013
|
+
codePoint -= 0x10000;
|
|
2014
|
+
res.push(codePoint >>> 10 & 0x3FF | 0xD800);
|
|
2015
|
+
codePoint = 0xDC00 | codePoint & 0x3FF;
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
res.push(codePoint);
|
|
2019
|
+
i += bytesPerSequence;
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
return decodeCodePointsArray(res)
|
|
2023
|
+
}
|
|
2024
|
+
|
|
2025
|
+
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
|
|
2026
|
+
// the lowest limit is Chrome, with 0x10000 args.
|
|
2027
|
+
// We go 1 magnitude less, for safety
|
|
2028
|
+
const MAX_ARGUMENTS_LENGTH = 0x1000;
|
|
2029
|
+
|
|
2030
|
+
function decodeCodePointsArray (codePoints) {
|
|
2031
|
+
const len = codePoints.length;
|
|
2032
|
+
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
2033
|
+
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
// Decode in chunks to avoid "call stack size exceeded".
|
|
2037
|
+
let res = '';
|
|
2038
|
+
let i = 0;
|
|
2039
|
+
while (i < len) {
|
|
2040
|
+
res += String.fromCharCode.apply(
|
|
2041
|
+
String,
|
|
2042
|
+
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
2043
|
+
);
|
|
2044
|
+
}
|
|
2045
|
+
return res
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
function asciiSlice (buf, start, end) {
|
|
2049
|
+
let ret = '';
|
|
2050
|
+
end = Math.min(buf.length, end);
|
|
2051
|
+
|
|
2052
|
+
for (let i = start; i < end; ++i) {
|
|
2053
|
+
ret += String.fromCharCode(buf[i] & 0x7F);
|
|
2054
|
+
}
|
|
2055
|
+
return ret
|
|
2056
|
+
}
|
|
2057
|
+
|
|
2058
|
+
function latin1Slice (buf, start, end) {
|
|
2059
|
+
let ret = '';
|
|
2060
|
+
end = Math.min(buf.length, end);
|
|
2061
|
+
|
|
2062
|
+
for (let i = start; i < end; ++i) {
|
|
2063
|
+
ret += String.fromCharCode(buf[i]);
|
|
2064
|
+
}
|
|
2065
|
+
return ret
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
function hexSlice (buf, start, end) {
|
|
2069
|
+
const len = buf.length;
|
|
2070
|
+
|
|
2071
|
+
if (!start || start < 0) start = 0;
|
|
2072
|
+
if (!end || end < 0 || end > len) end = len;
|
|
2073
|
+
|
|
2074
|
+
let out = '';
|
|
2075
|
+
for (let i = start; i < end; ++i) {
|
|
2076
|
+
out += hexSliceLookupTable[buf[i]];
|
|
2077
|
+
}
|
|
2078
|
+
return out
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
function utf16leSlice (buf, start, end) {
|
|
2082
|
+
const bytes = buf.slice(start, end);
|
|
2083
|
+
let res = '';
|
|
2084
|
+
// If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
|
|
2085
|
+
for (let i = 0; i < bytes.length - 1; i += 2) {
|
|
2086
|
+
res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256));
|
|
2087
|
+
}
|
|
2088
|
+
return res
|
|
2089
|
+
}
|
|
2090
|
+
|
|
2091
|
+
Buffer.prototype.slice = function slice (start, end) {
|
|
2092
|
+
const len = this.length;
|
|
2093
|
+
start = ~~start;
|
|
2094
|
+
end = end === undefined ? len : ~~end;
|
|
2095
|
+
|
|
2096
|
+
if (start < 0) {
|
|
2097
|
+
start += len;
|
|
2098
|
+
if (start < 0) start = 0;
|
|
2099
|
+
} else if (start > len) {
|
|
2100
|
+
start = len;
|
|
2101
|
+
}
|
|
2102
|
+
|
|
2103
|
+
if (end < 0) {
|
|
2104
|
+
end += len;
|
|
2105
|
+
if (end < 0) end = 0;
|
|
2106
|
+
} else if (end > len) {
|
|
2107
|
+
end = len;
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
if (end < start) end = start;
|
|
2111
|
+
|
|
2112
|
+
const newBuf = this.subarray(start, end);
|
|
2113
|
+
// Return an augmented `Uint8Array` instance
|
|
2114
|
+
Object.setPrototypeOf(newBuf, Buffer.prototype);
|
|
2115
|
+
|
|
2116
|
+
return newBuf
|
|
2117
|
+
};
|
|
2118
|
+
|
|
2119
|
+
/*
|
|
2120
|
+
* Need to make sure that buffer isn't trying to write out of bounds.
|
|
2121
|
+
*/
|
|
2122
|
+
function checkOffset (offset, ext, length) {
|
|
2123
|
+
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
|
|
2124
|
+
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2127
|
+
Buffer.prototype.readUintLE =
|
|
2128
|
+
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
|
|
2129
|
+
offset = offset >>> 0;
|
|
2130
|
+
byteLength = byteLength >>> 0;
|
|
2131
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
2132
|
+
|
|
2133
|
+
let val = this[offset];
|
|
2134
|
+
let mul = 1;
|
|
2135
|
+
let i = 0;
|
|
2136
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
2137
|
+
val += this[offset + i] * mul;
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
return val
|
|
2141
|
+
};
|
|
2142
|
+
|
|
2143
|
+
Buffer.prototype.readUintBE =
|
|
2144
|
+
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
|
|
2145
|
+
offset = offset >>> 0;
|
|
2146
|
+
byteLength = byteLength >>> 0;
|
|
2147
|
+
if (!noAssert) {
|
|
2148
|
+
checkOffset(offset, byteLength, this.length);
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
let val = this[offset + --byteLength];
|
|
2152
|
+
let mul = 1;
|
|
2153
|
+
while (byteLength > 0 && (mul *= 0x100)) {
|
|
2154
|
+
val += this[offset + --byteLength] * mul;
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
return val
|
|
2158
|
+
};
|
|
2159
|
+
|
|
2160
|
+
Buffer.prototype.readUint8 =
|
|
2161
|
+
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
|
|
2162
|
+
offset = offset >>> 0;
|
|
2163
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
2164
|
+
return this[offset]
|
|
2165
|
+
};
|
|
2166
|
+
|
|
2167
|
+
Buffer.prototype.readUint16LE =
|
|
2168
|
+
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
|
|
2169
|
+
offset = offset >>> 0;
|
|
2170
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
2171
|
+
return this[offset] | (this[offset + 1] << 8)
|
|
2172
|
+
};
|
|
2173
|
+
|
|
2174
|
+
Buffer.prototype.readUint16BE =
|
|
2175
|
+
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
|
|
2176
|
+
offset = offset >>> 0;
|
|
2177
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
2178
|
+
return (this[offset] << 8) | this[offset + 1]
|
|
2179
|
+
};
|
|
2180
|
+
|
|
2181
|
+
Buffer.prototype.readUint32LE =
|
|
2182
|
+
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
|
|
2183
|
+
offset = offset >>> 0;
|
|
2184
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
2185
|
+
|
|
2186
|
+
return ((this[offset]) |
|
|
2187
|
+
(this[offset + 1] << 8) |
|
|
2188
|
+
(this[offset + 2] << 16)) +
|
|
2189
|
+
(this[offset + 3] * 0x1000000)
|
|
2190
|
+
};
|
|
2191
|
+
|
|
2192
|
+
Buffer.prototype.readUint32BE =
|
|
2193
|
+
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
|
|
2194
|
+
offset = offset >>> 0;
|
|
2195
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
2196
|
+
|
|
2197
|
+
return (this[offset] * 0x1000000) +
|
|
2198
|
+
((this[offset + 1] << 16) |
|
|
2199
|
+
(this[offset + 2] << 8) |
|
|
2200
|
+
this[offset + 3])
|
|
2201
|
+
};
|
|
2202
|
+
|
|
2203
|
+
Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE (offset) {
|
|
2204
|
+
offset = offset >>> 0;
|
|
2205
|
+
validateNumber(offset, 'offset');
|
|
2206
|
+
const first = this[offset];
|
|
2207
|
+
const last = this[offset + 7];
|
|
2208
|
+
if (first === undefined || last === undefined) {
|
|
2209
|
+
boundsError(offset, this.length - 8);
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
const lo = first +
|
|
2213
|
+
this[++offset] * 2 ** 8 +
|
|
2214
|
+
this[++offset] * 2 ** 16 +
|
|
2215
|
+
this[++offset] * 2 ** 24;
|
|
2216
|
+
|
|
2217
|
+
const hi = this[++offset] +
|
|
2218
|
+
this[++offset] * 2 ** 8 +
|
|
2219
|
+
this[++offset] * 2 ** 16 +
|
|
2220
|
+
last * 2 ** 24;
|
|
2221
|
+
|
|
2222
|
+
return BigInt(lo) + (BigInt(hi) << BigInt(32))
|
|
2223
|
+
});
|
|
2224
|
+
|
|
2225
|
+
Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (offset) {
|
|
2226
|
+
offset = offset >>> 0;
|
|
2227
|
+
validateNumber(offset, 'offset');
|
|
2228
|
+
const first = this[offset];
|
|
2229
|
+
const last = this[offset + 7];
|
|
2230
|
+
if (first === undefined || last === undefined) {
|
|
2231
|
+
boundsError(offset, this.length - 8);
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2234
|
+
const hi = first * 2 ** 24 +
|
|
2235
|
+
this[++offset] * 2 ** 16 +
|
|
2236
|
+
this[++offset] * 2 ** 8 +
|
|
2237
|
+
this[++offset];
|
|
2238
|
+
|
|
2239
|
+
const lo = this[++offset] * 2 ** 24 +
|
|
2240
|
+
this[++offset] * 2 ** 16 +
|
|
2241
|
+
this[++offset] * 2 ** 8 +
|
|
2242
|
+
last;
|
|
2243
|
+
|
|
2244
|
+
return (BigInt(hi) << BigInt(32)) + BigInt(lo)
|
|
2245
|
+
});
|
|
2246
|
+
|
|
2247
|
+
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
|
|
2248
|
+
offset = offset >>> 0;
|
|
2249
|
+
byteLength = byteLength >>> 0;
|
|
2250
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
2251
|
+
|
|
2252
|
+
let val = this[offset];
|
|
2253
|
+
let mul = 1;
|
|
2254
|
+
let i = 0;
|
|
2255
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
2256
|
+
val += this[offset + i] * mul;
|
|
2257
|
+
}
|
|
2258
|
+
mul *= 0x80;
|
|
2259
|
+
|
|
2260
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
|
|
2261
|
+
|
|
2262
|
+
return val
|
|
2263
|
+
};
|
|
2264
|
+
|
|
2265
|
+
Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
|
|
2266
|
+
offset = offset >>> 0;
|
|
2267
|
+
byteLength = byteLength >>> 0;
|
|
2268
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
2269
|
+
|
|
2270
|
+
let i = byteLength;
|
|
2271
|
+
let mul = 1;
|
|
2272
|
+
let val = this[offset + --i];
|
|
2273
|
+
while (i > 0 && (mul *= 0x100)) {
|
|
2274
|
+
val += this[offset + --i] * mul;
|
|
2275
|
+
}
|
|
2276
|
+
mul *= 0x80;
|
|
2277
|
+
|
|
2278
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
|
|
2279
|
+
|
|
2280
|
+
return val
|
|
2281
|
+
};
|
|
2282
|
+
|
|
2283
|
+
Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
|
|
2284
|
+
offset = offset >>> 0;
|
|
2285
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
2286
|
+
if (!(this[offset] & 0x80)) return (this[offset])
|
|
2287
|
+
return ((0xff - this[offset] + 1) * -1)
|
|
2288
|
+
};
|
|
2289
|
+
|
|
2290
|
+
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
|
|
2291
|
+
offset = offset >>> 0;
|
|
2292
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
2293
|
+
const val = this[offset] | (this[offset + 1] << 8);
|
|
2294
|
+
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
2295
|
+
};
|
|
2296
|
+
|
|
2297
|
+
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
|
|
2298
|
+
offset = offset >>> 0;
|
|
2299
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
2300
|
+
const val = this[offset + 1] | (this[offset] << 8);
|
|
2301
|
+
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
2302
|
+
};
|
|
2303
|
+
|
|
2304
|
+
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
|
|
2305
|
+
offset = offset >>> 0;
|
|
2306
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
2307
|
+
|
|
2308
|
+
return (this[offset]) |
|
|
2309
|
+
(this[offset + 1] << 8) |
|
|
2310
|
+
(this[offset + 2] << 16) |
|
|
2311
|
+
(this[offset + 3] << 24)
|
|
2312
|
+
};
|
|
2313
|
+
|
|
2314
|
+
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
|
|
2315
|
+
offset = offset >>> 0;
|
|
2316
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
2317
|
+
|
|
2318
|
+
return (this[offset] << 24) |
|
|
2319
|
+
(this[offset + 1] << 16) |
|
|
2320
|
+
(this[offset + 2] << 8) |
|
|
2321
|
+
(this[offset + 3])
|
|
2322
|
+
};
|
|
2323
|
+
|
|
2324
|
+
Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE (offset) {
|
|
2325
|
+
offset = offset >>> 0;
|
|
2326
|
+
validateNumber(offset, 'offset');
|
|
2327
|
+
const first = this[offset];
|
|
2328
|
+
const last = this[offset + 7];
|
|
2329
|
+
if (first === undefined || last === undefined) {
|
|
2330
|
+
boundsError(offset, this.length - 8);
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2333
|
+
const val = this[offset + 4] +
|
|
2334
|
+
this[offset + 5] * 2 ** 8 +
|
|
2335
|
+
this[offset + 6] * 2 ** 16 +
|
|
2336
|
+
(last << 24); // Overflow
|
|
2337
|
+
|
|
2338
|
+
return (BigInt(val) << BigInt(32)) +
|
|
2339
|
+
BigInt(first +
|
|
2340
|
+
this[++offset] * 2 ** 8 +
|
|
2341
|
+
this[++offset] * 2 ** 16 +
|
|
2342
|
+
this[++offset] * 2 ** 24)
|
|
2343
|
+
});
|
|
2344
|
+
|
|
2345
|
+
Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE (offset) {
|
|
2346
|
+
offset = offset >>> 0;
|
|
2347
|
+
validateNumber(offset, 'offset');
|
|
2348
|
+
const first = this[offset];
|
|
2349
|
+
const last = this[offset + 7];
|
|
2350
|
+
if (first === undefined || last === undefined) {
|
|
2351
|
+
boundsError(offset, this.length - 8);
|
|
2352
|
+
}
|
|
2353
|
+
|
|
2354
|
+
const val = (first << 24) + // Overflow
|
|
2355
|
+
this[++offset] * 2 ** 16 +
|
|
2356
|
+
this[++offset] * 2 ** 8 +
|
|
2357
|
+
this[++offset];
|
|
2358
|
+
|
|
2359
|
+
return (BigInt(val) << BigInt(32)) +
|
|
2360
|
+
BigInt(this[++offset] * 2 ** 24 +
|
|
2361
|
+
this[++offset] * 2 ** 16 +
|
|
2362
|
+
this[++offset] * 2 ** 8 +
|
|
2363
|
+
last)
|
|
2364
|
+
});
|
|
2365
|
+
|
|
2366
|
+
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
|
|
2367
|
+
offset = offset >>> 0;
|
|
2368
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
2369
|
+
return ieee754$1.read(this, offset, true, 23, 4)
|
|
2370
|
+
};
|
|
2371
|
+
|
|
2372
|
+
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
|
|
2373
|
+
offset = offset >>> 0;
|
|
2374
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
2375
|
+
return ieee754$1.read(this, offset, false, 23, 4)
|
|
2376
|
+
};
|
|
2377
|
+
|
|
2378
|
+
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
|
|
2379
|
+
offset = offset >>> 0;
|
|
2380
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
2381
|
+
return ieee754$1.read(this, offset, true, 52, 8)
|
|
2382
|
+
};
|
|
2383
|
+
|
|
2384
|
+
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
|
|
2385
|
+
offset = offset >>> 0;
|
|
2386
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
2387
|
+
return ieee754$1.read(this, offset, false, 52, 8)
|
|
2388
|
+
};
|
|
2389
|
+
|
|
2390
|
+
function checkInt (buf, value, offset, ext, max, min) {
|
|
2391
|
+
if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
|
|
2392
|
+
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
|
|
2393
|
+
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
2394
|
+
}
|
|
2395
|
+
|
|
2396
|
+
Buffer.prototype.writeUintLE =
|
|
2397
|
+
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
|
|
2398
|
+
value = +value;
|
|
2399
|
+
offset = offset >>> 0;
|
|
2400
|
+
byteLength = byteLength >>> 0;
|
|
2401
|
+
if (!noAssert) {
|
|
2402
|
+
const maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
2403
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
2404
|
+
}
|
|
2405
|
+
|
|
2406
|
+
let mul = 1;
|
|
2407
|
+
let i = 0;
|
|
2408
|
+
this[offset] = value & 0xFF;
|
|
2409
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
2410
|
+
this[offset + i] = (value / mul) & 0xFF;
|
|
2411
|
+
}
|
|
2412
|
+
|
|
2413
|
+
return offset + byteLength
|
|
2414
|
+
};
|
|
2415
|
+
|
|
2416
|
+
Buffer.prototype.writeUintBE =
|
|
2417
|
+
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
|
|
2418
|
+
value = +value;
|
|
2419
|
+
offset = offset >>> 0;
|
|
2420
|
+
byteLength = byteLength >>> 0;
|
|
2421
|
+
if (!noAssert) {
|
|
2422
|
+
const maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
2423
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2426
|
+
let i = byteLength - 1;
|
|
2427
|
+
let mul = 1;
|
|
2428
|
+
this[offset + i] = value & 0xFF;
|
|
2429
|
+
while (--i >= 0 && (mul *= 0x100)) {
|
|
2430
|
+
this[offset + i] = (value / mul) & 0xFF;
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2433
|
+
return offset + byteLength
|
|
2434
|
+
};
|
|
2435
|
+
|
|
2436
|
+
Buffer.prototype.writeUint8 =
|
|
2437
|
+
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
|
|
2438
|
+
value = +value;
|
|
2439
|
+
offset = offset >>> 0;
|
|
2440
|
+
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
|
|
2441
|
+
this[offset] = (value & 0xff);
|
|
2442
|
+
return offset + 1
|
|
2443
|
+
};
|
|
2444
|
+
|
|
2445
|
+
Buffer.prototype.writeUint16LE =
|
|
2446
|
+
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
|
|
2447
|
+
value = +value;
|
|
2448
|
+
offset = offset >>> 0;
|
|
2449
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
|
2450
|
+
this[offset] = (value & 0xff);
|
|
2451
|
+
this[offset + 1] = (value >>> 8);
|
|
2452
|
+
return offset + 2
|
|
2453
|
+
};
|
|
2454
|
+
|
|
2455
|
+
Buffer.prototype.writeUint16BE =
|
|
2456
|
+
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
|
|
2457
|
+
value = +value;
|
|
2458
|
+
offset = offset >>> 0;
|
|
2459
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
|
2460
|
+
this[offset] = (value >>> 8);
|
|
2461
|
+
this[offset + 1] = (value & 0xff);
|
|
2462
|
+
return offset + 2
|
|
2463
|
+
};
|
|
2464
|
+
|
|
2465
|
+
Buffer.prototype.writeUint32LE =
|
|
2466
|
+
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
|
|
2467
|
+
value = +value;
|
|
2468
|
+
offset = offset >>> 0;
|
|
2469
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
2470
|
+
this[offset + 3] = (value >>> 24);
|
|
2471
|
+
this[offset + 2] = (value >>> 16);
|
|
2472
|
+
this[offset + 1] = (value >>> 8);
|
|
2473
|
+
this[offset] = (value & 0xff);
|
|
2474
|
+
return offset + 4
|
|
2475
|
+
};
|
|
2476
|
+
|
|
2477
|
+
Buffer.prototype.writeUint32BE =
|
|
2478
|
+
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
|
|
2479
|
+
value = +value;
|
|
2480
|
+
offset = offset >>> 0;
|
|
2481
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
2482
|
+
this[offset] = (value >>> 24);
|
|
2483
|
+
this[offset + 1] = (value >>> 16);
|
|
2484
|
+
this[offset + 2] = (value >>> 8);
|
|
2485
|
+
this[offset + 3] = (value & 0xff);
|
|
2486
|
+
return offset + 4
|
|
2487
|
+
};
|
|
2488
|
+
|
|
2489
|
+
function wrtBigUInt64LE (buf, value, offset, min, max) {
|
|
2490
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
2491
|
+
|
|
2492
|
+
let lo = Number(value & BigInt(0xffffffff));
|
|
2493
|
+
buf[offset++] = lo;
|
|
2494
|
+
lo = lo >> 8;
|
|
2495
|
+
buf[offset++] = lo;
|
|
2496
|
+
lo = lo >> 8;
|
|
2497
|
+
buf[offset++] = lo;
|
|
2498
|
+
lo = lo >> 8;
|
|
2499
|
+
buf[offset++] = lo;
|
|
2500
|
+
let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
|
|
2501
|
+
buf[offset++] = hi;
|
|
2502
|
+
hi = hi >> 8;
|
|
2503
|
+
buf[offset++] = hi;
|
|
2504
|
+
hi = hi >> 8;
|
|
2505
|
+
buf[offset++] = hi;
|
|
2506
|
+
hi = hi >> 8;
|
|
2507
|
+
buf[offset++] = hi;
|
|
2508
|
+
return offset
|
|
2509
|
+
}
|
|
2510
|
+
|
|
2511
|
+
function wrtBigUInt64BE (buf, value, offset, min, max) {
|
|
2512
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
2513
|
+
|
|
2514
|
+
let lo = Number(value & BigInt(0xffffffff));
|
|
2515
|
+
buf[offset + 7] = lo;
|
|
2516
|
+
lo = lo >> 8;
|
|
2517
|
+
buf[offset + 6] = lo;
|
|
2518
|
+
lo = lo >> 8;
|
|
2519
|
+
buf[offset + 5] = lo;
|
|
2520
|
+
lo = lo >> 8;
|
|
2521
|
+
buf[offset + 4] = lo;
|
|
2522
|
+
let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
|
|
2523
|
+
buf[offset + 3] = hi;
|
|
2524
|
+
hi = hi >> 8;
|
|
2525
|
+
buf[offset + 2] = hi;
|
|
2526
|
+
hi = hi >> 8;
|
|
2527
|
+
buf[offset + 1] = hi;
|
|
2528
|
+
hi = hi >> 8;
|
|
2529
|
+
buf[offset] = hi;
|
|
2530
|
+
return offset + 8
|
|
2531
|
+
}
|
|
2532
|
+
|
|
2533
|
+
Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) {
|
|
2534
|
+
return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
|
|
2535
|
+
});
|
|
2536
|
+
|
|
2537
|
+
Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) {
|
|
2538
|
+
return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
|
|
2539
|
+
});
|
|
2540
|
+
|
|
2541
|
+
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
|
|
2542
|
+
value = +value;
|
|
2543
|
+
offset = offset >>> 0;
|
|
2544
|
+
if (!noAssert) {
|
|
2545
|
+
const limit = Math.pow(2, (8 * byteLength) - 1);
|
|
2546
|
+
|
|
2547
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
2548
|
+
}
|
|
2549
|
+
|
|
2550
|
+
let i = 0;
|
|
2551
|
+
let mul = 1;
|
|
2552
|
+
let sub = 0;
|
|
2553
|
+
this[offset] = value & 0xFF;
|
|
2554
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
2555
|
+
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
2556
|
+
sub = 1;
|
|
2557
|
+
}
|
|
2558
|
+
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
|
|
2559
|
+
}
|
|
2560
|
+
|
|
2561
|
+
return offset + byteLength
|
|
2562
|
+
};
|
|
2563
|
+
|
|
2564
|
+
Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
|
|
2565
|
+
value = +value;
|
|
2566
|
+
offset = offset >>> 0;
|
|
2567
|
+
if (!noAssert) {
|
|
2568
|
+
const limit = Math.pow(2, (8 * byteLength) - 1);
|
|
2569
|
+
|
|
2570
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
2571
|
+
}
|
|
2572
|
+
|
|
2573
|
+
let i = byteLength - 1;
|
|
2574
|
+
let mul = 1;
|
|
2575
|
+
let sub = 0;
|
|
2576
|
+
this[offset + i] = value & 0xFF;
|
|
2577
|
+
while (--i >= 0 && (mul *= 0x100)) {
|
|
2578
|
+
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
2579
|
+
sub = 1;
|
|
2580
|
+
}
|
|
2581
|
+
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
|
|
2582
|
+
}
|
|
2583
|
+
|
|
2584
|
+
return offset + byteLength
|
|
2585
|
+
};
|
|
2586
|
+
|
|
2587
|
+
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
|
|
2588
|
+
value = +value;
|
|
2589
|
+
offset = offset >>> 0;
|
|
2590
|
+
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
|
|
2591
|
+
if (value < 0) value = 0xff + value + 1;
|
|
2592
|
+
this[offset] = (value & 0xff);
|
|
2593
|
+
return offset + 1
|
|
2594
|
+
};
|
|
2595
|
+
|
|
2596
|
+
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
|
|
2597
|
+
value = +value;
|
|
2598
|
+
offset = offset >>> 0;
|
|
2599
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
|
|
2600
|
+
this[offset] = (value & 0xff);
|
|
2601
|
+
this[offset + 1] = (value >>> 8);
|
|
2602
|
+
return offset + 2
|
|
2603
|
+
};
|
|
2604
|
+
|
|
2605
|
+
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
|
|
2606
|
+
value = +value;
|
|
2607
|
+
offset = offset >>> 0;
|
|
2608
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
|
|
2609
|
+
this[offset] = (value >>> 8);
|
|
2610
|
+
this[offset + 1] = (value & 0xff);
|
|
2611
|
+
return offset + 2
|
|
2612
|
+
};
|
|
2613
|
+
|
|
2614
|
+
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
|
|
2615
|
+
value = +value;
|
|
2616
|
+
offset = offset >>> 0;
|
|
2617
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
|
|
2618
|
+
this[offset] = (value & 0xff);
|
|
2619
|
+
this[offset + 1] = (value >>> 8);
|
|
2620
|
+
this[offset + 2] = (value >>> 16);
|
|
2621
|
+
this[offset + 3] = (value >>> 24);
|
|
2622
|
+
return offset + 4
|
|
2623
|
+
};
|
|
2624
|
+
|
|
2625
|
+
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
|
|
2626
|
+
value = +value;
|
|
2627
|
+
offset = offset >>> 0;
|
|
2628
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
|
|
2629
|
+
if (value < 0) value = 0xffffffff + value + 1;
|
|
2630
|
+
this[offset] = (value >>> 24);
|
|
2631
|
+
this[offset + 1] = (value >>> 16);
|
|
2632
|
+
this[offset + 2] = (value >>> 8);
|
|
2633
|
+
this[offset + 3] = (value & 0xff);
|
|
2634
|
+
return offset + 4
|
|
2635
|
+
};
|
|
2636
|
+
|
|
2637
|
+
Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) {
|
|
2638
|
+
return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
|
|
2639
|
+
});
|
|
2640
|
+
|
|
2641
|
+
Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) {
|
|
2642
|
+
return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
|
|
2643
|
+
});
|
|
2644
|
+
|
|
2645
|
+
function checkIEEE754 (buf, value, offset, ext, max, min) {
|
|
2646
|
+
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
2647
|
+
if (offset < 0) throw new RangeError('Index out of range')
|
|
2648
|
+
}
|
|
2649
|
+
|
|
2650
|
+
function writeFloat (buf, value, offset, littleEndian, noAssert) {
|
|
2651
|
+
value = +value;
|
|
2652
|
+
offset = offset >>> 0;
|
|
2653
|
+
if (!noAssert) {
|
|
2654
|
+
checkIEEE754(buf, value, offset, 4);
|
|
2655
|
+
}
|
|
2656
|
+
ieee754$1.write(buf, value, offset, littleEndian, 23, 4);
|
|
2657
|
+
return offset + 4
|
|
2658
|
+
}
|
|
2659
|
+
|
|
2660
|
+
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
|
|
2661
|
+
return writeFloat(this, value, offset, true, noAssert)
|
|
2662
|
+
};
|
|
2663
|
+
|
|
2664
|
+
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
|
|
2665
|
+
return writeFloat(this, value, offset, false, noAssert)
|
|
2666
|
+
};
|
|
2667
|
+
|
|
2668
|
+
function writeDouble (buf, value, offset, littleEndian, noAssert) {
|
|
2669
|
+
value = +value;
|
|
2670
|
+
offset = offset >>> 0;
|
|
2671
|
+
if (!noAssert) {
|
|
2672
|
+
checkIEEE754(buf, value, offset, 8);
|
|
2673
|
+
}
|
|
2674
|
+
ieee754$1.write(buf, value, offset, littleEndian, 52, 8);
|
|
2675
|
+
return offset + 8
|
|
2676
|
+
}
|
|
2677
|
+
|
|
2678
|
+
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
|
|
2679
|
+
return writeDouble(this, value, offset, true, noAssert)
|
|
2680
|
+
};
|
|
2681
|
+
|
|
2682
|
+
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
|
|
2683
|
+
return writeDouble(this, value, offset, false, noAssert)
|
|
2684
|
+
};
|
|
2685
|
+
|
|
2686
|
+
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
|
|
2687
|
+
Buffer.prototype.copy = function copy (target, targetStart, start, end) {
|
|
2688
|
+
if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
|
|
2689
|
+
if (!start) start = 0;
|
|
2690
|
+
if (!end && end !== 0) end = this.length;
|
|
2691
|
+
if (targetStart >= target.length) targetStart = target.length;
|
|
2692
|
+
if (!targetStart) targetStart = 0;
|
|
2693
|
+
if (end > 0 && end < start) end = start;
|
|
2694
|
+
|
|
2695
|
+
// Copy 0 bytes; we're done
|
|
2696
|
+
if (end === start) return 0
|
|
2697
|
+
if (target.length === 0 || this.length === 0) return 0
|
|
2698
|
+
|
|
2699
|
+
// Fatal error conditions
|
|
2700
|
+
if (targetStart < 0) {
|
|
2701
|
+
throw new RangeError('targetStart out of bounds')
|
|
2702
|
+
}
|
|
2703
|
+
if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
|
|
2704
|
+
if (end < 0) throw new RangeError('sourceEnd out of bounds')
|
|
2705
|
+
|
|
2706
|
+
// Are we oob?
|
|
2707
|
+
if (end > this.length) end = this.length;
|
|
2708
|
+
if (target.length - targetStart < end - start) {
|
|
2709
|
+
end = target.length - targetStart + start;
|
|
2710
|
+
}
|
|
2711
|
+
|
|
2712
|
+
const len = end - start;
|
|
2713
|
+
|
|
2714
|
+
if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
|
|
2715
|
+
// Use built-in when available, missing from IE11
|
|
2716
|
+
this.copyWithin(targetStart, start, end);
|
|
2717
|
+
} else {
|
|
2718
|
+
Uint8Array.prototype.set.call(
|
|
2719
|
+
target,
|
|
2720
|
+
this.subarray(start, end),
|
|
2721
|
+
targetStart
|
|
2722
|
+
);
|
|
2723
|
+
}
|
|
2724
|
+
|
|
2725
|
+
return len
|
|
2726
|
+
};
|
|
2727
|
+
|
|
2728
|
+
// Usage:
|
|
2729
|
+
// buffer.fill(number[, offset[, end]])
|
|
2730
|
+
// buffer.fill(buffer[, offset[, end]])
|
|
2731
|
+
// buffer.fill(string[, offset[, end]][, encoding])
|
|
2732
|
+
Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
|
2733
|
+
// Handle string cases:
|
|
2734
|
+
if (typeof val === 'string') {
|
|
2735
|
+
if (typeof start === 'string') {
|
|
2736
|
+
encoding = start;
|
|
2737
|
+
start = 0;
|
|
2738
|
+
end = this.length;
|
|
2739
|
+
} else if (typeof end === 'string') {
|
|
2740
|
+
encoding = end;
|
|
2741
|
+
end = this.length;
|
|
2742
|
+
}
|
|
2743
|
+
if (encoding !== undefined && typeof encoding !== 'string') {
|
|
2744
|
+
throw new TypeError('encoding must be a string')
|
|
2745
|
+
}
|
|
2746
|
+
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
|
2747
|
+
throw new TypeError('Unknown encoding: ' + encoding)
|
|
2748
|
+
}
|
|
2749
|
+
if (val.length === 1) {
|
|
2750
|
+
const code = val.charCodeAt(0);
|
|
2751
|
+
if ((encoding === 'utf8' && code < 128) ||
|
|
2752
|
+
encoding === 'latin1') {
|
|
2753
|
+
// Fast path: If `val` fits into a single byte, use that numeric value.
|
|
2754
|
+
val = code;
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
} else if (typeof val === 'number') {
|
|
2758
|
+
val = val & 255;
|
|
2759
|
+
} else if (typeof val === 'boolean') {
|
|
2760
|
+
val = Number(val);
|
|
2761
|
+
}
|
|
2762
|
+
|
|
2763
|
+
// Invalid ranges are not set to a default, so can range check early.
|
|
2764
|
+
if (start < 0 || this.length < start || this.length < end) {
|
|
2765
|
+
throw new RangeError('Out of range index')
|
|
2766
|
+
}
|
|
2767
|
+
|
|
2768
|
+
if (end <= start) {
|
|
2769
|
+
return this
|
|
2770
|
+
}
|
|
2771
|
+
|
|
2772
|
+
start = start >>> 0;
|
|
2773
|
+
end = end === undefined ? this.length : end >>> 0;
|
|
2774
|
+
|
|
2775
|
+
if (!val) val = 0;
|
|
2776
|
+
|
|
2777
|
+
let i;
|
|
2778
|
+
if (typeof val === 'number') {
|
|
2779
|
+
for (i = start; i < end; ++i) {
|
|
2780
|
+
this[i] = val;
|
|
2781
|
+
}
|
|
2782
|
+
} else {
|
|
2783
|
+
const bytes = Buffer.isBuffer(val)
|
|
2784
|
+
? val
|
|
2785
|
+
: Buffer.from(val, encoding);
|
|
2786
|
+
const len = bytes.length;
|
|
2787
|
+
if (len === 0) {
|
|
2788
|
+
throw new TypeError('The value "' + val +
|
|
2789
|
+
'" is invalid for argument "value"')
|
|
2790
|
+
}
|
|
2791
|
+
for (i = 0; i < end - start; ++i) {
|
|
2792
|
+
this[i + start] = bytes[i % len];
|
|
2793
|
+
}
|
|
2794
|
+
}
|
|
2795
|
+
|
|
2796
|
+
return this
|
|
2797
|
+
};
|
|
2798
|
+
|
|
2799
|
+
// CUSTOM ERRORS
|
|
2800
|
+
// =============
|
|
2801
|
+
|
|
2802
|
+
// Simplified versions from Node, changed for Buffer-only usage
|
|
2803
|
+
const errors = {};
|
|
2804
|
+
function E (sym, getMessage, Base) {
|
|
2805
|
+
errors[sym] = class NodeError extends Base {
|
|
2806
|
+
constructor () {
|
|
2807
|
+
super();
|
|
2808
|
+
|
|
2809
|
+
Object.defineProperty(this, 'message', {
|
|
2810
|
+
value: getMessage.apply(this, arguments),
|
|
2811
|
+
writable: true,
|
|
2812
|
+
configurable: true
|
|
2813
|
+
});
|
|
2814
|
+
|
|
2815
|
+
// Add the error code to the name to include it in the stack trace.
|
|
2816
|
+
this.name = `${this.name} [${sym}]`;
|
|
2817
|
+
// Access the stack to generate the error message including the error code
|
|
2818
|
+
// from the name.
|
|
2819
|
+
this.stack; // eslint-disable-line no-unused-expressions
|
|
2820
|
+
// Reset the name to the actual name.
|
|
2821
|
+
delete this.name;
|
|
2822
|
+
}
|
|
2823
|
+
|
|
2824
|
+
get code () {
|
|
2825
|
+
return sym
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
set code (value) {
|
|
2829
|
+
Object.defineProperty(this, 'code', {
|
|
2830
|
+
configurable: true,
|
|
2831
|
+
enumerable: true,
|
|
2832
|
+
value,
|
|
2833
|
+
writable: true
|
|
2834
|
+
});
|
|
2835
|
+
}
|
|
2836
|
+
|
|
2837
|
+
toString () {
|
|
2838
|
+
return `${this.name} [${sym}]: ${this.message}`
|
|
2839
|
+
}
|
|
2840
|
+
};
|
|
2841
|
+
}
|
|
2842
|
+
|
|
2843
|
+
E('ERR_BUFFER_OUT_OF_BOUNDS',
|
|
2844
|
+
function (name) {
|
|
2845
|
+
if (name) {
|
|
2846
|
+
return `${name} is outside of buffer bounds`
|
|
2847
|
+
}
|
|
2848
|
+
|
|
2849
|
+
return 'Attempt to access memory outside buffer bounds'
|
|
2850
|
+
}, RangeError);
|
|
2851
|
+
E('ERR_INVALID_ARG_TYPE',
|
|
2852
|
+
function (name, actual) {
|
|
2853
|
+
return `The "${name}" argument must be of type number. Received type ${typeof actual}`
|
|
2854
|
+
}, TypeError);
|
|
2855
|
+
E('ERR_OUT_OF_RANGE',
|
|
2856
|
+
function (str, range, input) {
|
|
2857
|
+
let msg = `The value of "${str}" is out of range.`;
|
|
2858
|
+
let received = input;
|
|
2859
|
+
if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
|
|
2860
|
+
received = addNumericalSeparator(String(input));
|
|
2861
|
+
} else if (typeof input === 'bigint') {
|
|
2862
|
+
received = String(input);
|
|
2863
|
+
if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
|
|
2864
|
+
received = addNumericalSeparator(received);
|
|
2865
|
+
}
|
|
2866
|
+
received += 'n';
|
|
2867
|
+
}
|
|
2868
|
+
msg += ` It must be ${range}. Received ${received}`;
|
|
2869
|
+
return msg
|
|
2870
|
+
}, RangeError);
|
|
2871
|
+
|
|
2872
|
+
function addNumericalSeparator (val) {
|
|
2873
|
+
let res = '';
|
|
2874
|
+
let i = val.length;
|
|
2875
|
+
const start = val[0] === '-' ? 1 : 0;
|
|
2876
|
+
for (; i >= start + 4; i -= 3) {
|
|
2877
|
+
res = `_${val.slice(i - 3, i)}${res}`;
|
|
2878
|
+
}
|
|
2879
|
+
return `${val.slice(0, i)}${res}`
|
|
2880
|
+
}
|
|
2881
|
+
|
|
2882
|
+
// CHECK FUNCTIONS
|
|
2883
|
+
// ===============
|
|
2884
|
+
|
|
2885
|
+
function checkBounds (buf, offset, byteLength) {
|
|
2886
|
+
validateNumber(offset, 'offset');
|
|
2887
|
+
if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
|
|
2888
|
+
boundsError(offset, buf.length - (byteLength + 1));
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2891
|
+
|
|
2892
|
+
function checkIntBI (value, min, max, buf, offset, byteLength) {
|
|
2893
|
+
if (value > max || value < min) {
|
|
2894
|
+
const n = typeof min === 'bigint' ? 'n' : '';
|
|
2895
|
+
let range;
|
|
2896
|
+
if (byteLength > 3) {
|
|
2897
|
+
if (min === 0 || min === BigInt(0)) {
|
|
2898
|
+
range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;
|
|
2899
|
+
} else {
|
|
2900
|
+
range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
|
|
2901
|
+
`${(byteLength + 1) * 8 - 1}${n}`;
|
|
2902
|
+
}
|
|
2903
|
+
} else {
|
|
2904
|
+
range = `>= ${min}${n} and <= ${max}${n}`;
|
|
2905
|
+
}
|
|
2906
|
+
throw new errors.ERR_OUT_OF_RANGE('value', range, value)
|
|
2907
|
+
}
|
|
2908
|
+
checkBounds(buf, offset, byteLength);
|
|
2909
|
+
}
|
|
2910
|
+
|
|
2911
|
+
function validateNumber (value, name) {
|
|
2912
|
+
if (typeof value !== 'number') {
|
|
2913
|
+
throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
|
|
2914
|
+
}
|
|
2915
|
+
}
|
|
2916
|
+
|
|
2917
|
+
function boundsError (value, length, type) {
|
|
2918
|
+
if (Math.floor(value) !== value) {
|
|
2919
|
+
validateNumber(value, type);
|
|
2920
|
+
throw new errors.ERR_OUT_OF_RANGE(type || 'offset', 'an integer', value)
|
|
2921
|
+
}
|
|
2922
|
+
|
|
2923
|
+
if (length < 0) {
|
|
2924
|
+
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
|
|
2925
|
+
}
|
|
2926
|
+
|
|
2927
|
+
throw new errors.ERR_OUT_OF_RANGE(type || 'offset',
|
|
2928
|
+
`>= ${type ? 1 : 0} and <= ${length}`,
|
|
2929
|
+
value)
|
|
2930
|
+
}
|
|
2931
|
+
|
|
2932
|
+
// HELPER FUNCTIONS
|
|
2933
|
+
// ================
|
|
2934
|
+
|
|
2935
|
+
const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
|
2936
|
+
|
|
2937
|
+
function base64clean (str) {
|
|
2938
|
+
// Node takes equal signs as end of the Base64 encoding
|
|
2939
|
+
str = str.split('=')[0];
|
|
2940
|
+
// Node strips out invalid characters like \n and \t from the string, base64-js does not
|
|
2941
|
+
str = str.trim().replace(INVALID_BASE64_RE, '');
|
|
2942
|
+
// Node converts strings with length < 2 to ''
|
|
2943
|
+
if (str.length < 2) return ''
|
|
2944
|
+
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
|
|
2945
|
+
while (str.length % 4 !== 0) {
|
|
2946
|
+
str = str + '=';
|
|
2947
|
+
}
|
|
2948
|
+
return str
|
|
2949
|
+
}
|
|
2950
|
+
|
|
2951
|
+
function utf8ToBytes (string, units) {
|
|
2952
|
+
units = units || Infinity;
|
|
2953
|
+
let codePoint;
|
|
2954
|
+
const length = string.length;
|
|
2955
|
+
let leadSurrogate = null;
|
|
2956
|
+
const bytes = [];
|
|
2957
|
+
|
|
2958
|
+
for (let i = 0; i < length; ++i) {
|
|
2959
|
+
codePoint = string.charCodeAt(i);
|
|
2960
|
+
|
|
2961
|
+
// is surrogate component
|
|
2962
|
+
if (codePoint > 0xD7FF && codePoint < 0xE000) {
|
|
2963
|
+
// last char was a lead
|
|
2964
|
+
if (!leadSurrogate) {
|
|
2965
|
+
// no lead yet
|
|
2966
|
+
if (codePoint > 0xDBFF) {
|
|
2967
|
+
// unexpected trail
|
|
2968
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
2969
|
+
continue
|
|
2970
|
+
} else if (i + 1 === length) {
|
|
2971
|
+
// unpaired lead
|
|
2972
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
2973
|
+
continue
|
|
2974
|
+
}
|
|
2975
|
+
|
|
2976
|
+
// valid lead
|
|
2977
|
+
leadSurrogate = codePoint;
|
|
2978
|
+
|
|
2979
|
+
continue
|
|
2980
|
+
}
|
|
2981
|
+
|
|
2982
|
+
// 2 leads in a row
|
|
2983
|
+
if (codePoint < 0xDC00) {
|
|
2984
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
2985
|
+
leadSurrogate = codePoint;
|
|
2986
|
+
continue
|
|
2987
|
+
}
|
|
2988
|
+
|
|
2989
|
+
// valid surrogate pair
|
|
2990
|
+
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
|
|
2991
|
+
} else if (leadSurrogate) {
|
|
2992
|
+
// valid bmp char, but last char was a lead
|
|
2993
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
2994
|
+
}
|
|
2995
|
+
|
|
2996
|
+
leadSurrogate = null;
|
|
2997
|
+
|
|
2998
|
+
// encode utf8
|
|
2999
|
+
if (codePoint < 0x80) {
|
|
3000
|
+
if ((units -= 1) < 0) break
|
|
3001
|
+
bytes.push(codePoint);
|
|
3002
|
+
} else if (codePoint < 0x800) {
|
|
3003
|
+
if ((units -= 2) < 0) break
|
|
3004
|
+
bytes.push(
|
|
3005
|
+
codePoint >> 0x6 | 0xC0,
|
|
3006
|
+
codePoint & 0x3F | 0x80
|
|
3007
|
+
);
|
|
3008
|
+
} else if (codePoint < 0x10000) {
|
|
3009
|
+
if ((units -= 3) < 0) break
|
|
3010
|
+
bytes.push(
|
|
3011
|
+
codePoint >> 0xC | 0xE0,
|
|
3012
|
+
codePoint >> 0x6 & 0x3F | 0x80,
|
|
3013
|
+
codePoint & 0x3F | 0x80
|
|
3014
|
+
);
|
|
3015
|
+
} else if (codePoint < 0x110000) {
|
|
3016
|
+
if ((units -= 4) < 0) break
|
|
3017
|
+
bytes.push(
|
|
3018
|
+
codePoint >> 0x12 | 0xF0,
|
|
3019
|
+
codePoint >> 0xC & 0x3F | 0x80,
|
|
3020
|
+
codePoint >> 0x6 & 0x3F | 0x80,
|
|
3021
|
+
codePoint & 0x3F | 0x80
|
|
3022
|
+
);
|
|
3023
|
+
} else {
|
|
3024
|
+
throw new Error('Invalid code point')
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
|
|
3028
|
+
return bytes
|
|
3029
|
+
}
|
|
3030
|
+
|
|
3031
|
+
function asciiToBytes (str) {
|
|
3032
|
+
const byteArray = [];
|
|
3033
|
+
for (let i = 0; i < str.length; ++i) {
|
|
3034
|
+
// Node's code seems to be doing this and not & 0x7F..
|
|
3035
|
+
byteArray.push(str.charCodeAt(i) & 0xFF);
|
|
3036
|
+
}
|
|
3037
|
+
return byteArray
|
|
3038
|
+
}
|
|
3039
|
+
|
|
3040
|
+
function utf16leToBytes (str, units) {
|
|
3041
|
+
let c, hi, lo;
|
|
3042
|
+
const byteArray = [];
|
|
3043
|
+
for (let i = 0; i < str.length; ++i) {
|
|
3044
|
+
if ((units -= 2) < 0) break
|
|
3045
|
+
|
|
3046
|
+
c = str.charCodeAt(i);
|
|
3047
|
+
hi = c >> 8;
|
|
3048
|
+
lo = c % 256;
|
|
3049
|
+
byteArray.push(lo);
|
|
3050
|
+
byteArray.push(hi);
|
|
3051
|
+
}
|
|
3052
|
+
|
|
3053
|
+
return byteArray
|
|
3054
|
+
}
|
|
3055
|
+
|
|
3056
|
+
function base64ToBytes (str) {
|
|
3057
|
+
return base64.toByteArray(base64clean(str))
|
|
3058
|
+
}
|
|
3059
|
+
|
|
3060
|
+
function blitBuffer (src, dst, offset, length) {
|
|
3061
|
+
let i;
|
|
3062
|
+
for (i = 0; i < length; ++i) {
|
|
3063
|
+
if ((i + offset >= dst.length) || (i >= src.length)) break
|
|
3064
|
+
dst[i + offset] = src[i];
|
|
3065
|
+
}
|
|
3066
|
+
return i
|
|
3067
|
+
}
|
|
3068
|
+
|
|
3069
|
+
// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
|
|
3070
|
+
// the `instanceof` check but they should be treated as of that type.
|
|
3071
|
+
// See: https://github.com/feross/buffer/issues/166
|
|
3072
|
+
function isInstance (obj, type) {
|
|
3073
|
+
return obj instanceof type ||
|
|
3074
|
+
(obj != null && obj.constructor != null && obj.constructor.name != null &&
|
|
3075
|
+
obj.constructor.name === type.name)
|
|
3076
|
+
}
|
|
3077
|
+
function numberIsNaN (obj) {
|
|
3078
|
+
// For IE11 support
|
|
3079
|
+
return obj !== obj // eslint-disable-line no-self-compare
|
|
3080
|
+
}
|
|
953
3081
|
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
};
|
|
3082
|
+
// Create lookup table for `toString('hex')`
|
|
3083
|
+
// See: https://github.com/feross/buffer/issues/219
|
|
3084
|
+
const hexSliceLookupTable = (function () {
|
|
3085
|
+
const alphabet = '0123456789abcdef';
|
|
3086
|
+
const table = new Array(256);
|
|
3087
|
+
for (let i = 0; i < 16; ++i) {
|
|
3088
|
+
const i16 = i * 16;
|
|
3089
|
+
for (let j = 0; j < 16; ++j) {
|
|
3090
|
+
table[i16 + j] = alphabet[i] + alphabet[j];
|
|
3091
|
+
}
|
|
3092
|
+
}
|
|
3093
|
+
return table
|
|
3094
|
+
})();
|
|
967
3095
|
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
};
|
|
3096
|
+
// Return not function with Error if BigInt not supported
|
|
3097
|
+
function defineBigIntMethod (fn) {
|
|
3098
|
+
return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
|
|
3099
|
+
}
|
|
973
3100
|
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
};
|
|
3101
|
+
function BufferBigIntNotDefined () {
|
|
3102
|
+
throw new Error('BigInt not supported')
|
|
3103
|
+
}
|
|
3104
|
+
} (buffer));
|
|
979
3105
|
|
|
980
3106
|
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
981
3107
|
|
|
982
3108
|
(function (module, exports) {
|
|
983
3109
|
/* eslint-disable node/no-deprecated-api */
|
|
984
|
-
var buffer =
|
|
985
|
-
var Buffer = buffer.Buffer;
|
|
3110
|
+
var buffer$1 = buffer;
|
|
3111
|
+
var Buffer = buffer$1.Buffer;
|
|
986
3112
|
|
|
987
3113
|
// alternative to using Object.keys for old browsers
|
|
988
3114
|
function copyProps (src, dst) {
|
|
@@ -991,10 +3117,10 @@ var safeBuffer = {
|
|
|
991
3117
|
}
|
|
992
3118
|
}
|
|
993
3119
|
if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
|
|
994
|
-
module.exports = buffer;
|
|
3120
|
+
module.exports = buffer$1;
|
|
995
3121
|
} else {
|
|
996
3122
|
// Copy properties from require('buffer')
|
|
997
|
-
copyProps(buffer, exports);
|
|
3123
|
+
copyProps(buffer$1, exports);
|
|
998
3124
|
exports.Buffer = SafeBuffer;
|
|
999
3125
|
}
|
|
1000
3126
|
|
|
@@ -1042,7 +3168,7 @@ var safeBuffer = {
|
|
|
1042
3168
|
if (typeof size !== 'number') {
|
|
1043
3169
|
throw new TypeError('Argument must be a number')
|
|
1044
3170
|
}
|
|
1045
|
-
return buffer.SlowBuffer(size)
|
|
3171
|
+
return buffer$1.SlowBuffer(size)
|
|
1046
3172
|
};
|
|
1047
3173
|
} (safeBuffer, safeBufferExports));
|
|
1048
3174
|
|
|
@@ -1101,7 +3227,487 @@ var readableBrowser = {
|
|
|
1101
3227
|
set exports(v){ readableBrowserExports = v; },
|
|
1102
3228
|
};
|
|
1103
3229
|
|
|
1104
|
-
var
|
|
3230
|
+
var eventsExports = {};
|
|
3231
|
+
var events = {
|
|
3232
|
+
get exports(){ return eventsExports; },
|
|
3233
|
+
set exports(v){ eventsExports = v; },
|
|
3234
|
+
};
|
|
3235
|
+
|
|
3236
|
+
var R = typeof Reflect === 'object' ? Reflect : null;
|
|
3237
|
+
var ReflectApply = R && typeof R.apply === 'function'
|
|
3238
|
+
? R.apply
|
|
3239
|
+
: function ReflectApply(target, receiver, args) {
|
|
3240
|
+
return Function.prototype.apply.call(target, receiver, args);
|
|
3241
|
+
};
|
|
3242
|
+
|
|
3243
|
+
var ReflectOwnKeys;
|
|
3244
|
+
if (R && typeof R.ownKeys === 'function') {
|
|
3245
|
+
ReflectOwnKeys = R.ownKeys;
|
|
3246
|
+
} else if (Object.getOwnPropertySymbols) {
|
|
3247
|
+
ReflectOwnKeys = function ReflectOwnKeys(target) {
|
|
3248
|
+
return Object.getOwnPropertyNames(target)
|
|
3249
|
+
.concat(Object.getOwnPropertySymbols(target));
|
|
3250
|
+
};
|
|
3251
|
+
} else {
|
|
3252
|
+
ReflectOwnKeys = function ReflectOwnKeys(target) {
|
|
3253
|
+
return Object.getOwnPropertyNames(target);
|
|
3254
|
+
};
|
|
3255
|
+
}
|
|
3256
|
+
|
|
3257
|
+
function ProcessEmitWarning(warning) {
|
|
3258
|
+
if (console && console.warn) console.warn(warning);
|
|
3259
|
+
}
|
|
3260
|
+
|
|
3261
|
+
var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
|
|
3262
|
+
return value !== value;
|
|
3263
|
+
};
|
|
3264
|
+
|
|
3265
|
+
function EventEmitter() {
|
|
3266
|
+
EventEmitter.init.call(this);
|
|
3267
|
+
}
|
|
3268
|
+
events.exports = EventEmitter;
|
|
3269
|
+
eventsExports.once = once$2;
|
|
3270
|
+
|
|
3271
|
+
// Backwards-compat with node 0.10.x
|
|
3272
|
+
EventEmitter.EventEmitter = EventEmitter;
|
|
3273
|
+
|
|
3274
|
+
EventEmitter.prototype._events = undefined;
|
|
3275
|
+
EventEmitter.prototype._eventsCount = 0;
|
|
3276
|
+
EventEmitter.prototype._maxListeners = undefined;
|
|
3277
|
+
|
|
3278
|
+
// By default EventEmitters will print a warning if more than 10 listeners are
|
|
3279
|
+
// added to it. This is a useful default which helps finding memory leaks.
|
|
3280
|
+
var defaultMaxListeners = 10;
|
|
3281
|
+
|
|
3282
|
+
function checkListener(listener) {
|
|
3283
|
+
if (typeof listener !== 'function') {
|
|
3284
|
+
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
|
|
3288
|
+
Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
|
|
3289
|
+
enumerable: true,
|
|
3290
|
+
get: function() {
|
|
3291
|
+
return defaultMaxListeners;
|
|
3292
|
+
},
|
|
3293
|
+
set: function(arg) {
|
|
3294
|
+
if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
|
|
3295
|
+
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
|
|
3296
|
+
}
|
|
3297
|
+
defaultMaxListeners = arg;
|
|
3298
|
+
}
|
|
3299
|
+
});
|
|
3300
|
+
|
|
3301
|
+
EventEmitter.init = function() {
|
|
3302
|
+
|
|
3303
|
+
if (this._events === undefined ||
|
|
3304
|
+
this._events === Object.getPrototypeOf(this)._events) {
|
|
3305
|
+
this._events = Object.create(null);
|
|
3306
|
+
this._eventsCount = 0;
|
|
3307
|
+
}
|
|
3308
|
+
|
|
3309
|
+
this._maxListeners = this._maxListeners || undefined;
|
|
3310
|
+
};
|
|
3311
|
+
|
|
3312
|
+
// Obviously not all Emitters should be limited to 10. This function allows
|
|
3313
|
+
// that to be increased. Set to zero for unlimited.
|
|
3314
|
+
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
|
|
3315
|
+
if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
|
|
3316
|
+
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
|
|
3317
|
+
}
|
|
3318
|
+
this._maxListeners = n;
|
|
3319
|
+
return this;
|
|
3320
|
+
};
|
|
3321
|
+
|
|
3322
|
+
function _getMaxListeners(that) {
|
|
3323
|
+
if (that._maxListeners === undefined)
|
|
3324
|
+
return EventEmitter.defaultMaxListeners;
|
|
3325
|
+
return that._maxListeners;
|
|
3326
|
+
}
|
|
3327
|
+
|
|
3328
|
+
EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
|
|
3329
|
+
return _getMaxListeners(this);
|
|
3330
|
+
};
|
|
3331
|
+
|
|
3332
|
+
EventEmitter.prototype.emit = function emit(type) {
|
|
3333
|
+
var args = [];
|
|
3334
|
+
for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
|
|
3335
|
+
var doError = (type === 'error');
|
|
3336
|
+
|
|
3337
|
+
var events = this._events;
|
|
3338
|
+
if (events !== undefined)
|
|
3339
|
+
doError = (doError && events.error === undefined);
|
|
3340
|
+
else if (!doError)
|
|
3341
|
+
return false;
|
|
3342
|
+
|
|
3343
|
+
// If there is no 'error' event listener then throw.
|
|
3344
|
+
if (doError) {
|
|
3345
|
+
var er;
|
|
3346
|
+
if (args.length > 0)
|
|
3347
|
+
er = args[0];
|
|
3348
|
+
if (er instanceof Error) {
|
|
3349
|
+
// Note: The comments on the `throw` lines are intentional, they show
|
|
3350
|
+
// up in Node's output if this results in an unhandled exception.
|
|
3351
|
+
throw er; // Unhandled 'error' event
|
|
3352
|
+
}
|
|
3353
|
+
// At least give some kind of context to the user
|
|
3354
|
+
var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
|
|
3355
|
+
err.context = er;
|
|
3356
|
+
throw err; // Unhandled 'error' event
|
|
3357
|
+
}
|
|
3358
|
+
|
|
3359
|
+
var handler = events[type];
|
|
3360
|
+
|
|
3361
|
+
if (handler === undefined)
|
|
3362
|
+
return false;
|
|
3363
|
+
|
|
3364
|
+
if (typeof handler === 'function') {
|
|
3365
|
+
ReflectApply(handler, this, args);
|
|
3366
|
+
} else {
|
|
3367
|
+
var len = handler.length;
|
|
3368
|
+
var listeners = arrayClone(handler, len);
|
|
3369
|
+
for (var i = 0; i < len; ++i)
|
|
3370
|
+
ReflectApply(listeners[i], this, args);
|
|
3371
|
+
}
|
|
3372
|
+
|
|
3373
|
+
return true;
|
|
3374
|
+
};
|
|
3375
|
+
|
|
3376
|
+
function _addListener(target, type, listener, prepend) {
|
|
3377
|
+
var m;
|
|
3378
|
+
var events;
|
|
3379
|
+
var existing;
|
|
3380
|
+
|
|
3381
|
+
checkListener(listener);
|
|
3382
|
+
|
|
3383
|
+
events = target._events;
|
|
3384
|
+
if (events === undefined) {
|
|
3385
|
+
events = target._events = Object.create(null);
|
|
3386
|
+
target._eventsCount = 0;
|
|
3387
|
+
} else {
|
|
3388
|
+
// To avoid recursion in the case that type === "newListener"! Before
|
|
3389
|
+
// adding it to the listeners, first emit "newListener".
|
|
3390
|
+
if (events.newListener !== undefined) {
|
|
3391
|
+
target.emit('newListener', type,
|
|
3392
|
+
listener.listener ? listener.listener : listener);
|
|
3393
|
+
|
|
3394
|
+
// Re-assign `events` because a newListener handler could have caused the
|
|
3395
|
+
// this._events to be assigned to a new object
|
|
3396
|
+
events = target._events;
|
|
3397
|
+
}
|
|
3398
|
+
existing = events[type];
|
|
3399
|
+
}
|
|
3400
|
+
|
|
3401
|
+
if (existing === undefined) {
|
|
3402
|
+
// Optimize the case of one listener. Don't need the extra array object.
|
|
3403
|
+
existing = events[type] = listener;
|
|
3404
|
+
++target._eventsCount;
|
|
3405
|
+
} else {
|
|
3406
|
+
if (typeof existing === 'function') {
|
|
3407
|
+
// Adding the second element, need to change to array.
|
|
3408
|
+
existing = events[type] =
|
|
3409
|
+
prepend ? [listener, existing] : [existing, listener];
|
|
3410
|
+
// If we've already got an array, just append.
|
|
3411
|
+
} else if (prepend) {
|
|
3412
|
+
existing.unshift(listener);
|
|
3413
|
+
} else {
|
|
3414
|
+
existing.push(listener);
|
|
3415
|
+
}
|
|
3416
|
+
|
|
3417
|
+
// Check for listener leak
|
|
3418
|
+
m = _getMaxListeners(target);
|
|
3419
|
+
if (m > 0 && existing.length > m && !existing.warned) {
|
|
3420
|
+
existing.warned = true;
|
|
3421
|
+
// No error code for this since it is a Warning
|
|
3422
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
3423
|
+
var w = new Error('Possible EventEmitter memory leak detected. ' +
|
|
3424
|
+
existing.length + ' ' + String(type) + ' listeners ' +
|
|
3425
|
+
'added. Use emitter.setMaxListeners() to ' +
|
|
3426
|
+
'increase limit');
|
|
3427
|
+
w.name = 'MaxListenersExceededWarning';
|
|
3428
|
+
w.emitter = target;
|
|
3429
|
+
w.type = type;
|
|
3430
|
+
w.count = existing.length;
|
|
3431
|
+
ProcessEmitWarning(w);
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3434
|
+
|
|
3435
|
+
return target;
|
|
3436
|
+
}
|
|
3437
|
+
|
|
3438
|
+
EventEmitter.prototype.addListener = function addListener(type, listener) {
|
|
3439
|
+
return _addListener(this, type, listener, false);
|
|
3440
|
+
};
|
|
3441
|
+
|
|
3442
|
+
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
|
3443
|
+
|
|
3444
|
+
EventEmitter.prototype.prependListener =
|
|
3445
|
+
function prependListener(type, listener) {
|
|
3446
|
+
return _addListener(this, type, listener, true);
|
|
3447
|
+
};
|
|
3448
|
+
|
|
3449
|
+
function onceWrapper() {
|
|
3450
|
+
if (!this.fired) {
|
|
3451
|
+
this.target.removeListener(this.type, this.wrapFn);
|
|
3452
|
+
this.fired = true;
|
|
3453
|
+
if (arguments.length === 0)
|
|
3454
|
+
return this.listener.call(this.target);
|
|
3455
|
+
return this.listener.apply(this.target, arguments);
|
|
3456
|
+
}
|
|
3457
|
+
}
|
|
3458
|
+
|
|
3459
|
+
function _onceWrap(target, type, listener) {
|
|
3460
|
+
var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
|
|
3461
|
+
var wrapped = onceWrapper.bind(state);
|
|
3462
|
+
wrapped.listener = listener;
|
|
3463
|
+
state.wrapFn = wrapped;
|
|
3464
|
+
return wrapped;
|
|
3465
|
+
}
|
|
3466
|
+
|
|
3467
|
+
EventEmitter.prototype.once = function once(type, listener) {
|
|
3468
|
+
checkListener(listener);
|
|
3469
|
+
this.on(type, _onceWrap(this, type, listener));
|
|
3470
|
+
return this;
|
|
3471
|
+
};
|
|
3472
|
+
|
|
3473
|
+
EventEmitter.prototype.prependOnceListener =
|
|
3474
|
+
function prependOnceListener(type, listener) {
|
|
3475
|
+
checkListener(listener);
|
|
3476
|
+
this.prependListener(type, _onceWrap(this, type, listener));
|
|
3477
|
+
return this;
|
|
3478
|
+
};
|
|
3479
|
+
|
|
3480
|
+
// Emits a 'removeListener' event if and only if the listener was removed.
|
|
3481
|
+
EventEmitter.prototype.removeListener =
|
|
3482
|
+
function removeListener(type, listener) {
|
|
3483
|
+
var list, events, position, i, originalListener;
|
|
3484
|
+
|
|
3485
|
+
checkListener(listener);
|
|
3486
|
+
|
|
3487
|
+
events = this._events;
|
|
3488
|
+
if (events === undefined)
|
|
3489
|
+
return this;
|
|
3490
|
+
|
|
3491
|
+
list = events[type];
|
|
3492
|
+
if (list === undefined)
|
|
3493
|
+
return this;
|
|
3494
|
+
|
|
3495
|
+
if (list === listener || list.listener === listener) {
|
|
3496
|
+
if (--this._eventsCount === 0)
|
|
3497
|
+
this._events = Object.create(null);
|
|
3498
|
+
else {
|
|
3499
|
+
delete events[type];
|
|
3500
|
+
if (events.removeListener)
|
|
3501
|
+
this.emit('removeListener', type, list.listener || listener);
|
|
3502
|
+
}
|
|
3503
|
+
} else if (typeof list !== 'function') {
|
|
3504
|
+
position = -1;
|
|
3505
|
+
|
|
3506
|
+
for (i = list.length - 1; i >= 0; i--) {
|
|
3507
|
+
if (list[i] === listener || list[i].listener === listener) {
|
|
3508
|
+
originalListener = list[i].listener;
|
|
3509
|
+
position = i;
|
|
3510
|
+
break;
|
|
3511
|
+
}
|
|
3512
|
+
}
|
|
3513
|
+
|
|
3514
|
+
if (position < 0)
|
|
3515
|
+
return this;
|
|
3516
|
+
|
|
3517
|
+
if (position === 0)
|
|
3518
|
+
list.shift();
|
|
3519
|
+
else {
|
|
3520
|
+
spliceOne(list, position);
|
|
3521
|
+
}
|
|
3522
|
+
|
|
3523
|
+
if (list.length === 1)
|
|
3524
|
+
events[type] = list[0];
|
|
3525
|
+
|
|
3526
|
+
if (events.removeListener !== undefined)
|
|
3527
|
+
this.emit('removeListener', type, originalListener || listener);
|
|
3528
|
+
}
|
|
3529
|
+
|
|
3530
|
+
return this;
|
|
3531
|
+
};
|
|
3532
|
+
|
|
3533
|
+
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
3534
|
+
|
|
3535
|
+
EventEmitter.prototype.removeAllListeners =
|
|
3536
|
+
function removeAllListeners(type) {
|
|
3537
|
+
var listeners, events, i;
|
|
3538
|
+
|
|
3539
|
+
events = this._events;
|
|
3540
|
+
if (events === undefined)
|
|
3541
|
+
return this;
|
|
3542
|
+
|
|
3543
|
+
// not listening for removeListener, no need to emit
|
|
3544
|
+
if (events.removeListener === undefined) {
|
|
3545
|
+
if (arguments.length === 0) {
|
|
3546
|
+
this._events = Object.create(null);
|
|
3547
|
+
this._eventsCount = 0;
|
|
3548
|
+
} else if (events[type] !== undefined) {
|
|
3549
|
+
if (--this._eventsCount === 0)
|
|
3550
|
+
this._events = Object.create(null);
|
|
3551
|
+
else
|
|
3552
|
+
delete events[type];
|
|
3553
|
+
}
|
|
3554
|
+
return this;
|
|
3555
|
+
}
|
|
3556
|
+
|
|
3557
|
+
// emit removeListener for all listeners on all events
|
|
3558
|
+
if (arguments.length === 0) {
|
|
3559
|
+
var keys = Object.keys(events);
|
|
3560
|
+
var key;
|
|
3561
|
+
for (i = 0; i < keys.length; ++i) {
|
|
3562
|
+
key = keys[i];
|
|
3563
|
+
if (key === 'removeListener') continue;
|
|
3564
|
+
this.removeAllListeners(key);
|
|
3565
|
+
}
|
|
3566
|
+
this.removeAllListeners('removeListener');
|
|
3567
|
+
this._events = Object.create(null);
|
|
3568
|
+
this._eventsCount = 0;
|
|
3569
|
+
return this;
|
|
3570
|
+
}
|
|
3571
|
+
|
|
3572
|
+
listeners = events[type];
|
|
3573
|
+
|
|
3574
|
+
if (typeof listeners === 'function') {
|
|
3575
|
+
this.removeListener(type, listeners);
|
|
3576
|
+
} else if (listeners !== undefined) {
|
|
3577
|
+
// LIFO order
|
|
3578
|
+
for (i = listeners.length - 1; i >= 0; i--) {
|
|
3579
|
+
this.removeListener(type, listeners[i]);
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3582
|
+
|
|
3583
|
+
return this;
|
|
3584
|
+
};
|
|
3585
|
+
|
|
3586
|
+
function _listeners(target, type, unwrap) {
|
|
3587
|
+
var events = target._events;
|
|
3588
|
+
|
|
3589
|
+
if (events === undefined)
|
|
3590
|
+
return [];
|
|
3591
|
+
|
|
3592
|
+
var evlistener = events[type];
|
|
3593
|
+
if (evlistener === undefined)
|
|
3594
|
+
return [];
|
|
3595
|
+
|
|
3596
|
+
if (typeof evlistener === 'function')
|
|
3597
|
+
return unwrap ? [evlistener.listener || evlistener] : [evlistener];
|
|
3598
|
+
|
|
3599
|
+
return unwrap ?
|
|
3600
|
+
unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
|
|
3601
|
+
}
|
|
3602
|
+
|
|
3603
|
+
EventEmitter.prototype.listeners = function listeners(type) {
|
|
3604
|
+
return _listeners(this, type, true);
|
|
3605
|
+
};
|
|
3606
|
+
|
|
3607
|
+
EventEmitter.prototype.rawListeners = function rawListeners(type) {
|
|
3608
|
+
return _listeners(this, type, false);
|
|
3609
|
+
};
|
|
3610
|
+
|
|
3611
|
+
EventEmitter.listenerCount = function(emitter, type) {
|
|
3612
|
+
if (typeof emitter.listenerCount === 'function') {
|
|
3613
|
+
return emitter.listenerCount(type);
|
|
3614
|
+
} else {
|
|
3615
|
+
return listenerCount.call(emitter, type);
|
|
3616
|
+
}
|
|
3617
|
+
};
|
|
3618
|
+
|
|
3619
|
+
EventEmitter.prototype.listenerCount = listenerCount;
|
|
3620
|
+
function listenerCount(type) {
|
|
3621
|
+
var events = this._events;
|
|
3622
|
+
|
|
3623
|
+
if (events !== undefined) {
|
|
3624
|
+
var evlistener = events[type];
|
|
3625
|
+
|
|
3626
|
+
if (typeof evlistener === 'function') {
|
|
3627
|
+
return 1;
|
|
3628
|
+
} else if (evlistener !== undefined) {
|
|
3629
|
+
return evlistener.length;
|
|
3630
|
+
}
|
|
3631
|
+
}
|
|
3632
|
+
|
|
3633
|
+
return 0;
|
|
3634
|
+
}
|
|
3635
|
+
|
|
3636
|
+
EventEmitter.prototype.eventNames = function eventNames() {
|
|
3637
|
+
return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
|
|
3638
|
+
};
|
|
3639
|
+
|
|
3640
|
+
function arrayClone(arr, n) {
|
|
3641
|
+
var copy = new Array(n);
|
|
3642
|
+
for (var i = 0; i < n; ++i)
|
|
3643
|
+
copy[i] = arr[i];
|
|
3644
|
+
return copy;
|
|
3645
|
+
}
|
|
3646
|
+
|
|
3647
|
+
function spliceOne(list, index) {
|
|
3648
|
+
for (; index + 1 < list.length; index++)
|
|
3649
|
+
list[index] = list[index + 1];
|
|
3650
|
+
list.pop();
|
|
3651
|
+
}
|
|
3652
|
+
|
|
3653
|
+
function unwrapListeners(arr) {
|
|
3654
|
+
var ret = new Array(arr.length);
|
|
3655
|
+
for (var i = 0; i < ret.length; ++i) {
|
|
3656
|
+
ret[i] = arr[i].listener || arr[i];
|
|
3657
|
+
}
|
|
3658
|
+
return ret;
|
|
3659
|
+
}
|
|
3660
|
+
|
|
3661
|
+
function once$2(emitter, name) {
|
|
3662
|
+
return new Promise(function (resolve, reject) {
|
|
3663
|
+
function errorListener(err) {
|
|
3664
|
+
emitter.removeListener(name, resolver);
|
|
3665
|
+
reject(err);
|
|
3666
|
+
}
|
|
3667
|
+
|
|
3668
|
+
function resolver() {
|
|
3669
|
+
if (typeof emitter.removeListener === 'function') {
|
|
3670
|
+
emitter.removeListener('error', errorListener);
|
|
3671
|
+
}
|
|
3672
|
+
resolve([].slice.call(arguments));
|
|
3673
|
+
}
|
|
3674
|
+
eventTargetAgnosticAddListener(emitter, name, resolver, { once: true });
|
|
3675
|
+
if (name !== 'error') {
|
|
3676
|
+
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
|
|
3677
|
+
}
|
|
3678
|
+
});
|
|
3679
|
+
}
|
|
3680
|
+
|
|
3681
|
+
function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
|
|
3682
|
+
if (typeof emitter.on === 'function') {
|
|
3683
|
+
eventTargetAgnosticAddListener(emitter, 'error', handler, flags);
|
|
3684
|
+
}
|
|
3685
|
+
}
|
|
3686
|
+
|
|
3687
|
+
function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
3688
|
+
if (typeof emitter.on === 'function') {
|
|
3689
|
+
if (flags.once) {
|
|
3690
|
+
emitter.once(name, listener);
|
|
3691
|
+
} else {
|
|
3692
|
+
emitter.on(name, listener);
|
|
3693
|
+
}
|
|
3694
|
+
} else if (typeof emitter.addEventListener === 'function') {
|
|
3695
|
+
// EventTarget does not have `error` event semantics like Node
|
|
3696
|
+
// EventEmitters, we do not listen for `error` events here.
|
|
3697
|
+
emitter.addEventListener(name, function wrapListener(arg) {
|
|
3698
|
+
// IE does not have builtin `{ once: true }` support so we
|
|
3699
|
+
// have to do it manually.
|
|
3700
|
+
if (flags.once) {
|
|
3701
|
+
emitter.removeEventListener(name, wrapListener);
|
|
3702
|
+
}
|
|
3703
|
+
listener(arg);
|
|
3704
|
+
});
|
|
3705
|
+
} else {
|
|
3706
|
+
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
|
|
3707
|
+
}
|
|
3708
|
+
}
|
|
3709
|
+
|
|
3710
|
+
var streamBrowser = eventsExports.EventEmitter;
|
|
1105
3711
|
|
|
1106
3712
|
var buffer_list;
|
|
1107
3713
|
var hasRequiredBuffer_list;
|
|
@@ -1115,9 +3721,9 @@ function requireBuffer_list () {
|
|
|
1115
3721
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1116
3722
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
1117
3723
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1118
|
-
const _require =
|
|
3724
|
+
const _require = buffer,
|
|
1119
3725
|
Buffer = _require.Buffer;
|
|
1120
|
-
const _require2 = require$$3,
|
|
3726
|
+
const _require2 = require$$3$1,
|
|
1121
3727
|
inspect = _require2.inspect;
|
|
1122
3728
|
const custom = inspect && inspect.custom || 'inspect';
|
|
1123
3729
|
function copyBuffer(src, target, offset) {
|
|
@@ -1612,7 +4218,7 @@ function require_stream_writable () {
|
|
|
1612
4218
|
var Stream = streamBrowser;
|
|
1613
4219
|
/*</replacement>*/
|
|
1614
4220
|
|
|
1615
|
-
const Buffer =
|
|
4221
|
+
const Buffer = buffer.Buffer;
|
|
1616
4222
|
const OurUint8Array = (typeof commonjsGlobal !== 'undefined' ? commonjsGlobal : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {};
|
|
1617
4223
|
function _uint8ArrayToBuffer(chunk) {
|
|
1618
4224
|
return Buffer.from(chunk);
|
|
@@ -2885,7 +5491,7 @@ function require_stream_readable () {
|
|
|
2885
5491
|
Readable.ReadableState = ReadableState;
|
|
2886
5492
|
|
|
2887
5493
|
/*<replacement>*/
|
|
2888
|
-
|
|
5494
|
+
eventsExports.EventEmitter;
|
|
2889
5495
|
var EElistenerCount = function EElistenerCount(emitter, type) {
|
|
2890
5496
|
return emitter.listeners(type).length;
|
|
2891
5497
|
};
|
|
@@ -2895,7 +5501,7 @@ function require_stream_readable () {
|
|
|
2895
5501
|
var Stream = streamBrowser;
|
|
2896
5502
|
/*</replacement>*/
|
|
2897
5503
|
|
|
2898
|
-
const Buffer =
|
|
5504
|
+
const Buffer = buffer.Buffer;
|
|
2899
5505
|
const OurUint8Array = (typeof commonjsGlobal !== 'undefined' ? commonjsGlobal : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {};
|
|
2900
5506
|
function _uint8ArrayToBuffer(chunk) {
|
|
2901
5507
|
return Buffer.from(chunk);
|
|
@@ -2905,7 +5511,7 @@ function require_stream_readable () {
|
|
|
2905
5511
|
}
|
|
2906
5512
|
|
|
2907
5513
|
/*<replacement>*/
|
|
2908
|
-
const debugUtil = require$$3;
|
|
5514
|
+
const debugUtil = require$$3$1;
|
|
2909
5515
|
let debug;
|
|
2910
5516
|
if (debugUtil && debugUtil.debuglog) {
|
|
2911
5517
|
debug = debugUtil.debuglog('stream');
|
|
@@ -4112,6 +6718,8 @@ var pipeline_1 = pipeline;
|
|
|
4112
6718
|
exports.pipeline = pipeline_1;
|
|
4113
6719
|
} (readableBrowser, readableBrowserExports));
|
|
4114
6720
|
|
|
6721
|
+
var require$$3 = /*@__PURE__*/getDefaultExportFromCjs(readableBrowserExports);
|
|
6722
|
+
|
|
4115
6723
|
/*! queue-microtask. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
4116
6724
|
|
|
4117
6725
|
let promise;
|
|
@@ -4193,13 +6801,13 @@ var errCode$1 = createError;
|
|
|
4193
6801
|
|
|
4194
6802
|
/*! simple-peer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
4195
6803
|
|
|
4196
|
-
const debug =
|
|
6804
|
+
const debug = require$$0('simple-peer');
|
|
4197
6805
|
const getBrowserRTC = getBrowserRtc;
|
|
4198
6806
|
const randombytes = browserExports;
|
|
4199
|
-
const stream =
|
|
6807
|
+
const stream = require$$3;
|
|
4200
6808
|
const queueMicrotask$1 = queueMicrotask_1; // TODO: remove when Node 10 is not supported
|
|
4201
6809
|
const errCode = errCode$1;
|
|
4202
|
-
const { Buffer } =
|
|
6810
|
+
const { Buffer } = buffer;
|
|
4203
6811
|
|
|
4204
6812
|
const MAX_BUFFERED_AMOUNT = 64 * 1024;
|
|
4205
6813
|
const ICECOMPLETE_TIMEOUT = 5 * 1000;
|
|
@@ -4219,7 +6827,7 @@ function warn (message) {
|
|
|
4219
6827
|
* Duplex stream.
|
|
4220
6828
|
* @param {Object} opts
|
|
4221
6829
|
*/
|
|
4222
|
-
|
|
6830
|
+
class Peer extends stream.Duplex {
|
|
4223
6831
|
constructor (opts) {
|
|
4224
6832
|
opts = Object.assign({
|
|
4225
6833
|
allowHalfOpen: false
|
|
@@ -5220,16 +7828,16 @@ let Peer$1 = class Peer extends stream.Duplex {
|
|
|
5220
7828
|
args[0] = '[' + this._id + '] ' + args[0];
|
|
5221
7829
|
debug.apply(null, args);
|
|
5222
7830
|
}
|
|
5223
|
-
}
|
|
7831
|
+
}
|
|
5224
7832
|
|
|
5225
|
-
Peer
|
|
7833
|
+
Peer.WEBRTC_SUPPORT = !!getBrowserRTC();
|
|
5226
7834
|
|
|
5227
7835
|
/**
|
|
5228
7836
|
* Expose peer and data channel config for overriding all Peer
|
|
5229
7837
|
* instances. Otherwise, just set opts.config or opts.channelConfig
|
|
5230
7838
|
* when constructing a Peer.
|
|
5231
7839
|
*/
|
|
5232
|
-
Peer
|
|
7840
|
+
Peer.config = {
|
|
5233
7841
|
iceServers: [
|
|
5234
7842
|
{
|
|
5235
7843
|
urls: [
|
|
@@ -5241,391 +7849,8 @@ Peer$1.config = {
|
|
|
5241
7849
|
sdpSemantics: 'unified-plan'
|
|
5242
7850
|
};
|
|
5243
7851
|
|
|
5244
|
-
Peer
|
|
5245
|
-
|
|
5246
|
-
var simplePeer = Peer$1;
|
|
5247
|
-
|
|
5248
|
-
class Peer {
|
|
5249
|
-
#connection;
|
|
5250
|
-
#connected = false;
|
|
5251
|
-
#messageQue = [];
|
|
5252
|
-
#chunksQue = {};
|
|
5253
|
-
#channel;
|
|
5254
|
-
id;
|
|
5255
|
-
#peerId;
|
|
5256
|
-
#channelName;
|
|
5257
|
-
#chunkSize = 16 * 1024; // 16384
|
|
5258
|
-
#queRunning = false;
|
|
5259
|
-
#MAX_BUFFERED_AMOUNT = 16 * 1024 * 1024;
|
|
5260
|
-
initiator = false;
|
|
5261
|
-
state;
|
|
5262
|
-
#makingOffer = false;
|
|
5263
|
-
get connection() {
|
|
5264
|
-
return this.#connection;
|
|
5265
|
-
}
|
|
5266
|
-
get connected() {
|
|
5267
|
-
return this.#connected;
|
|
5268
|
-
}
|
|
5269
|
-
get readyState() {
|
|
5270
|
-
return this.#channel?.readyState;
|
|
5271
|
-
}
|
|
5272
|
-
get channelName() {
|
|
5273
|
-
return this.#channelName;
|
|
5274
|
-
}
|
|
5275
|
-
/**
|
|
5276
|
-
* @params {Object} options
|
|
5277
|
-
* @params {string} options.channelName - this peerid : otherpeer id
|
|
5278
|
-
*/
|
|
5279
|
-
constructor(options = {}) {
|
|
5280
|
-
this._in = this._in.bind(this);
|
|
5281
|
-
this.offerOptions = options.offerOptions;
|
|
5282
|
-
this.initiator = options.initiator;
|
|
5283
|
-
this.streams = options.streams;
|
|
5284
|
-
this.socketClient = options.socketClient;
|
|
5285
|
-
this.id = options.id;
|
|
5286
|
-
this.to = options.to;
|
|
5287
|
-
this.bw = {
|
|
5288
|
-
up: 0,
|
|
5289
|
-
down: 0
|
|
5290
|
-
};
|
|
5291
|
-
this.#channelName = options.channelName;
|
|
5292
|
-
this.#peerId = options.peerId;
|
|
5293
|
-
this.options = options;
|
|
5294
|
-
return this.#init();
|
|
5295
|
-
}
|
|
5296
|
-
get peerId() {
|
|
5297
|
-
return this.#peerId;
|
|
5298
|
-
}
|
|
5299
|
-
set socketClient(value) {
|
|
5300
|
-
// this.socketClient?.pubsub.unsubscribe('signal', this._in)
|
|
5301
|
-
this._socketClient = value;
|
|
5302
|
-
this._socketClient.pubsub.subscribe('signal', this._in);
|
|
5303
|
-
}
|
|
5304
|
-
get socketClient() {
|
|
5305
|
-
return this._socketClient;
|
|
5306
|
-
}
|
|
5307
|
-
splitMessage(message) {
|
|
5308
|
-
const chunks = [];
|
|
5309
|
-
message = pako.deflate(message);
|
|
5310
|
-
const size = message.byteLength || message.length;
|
|
5311
|
-
let offset = 0;
|
|
5312
|
-
return new Promise((resolve, reject) => {
|
|
5313
|
-
const splitMessage = () => {
|
|
5314
|
-
const chunk = message.slice(offset, offset + this.#chunkSize > size ? size : offset + this.#chunkSize);
|
|
5315
|
-
offset += this.#chunkSize;
|
|
5316
|
-
chunks.push(chunk);
|
|
5317
|
-
if (offset < size)
|
|
5318
|
-
return splitMessage();
|
|
5319
|
-
else
|
|
5320
|
-
resolve({ chunks, size });
|
|
5321
|
-
};
|
|
5322
|
-
splitMessage();
|
|
5323
|
-
});
|
|
5324
|
-
}
|
|
5325
|
-
async #runQue() {
|
|
5326
|
-
this.#queRunning = true;
|
|
5327
|
-
if (this.#messageQue.length > 0 && this.#channel?.bufferedAmount + this.#messageQue[0]?.length < this.#MAX_BUFFERED_AMOUNT) {
|
|
5328
|
-
const message = this.#messageQue.shift();
|
|
5329
|
-
await this.#connection.send(message);
|
|
5330
|
-
if (this.#messageQue.length > 0)
|
|
5331
|
-
return this.#runQue();
|
|
5332
|
-
// switch (this.#channel?.readyState) {
|
|
5333
|
-
// case 'open':
|
|
5334
|
-
// await this.#channel.send(message);
|
|
5335
|
-
// if (this.#messageQue.length > 0) return this.#runQue()
|
|
5336
|
-
// else this.#queRunning = false
|
|
5337
|
-
// break;
|
|
5338
|
-
// case 'closed':
|
|
5339
|
-
// case 'closing':
|
|
5340
|
-
// this.#messageQue = []
|
|
5341
|
-
// this.#queRunning = false
|
|
5342
|
-
// debug('channel already closed, this usually means a bad implementation, try checking the readyState or check if the peer is connected before sending');
|
|
5343
|
-
// break;
|
|
5344
|
-
// case undefined:
|
|
5345
|
-
// this.#messageQue = []
|
|
5346
|
-
// this.#queRunning = false
|
|
5347
|
-
// debug(`trying to send before a channel is created`);
|
|
5348
|
-
// break;
|
|
5349
|
-
// }
|
|
5350
|
-
}
|
|
5351
|
-
else {
|
|
5352
|
-
return setTimeout(() => this.#runQue(), 50);
|
|
5353
|
-
}
|
|
5354
|
-
}
|
|
5355
|
-
#trySend({ size, id, chunks }) {
|
|
5356
|
-
let offset = 0;
|
|
5357
|
-
for (const chunk of chunks) {
|
|
5358
|
-
const start = offset;
|
|
5359
|
-
const end = offset + chunk.length;
|
|
5360
|
-
const message = new TextEncoder().encode(JSON.stringify({ size, id, chunk, start, end }));
|
|
5361
|
-
this.#messageQue.push(message);
|
|
5362
|
-
}
|
|
5363
|
-
if (!this.queRunning)
|
|
5364
|
-
return this.#runQue();
|
|
5365
|
-
}
|
|
5366
|
-
async send(message, id) {
|
|
5367
|
-
const { chunks, size } = await this.splitMessage(message);
|
|
5368
|
-
return this.#trySend({ size, id, chunks });
|
|
5369
|
-
}
|
|
5370
|
-
request(data) {
|
|
5371
|
-
return new Promise((resolve, reject) => {
|
|
5372
|
-
const id = Math.random().toString(36).slice(-12);
|
|
5373
|
-
const _onData = message => {
|
|
5374
|
-
if (message.id === id) {
|
|
5375
|
-
resolve(message.data);
|
|
5376
|
-
pubsub.unsubscribe(`peer:data`, _onData);
|
|
5377
|
-
}
|
|
5378
|
-
};
|
|
5379
|
-
pubsub.subscribe(`peer:data`, _onData);
|
|
5380
|
-
// cleanup subscriptions
|
|
5381
|
-
// setTimeout(() => {
|
|
5382
|
-
// pubsub.unsubscribe(`peer:data-request-${id}`, _onData)
|
|
5383
|
-
// }, 5000);
|
|
5384
|
-
this.send(data, id);
|
|
5385
|
-
});
|
|
5386
|
-
}
|
|
5387
|
-
async #init() {
|
|
5388
|
-
try {
|
|
5389
|
-
if (!globalThis.pako) {
|
|
5390
|
-
const importee = await import('./pako.esm-aa674ebf.js');
|
|
5391
|
-
globalThis.pako = importee.default;
|
|
5392
|
-
}
|
|
5393
|
-
const iceServers = [{
|
|
5394
|
-
urls: 'stun:stun.l.google.com:19302' // Google's public STUN server
|
|
5395
|
-
}, {
|
|
5396
|
-
urls: "stun:openrelay.metered.ca:80",
|
|
5397
|
-
}, {
|
|
5398
|
-
urls: "turn:openrelay.metered.ca:443",
|
|
5399
|
-
username: "openrelayproject",
|
|
5400
|
-
credential: "openrelayproject",
|
|
5401
|
-
}, {
|
|
5402
|
-
urls: "turn:openrelay.metered.ca:443?transport=tcp",
|
|
5403
|
-
username: "openrelayproject",
|
|
5404
|
-
credential: "openrelayproject",
|
|
5405
|
-
}];
|
|
5406
|
-
this.#connection = new simplePeer({
|
|
5407
|
-
channelName: this.channelName,
|
|
5408
|
-
initiator: this.initiator,
|
|
5409
|
-
peerId: this.peerId,
|
|
5410
|
-
wrtc: globalThis.wrtc,
|
|
5411
|
-
config: {
|
|
5412
|
-
iceServers
|
|
5413
|
-
}
|
|
5414
|
-
});
|
|
5415
|
-
this.#connection.on('signal', signal => {
|
|
5416
|
-
this._sendMessage({ signal });
|
|
5417
|
-
});
|
|
5418
|
-
this.#connection.on('connected', () => {
|
|
5419
|
-
this.#connected = true;
|
|
5420
|
-
pubsub.publish('peer:connected', this);
|
|
5421
|
-
});
|
|
5422
|
-
this.#connection.on('close', () => {
|
|
5423
|
-
this.close();
|
|
5424
|
-
});
|
|
5425
|
-
this.#connection.on('data', data => {
|
|
5426
|
-
this._handleMessage(data);
|
|
5427
|
-
});
|
|
5428
|
-
this.#connection.on('error', (e) => {
|
|
5429
|
-
pubsub.publish('connection closed', this);
|
|
5430
|
-
console.log(e);
|
|
5431
|
-
this.close();
|
|
5432
|
-
});
|
|
5433
|
-
}
|
|
5434
|
-
catch (e) {
|
|
5435
|
-
console.log(e);
|
|
5436
|
-
}
|
|
5437
|
-
return this;
|
|
5438
|
-
}
|
|
5439
|
-
_handleMessage(message) {
|
|
5440
|
-
console.log({ message });
|
|
5441
|
-
message = JSON.parse(new TextDecoder().decode(message.data));
|
|
5442
|
-
// allow sharding (multiple peers share data)
|
|
5443
|
-
pubsub.publish('peernet:shard', message);
|
|
5444
|
-
const { id } = message;
|
|
5445
|
-
if (!this.#chunksQue[id])
|
|
5446
|
-
this.#chunksQue[id] = [];
|
|
5447
|
-
if (message.size > this.#chunksQue[id].length || message.size === this.#chunksQue[id].length) {
|
|
5448
|
-
for (const value of Object.values(message.chunk)) {
|
|
5449
|
-
this.#chunksQue[id].push(value);
|
|
5450
|
-
}
|
|
5451
|
-
}
|
|
5452
|
-
if (message.size === this.#chunksQue[id].length) {
|
|
5453
|
-
let data = new Uint8Array(Object.values(this.#chunksQue[id]));
|
|
5454
|
-
delete this.#chunksQue[id];
|
|
5455
|
-
data = pako.inflate(data);
|
|
5456
|
-
pubsub.publish('peer:data', { id, data, from: this.peerId });
|
|
5457
|
-
}
|
|
5458
|
-
this.bw.down += message.byteLength || message.length;
|
|
5459
|
-
}
|
|
5460
|
-
_sendMessage(message) {
|
|
5461
|
-
this.socketClient.send({ url: 'signal', params: {
|
|
5462
|
-
to: this.to,
|
|
5463
|
-
from: this.id,
|
|
5464
|
-
channelName: this.channelName,
|
|
5465
|
-
...message
|
|
5466
|
-
} });
|
|
5467
|
-
}
|
|
5468
|
-
async _in(message, data) {
|
|
5469
|
-
if (message.signal)
|
|
5470
|
-
return this.#connection.signal(message.signal);
|
|
5471
|
-
}
|
|
5472
|
-
close() {
|
|
5473
|
-
// debug(`closing ${this.peerId}`)
|
|
5474
|
-
this.#connected = false;
|
|
5475
|
-
// this.#channel?.close()
|
|
5476
|
-
// this.#connection?.exit()
|
|
5477
|
-
this.socketClient.pubsub.unsubscribe('signal', this._in);
|
|
5478
|
-
}
|
|
5479
|
-
}
|
|
7852
|
+
Peer.channelConfig = {};
|
|
5480
7853
|
|
|
5481
|
-
|
|
5482
|
-
#peerConnection;
|
|
5483
|
-
#connections = {};
|
|
5484
|
-
#stars = {};
|
|
5485
|
-
id;
|
|
5486
|
-
networkVersion;
|
|
5487
|
-
starsConfig;
|
|
5488
|
-
socketClient;
|
|
5489
|
-
get connections() {
|
|
5490
|
-
return { ...this.#connections };
|
|
5491
|
-
}
|
|
5492
|
-
get peers() {
|
|
5493
|
-
return Object.entries(this.#connections);
|
|
5494
|
-
}
|
|
5495
|
-
constructor(id, networkVersion = 'peach', stars = ['wss://peach.leofcoin.org']) {
|
|
5496
|
-
this.id = id || Math.random().toString(36).slice(-12);
|
|
5497
|
-
this.peerJoined = this.peerJoined.bind(this);
|
|
5498
|
-
this.peerLeft = this.peerLeft.bind(this);
|
|
5499
|
-
this.starLeft = this.starLeft.bind(this);
|
|
5500
|
-
this.starJoined = this.starJoined.bind(this);
|
|
5501
|
-
this.networkVersion = networkVersion;
|
|
5502
|
-
this._init(stars);
|
|
5503
|
-
}
|
|
5504
|
-
async _init(stars = []) {
|
|
5505
|
-
this.starsConfig = stars;
|
|
5506
|
-
// reconnectJob()
|
|
5507
|
-
if (!globalThis.RTCPeerConnection)
|
|
5508
|
-
globalThis.wrtc = (await import('./browser-10ffabe1.js').then(function (n) { return n.b; })).default;
|
|
5509
|
-
else
|
|
5510
|
-
globalThis.wrtc = {
|
|
5511
|
-
RTCPeerConnection,
|
|
5512
|
-
RTCSessionDescription,
|
|
5513
|
-
RTCIceCandidate
|
|
5514
|
-
};
|
|
5515
|
-
for (const star of stars) {
|
|
5516
|
-
try {
|
|
5517
|
-
this.socketClient = await socketRequestClient(star, this.networkVersion);
|
|
5518
|
-
const id = await this.socketClient.request({ url: 'id', params: { from: this.id } });
|
|
5519
|
-
this.socketClient.peerId = id;
|
|
5520
|
-
this.#stars[id] = this.socketClient;
|
|
5521
|
-
}
|
|
5522
|
-
catch (e) {
|
|
5523
|
-
if (stars.indexOf(star) === stars.length - 1 && !this.socketClient)
|
|
5524
|
-
throw new Error(`No star available to connect`);
|
|
5525
|
-
}
|
|
5526
|
-
}
|
|
5527
|
-
this.setupListeners();
|
|
5528
|
-
const peers = await this.socketClient.peernet.join({ id: this.id });
|
|
5529
|
-
for (const id of peers) {
|
|
5530
|
-
if (id !== this.id && !this.#connections[id])
|
|
5531
|
-
this.#connections[id] = await new Peer({ channelName: `${id}:${this.id}`, socketClient: this.socketClient, id: this.id, to: id, peerId: id });
|
|
5532
|
-
}
|
|
5533
|
-
pubsub.subscribe('connection closed', (peer) => {
|
|
5534
|
-
this.removePeer(peer.peerId);
|
|
5535
|
-
setTimeout(() => {
|
|
5536
|
-
this.peerJoined(peer.peerId);
|
|
5537
|
-
}, 1000);
|
|
5538
|
-
});
|
|
5539
|
-
}
|
|
5540
|
-
setupListeners() {
|
|
5541
|
-
this.socketClient.subscribe('peer:joined', this.peerJoined);
|
|
5542
|
-
this.socketClient.subscribe('peer:left', this.peerLeft);
|
|
5543
|
-
this.socketClient.subscribe('star:left', this.starLeft);
|
|
5544
|
-
}
|
|
5545
|
-
starJoined(id) {
|
|
5546
|
-
if (this.#stars[id]) {
|
|
5547
|
-
this.#stars[id].close();
|
|
5548
|
-
delete this.#stars[id];
|
|
5549
|
-
}
|
|
5550
|
-
console.log(`star ${id} joined`);
|
|
5551
|
-
}
|
|
5552
|
-
async starLeft(id) {
|
|
5553
|
-
if (this.#stars[id]) {
|
|
5554
|
-
this.#stars[id].close();
|
|
5555
|
-
delete this.#stars[id];
|
|
5556
|
-
}
|
|
5557
|
-
if (this.socketClient?.peerId === id) {
|
|
5558
|
-
this.socketClient.unsubscribe('peer:joined', this.peerJoined);
|
|
5559
|
-
this.socketClient.unsubscribe('peer:left', this.peerLeft);
|
|
5560
|
-
this.socketClient.unsubscribe('star:left', this.starLeft);
|
|
5561
|
-
this.socketClient.close();
|
|
5562
|
-
this.socketClient = undefined;
|
|
5563
|
-
for (const star of this.starsConfig) {
|
|
5564
|
-
try {
|
|
5565
|
-
this.socketClient = await socketRequestClient(star, this.networkVersion);
|
|
5566
|
-
if (!this.socketClient?.client?._connection.connected)
|
|
5567
|
-
return;
|
|
5568
|
-
const id = await this.socketClient.request({ url: 'id', params: { from: this.id } });
|
|
5569
|
-
this.#stars[id] = this.socketClient;
|
|
5570
|
-
this.socketClient.peerId = id;
|
|
5571
|
-
const peers = await this.socketClient.peernet.join({ id: this.id });
|
|
5572
|
-
this.setupListeners();
|
|
5573
|
-
for (const id of peers) {
|
|
5574
|
-
if (id !== this.id) {
|
|
5575
|
-
if (!this.#connections[id]) {
|
|
5576
|
-
if (id !== this.id)
|
|
5577
|
-
this.#connections[id] = await new Peer({ channelName: `${id}:${this.id}`, socketClient: this.socketClient, id: this.id, to: id, peerId: id });
|
|
5578
|
-
}
|
|
5579
|
-
}
|
|
5580
|
-
}
|
|
5581
|
-
}
|
|
5582
|
-
catch (e) {
|
|
5583
|
-
console.log(e);
|
|
5584
|
-
if (this.starsConfig.indexOf(star) === this.starsConfig.length - 1 && !this.socketClient)
|
|
5585
|
-
throw new Error(`No star available to connect`);
|
|
5586
|
-
}
|
|
5587
|
-
}
|
|
5588
|
-
}
|
|
5589
|
-
globalThis.debug(`star ${id} left`);
|
|
5590
|
-
}
|
|
5591
|
-
peerLeft(peer) {
|
|
5592
|
-
const id = peer.peerId || peer;
|
|
5593
|
-
if (this.#connections[id]) {
|
|
5594
|
-
this.#connections[id].close();
|
|
5595
|
-
delete this.#connections[id];
|
|
5596
|
-
}
|
|
5597
|
-
globalThis.debug(`peer ${id} left`);
|
|
5598
|
-
}
|
|
5599
|
-
async peerJoined(peer, signal) {
|
|
5600
|
-
const id = peer.peerId || peer;
|
|
5601
|
-
if (this.#connections[id]) {
|
|
5602
|
-
if (this.#connections[id].connected)
|
|
5603
|
-
this.#connections[id].close();
|
|
5604
|
-
delete this.#connections[id];
|
|
5605
|
-
}
|
|
5606
|
-
// RTCPeerConnection
|
|
5607
|
-
this.#connections[id] = await new Peer({ initiator: true, channelName: `${this.id}:${id}`, socketClient: this.socketClient, id: this.id, to: id, peerId: id });
|
|
5608
|
-
globalThis.debug(`peer ${id} joined`);
|
|
5609
|
-
}
|
|
5610
|
-
removePeer(peer) {
|
|
5611
|
-
const id = peer.peerId || peer;
|
|
5612
|
-
if (this.#connections[id]) {
|
|
5613
|
-
this.#connections[id].connected && this.#connections[id].close();
|
|
5614
|
-
delete this.#connections[id];
|
|
5615
|
-
}
|
|
5616
|
-
globalThis.debug(`peer ${id} removed`);
|
|
5617
|
-
}
|
|
5618
|
-
async close() {
|
|
5619
|
-
this.socketClient.unsubscribe('peer:joined', this.peerJoined);
|
|
5620
|
-
this.socketClient.unsubscribe('peer:left', this.peerLeft);
|
|
5621
|
-
this.socketClient.unsubscribe('star:left', this.starLeft);
|
|
5622
|
-
const promises = [
|
|
5623
|
-
Object.values(this.#connections).map(connection => connection.close()),
|
|
5624
|
-
Object.values(this.#stars).map(connection => connection.close()),
|
|
5625
|
-
this.socketClient.close()
|
|
5626
|
-
];
|
|
5627
|
-
return Promise.allSettled(promises);
|
|
5628
|
-
}
|
|
5629
|
-
}
|
|
7854
|
+
var simplePeer = Peer;
|
|
5630
7855
|
|
|
5631
|
-
export {
|
|
7856
|
+
export { simplePeer as default };
|