deepline 0.3.294 → 0.3.295
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundling-sources/sdk/src/compat.ts +35 -7
- package/dist/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/tool-http-errors.ts +14 -1
- package/dist/cli/auth-EDTRERZP.mjs +31 -0
- package/dist/cli/auth-TDHKB277.js +31 -0
- package/dist/cli/billing-ELIDPILY.js +1749 -0
- package/dist/cli/billing-EXGXJVAU.mjs +1749 -0
- package/dist/cli/chunk-2S5Y3TZP.js +5688 -0
- package/dist/cli/chunk-3KC45UVF.js +150 -0
- package/dist/cli/chunk-3XX5TEA4.js +15 -0
- package/dist/cli/chunk-4MBOJQPL.mjs +0 -0
- package/dist/cli/chunk-4NEFYBF7.js +2240 -0
- package/dist/cli/chunk-5JLQPVNX.js +3056 -0
- package/dist/cli/chunk-5KDKFHZI.js +1269 -0
- package/dist/cli/chunk-6A3TJUWC.js +76 -0
- package/dist/cli/chunk-6O5YZOVN.mjs +890 -0
- package/dist/cli/chunk-7P5AA3SN.js +344 -0
- package/dist/cli/chunk-AYHLUHE5.js +52 -0
- package/dist/cli/chunk-CBVIJSHF.mjs +560 -0
- package/dist/cli/chunk-CFVVCN4A.js +735 -0
- package/dist/cli/chunk-COGTRVWW.js +30 -0
- package/dist/cli/chunk-D4AZUZO4.js +190 -0
- package/dist/cli/chunk-DLIRSHV6.mjs +28 -0
- package/dist/cli/chunk-EACVZI6N.mjs +1995 -0
- package/dist/cli/chunk-EDWJY6T4.mjs +3056 -0
- package/dist/cli/chunk-EXMLR72R.mjs +0 -0
- package/dist/cli/chunk-F35VOIQL.js +890 -0
- package/dist/cli/chunk-GAMFK2ZP.mjs +148 -0
- package/dist/cli/chunk-GHRQQPW2.mjs +2240 -0
- package/dist/cli/chunk-GONRLVV3.js +3440 -0
- package/dist/cli/chunk-GVUJJJ5G.mjs +76 -0
- package/dist/cli/chunk-H7HIDGZ7.mjs +150 -0
- package/dist/cli/chunk-HUZXWOSK.mjs +503 -0
- package/dist/cli/chunk-I5YZLGMG.js +1 -0
- package/dist/cli/chunk-ITOFSXIU.mjs +15 -0
- package/dist/cli/chunk-J5NA2TTX.js +503 -0
- package/dist/cli/chunk-JCS5TPNY.mjs +3440 -0
- package/dist/cli/chunk-JNNOCMQY.js +47 -0
- package/dist/cli/chunk-KRD6H754.mjs +30 -0
- package/dist/cli/chunk-LA46MMTL.js +560 -0
- package/dist/cli/chunk-LDWT7RJK.mjs +190 -0
- package/dist/cli/chunk-M2V26OR5.js +499 -0
- package/dist/cli/chunk-MIMASXO4.mjs +389 -0
- package/dist/cli/chunk-MROPCKW2.mjs +190 -0
- package/dist/cli/chunk-NXDRDJ4K.js +389 -0
- package/dist/cli/chunk-NXGCO4JB.mjs +344 -0
- package/dist/cli/chunk-OG64RBAC.js +6 -0
- package/dist/cli/chunk-OQYEC4GL.mjs +34 -0
- package/dist/cli/chunk-OWJZUE3Y.mjs +103 -0
- package/dist/cli/chunk-SDK3ZA2C.js +103 -0
- package/dist/cli/chunk-SFLARO4Y.mjs +47 -0
- package/dist/cli/chunk-SVIIIYIQ.js +923 -0
- package/dist/cli/chunk-TAC3JIFE.mjs +354 -0
- package/dist/cli/chunk-U3PI7HBM.js +34 -0
- package/dist/cli/chunk-UFS752TU.mjs +52 -0
- package/dist/cli/chunk-UI37DQE7.mjs +499 -0
- package/dist/cli/chunk-UNEMDKXN.js +1 -0
- package/dist/cli/chunk-WB6Z2Q44.mjs +1622 -0
- package/dist/cli/chunk-WJYPBHTE.js +148 -0
- package/dist/cli/chunk-WOHBA5PV.js +354 -0
- package/dist/cli/chunk-WQICC2B3.js +190 -0
- package/dist/cli/chunk-WZYKRD7T.mjs +6 -0
- package/dist/cli/chunk-XL2FO6CW.mjs +5688 -0
- package/dist/cli/chunk-XNYIZMNQ.js +28 -0
- package/dist/cli/chunk-XRK2TZT5.js +1995 -0
- package/dist/cli/chunk-YJYPL5OK.mjs +1269 -0
- package/dist/cli/chunk-YWNDYCXR.mjs +735 -0
- package/dist/cli/chunk-YWWAF7KZ.mjs +923 -0
- package/dist/cli/chunk-ZDO3TO3M.js +1622 -0
- package/dist/cli/client-4JVOYVC5.js +20 -0
- package/dist/cli/client-EEN2IJN2.mjs +20 -0
- package/dist/cli/csv-BOHBEP2I.mjs +585 -0
- package/dist/cli/csv-S5NYRUEX.js +585 -0
- package/dist/cli/db-CLODWCOB.mjs +486 -0
- package/dist/cli/db-F6PKFOOV.js +486 -0
- package/dist/cli/executions-5TQAKLJU.js +28 -0
- package/dist/cli/executions-MAKW6QOY.mjs +28 -0
- package/dist/cli/feedback-GV4QJFEN.js +107 -0
- package/dist/cli/feedback-XY24TW7H.mjs +107 -0
- package/dist/cli/getting-started.js +18 -76
- package/dist/cli/getting-started.mjs +10 -37
- package/dist/cli/git-6S2C22T5.js +23 -0
- package/dist/cli/git-OZLBD5HH.mjs +23 -0
- package/dist/cli/index.js +291 -54294
- package/dist/cli/index.mjs +209 -54352
- package/dist/cli/legacy-noops-LLCGDPQE.js +157 -0
- package/dist/cli/legacy-noops-TYH3TW2D.mjs +157 -0
- package/dist/cli/monitors-CABMB4DW.js +3251 -0
- package/dist/cli/monitors-TTD55HMK.mjs +3251 -0
- package/dist/cli/org-MSF3RG76.js +849 -0
- package/dist/cli/org-SFJ77MWY.mjs +849 -0
- package/dist/cli/play-NXHJSCKL.mjs +18439 -0
- package/dist/cli/play-OKSFNNO4.js +18439 -0
- package/dist/cli/providers-QC2ERERL.js +95 -0
- package/dist/cli/providers-TIIAZEUA.mjs +95 -0
- package/dist/cli/proxy-env-EBANZHPV.js +161 -0
- package/dist/cli/proxy-env-M4ZHXHRL.mjs +161 -0
- package/dist/cli/quickstart-ICANHLMI.js +69 -0
- package/dist/cli/quickstart-KWUOP3FI.mjs +69 -0
- package/dist/cli/search-U5H2FDOO.mjs +18 -0
- package/dist/cli/search-XQRQOLWS.js +18 -0
- package/dist/cli/secrets-3J6YTWFA.mjs +400 -0
- package/dist/cli/secrets-YNMNZNOM.js +400 -0
- package/dist/cli/sessions-CLEES4L6.mjs +15 -0
- package/dist/cli/sessions-J6VR47FG.js +15 -0
- package/dist/cli/settings-EEKZMTY4.js +846 -0
- package/dist/cli/settings-UVLOQZRH.mjs +846 -0
- package/dist/cli/setup-DLMDXPGJ.mjs +1257 -0
- package/dist/cli/setup-HC4Q7QM4.js +1257 -0
- package/dist/cli/skills-33PHFBSB.mjs +28 -0
- package/dist/cli/skills-LFRY3KPX.js +28 -0
- package/dist/cli/tools-3COEPKML.mjs +2955 -0
- package/dist/cli/tools-QXEVCN45.js +2955 -0
- package/dist/cli/update-LSAC4FF5.mjs +28 -0
- package/dist/cli/update-NXHSPYXA.js +28 -0
- package/dist/cli/workflow-7S44OECF.mjs +1936 -0
- package/dist/cli/workflow-QPZWYSZE.js +1936 -0
- package/dist/helpers.js +6 -32
- package/dist/helpers.mjs +2 -0
- package/dist/index.js +1972 -12825
- package/dist/index.mjs +1910 -12672
- package/dist/install-integrity.json +110 -0
- package/dist/monitor-fleet-contract.js +31 -730
- package/dist/monitor-fleet-contract.mjs +18 -667
- package/dist/monitor-input-contract.js +10 -390
- package/dist/monitor-input-contract.mjs +7 -348
- package/dist/plays/bundle-play-file.mjs +13 -5178
- package/dist/plays/csv-data-input.js +5 -3132
- package/dist/plays/csv-data-input.mjs +5 -3105
- package/dist/plays/run-request.js +56 -664
- package/dist/plays/run-request.mjs +30 -588
- package/dist/release.d.mts +1 -1
- package/dist/release.d.ts +1 -1
- package/dist/release.js +5 -212
- package/dist/release.mjs +5 -185
- package/package.json +1 -1
|
@@ -1,3135 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from2, except, desc) => {
|
|
11
|
-
if (from2 && typeof from2 === "object" || typeof from2 === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from2))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from2[key], enumerable: !(desc = __getOwnPropDesc(from2, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
parseCsvDataInput: () => parseCsvDataInput
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(csv_data_input_exports);
|
|
3
|
+
var _chunk5JLQPVNXjs = require('../cli/chunk-5JLQPVNX.js');
|
|
4
|
+
require('../cli/chunk-7P5AA3SN.js');
|
|
5
|
+
require('../cli/chunk-COGTRVWW.js');
|
|
26
6
|
|
|
27
|
-
// node_modules/csv-parse/dist/esm/sync.js
|
|
28
|
-
var global$1 = typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};
|
|
29
|
-
var lookup = [];
|
|
30
|
-
var revLookup = [];
|
|
31
|
-
var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
|
|
32
|
-
var inited = false;
|
|
33
|
-
function init() {
|
|
34
|
-
inited = true;
|
|
35
|
-
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
36
|
-
for (var i = 0, len = code.length; i < len; ++i) {
|
|
37
|
-
lookup[i] = code[i];
|
|
38
|
-
revLookup[code.charCodeAt(i)] = i;
|
|
39
|
-
}
|
|
40
|
-
revLookup["-".charCodeAt(0)] = 62;
|
|
41
|
-
revLookup["_".charCodeAt(0)] = 63;
|
|
42
|
-
}
|
|
43
|
-
function toByteArray(b64) {
|
|
44
|
-
if (!inited) {
|
|
45
|
-
init();
|
|
46
|
-
}
|
|
47
|
-
var i, j, l, tmp, placeHolders, arr;
|
|
48
|
-
var len = b64.length;
|
|
49
|
-
if (len % 4 > 0) {
|
|
50
|
-
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
51
|
-
}
|
|
52
|
-
placeHolders = b64[len - 2] === "=" ? 2 : b64[len - 1] === "=" ? 1 : 0;
|
|
53
|
-
arr = new Arr(len * 3 / 4 - placeHolders);
|
|
54
|
-
l = placeHolders > 0 ? len - 4 : len;
|
|
55
|
-
var L = 0;
|
|
56
|
-
for (i = 0, j = 0; i < l; i += 4, j += 3) {
|
|
57
|
-
tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)];
|
|
58
|
-
arr[L++] = tmp >> 16 & 255;
|
|
59
|
-
arr[L++] = tmp >> 8 & 255;
|
|
60
|
-
arr[L++] = tmp & 255;
|
|
61
|
-
}
|
|
62
|
-
if (placeHolders === 2) {
|
|
63
|
-
tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4;
|
|
64
|
-
arr[L++] = tmp & 255;
|
|
65
|
-
} else if (placeHolders === 1) {
|
|
66
|
-
tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2;
|
|
67
|
-
arr[L++] = tmp >> 8 & 255;
|
|
68
|
-
arr[L++] = tmp & 255;
|
|
69
|
-
}
|
|
70
|
-
return arr;
|
|
71
|
-
}
|
|
72
|
-
function tripletToBase64(num) {
|
|
73
|
-
return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
|
|
74
|
-
}
|
|
75
|
-
function encodeChunk(uint8, start, end) {
|
|
76
|
-
var tmp;
|
|
77
|
-
var output = [];
|
|
78
|
-
for (var i = start; i < end; i += 3) {
|
|
79
|
-
tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + uint8[i + 2];
|
|
80
|
-
output.push(tripletToBase64(tmp));
|
|
81
|
-
}
|
|
82
|
-
return output.join("");
|
|
83
|
-
}
|
|
84
|
-
function fromByteArray(uint8) {
|
|
85
|
-
if (!inited) {
|
|
86
|
-
init();
|
|
87
|
-
}
|
|
88
|
-
var tmp;
|
|
89
|
-
var len = uint8.length;
|
|
90
|
-
var extraBytes = len % 3;
|
|
91
|
-
var output = "";
|
|
92
|
-
var parts = [];
|
|
93
|
-
var maxChunkLength = 16383;
|
|
94
|
-
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
|
|
95
|
-
parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength));
|
|
96
|
-
}
|
|
97
|
-
if (extraBytes === 1) {
|
|
98
|
-
tmp = uint8[len - 1];
|
|
99
|
-
output += lookup[tmp >> 2];
|
|
100
|
-
output += lookup[tmp << 4 & 63];
|
|
101
|
-
output += "==";
|
|
102
|
-
} else if (extraBytes === 2) {
|
|
103
|
-
tmp = (uint8[len - 2] << 8) + uint8[len - 1];
|
|
104
|
-
output += lookup[tmp >> 10];
|
|
105
|
-
output += lookup[tmp >> 4 & 63];
|
|
106
|
-
output += lookup[tmp << 2 & 63];
|
|
107
|
-
output += "=";
|
|
108
|
-
}
|
|
109
|
-
parts.push(output);
|
|
110
|
-
return parts.join("");
|
|
111
|
-
}
|
|
112
|
-
function read(buffer, offset, isLE, mLen, nBytes) {
|
|
113
|
-
var e, m;
|
|
114
|
-
var eLen = nBytes * 8 - mLen - 1;
|
|
115
|
-
var eMax = (1 << eLen) - 1;
|
|
116
|
-
var eBias = eMax >> 1;
|
|
117
|
-
var nBits = -7;
|
|
118
|
-
var i = isLE ? nBytes - 1 : 0;
|
|
119
|
-
var d = isLE ? -1 : 1;
|
|
120
|
-
var s = buffer[offset + i];
|
|
121
|
-
i += d;
|
|
122
|
-
e = s & (1 << -nBits) - 1;
|
|
123
|
-
s >>= -nBits;
|
|
124
|
-
nBits += eLen;
|
|
125
|
-
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {
|
|
126
|
-
}
|
|
127
|
-
m = e & (1 << -nBits) - 1;
|
|
128
|
-
e >>= -nBits;
|
|
129
|
-
nBits += mLen;
|
|
130
|
-
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {
|
|
131
|
-
}
|
|
132
|
-
if (e === 0) {
|
|
133
|
-
e = 1 - eBias;
|
|
134
|
-
} else if (e === eMax) {
|
|
135
|
-
return m ? NaN : (s ? -1 : 1) * Infinity;
|
|
136
|
-
} else {
|
|
137
|
-
m = m + Math.pow(2, mLen);
|
|
138
|
-
e = e - eBias;
|
|
139
|
-
}
|
|
140
|
-
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
141
|
-
}
|
|
142
|
-
function write(buffer, value, offset, isLE, mLen, nBytes) {
|
|
143
|
-
var e, m, c;
|
|
144
|
-
var eLen = nBytes * 8 - mLen - 1;
|
|
145
|
-
var eMax = (1 << eLen) - 1;
|
|
146
|
-
var eBias = eMax >> 1;
|
|
147
|
-
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
148
|
-
var i = isLE ? 0 : nBytes - 1;
|
|
149
|
-
var d = isLE ? 1 : -1;
|
|
150
|
-
var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
151
|
-
value = Math.abs(value);
|
|
152
|
-
if (isNaN(value) || value === Infinity) {
|
|
153
|
-
m = isNaN(value) ? 1 : 0;
|
|
154
|
-
e = eMax;
|
|
155
|
-
} else {
|
|
156
|
-
e = Math.floor(Math.log(value) / Math.LN2);
|
|
157
|
-
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
158
|
-
e--;
|
|
159
|
-
c *= 2;
|
|
160
|
-
}
|
|
161
|
-
if (e + eBias >= 1) {
|
|
162
|
-
value += rt / c;
|
|
163
|
-
} else {
|
|
164
|
-
value += rt * Math.pow(2, 1 - eBias);
|
|
165
|
-
}
|
|
166
|
-
if (value * c >= 2) {
|
|
167
|
-
e++;
|
|
168
|
-
c /= 2;
|
|
169
|
-
}
|
|
170
|
-
if (e + eBias >= eMax) {
|
|
171
|
-
m = 0;
|
|
172
|
-
e = eMax;
|
|
173
|
-
} else if (e + eBias >= 1) {
|
|
174
|
-
m = (value * c - 1) * Math.pow(2, mLen);
|
|
175
|
-
e = e + eBias;
|
|
176
|
-
} else {
|
|
177
|
-
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
178
|
-
e = 0;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) {
|
|
182
|
-
}
|
|
183
|
-
e = e << mLen | m;
|
|
184
|
-
eLen += mLen;
|
|
185
|
-
for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {
|
|
186
|
-
}
|
|
187
|
-
buffer[offset + i - d] |= s * 128;
|
|
188
|
-
}
|
|
189
|
-
var toString = {}.toString;
|
|
190
|
-
var isArray = Array.isArray || function(arr) {
|
|
191
|
-
return toString.call(arr) == "[object Array]";
|
|
192
|
-
};
|
|
193
|
-
var INSPECT_MAX_BYTES = 50;
|
|
194
|
-
Buffer2.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== void 0 ? global$1.TYPED_ARRAY_SUPPORT : true;
|
|
195
|
-
kMaxLength();
|
|
196
|
-
function kMaxLength() {
|
|
197
|
-
return Buffer2.TYPED_ARRAY_SUPPORT ? 2147483647 : 1073741823;
|
|
198
|
-
}
|
|
199
|
-
function createBuffer(that, length) {
|
|
200
|
-
if (kMaxLength() < length) {
|
|
201
|
-
throw new RangeError("Invalid typed array length");
|
|
202
|
-
}
|
|
203
|
-
if (Buffer2.TYPED_ARRAY_SUPPORT) {
|
|
204
|
-
that = new Uint8Array(length);
|
|
205
|
-
that.__proto__ = Buffer2.prototype;
|
|
206
|
-
} else {
|
|
207
|
-
if (that === null) {
|
|
208
|
-
that = new Buffer2(length);
|
|
209
|
-
}
|
|
210
|
-
that.length = length;
|
|
211
|
-
}
|
|
212
|
-
return that;
|
|
213
|
-
}
|
|
214
|
-
function Buffer2(arg, encodingOrOffset, length) {
|
|
215
|
-
if (!Buffer2.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer2)) {
|
|
216
|
-
return new Buffer2(arg, encodingOrOffset, length);
|
|
217
|
-
}
|
|
218
|
-
if (typeof arg === "number") {
|
|
219
|
-
if (typeof encodingOrOffset === "string") {
|
|
220
|
-
throw new Error(
|
|
221
|
-
"If encoding is specified then the first argument must be a string"
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
return allocUnsafe(this, arg);
|
|
225
|
-
}
|
|
226
|
-
return from(this, arg, encodingOrOffset, length);
|
|
227
|
-
}
|
|
228
|
-
Buffer2.poolSize = 8192;
|
|
229
|
-
Buffer2._augment = function(arr) {
|
|
230
|
-
arr.__proto__ = Buffer2.prototype;
|
|
231
|
-
return arr;
|
|
232
|
-
};
|
|
233
|
-
function from(that, value, encodingOrOffset, length) {
|
|
234
|
-
if (typeof value === "number") {
|
|
235
|
-
throw new TypeError('"value" argument must not be a number');
|
|
236
|
-
}
|
|
237
|
-
if (typeof ArrayBuffer !== "undefined" && value instanceof ArrayBuffer) {
|
|
238
|
-
return fromArrayBuffer(that, value, encodingOrOffset, length);
|
|
239
|
-
}
|
|
240
|
-
if (typeof value === "string") {
|
|
241
|
-
return fromString(that, value, encodingOrOffset);
|
|
242
|
-
}
|
|
243
|
-
return fromObject(that, value);
|
|
244
|
-
}
|
|
245
|
-
Buffer2.from = function(value, encodingOrOffset, length) {
|
|
246
|
-
return from(null, value, encodingOrOffset, length);
|
|
247
|
-
};
|
|
248
|
-
if (Buffer2.TYPED_ARRAY_SUPPORT) {
|
|
249
|
-
Buffer2.prototype.__proto__ = Uint8Array.prototype;
|
|
250
|
-
Buffer2.__proto__ = Uint8Array;
|
|
251
|
-
if (typeof Symbol !== "undefined" && Symbol.species && Buffer2[Symbol.species] === Buffer2) ;
|
|
252
|
-
}
|
|
253
|
-
function assertSize(size) {
|
|
254
|
-
if (typeof size !== "number") {
|
|
255
|
-
throw new TypeError('"size" argument must be a number');
|
|
256
|
-
} else if (size < 0) {
|
|
257
|
-
throw new RangeError('"size" argument must not be negative');
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
function alloc(that, size, fill2, encoding) {
|
|
261
|
-
assertSize(size);
|
|
262
|
-
if (size <= 0) {
|
|
263
|
-
return createBuffer(that, size);
|
|
264
|
-
}
|
|
265
|
-
if (fill2 !== void 0) {
|
|
266
|
-
return typeof encoding === "string" ? createBuffer(that, size).fill(fill2, encoding) : createBuffer(that, size).fill(fill2);
|
|
267
|
-
}
|
|
268
|
-
return createBuffer(that, size);
|
|
269
|
-
}
|
|
270
|
-
Buffer2.alloc = function(size, fill2, encoding) {
|
|
271
|
-
return alloc(null, size, fill2, encoding);
|
|
272
|
-
};
|
|
273
|
-
function allocUnsafe(that, size) {
|
|
274
|
-
assertSize(size);
|
|
275
|
-
that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
|
|
276
|
-
if (!Buffer2.TYPED_ARRAY_SUPPORT) {
|
|
277
|
-
for (var i = 0; i < size; ++i) {
|
|
278
|
-
that[i] = 0;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
return that;
|
|
282
|
-
}
|
|
283
|
-
Buffer2.allocUnsafe = function(size) {
|
|
284
|
-
return allocUnsafe(null, size);
|
|
285
|
-
};
|
|
286
|
-
Buffer2.allocUnsafeSlow = function(size) {
|
|
287
|
-
return allocUnsafe(null, size);
|
|
288
|
-
};
|
|
289
|
-
function fromString(that, string, encoding) {
|
|
290
|
-
if (typeof encoding !== "string" || encoding === "") {
|
|
291
|
-
encoding = "utf8";
|
|
292
|
-
}
|
|
293
|
-
if (!Buffer2.isEncoding(encoding)) {
|
|
294
|
-
throw new TypeError('"encoding" must be a valid string encoding');
|
|
295
|
-
}
|
|
296
|
-
var length = byteLength(string, encoding) | 0;
|
|
297
|
-
that = createBuffer(that, length);
|
|
298
|
-
var actual = that.write(string, encoding);
|
|
299
|
-
if (actual !== length) {
|
|
300
|
-
that = that.slice(0, actual);
|
|
301
|
-
}
|
|
302
|
-
return that;
|
|
303
|
-
}
|
|
304
|
-
function fromArrayLike(that, array) {
|
|
305
|
-
var length = array.length < 0 ? 0 : checked(array.length) | 0;
|
|
306
|
-
that = createBuffer(that, length);
|
|
307
|
-
for (var i = 0; i < length; i += 1) {
|
|
308
|
-
that[i] = array[i] & 255;
|
|
309
|
-
}
|
|
310
|
-
return that;
|
|
311
|
-
}
|
|
312
|
-
function fromArrayBuffer(that, array, byteOffset, length) {
|
|
313
|
-
array.byteLength;
|
|
314
|
-
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
315
|
-
throw new RangeError("'offset' is out of bounds");
|
|
316
|
-
}
|
|
317
|
-
if (array.byteLength < byteOffset + (length || 0)) {
|
|
318
|
-
throw new RangeError("'length' is out of bounds");
|
|
319
|
-
}
|
|
320
|
-
if (byteOffset === void 0 && length === void 0) {
|
|
321
|
-
array = new Uint8Array(array);
|
|
322
|
-
} else if (length === void 0) {
|
|
323
|
-
array = new Uint8Array(array, byteOffset);
|
|
324
|
-
} else {
|
|
325
|
-
array = new Uint8Array(array, byteOffset, length);
|
|
326
|
-
}
|
|
327
|
-
if (Buffer2.TYPED_ARRAY_SUPPORT) {
|
|
328
|
-
that = array;
|
|
329
|
-
that.__proto__ = Buffer2.prototype;
|
|
330
|
-
} else {
|
|
331
|
-
that = fromArrayLike(that, array);
|
|
332
|
-
}
|
|
333
|
-
return that;
|
|
334
|
-
}
|
|
335
|
-
function fromObject(that, obj) {
|
|
336
|
-
if (internalIsBuffer(obj)) {
|
|
337
|
-
var len = checked(obj.length) | 0;
|
|
338
|
-
that = createBuffer(that, len);
|
|
339
|
-
if (that.length === 0) {
|
|
340
|
-
return that;
|
|
341
|
-
}
|
|
342
|
-
obj.copy(that, 0, 0, len);
|
|
343
|
-
return that;
|
|
344
|
-
}
|
|
345
|
-
if (obj) {
|
|
346
|
-
if (typeof ArrayBuffer !== "undefined" && obj.buffer instanceof ArrayBuffer || "length" in obj) {
|
|
347
|
-
if (typeof obj.length !== "number" || isnan(obj.length)) {
|
|
348
|
-
return createBuffer(that, 0);
|
|
349
|
-
}
|
|
350
|
-
return fromArrayLike(that, obj);
|
|
351
|
-
}
|
|
352
|
-
if (obj.type === "Buffer" && isArray(obj.data)) {
|
|
353
|
-
return fromArrayLike(that, obj.data);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.");
|
|
357
|
-
}
|
|
358
|
-
function checked(length) {
|
|
359
|
-
if (length >= kMaxLength()) {
|
|
360
|
-
throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + kMaxLength().toString(16) + " bytes");
|
|
361
|
-
}
|
|
362
|
-
return length | 0;
|
|
363
|
-
}
|
|
364
|
-
Buffer2.isBuffer = isBuffer;
|
|
365
|
-
function internalIsBuffer(b) {
|
|
366
|
-
return !!(b != null && b._isBuffer);
|
|
367
|
-
}
|
|
368
|
-
Buffer2.compare = function compare(a, b) {
|
|
369
|
-
if (!internalIsBuffer(a) || !internalIsBuffer(b)) {
|
|
370
|
-
throw new TypeError("Arguments must be Buffers");
|
|
371
|
-
}
|
|
372
|
-
if (a === b) return 0;
|
|
373
|
-
var x = a.length;
|
|
374
|
-
var y = b.length;
|
|
375
|
-
for (var i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
376
|
-
if (a[i] !== b[i]) {
|
|
377
|
-
x = a[i];
|
|
378
|
-
y = b[i];
|
|
379
|
-
break;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
if (x < y) return -1;
|
|
383
|
-
if (y < x) return 1;
|
|
384
|
-
return 0;
|
|
385
|
-
};
|
|
386
|
-
Buffer2.isEncoding = function isEncoding(encoding) {
|
|
387
|
-
switch (String(encoding).toLowerCase()) {
|
|
388
|
-
case "hex":
|
|
389
|
-
case "utf8":
|
|
390
|
-
case "utf-8":
|
|
391
|
-
case "ascii":
|
|
392
|
-
case "latin1":
|
|
393
|
-
case "binary":
|
|
394
|
-
case "base64":
|
|
395
|
-
case "ucs2":
|
|
396
|
-
case "ucs-2":
|
|
397
|
-
case "utf16le":
|
|
398
|
-
case "utf-16le":
|
|
399
|
-
return true;
|
|
400
|
-
default:
|
|
401
|
-
return false;
|
|
402
|
-
}
|
|
403
|
-
};
|
|
404
|
-
Buffer2.concat = function concat(list, length) {
|
|
405
|
-
if (!isArray(list)) {
|
|
406
|
-
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
407
|
-
}
|
|
408
|
-
if (list.length === 0) {
|
|
409
|
-
return Buffer2.alloc(0);
|
|
410
|
-
}
|
|
411
|
-
var i;
|
|
412
|
-
if (length === void 0) {
|
|
413
|
-
length = 0;
|
|
414
|
-
for (i = 0; i < list.length; ++i) {
|
|
415
|
-
length += list[i].length;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
var buffer = Buffer2.allocUnsafe(length);
|
|
419
|
-
var pos = 0;
|
|
420
|
-
for (i = 0; i < list.length; ++i) {
|
|
421
|
-
var buf = list[i];
|
|
422
|
-
if (!internalIsBuffer(buf)) {
|
|
423
|
-
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
424
|
-
}
|
|
425
|
-
buf.copy(buffer, pos);
|
|
426
|
-
pos += buf.length;
|
|
427
|
-
}
|
|
428
|
-
return buffer;
|
|
429
|
-
};
|
|
430
|
-
function byteLength(string, encoding) {
|
|
431
|
-
if (internalIsBuffer(string)) {
|
|
432
|
-
return string.length;
|
|
433
|
-
}
|
|
434
|
-
if (typeof ArrayBuffer !== "undefined" && typeof ArrayBuffer.isView === "function" && (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
|
|
435
|
-
return string.byteLength;
|
|
436
|
-
}
|
|
437
|
-
if (typeof string !== "string") {
|
|
438
|
-
string = "" + string;
|
|
439
|
-
}
|
|
440
|
-
var len = string.length;
|
|
441
|
-
if (len === 0) return 0;
|
|
442
|
-
var loweredCase = false;
|
|
443
|
-
for (; ; ) {
|
|
444
|
-
switch (encoding) {
|
|
445
|
-
case "ascii":
|
|
446
|
-
case "latin1":
|
|
447
|
-
case "binary":
|
|
448
|
-
return len;
|
|
449
|
-
case "utf8":
|
|
450
|
-
case "utf-8":
|
|
451
|
-
case void 0:
|
|
452
|
-
return utf8ToBytes(string).length;
|
|
453
|
-
case "ucs2":
|
|
454
|
-
case "ucs-2":
|
|
455
|
-
case "utf16le":
|
|
456
|
-
case "utf-16le":
|
|
457
|
-
return len * 2;
|
|
458
|
-
case "hex":
|
|
459
|
-
return len >>> 1;
|
|
460
|
-
case "base64":
|
|
461
|
-
return base64ToBytes(string).length;
|
|
462
|
-
default:
|
|
463
|
-
if (loweredCase) return utf8ToBytes(string).length;
|
|
464
|
-
encoding = ("" + encoding).toLowerCase();
|
|
465
|
-
loweredCase = true;
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
Buffer2.byteLength = byteLength;
|
|
470
|
-
function slowToString(encoding, start, end) {
|
|
471
|
-
var loweredCase = false;
|
|
472
|
-
if (start === void 0 || start < 0) {
|
|
473
|
-
start = 0;
|
|
474
|
-
}
|
|
475
|
-
if (start > this.length) {
|
|
476
|
-
return "";
|
|
477
|
-
}
|
|
478
|
-
if (end === void 0 || end > this.length) {
|
|
479
|
-
end = this.length;
|
|
480
|
-
}
|
|
481
|
-
if (end <= 0) {
|
|
482
|
-
return "";
|
|
483
|
-
}
|
|
484
|
-
end >>>= 0;
|
|
485
|
-
start >>>= 0;
|
|
486
|
-
if (end <= start) {
|
|
487
|
-
return "";
|
|
488
|
-
}
|
|
489
|
-
if (!encoding) encoding = "utf8";
|
|
490
|
-
while (true) {
|
|
491
|
-
switch (encoding) {
|
|
492
|
-
case "hex":
|
|
493
|
-
return hexSlice(this, start, end);
|
|
494
|
-
case "utf8":
|
|
495
|
-
case "utf-8":
|
|
496
|
-
return utf8Slice(this, start, end);
|
|
497
|
-
case "ascii":
|
|
498
|
-
return asciiSlice(this, start, end);
|
|
499
|
-
case "latin1":
|
|
500
|
-
case "binary":
|
|
501
|
-
return latin1Slice(this, start, end);
|
|
502
|
-
case "base64":
|
|
503
|
-
return base64Slice(this, start, end);
|
|
504
|
-
case "ucs2":
|
|
505
|
-
case "ucs-2":
|
|
506
|
-
case "utf16le":
|
|
507
|
-
case "utf-16le":
|
|
508
|
-
return utf16leSlice(this, start, end);
|
|
509
|
-
default:
|
|
510
|
-
if (loweredCase) throw new TypeError("Unknown encoding: " + encoding);
|
|
511
|
-
encoding = (encoding + "").toLowerCase();
|
|
512
|
-
loweredCase = true;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
Buffer2.prototype._isBuffer = true;
|
|
517
|
-
function swap(b, n, m) {
|
|
518
|
-
var i = b[n];
|
|
519
|
-
b[n] = b[m];
|
|
520
|
-
b[m] = i;
|
|
521
|
-
}
|
|
522
|
-
Buffer2.prototype.swap16 = function swap16() {
|
|
523
|
-
var len = this.length;
|
|
524
|
-
if (len % 2 !== 0) {
|
|
525
|
-
throw new RangeError("Buffer size must be a multiple of 16-bits");
|
|
526
|
-
}
|
|
527
|
-
for (var i = 0; i < len; i += 2) {
|
|
528
|
-
swap(this, i, i + 1);
|
|
529
|
-
}
|
|
530
|
-
return this;
|
|
531
|
-
};
|
|
532
|
-
Buffer2.prototype.swap32 = function swap32() {
|
|
533
|
-
var len = this.length;
|
|
534
|
-
if (len % 4 !== 0) {
|
|
535
|
-
throw new RangeError("Buffer size must be a multiple of 32-bits");
|
|
536
|
-
}
|
|
537
|
-
for (var i = 0; i < len; i += 4) {
|
|
538
|
-
swap(this, i, i + 3);
|
|
539
|
-
swap(this, i + 1, i + 2);
|
|
540
|
-
}
|
|
541
|
-
return this;
|
|
542
|
-
};
|
|
543
|
-
Buffer2.prototype.swap64 = function swap64() {
|
|
544
|
-
var len = this.length;
|
|
545
|
-
if (len % 8 !== 0) {
|
|
546
|
-
throw new RangeError("Buffer size must be a multiple of 64-bits");
|
|
547
|
-
}
|
|
548
|
-
for (var i = 0; i < len; i += 8) {
|
|
549
|
-
swap(this, i, i + 7);
|
|
550
|
-
swap(this, i + 1, i + 6);
|
|
551
|
-
swap(this, i + 2, i + 5);
|
|
552
|
-
swap(this, i + 3, i + 4);
|
|
553
|
-
}
|
|
554
|
-
return this;
|
|
555
|
-
};
|
|
556
|
-
Buffer2.prototype.toString = function toString2() {
|
|
557
|
-
var length = this.length | 0;
|
|
558
|
-
if (length === 0) return "";
|
|
559
|
-
if (arguments.length === 0) return utf8Slice(this, 0, length);
|
|
560
|
-
return slowToString.apply(this, arguments);
|
|
561
|
-
};
|
|
562
|
-
Buffer2.prototype.equals = function equals(b) {
|
|
563
|
-
if (!internalIsBuffer(b)) throw new TypeError("Argument must be a Buffer");
|
|
564
|
-
if (this === b) return true;
|
|
565
|
-
return Buffer2.compare(this, b) === 0;
|
|
566
|
-
};
|
|
567
|
-
Buffer2.prototype.inspect = function inspect() {
|
|
568
|
-
var str = "";
|
|
569
|
-
var max = INSPECT_MAX_BYTES;
|
|
570
|
-
if (this.length > 0) {
|
|
571
|
-
str = this.toString("hex", 0, max).match(/.{2}/g).join(" ");
|
|
572
|
-
if (this.length > max) str += " ... ";
|
|
573
|
-
}
|
|
574
|
-
return "<Buffer " + str + ">";
|
|
575
|
-
};
|
|
576
|
-
Buffer2.prototype.compare = function compare2(target, start, end, thisStart, thisEnd) {
|
|
577
|
-
if (!internalIsBuffer(target)) {
|
|
578
|
-
throw new TypeError("Argument must be a Buffer");
|
|
579
|
-
}
|
|
580
|
-
if (start === void 0) {
|
|
581
|
-
start = 0;
|
|
582
|
-
}
|
|
583
|
-
if (end === void 0) {
|
|
584
|
-
end = target ? target.length : 0;
|
|
585
|
-
}
|
|
586
|
-
if (thisStart === void 0) {
|
|
587
|
-
thisStart = 0;
|
|
588
|
-
}
|
|
589
|
-
if (thisEnd === void 0) {
|
|
590
|
-
thisEnd = this.length;
|
|
591
|
-
}
|
|
592
|
-
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
593
|
-
throw new RangeError("out of range index");
|
|
594
|
-
}
|
|
595
|
-
if (thisStart >= thisEnd && start >= end) {
|
|
596
|
-
return 0;
|
|
597
|
-
}
|
|
598
|
-
if (thisStart >= thisEnd) {
|
|
599
|
-
return -1;
|
|
600
|
-
}
|
|
601
|
-
if (start >= end) {
|
|
602
|
-
return 1;
|
|
603
|
-
}
|
|
604
|
-
start >>>= 0;
|
|
605
|
-
end >>>= 0;
|
|
606
|
-
thisStart >>>= 0;
|
|
607
|
-
thisEnd >>>= 0;
|
|
608
|
-
if (this === target) return 0;
|
|
609
|
-
var x = thisEnd - thisStart;
|
|
610
|
-
var y = end - start;
|
|
611
|
-
var len = Math.min(x, y);
|
|
612
|
-
var thisCopy = this.slice(thisStart, thisEnd);
|
|
613
|
-
var targetCopy = target.slice(start, end);
|
|
614
|
-
for (var i = 0; i < len; ++i) {
|
|
615
|
-
if (thisCopy[i] !== targetCopy[i]) {
|
|
616
|
-
x = thisCopy[i];
|
|
617
|
-
y = targetCopy[i];
|
|
618
|
-
break;
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
if (x < y) return -1;
|
|
622
|
-
if (y < x) return 1;
|
|
623
|
-
return 0;
|
|
624
|
-
};
|
|
625
|
-
function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
|
|
626
|
-
if (buffer.length === 0) return -1;
|
|
627
|
-
if (typeof byteOffset === "string") {
|
|
628
|
-
encoding = byteOffset;
|
|
629
|
-
byteOffset = 0;
|
|
630
|
-
} else if (byteOffset > 2147483647) {
|
|
631
|
-
byteOffset = 2147483647;
|
|
632
|
-
} else if (byteOffset < -2147483648) {
|
|
633
|
-
byteOffset = -2147483648;
|
|
634
|
-
}
|
|
635
|
-
byteOffset = +byteOffset;
|
|
636
|
-
if (isNaN(byteOffset)) {
|
|
637
|
-
byteOffset = dir ? 0 : buffer.length - 1;
|
|
638
|
-
}
|
|
639
|
-
if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
|
|
640
|
-
if (byteOffset >= buffer.length) {
|
|
641
|
-
if (dir) return -1;
|
|
642
|
-
else byteOffset = buffer.length - 1;
|
|
643
|
-
} else if (byteOffset < 0) {
|
|
644
|
-
if (dir) byteOffset = 0;
|
|
645
|
-
else return -1;
|
|
646
|
-
}
|
|
647
|
-
if (typeof val === "string") {
|
|
648
|
-
val = Buffer2.from(val, encoding);
|
|
649
|
-
}
|
|
650
|
-
if (internalIsBuffer(val)) {
|
|
651
|
-
if (val.length === 0) {
|
|
652
|
-
return -1;
|
|
653
|
-
}
|
|
654
|
-
return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
|
|
655
|
-
} else if (typeof val === "number") {
|
|
656
|
-
val = val & 255;
|
|
657
|
-
if (Buffer2.TYPED_ARRAY_SUPPORT && typeof Uint8Array.prototype.indexOf === "function") {
|
|
658
|
-
if (dir) {
|
|
659
|
-
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
|
|
660
|
-
} else {
|
|
661
|
-
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
|
|
665
|
-
}
|
|
666
|
-
throw new TypeError("val must be string, number or Buffer");
|
|
667
|
-
}
|
|
668
|
-
function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
|
|
669
|
-
var indexSize = 1;
|
|
670
|
-
var arrLength = arr.length;
|
|
671
|
-
var valLength = val.length;
|
|
672
|
-
if (encoding !== void 0) {
|
|
673
|
-
encoding = String(encoding).toLowerCase();
|
|
674
|
-
if (encoding === "ucs2" || encoding === "ucs-2" || encoding === "utf16le" || encoding === "utf-16le") {
|
|
675
|
-
if (arr.length < 2 || val.length < 2) {
|
|
676
|
-
return -1;
|
|
677
|
-
}
|
|
678
|
-
indexSize = 2;
|
|
679
|
-
arrLength /= 2;
|
|
680
|
-
valLength /= 2;
|
|
681
|
-
byteOffset /= 2;
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
function read2(buf, i2) {
|
|
685
|
-
if (indexSize === 1) {
|
|
686
|
-
return buf[i2];
|
|
687
|
-
} else {
|
|
688
|
-
return buf.readUInt16BE(i2 * indexSize);
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
var i;
|
|
692
|
-
if (dir) {
|
|
693
|
-
var foundIndex = -1;
|
|
694
|
-
for (i = byteOffset; i < arrLength; i++) {
|
|
695
|
-
if (read2(arr, i) === read2(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
696
|
-
if (foundIndex === -1) foundIndex = i;
|
|
697
|
-
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
|
|
698
|
-
} else {
|
|
699
|
-
if (foundIndex !== -1) i -= i - foundIndex;
|
|
700
|
-
foundIndex = -1;
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
} else {
|
|
704
|
-
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
|
|
705
|
-
for (i = byteOffset; i >= 0; i--) {
|
|
706
|
-
var found = true;
|
|
707
|
-
for (var j = 0; j < valLength; j++) {
|
|
708
|
-
if (read2(arr, i + j) !== read2(val, j)) {
|
|
709
|
-
found = false;
|
|
710
|
-
break;
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
if (found) return i;
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
return -1;
|
|
717
|
-
}
|
|
718
|
-
Buffer2.prototype.includes = function includes(val, byteOffset, encoding) {
|
|
719
|
-
return this.indexOf(val, byteOffset, encoding) !== -1;
|
|
720
|
-
};
|
|
721
|
-
Buffer2.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
|
|
722
|
-
return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
|
|
723
|
-
};
|
|
724
|
-
Buffer2.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
|
|
725
|
-
return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
|
|
726
|
-
};
|
|
727
|
-
function hexWrite(buf, string, offset, length) {
|
|
728
|
-
offset = Number(offset) || 0;
|
|
729
|
-
var remaining = buf.length - offset;
|
|
730
|
-
if (!length) {
|
|
731
|
-
length = remaining;
|
|
732
|
-
} else {
|
|
733
|
-
length = Number(length);
|
|
734
|
-
if (length > remaining) {
|
|
735
|
-
length = remaining;
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
var strLen = string.length;
|
|
739
|
-
if (strLen % 2 !== 0) throw new TypeError("Invalid hex string");
|
|
740
|
-
if (length > strLen / 2) {
|
|
741
|
-
length = strLen / 2;
|
|
742
|
-
}
|
|
743
|
-
for (var i = 0; i < length; ++i) {
|
|
744
|
-
var parsed = parseInt(string.substr(i * 2, 2), 16);
|
|
745
|
-
if (isNaN(parsed)) return i;
|
|
746
|
-
buf[offset + i] = parsed;
|
|
747
|
-
}
|
|
748
|
-
return i;
|
|
749
|
-
}
|
|
750
|
-
function utf8Write(buf, string, offset, length) {
|
|
751
|
-
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
|
|
752
|
-
}
|
|
753
|
-
function asciiWrite(buf, string, offset, length) {
|
|
754
|
-
return blitBuffer(asciiToBytes(string), buf, offset, length);
|
|
755
|
-
}
|
|
756
|
-
function latin1Write(buf, string, offset, length) {
|
|
757
|
-
return asciiWrite(buf, string, offset, length);
|
|
758
|
-
}
|
|
759
|
-
function base64Write(buf, string, offset, length) {
|
|
760
|
-
return blitBuffer(base64ToBytes(string), buf, offset, length);
|
|
761
|
-
}
|
|
762
|
-
function ucs2Write(buf, string, offset, length) {
|
|
763
|
-
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
|
|
764
|
-
}
|
|
765
|
-
Buffer2.prototype.write = function write2(string, offset, length, encoding) {
|
|
766
|
-
if (offset === void 0) {
|
|
767
|
-
encoding = "utf8";
|
|
768
|
-
length = this.length;
|
|
769
|
-
offset = 0;
|
|
770
|
-
} else if (length === void 0 && typeof offset === "string") {
|
|
771
|
-
encoding = offset;
|
|
772
|
-
length = this.length;
|
|
773
|
-
offset = 0;
|
|
774
|
-
} else if (isFinite(offset)) {
|
|
775
|
-
offset = offset | 0;
|
|
776
|
-
if (isFinite(length)) {
|
|
777
|
-
length = length | 0;
|
|
778
|
-
if (encoding === void 0) encoding = "utf8";
|
|
779
|
-
} else {
|
|
780
|
-
encoding = length;
|
|
781
|
-
length = void 0;
|
|
782
|
-
}
|
|
783
|
-
} else {
|
|
784
|
-
throw new Error(
|
|
785
|
-
"Buffer.write(string, encoding, offset[, length]) is no longer supported"
|
|
786
|
-
);
|
|
787
|
-
}
|
|
788
|
-
var remaining = this.length - offset;
|
|
789
|
-
if (length === void 0 || length > remaining) length = remaining;
|
|
790
|
-
if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
|
|
791
|
-
throw new RangeError("Attempt to write outside buffer bounds");
|
|
792
|
-
}
|
|
793
|
-
if (!encoding) encoding = "utf8";
|
|
794
|
-
var loweredCase = false;
|
|
795
|
-
for (; ; ) {
|
|
796
|
-
switch (encoding) {
|
|
797
|
-
case "hex":
|
|
798
|
-
return hexWrite(this, string, offset, length);
|
|
799
|
-
case "utf8":
|
|
800
|
-
case "utf-8":
|
|
801
|
-
return utf8Write(this, string, offset, length);
|
|
802
|
-
case "ascii":
|
|
803
|
-
return asciiWrite(this, string, offset, length);
|
|
804
|
-
case "latin1":
|
|
805
|
-
case "binary":
|
|
806
|
-
return latin1Write(this, string, offset, length);
|
|
807
|
-
case "base64":
|
|
808
|
-
return base64Write(this, string, offset, length);
|
|
809
|
-
case "ucs2":
|
|
810
|
-
case "ucs-2":
|
|
811
|
-
case "utf16le":
|
|
812
|
-
case "utf-16le":
|
|
813
|
-
return ucs2Write(this, string, offset, length);
|
|
814
|
-
default:
|
|
815
|
-
if (loweredCase) throw new TypeError("Unknown encoding: " + encoding);
|
|
816
|
-
encoding = ("" + encoding).toLowerCase();
|
|
817
|
-
loweredCase = true;
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
};
|
|
821
|
-
Buffer2.prototype.toJSON = function toJSON() {
|
|
822
|
-
return {
|
|
823
|
-
type: "Buffer",
|
|
824
|
-
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
825
|
-
};
|
|
826
|
-
};
|
|
827
|
-
function base64Slice(buf, start, end) {
|
|
828
|
-
if (start === 0 && end === buf.length) {
|
|
829
|
-
return fromByteArray(buf);
|
|
830
|
-
} else {
|
|
831
|
-
return fromByteArray(buf.slice(start, end));
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
function utf8Slice(buf, start, end) {
|
|
835
|
-
end = Math.min(buf.length, end);
|
|
836
|
-
var res = [];
|
|
837
|
-
var i = start;
|
|
838
|
-
while (i < end) {
|
|
839
|
-
var firstByte = buf[i];
|
|
840
|
-
var codePoint = null;
|
|
841
|
-
var bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
|
|
842
|
-
if (i + bytesPerSequence <= end) {
|
|
843
|
-
var secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
844
|
-
switch (bytesPerSequence) {
|
|
845
|
-
case 1:
|
|
846
|
-
if (firstByte < 128) {
|
|
847
|
-
codePoint = firstByte;
|
|
848
|
-
}
|
|
849
|
-
break;
|
|
850
|
-
case 2:
|
|
851
|
-
secondByte = buf[i + 1];
|
|
852
|
-
if ((secondByte & 192) === 128) {
|
|
853
|
-
tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
|
|
854
|
-
if (tempCodePoint > 127) {
|
|
855
|
-
codePoint = tempCodePoint;
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
break;
|
|
859
|
-
case 3:
|
|
860
|
-
secondByte = buf[i + 1];
|
|
861
|
-
thirdByte = buf[i + 2];
|
|
862
|
-
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
|
|
863
|
-
tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
|
|
864
|
-
if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {
|
|
865
|
-
codePoint = tempCodePoint;
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
break;
|
|
869
|
-
case 4:
|
|
870
|
-
secondByte = buf[i + 1];
|
|
871
|
-
thirdByte = buf[i + 2];
|
|
872
|
-
fourthByte = buf[i + 3];
|
|
873
|
-
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
|
|
874
|
-
tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
|
|
875
|
-
if (tempCodePoint > 65535 && tempCodePoint < 1114112) {
|
|
876
|
-
codePoint = tempCodePoint;
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
if (codePoint === null) {
|
|
882
|
-
codePoint = 65533;
|
|
883
|
-
bytesPerSequence = 1;
|
|
884
|
-
} else if (codePoint > 65535) {
|
|
885
|
-
codePoint -= 65536;
|
|
886
|
-
res.push(codePoint >>> 10 & 1023 | 55296);
|
|
887
|
-
codePoint = 56320 | codePoint & 1023;
|
|
888
|
-
}
|
|
889
|
-
res.push(codePoint);
|
|
890
|
-
i += bytesPerSequence;
|
|
891
|
-
}
|
|
892
|
-
return decodeCodePointsArray(res);
|
|
893
|
-
}
|
|
894
|
-
var MAX_ARGUMENTS_LENGTH = 4096;
|
|
895
|
-
function decodeCodePointsArray(codePoints) {
|
|
896
|
-
var len = codePoints.length;
|
|
897
|
-
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
898
|
-
return String.fromCharCode.apply(String, codePoints);
|
|
899
|
-
}
|
|
900
|
-
var res = "";
|
|
901
|
-
var i = 0;
|
|
902
|
-
while (i < len) {
|
|
903
|
-
res += String.fromCharCode.apply(
|
|
904
|
-
String,
|
|
905
|
-
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
906
|
-
);
|
|
907
|
-
}
|
|
908
|
-
return res;
|
|
909
|
-
}
|
|
910
|
-
function asciiSlice(buf, start, end) {
|
|
911
|
-
var ret = "";
|
|
912
|
-
end = Math.min(buf.length, end);
|
|
913
|
-
for (var i = start; i < end; ++i) {
|
|
914
|
-
ret += String.fromCharCode(buf[i] & 127);
|
|
915
|
-
}
|
|
916
|
-
return ret;
|
|
917
|
-
}
|
|
918
|
-
function latin1Slice(buf, start, end) {
|
|
919
|
-
var ret = "";
|
|
920
|
-
end = Math.min(buf.length, end);
|
|
921
|
-
for (var i = start; i < end; ++i) {
|
|
922
|
-
ret += String.fromCharCode(buf[i]);
|
|
923
|
-
}
|
|
924
|
-
return ret;
|
|
925
|
-
}
|
|
926
|
-
function hexSlice(buf, start, end) {
|
|
927
|
-
var len = buf.length;
|
|
928
|
-
if (!start || start < 0) start = 0;
|
|
929
|
-
if (!end || end < 0 || end > len) end = len;
|
|
930
|
-
var out = "";
|
|
931
|
-
for (var i = start; i < end; ++i) {
|
|
932
|
-
out += toHex(buf[i]);
|
|
933
|
-
}
|
|
934
|
-
return out;
|
|
935
|
-
}
|
|
936
|
-
function utf16leSlice(buf, start, end) {
|
|
937
|
-
var bytes = buf.slice(start, end);
|
|
938
|
-
var res = "";
|
|
939
|
-
for (var i = 0; i < bytes.length; i += 2) {
|
|
940
|
-
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
|
|
941
|
-
}
|
|
942
|
-
return res;
|
|
943
|
-
}
|
|
944
|
-
Buffer2.prototype.slice = function slice(start, end) {
|
|
945
|
-
var len = this.length;
|
|
946
|
-
start = ~~start;
|
|
947
|
-
end = end === void 0 ? len : ~~end;
|
|
948
|
-
if (start < 0) {
|
|
949
|
-
start += len;
|
|
950
|
-
if (start < 0) start = 0;
|
|
951
|
-
} else if (start > len) {
|
|
952
|
-
start = len;
|
|
953
|
-
}
|
|
954
|
-
if (end < 0) {
|
|
955
|
-
end += len;
|
|
956
|
-
if (end < 0) end = 0;
|
|
957
|
-
} else if (end > len) {
|
|
958
|
-
end = len;
|
|
959
|
-
}
|
|
960
|
-
if (end < start) end = start;
|
|
961
|
-
var newBuf;
|
|
962
|
-
if (Buffer2.TYPED_ARRAY_SUPPORT) {
|
|
963
|
-
newBuf = this.subarray(start, end);
|
|
964
|
-
newBuf.__proto__ = Buffer2.prototype;
|
|
965
|
-
} else {
|
|
966
|
-
var sliceLen = end - start;
|
|
967
|
-
newBuf = new Buffer2(sliceLen, void 0);
|
|
968
|
-
for (var i = 0; i < sliceLen; ++i) {
|
|
969
|
-
newBuf[i] = this[i + start];
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
return newBuf;
|
|
973
|
-
};
|
|
974
|
-
function checkOffset(offset, ext, length) {
|
|
975
|
-
if (offset % 1 !== 0 || offset < 0) throw new RangeError("offset is not uint");
|
|
976
|
-
if (offset + ext > length) throw new RangeError("Trying to access beyond buffer length");
|
|
977
|
-
}
|
|
978
|
-
Buffer2.prototype.readUIntLE = function readUIntLE(offset, byteLength2, noAssert) {
|
|
979
|
-
offset = offset | 0;
|
|
980
|
-
byteLength2 = byteLength2 | 0;
|
|
981
|
-
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
982
|
-
var val = this[offset];
|
|
983
|
-
var mul = 1;
|
|
984
|
-
var i = 0;
|
|
985
|
-
while (++i < byteLength2 && (mul *= 256)) {
|
|
986
|
-
val += this[offset + i] * mul;
|
|
987
|
-
}
|
|
988
|
-
return val;
|
|
989
|
-
};
|
|
990
|
-
Buffer2.prototype.readUIntBE = function readUIntBE(offset, byteLength2, noAssert) {
|
|
991
|
-
offset = offset | 0;
|
|
992
|
-
byteLength2 = byteLength2 | 0;
|
|
993
|
-
if (!noAssert) {
|
|
994
|
-
checkOffset(offset, byteLength2, this.length);
|
|
995
|
-
}
|
|
996
|
-
var val = this[offset + --byteLength2];
|
|
997
|
-
var mul = 1;
|
|
998
|
-
while (byteLength2 > 0 && (mul *= 256)) {
|
|
999
|
-
val += this[offset + --byteLength2] * mul;
|
|
1000
|
-
}
|
|
1001
|
-
return val;
|
|
1002
|
-
};
|
|
1003
|
-
Buffer2.prototype.readUInt8 = function readUInt8(offset, noAssert) {
|
|
1004
|
-
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1005
|
-
return this[offset];
|
|
1006
|
-
};
|
|
1007
|
-
Buffer2.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
|
|
1008
|
-
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1009
|
-
return this[offset] | this[offset + 1] << 8;
|
|
1010
|
-
};
|
|
1011
|
-
Buffer2.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
|
|
1012
|
-
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1013
|
-
return this[offset] << 8 | this[offset + 1];
|
|
1014
|
-
};
|
|
1015
|
-
Buffer2.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
|
|
1016
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1017
|
-
return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;
|
|
1018
|
-
};
|
|
1019
|
-
Buffer2.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
|
|
1020
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1021
|
-
return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
|
|
1022
|
-
};
|
|
1023
|
-
Buffer2.prototype.readIntLE = function readIntLE(offset, byteLength2, noAssert) {
|
|
1024
|
-
offset = offset | 0;
|
|
1025
|
-
byteLength2 = byteLength2 | 0;
|
|
1026
|
-
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1027
|
-
var val = this[offset];
|
|
1028
|
-
var mul = 1;
|
|
1029
|
-
var i = 0;
|
|
1030
|
-
while (++i < byteLength2 && (mul *= 256)) {
|
|
1031
|
-
val += this[offset + i] * mul;
|
|
1032
|
-
}
|
|
1033
|
-
mul *= 128;
|
|
1034
|
-
if (val >= mul) val -= Math.pow(2, 8 * byteLength2);
|
|
1035
|
-
return val;
|
|
1036
|
-
};
|
|
1037
|
-
Buffer2.prototype.readIntBE = function readIntBE(offset, byteLength2, noAssert) {
|
|
1038
|
-
offset = offset | 0;
|
|
1039
|
-
byteLength2 = byteLength2 | 0;
|
|
1040
|
-
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1041
|
-
var i = byteLength2;
|
|
1042
|
-
var mul = 1;
|
|
1043
|
-
var val = this[offset + --i];
|
|
1044
|
-
while (i > 0 && (mul *= 256)) {
|
|
1045
|
-
val += this[offset + --i] * mul;
|
|
1046
|
-
}
|
|
1047
|
-
mul *= 128;
|
|
1048
|
-
if (val >= mul) val -= Math.pow(2, 8 * byteLength2);
|
|
1049
|
-
return val;
|
|
1050
|
-
};
|
|
1051
|
-
Buffer2.prototype.readInt8 = function readInt8(offset, noAssert) {
|
|
1052
|
-
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1053
|
-
if (!(this[offset] & 128)) return this[offset];
|
|
1054
|
-
return (255 - this[offset] + 1) * -1;
|
|
1055
|
-
};
|
|
1056
|
-
Buffer2.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
|
|
1057
|
-
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1058
|
-
var val = this[offset] | this[offset + 1] << 8;
|
|
1059
|
-
return val & 32768 ? val | 4294901760 : val;
|
|
1060
|
-
};
|
|
1061
|
-
Buffer2.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
|
|
1062
|
-
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1063
|
-
var val = this[offset + 1] | this[offset] << 8;
|
|
1064
|
-
return val & 32768 ? val | 4294901760 : val;
|
|
1065
|
-
};
|
|
1066
|
-
Buffer2.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
|
|
1067
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1068
|
-
return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
|
|
1069
|
-
};
|
|
1070
|
-
Buffer2.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
|
|
1071
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1072
|
-
return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
|
|
1073
|
-
};
|
|
1074
|
-
Buffer2.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
|
|
1075
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1076
|
-
return read(this, offset, true, 23, 4);
|
|
1077
|
-
};
|
|
1078
|
-
Buffer2.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
|
|
1079
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1080
|
-
return read(this, offset, false, 23, 4);
|
|
1081
|
-
};
|
|
1082
|
-
Buffer2.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
|
|
1083
|
-
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1084
|
-
return read(this, offset, true, 52, 8);
|
|
1085
|
-
};
|
|
1086
|
-
Buffer2.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
|
|
1087
|
-
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1088
|
-
return read(this, offset, false, 52, 8);
|
|
1089
|
-
};
|
|
1090
|
-
function checkInt(buf, value, offset, ext, max, min) {
|
|
1091
|
-
if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance');
|
|
1092
|
-
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds');
|
|
1093
|
-
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
|
1094
|
-
}
|
|
1095
|
-
Buffer2.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength2, noAssert) {
|
|
1096
|
-
value = +value;
|
|
1097
|
-
offset = offset | 0;
|
|
1098
|
-
byteLength2 = byteLength2 | 0;
|
|
1099
|
-
if (!noAssert) {
|
|
1100
|
-
var maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
1101
|
-
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1102
|
-
}
|
|
1103
|
-
var mul = 1;
|
|
1104
|
-
var i = 0;
|
|
1105
|
-
this[offset] = value & 255;
|
|
1106
|
-
while (++i < byteLength2 && (mul *= 256)) {
|
|
1107
|
-
this[offset + i] = value / mul & 255;
|
|
1108
|
-
}
|
|
1109
|
-
return offset + byteLength2;
|
|
1110
|
-
};
|
|
1111
|
-
Buffer2.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength2, noAssert) {
|
|
1112
|
-
value = +value;
|
|
1113
|
-
offset = offset | 0;
|
|
1114
|
-
byteLength2 = byteLength2 | 0;
|
|
1115
|
-
if (!noAssert) {
|
|
1116
|
-
var maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
1117
|
-
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1118
|
-
}
|
|
1119
|
-
var i = byteLength2 - 1;
|
|
1120
|
-
var mul = 1;
|
|
1121
|
-
this[offset + i] = value & 255;
|
|
1122
|
-
while (--i >= 0 && (mul *= 256)) {
|
|
1123
|
-
this[offset + i] = value / mul & 255;
|
|
1124
|
-
}
|
|
1125
|
-
return offset + byteLength2;
|
|
1126
|
-
};
|
|
1127
|
-
Buffer2.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
|
|
1128
|
-
value = +value;
|
|
1129
|
-
offset = offset | 0;
|
|
1130
|
-
if (!noAssert) checkInt(this, value, offset, 1, 255, 0);
|
|
1131
|
-
if (!Buffer2.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
|
|
1132
|
-
this[offset] = value & 255;
|
|
1133
|
-
return offset + 1;
|
|
1134
|
-
};
|
|
1135
|
-
function objectWriteUInt16(buf, value, offset, littleEndian) {
|
|
1136
|
-
if (value < 0) value = 65535 + value + 1;
|
|
1137
|
-
for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
|
|
1138
|
-
buf[offset + i] = (value & 255 << 8 * (littleEndian ? i : 1 - i)) >>> (littleEndian ? i : 1 - i) * 8;
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
Buffer2.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
|
|
1142
|
-
value = +value;
|
|
1143
|
-
offset = offset | 0;
|
|
1144
|
-
if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);
|
|
1145
|
-
if (Buffer2.TYPED_ARRAY_SUPPORT) {
|
|
1146
|
-
this[offset] = value & 255;
|
|
1147
|
-
this[offset + 1] = value >>> 8;
|
|
1148
|
-
} else {
|
|
1149
|
-
objectWriteUInt16(this, value, offset, true);
|
|
1150
|
-
}
|
|
1151
|
-
return offset + 2;
|
|
1152
|
-
};
|
|
1153
|
-
Buffer2.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
|
|
1154
|
-
value = +value;
|
|
1155
|
-
offset = offset | 0;
|
|
1156
|
-
if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);
|
|
1157
|
-
if (Buffer2.TYPED_ARRAY_SUPPORT) {
|
|
1158
|
-
this[offset] = value >>> 8;
|
|
1159
|
-
this[offset + 1] = value & 255;
|
|
1160
|
-
} else {
|
|
1161
|
-
objectWriteUInt16(this, value, offset, false);
|
|
1162
|
-
}
|
|
1163
|
-
return offset + 2;
|
|
1164
|
-
};
|
|
1165
|
-
function objectWriteUInt32(buf, value, offset, littleEndian) {
|
|
1166
|
-
if (value < 0) value = 4294967295 + value + 1;
|
|
1167
|
-
for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
|
|
1168
|
-
buf[offset + i] = value >>> (littleEndian ? i : 3 - i) * 8 & 255;
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
Buffer2.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
|
|
1172
|
-
value = +value;
|
|
1173
|
-
offset = offset | 0;
|
|
1174
|
-
if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);
|
|
1175
|
-
if (Buffer2.TYPED_ARRAY_SUPPORT) {
|
|
1176
|
-
this[offset + 3] = value >>> 24;
|
|
1177
|
-
this[offset + 2] = value >>> 16;
|
|
1178
|
-
this[offset + 1] = value >>> 8;
|
|
1179
|
-
this[offset] = value & 255;
|
|
1180
|
-
} else {
|
|
1181
|
-
objectWriteUInt32(this, value, offset, true);
|
|
1182
|
-
}
|
|
1183
|
-
return offset + 4;
|
|
1184
|
-
};
|
|
1185
|
-
Buffer2.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
|
|
1186
|
-
value = +value;
|
|
1187
|
-
offset = offset | 0;
|
|
1188
|
-
if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);
|
|
1189
|
-
if (Buffer2.TYPED_ARRAY_SUPPORT) {
|
|
1190
|
-
this[offset] = value >>> 24;
|
|
1191
|
-
this[offset + 1] = value >>> 16;
|
|
1192
|
-
this[offset + 2] = value >>> 8;
|
|
1193
|
-
this[offset + 3] = value & 255;
|
|
1194
|
-
} else {
|
|
1195
|
-
objectWriteUInt32(this, value, offset, false);
|
|
1196
|
-
}
|
|
1197
|
-
return offset + 4;
|
|
1198
|
-
};
|
|
1199
|
-
Buffer2.prototype.writeIntLE = function writeIntLE(value, offset, byteLength2, noAssert) {
|
|
1200
|
-
value = +value;
|
|
1201
|
-
offset = offset | 0;
|
|
1202
|
-
if (!noAssert) {
|
|
1203
|
-
var limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1204
|
-
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1205
|
-
}
|
|
1206
|
-
var i = 0;
|
|
1207
|
-
var mul = 1;
|
|
1208
|
-
var sub = 0;
|
|
1209
|
-
this[offset] = value & 255;
|
|
1210
|
-
while (++i < byteLength2 && (mul *= 256)) {
|
|
1211
|
-
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
1212
|
-
sub = 1;
|
|
1213
|
-
}
|
|
1214
|
-
this[offset + i] = (value / mul >> 0) - sub & 255;
|
|
1215
|
-
}
|
|
1216
|
-
return offset + byteLength2;
|
|
1217
|
-
};
|
|
1218
|
-
Buffer2.prototype.writeIntBE = function writeIntBE(value, offset, byteLength2, noAssert) {
|
|
1219
|
-
value = +value;
|
|
1220
|
-
offset = offset | 0;
|
|
1221
|
-
if (!noAssert) {
|
|
1222
|
-
var limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1223
|
-
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1224
|
-
}
|
|
1225
|
-
var i = byteLength2 - 1;
|
|
1226
|
-
var mul = 1;
|
|
1227
|
-
var sub = 0;
|
|
1228
|
-
this[offset + i] = value & 255;
|
|
1229
|
-
while (--i >= 0 && (mul *= 256)) {
|
|
1230
|
-
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
1231
|
-
sub = 1;
|
|
1232
|
-
}
|
|
1233
|
-
this[offset + i] = (value / mul >> 0) - sub & 255;
|
|
1234
|
-
}
|
|
1235
|
-
return offset + byteLength2;
|
|
1236
|
-
};
|
|
1237
|
-
Buffer2.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
|
|
1238
|
-
value = +value;
|
|
1239
|
-
offset = offset | 0;
|
|
1240
|
-
if (!noAssert) checkInt(this, value, offset, 1, 127, -128);
|
|
1241
|
-
if (!Buffer2.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
|
|
1242
|
-
if (value < 0) value = 255 + value + 1;
|
|
1243
|
-
this[offset] = value & 255;
|
|
1244
|
-
return offset + 1;
|
|
1245
|
-
};
|
|
1246
|
-
Buffer2.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
|
|
1247
|
-
value = +value;
|
|
1248
|
-
offset = offset | 0;
|
|
1249
|
-
if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);
|
|
1250
|
-
if (Buffer2.TYPED_ARRAY_SUPPORT) {
|
|
1251
|
-
this[offset] = value & 255;
|
|
1252
|
-
this[offset + 1] = value >>> 8;
|
|
1253
|
-
} else {
|
|
1254
|
-
objectWriteUInt16(this, value, offset, true);
|
|
1255
|
-
}
|
|
1256
|
-
return offset + 2;
|
|
1257
|
-
};
|
|
1258
|
-
Buffer2.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
|
|
1259
|
-
value = +value;
|
|
1260
|
-
offset = offset | 0;
|
|
1261
|
-
if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);
|
|
1262
|
-
if (Buffer2.TYPED_ARRAY_SUPPORT) {
|
|
1263
|
-
this[offset] = value >>> 8;
|
|
1264
|
-
this[offset + 1] = value & 255;
|
|
1265
|
-
} else {
|
|
1266
|
-
objectWriteUInt16(this, value, offset, false);
|
|
1267
|
-
}
|
|
1268
|
-
return offset + 2;
|
|
1269
|
-
};
|
|
1270
|
-
Buffer2.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
|
|
1271
|
-
value = +value;
|
|
1272
|
-
offset = offset | 0;
|
|
1273
|
-
if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1274
|
-
if (Buffer2.TYPED_ARRAY_SUPPORT) {
|
|
1275
|
-
this[offset] = value & 255;
|
|
1276
|
-
this[offset + 1] = value >>> 8;
|
|
1277
|
-
this[offset + 2] = value >>> 16;
|
|
1278
|
-
this[offset + 3] = value >>> 24;
|
|
1279
|
-
} else {
|
|
1280
|
-
objectWriteUInt32(this, value, offset, true);
|
|
1281
|
-
}
|
|
1282
|
-
return offset + 4;
|
|
1283
|
-
};
|
|
1284
|
-
Buffer2.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
|
|
1285
|
-
value = +value;
|
|
1286
|
-
offset = offset | 0;
|
|
1287
|
-
if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1288
|
-
if (value < 0) value = 4294967295 + value + 1;
|
|
1289
|
-
if (Buffer2.TYPED_ARRAY_SUPPORT) {
|
|
1290
|
-
this[offset] = value >>> 24;
|
|
1291
|
-
this[offset + 1] = value >>> 16;
|
|
1292
|
-
this[offset + 2] = value >>> 8;
|
|
1293
|
-
this[offset + 3] = value & 255;
|
|
1294
|
-
} else {
|
|
1295
|
-
objectWriteUInt32(this, value, offset, false);
|
|
1296
|
-
}
|
|
1297
|
-
return offset + 4;
|
|
1298
|
-
};
|
|
1299
|
-
function checkIEEE754(buf, value, offset, ext, max, min) {
|
|
1300
|
-
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
|
1301
|
-
if (offset < 0) throw new RangeError("Index out of range");
|
|
1302
|
-
}
|
|
1303
|
-
function writeFloat(buf, value, offset, littleEndian, noAssert) {
|
|
1304
|
-
if (!noAssert) {
|
|
1305
|
-
checkIEEE754(buf, value, offset, 4);
|
|
1306
|
-
}
|
|
1307
|
-
write(buf, value, offset, littleEndian, 23, 4);
|
|
1308
|
-
return offset + 4;
|
|
1309
|
-
}
|
|
1310
|
-
Buffer2.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
|
|
1311
|
-
return writeFloat(this, value, offset, true, noAssert);
|
|
1312
|
-
};
|
|
1313
|
-
Buffer2.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
|
|
1314
|
-
return writeFloat(this, value, offset, false, noAssert);
|
|
1315
|
-
};
|
|
1316
|
-
function writeDouble(buf, value, offset, littleEndian, noAssert) {
|
|
1317
|
-
if (!noAssert) {
|
|
1318
|
-
checkIEEE754(buf, value, offset, 8);
|
|
1319
|
-
}
|
|
1320
|
-
write(buf, value, offset, littleEndian, 52, 8);
|
|
1321
|
-
return offset + 8;
|
|
1322
|
-
}
|
|
1323
|
-
Buffer2.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
|
|
1324
|
-
return writeDouble(this, value, offset, true, noAssert);
|
|
1325
|
-
};
|
|
1326
|
-
Buffer2.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
|
|
1327
|
-
return writeDouble(this, value, offset, false, noAssert);
|
|
1328
|
-
};
|
|
1329
|
-
Buffer2.prototype.copy = function copy(target, targetStart, start, end) {
|
|
1330
|
-
if (!start) start = 0;
|
|
1331
|
-
if (!end && end !== 0) end = this.length;
|
|
1332
|
-
if (targetStart >= target.length) targetStart = target.length;
|
|
1333
|
-
if (!targetStart) targetStart = 0;
|
|
1334
|
-
if (end > 0 && end < start) end = start;
|
|
1335
|
-
if (end === start) return 0;
|
|
1336
|
-
if (target.length === 0 || this.length === 0) return 0;
|
|
1337
|
-
if (targetStart < 0) {
|
|
1338
|
-
throw new RangeError("targetStart out of bounds");
|
|
1339
|
-
}
|
|
1340
|
-
if (start < 0 || start >= this.length) throw new RangeError("sourceStart out of bounds");
|
|
1341
|
-
if (end < 0) throw new RangeError("sourceEnd out of bounds");
|
|
1342
|
-
if (end > this.length) end = this.length;
|
|
1343
|
-
if (target.length - targetStart < end - start) {
|
|
1344
|
-
end = target.length - targetStart + start;
|
|
1345
|
-
}
|
|
1346
|
-
var len = end - start;
|
|
1347
|
-
var i;
|
|
1348
|
-
if (this === target && start < targetStart && targetStart < end) {
|
|
1349
|
-
for (i = len - 1; i >= 0; --i) {
|
|
1350
|
-
target[i + targetStart] = this[i + start];
|
|
1351
|
-
}
|
|
1352
|
-
} else if (len < 1e3 || !Buffer2.TYPED_ARRAY_SUPPORT) {
|
|
1353
|
-
for (i = 0; i < len; ++i) {
|
|
1354
|
-
target[i + targetStart] = this[i + start];
|
|
1355
|
-
}
|
|
1356
|
-
} else {
|
|
1357
|
-
Uint8Array.prototype.set.call(
|
|
1358
|
-
target,
|
|
1359
|
-
this.subarray(start, start + len),
|
|
1360
|
-
targetStart
|
|
1361
|
-
);
|
|
1362
|
-
}
|
|
1363
|
-
return len;
|
|
1364
|
-
};
|
|
1365
|
-
Buffer2.prototype.fill = function fill(val, start, end, encoding) {
|
|
1366
|
-
if (typeof val === "string") {
|
|
1367
|
-
if (typeof start === "string") {
|
|
1368
|
-
encoding = start;
|
|
1369
|
-
start = 0;
|
|
1370
|
-
end = this.length;
|
|
1371
|
-
} else if (typeof end === "string") {
|
|
1372
|
-
encoding = end;
|
|
1373
|
-
end = this.length;
|
|
1374
|
-
}
|
|
1375
|
-
if (val.length === 1) {
|
|
1376
|
-
var code = val.charCodeAt(0);
|
|
1377
|
-
if (code < 256) {
|
|
1378
|
-
val = code;
|
|
1379
|
-
}
|
|
1380
|
-
}
|
|
1381
|
-
if (encoding !== void 0 && typeof encoding !== "string") {
|
|
1382
|
-
throw new TypeError("encoding must be a string");
|
|
1383
|
-
}
|
|
1384
|
-
if (typeof encoding === "string" && !Buffer2.isEncoding(encoding)) {
|
|
1385
|
-
throw new TypeError("Unknown encoding: " + encoding);
|
|
1386
|
-
}
|
|
1387
|
-
} else if (typeof val === "number") {
|
|
1388
|
-
val = val & 255;
|
|
1389
|
-
}
|
|
1390
|
-
if (start < 0 || this.length < start || this.length < end) {
|
|
1391
|
-
throw new RangeError("Out of range index");
|
|
1392
|
-
}
|
|
1393
|
-
if (end <= start) {
|
|
1394
|
-
return this;
|
|
1395
|
-
}
|
|
1396
|
-
start = start >>> 0;
|
|
1397
|
-
end = end === void 0 ? this.length : end >>> 0;
|
|
1398
|
-
if (!val) val = 0;
|
|
1399
|
-
var i;
|
|
1400
|
-
if (typeof val === "number") {
|
|
1401
|
-
for (i = start; i < end; ++i) {
|
|
1402
|
-
this[i] = val;
|
|
1403
|
-
}
|
|
1404
|
-
} else {
|
|
1405
|
-
var bytes = internalIsBuffer(val) ? val : utf8ToBytes(new Buffer2(val, encoding).toString());
|
|
1406
|
-
var len = bytes.length;
|
|
1407
|
-
for (i = 0; i < end - start; ++i) {
|
|
1408
|
-
this[i + start] = bytes[i % len];
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
return this;
|
|
1412
|
-
};
|
|
1413
|
-
var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
|
|
1414
|
-
function base64clean(str) {
|
|
1415
|
-
str = stringtrim(str).replace(INVALID_BASE64_RE, "");
|
|
1416
|
-
if (str.length < 2) return "";
|
|
1417
|
-
while (str.length % 4 !== 0) {
|
|
1418
|
-
str = str + "=";
|
|
1419
|
-
}
|
|
1420
|
-
return str;
|
|
1421
|
-
}
|
|
1422
|
-
function stringtrim(str) {
|
|
1423
|
-
if (str.trim) return str.trim();
|
|
1424
|
-
return str.replace(/^\s+|\s+$/g, "");
|
|
1425
|
-
}
|
|
1426
|
-
function toHex(n) {
|
|
1427
|
-
if (n < 16) return "0" + n.toString(16);
|
|
1428
|
-
return n.toString(16);
|
|
1429
|
-
}
|
|
1430
|
-
function utf8ToBytes(string, units) {
|
|
1431
|
-
units = units || Infinity;
|
|
1432
|
-
var codePoint;
|
|
1433
|
-
var length = string.length;
|
|
1434
|
-
var leadSurrogate = null;
|
|
1435
|
-
var bytes = [];
|
|
1436
|
-
for (var i = 0; i < length; ++i) {
|
|
1437
|
-
codePoint = string.charCodeAt(i);
|
|
1438
|
-
if (codePoint > 55295 && codePoint < 57344) {
|
|
1439
|
-
if (!leadSurrogate) {
|
|
1440
|
-
if (codePoint > 56319) {
|
|
1441
|
-
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1442
|
-
continue;
|
|
1443
|
-
} else if (i + 1 === length) {
|
|
1444
|
-
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1445
|
-
continue;
|
|
1446
|
-
}
|
|
1447
|
-
leadSurrogate = codePoint;
|
|
1448
|
-
continue;
|
|
1449
|
-
}
|
|
1450
|
-
if (codePoint < 56320) {
|
|
1451
|
-
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1452
|
-
leadSurrogate = codePoint;
|
|
1453
|
-
continue;
|
|
1454
|
-
}
|
|
1455
|
-
codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;
|
|
1456
|
-
} else if (leadSurrogate) {
|
|
1457
|
-
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1458
|
-
}
|
|
1459
|
-
leadSurrogate = null;
|
|
1460
|
-
if (codePoint < 128) {
|
|
1461
|
-
if ((units -= 1) < 0) break;
|
|
1462
|
-
bytes.push(codePoint);
|
|
1463
|
-
} else if (codePoint < 2048) {
|
|
1464
|
-
if ((units -= 2) < 0) break;
|
|
1465
|
-
bytes.push(
|
|
1466
|
-
codePoint >> 6 | 192,
|
|
1467
|
-
codePoint & 63 | 128
|
|
1468
|
-
);
|
|
1469
|
-
} else if (codePoint < 65536) {
|
|
1470
|
-
if ((units -= 3) < 0) break;
|
|
1471
|
-
bytes.push(
|
|
1472
|
-
codePoint >> 12 | 224,
|
|
1473
|
-
codePoint >> 6 & 63 | 128,
|
|
1474
|
-
codePoint & 63 | 128
|
|
1475
|
-
);
|
|
1476
|
-
} else if (codePoint < 1114112) {
|
|
1477
|
-
if ((units -= 4) < 0) break;
|
|
1478
|
-
bytes.push(
|
|
1479
|
-
codePoint >> 18 | 240,
|
|
1480
|
-
codePoint >> 12 & 63 | 128,
|
|
1481
|
-
codePoint >> 6 & 63 | 128,
|
|
1482
|
-
codePoint & 63 | 128
|
|
1483
|
-
);
|
|
1484
|
-
} else {
|
|
1485
|
-
throw new Error("Invalid code point");
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
return bytes;
|
|
1489
|
-
}
|
|
1490
|
-
function asciiToBytes(str) {
|
|
1491
|
-
var byteArray = [];
|
|
1492
|
-
for (var i = 0; i < str.length; ++i) {
|
|
1493
|
-
byteArray.push(str.charCodeAt(i) & 255);
|
|
1494
|
-
}
|
|
1495
|
-
return byteArray;
|
|
1496
|
-
}
|
|
1497
|
-
function utf16leToBytes(str, units) {
|
|
1498
|
-
var c, hi, lo;
|
|
1499
|
-
var byteArray = [];
|
|
1500
|
-
for (var i = 0; i < str.length; ++i) {
|
|
1501
|
-
if ((units -= 2) < 0) break;
|
|
1502
|
-
c = str.charCodeAt(i);
|
|
1503
|
-
hi = c >> 8;
|
|
1504
|
-
lo = c % 256;
|
|
1505
|
-
byteArray.push(lo);
|
|
1506
|
-
byteArray.push(hi);
|
|
1507
|
-
}
|
|
1508
|
-
return byteArray;
|
|
1509
|
-
}
|
|
1510
|
-
function base64ToBytes(str) {
|
|
1511
|
-
return toByteArray(base64clean(str));
|
|
1512
|
-
}
|
|
1513
|
-
function blitBuffer(src, dst, offset, length) {
|
|
1514
|
-
for (var i = 0; i < length; ++i) {
|
|
1515
|
-
if (i + offset >= dst.length || i >= src.length) break;
|
|
1516
|
-
dst[i + offset] = src[i];
|
|
1517
|
-
}
|
|
1518
|
-
return i;
|
|
1519
|
-
}
|
|
1520
|
-
function isnan(val) {
|
|
1521
|
-
return val !== val;
|
|
1522
|
-
}
|
|
1523
|
-
function isBuffer(obj) {
|
|
1524
|
-
return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj));
|
|
1525
|
-
}
|
|
1526
|
-
function isFastBuffer(obj) {
|
|
1527
|
-
return !!obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
|
|
1528
|
-
}
|
|
1529
|
-
function isSlowBuffer(obj) {
|
|
1530
|
-
return typeof obj.readFloatLE === "function" && typeof obj.slice === "function" && isFastBuffer(obj.slice(0, 0));
|
|
1531
|
-
}
|
|
1532
|
-
var CsvError = class _CsvError extends Error {
|
|
1533
|
-
constructor(code, message, options, ...contexts) {
|
|
1534
|
-
if (Array.isArray(message)) message = message.join(" ").trim();
|
|
1535
|
-
super(message);
|
|
1536
|
-
if (Error.captureStackTrace !== void 0) {
|
|
1537
|
-
Error.captureStackTrace(this, _CsvError);
|
|
1538
|
-
}
|
|
1539
|
-
this.code = code;
|
|
1540
|
-
for (const context of contexts) {
|
|
1541
|
-
for (const key in context) {
|
|
1542
|
-
const value = context[key];
|
|
1543
|
-
this[key] = isBuffer(value) ? value.toString(options.encoding) : value == null ? value : JSON.parse(JSON.stringify(value));
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
}
|
|
1547
|
-
};
|
|
1548
|
-
var is_object = function(obj) {
|
|
1549
|
-
return typeof obj === "object" && obj !== null && !Array.isArray(obj);
|
|
1550
|
-
};
|
|
1551
|
-
var normalize_columns_array = function(columns) {
|
|
1552
|
-
const normalizedColumns = [];
|
|
1553
|
-
for (let i = 0, l = columns.length; i < l; i++) {
|
|
1554
|
-
const column = columns[i];
|
|
1555
|
-
if (column === void 0 || column === null || column === false) {
|
|
1556
|
-
normalizedColumns[i] = { disabled: true };
|
|
1557
|
-
} else if (typeof column === "string") {
|
|
1558
|
-
normalizedColumns[i] = { name: column };
|
|
1559
|
-
} else if (is_object(column)) {
|
|
1560
|
-
if (typeof column.name !== "string") {
|
|
1561
|
-
throw new CsvError("CSV_OPTION_COLUMNS_MISSING_NAME", [
|
|
1562
|
-
"Option columns missing name:",
|
|
1563
|
-
`property "name" is required at position ${i}`,
|
|
1564
|
-
"when column is an object literal"
|
|
1565
|
-
]);
|
|
1566
|
-
}
|
|
1567
|
-
normalizedColumns[i] = column;
|
|
1568
|
-
} else {
|
|
1569
|
-
throw new CsvError("CSV_INVALID_COLUMN_DEFINITION", [
|
|
1570
|
-
"Invalid column definition:",
|
|
1571
|
-
"expect a string or a literal object,",
|
|
1572
|
-
`got ${JSON.stringify(column)} at position ${i}`
|
|
1573
|
-
]);
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
return normalizedColumns;
|
|
1577
|
-
};
|
|
1578
|
-
var ResizeableBuffer = class {
|
|
1579
|
-
constructor(size = 100) {
|
|
1580
|
-
this.size = size;
|
|
1581
|
-
this.length = 0;
|
|
1582
|
-
this.buf = Buffer2.allocUnsafe(size);
|
|
1583
|
-
}
|
|
1584
|
-
prepend(val) {
|
|
1585
|
-
if (isBuffer(val)) {
|
|
1586
|
-
const length = this.length + val.length;
|
|
1587
|
-
if (length >= this.size) {
|
|
1588
|
-
this.resize();
|
|
1589
|
-
if (length >= this.size) {
|
|
1590
|
-
throw Error("INVALID_BUFFER_STATE");
|
|
1591
|
-
}
|
|
1592
|
-
}
|
|
1593
|
-
const buf = this.buf;
|
|
1594
|
-
this.buf = Buffer2.allocUnsafe(this.size);
|
|
1595
|
-
val.copy(this.buf, 0);
|
|
1596
|
-
buf.copy(this.buf, val.length);
|
|
1597
|
-
this.length += val.length;
|
|
1598
|
-
} else {
|
|
1599
|
-
const length = this.length++;
|
|
1600
|
-
if (length === this.size) {
|
|
1601
|
-
this.resize();
|
|
1602
|
-
}
|
|
1603
|
-
const buf = this.clone();
|
|
1604
|
-
this.buf[0] = val;
|
|
1605
|
-
buf.copy(this.buf, 1, 0, length);
|
|
1606
|
-
}
|
|
1607
|
-
}
|
|
1608
|
-
append(val) {
|
|
1609
|
-
const length = this.length++;
|
|
1610
|
-
if (length === this.size) {
|
|
1611
|
-
this.resize();
|
|
1612
|
-
}
|
|
1613
|
-
this.buf[length] = val;
|
|
1614
|
-
}
|
|
1615
|
-
clone() {
|
|
1616
|
-
return Buffer2.from(this.buf.slice(0, this.length));
|
|
1617
|
-
}
|
|
1618
|
-
resize() {
|
|
1619
|
-
const length = this.length;
|
|
1620
|
-
this.size = this.size * 2;
|
|
1621
|
-
const buf = Buffer2.allocUnsafe(this.size);
|
|
1622
|
-
this.buf.copy(buf, 0, 0, length);
|
|
1623
|
-
this.buf = buf;
|
|
1624
|
-
}
|
|
1625
|
-
toString(encoding) {
|
|
1626
|
-
if (encoding) {
|
|
1627
|
-
return this.buf.slice(0, this.length).toString(encoding);
|
|
1628
|
-
} else {
|
|
1629
|
-
return Uint8Array.prototype.slice.call(this.buf.slice(0, this.length));
|
|
1630
|
-
}
|
|
1631
|
-
}
|
|
1632
|
-
toJSON() {
|
|
1633
|
-
return this.toString("utf8");
|
|
1634
|
-
}
|
|
1635
|
-
reset() {
|
|
1636
|
-
this.length = 0;
|
|
1637
|
-
}
|
|
1638
|
-
};
|
|
1639
|
-
var np = 12;
|
|
1640
|
-
var cr$1 = 13;
|
|
1641
|
-
var nl$1 = 10;
|
|
1642
|
-
var space = 32;
|
|
1643
|
-
var tab = 9;
|
|
1644
|
-
var init_state = function(options) {
|
|
1645
|
-
return {
|
|
1646
|
-
bomSkipped: false,
|
|
1647
|
-
bufBytesStart: 0,
|
|
1648
|
-
castField: options.cast_function,
|
|
1649
|
-
commenting: false,
|
|
1650
|
-
// Current error encountered by a record
|
|
1651
|
-
error: void 0,
|
|
1652
|
-
enabled: options.from_line === 1,
|
|
1653
|
-
escaping: false,
|
|
1654
|
-
escapeIsQuote: isBuffer(options.escape) && isBuffer(options.quote) && Buffer2.compare(options.escape, options.quote) === 0,
|
|
1655
|
-
// columns can be `false`, `true`, `Array`
|
|
1656
|
-
expectedRecordLength: Array.isArray(options.columns) ? options.columns.length : void 0,
|
|
1657
|
-
field: new ResizeableBuffer(20),
|
|
1658
|
-
firstLineToHeaders: options.cast_first_line_to_header,
|
|
1659
|
-
needMoreDataSize: Math.max(
|
|
1660
|
-
// Skip if the remaining buffer smaller than comment
|
|
1661
|
-
options.comment !== null ? options.comment.length : 0,
|
|
1662
|
-
...options.delimiter.map((delimiter) => delimiter.length),
|
|
1663
|
-
// Skip if the remaining buffer can be escape sequence
|
|
1664
|
-
options.quote !== null ? options.quote.length : 0
|
|
1665
|
-
),
|
|
1666
|
-
previousBuf: void 0,
|
|
1667
|
-
quoting: false,
|
|
1668
|
-
stop: false,
|
|
1669
|
-
rawBuffer: new ResizeableBuffer(100),
|
|
1670
|
-
record: [],
|
|
1671
|
-
recordHasError: false,
|
|
1672
|
-
record_length: 0,
|
|
1673
|
-
recordDelimiterMaxLength: options.record_delimiter.length === 0 ? 0 : Math.max(...options.record_delimiter.map((v) => v.length)),
|
|
1674
|
-
trimChars: [
|
|
1675
|
-
Buffer2.from(" ", options.encoding)[0],
|
|
1676
|
-
Buffer2.from(" ", options.encoding)[0]
|
|
1677
|
-
],
|
|
1678
|
-
wasQuoting: false,
|
|
1679
|
-
wasRowDelimiter: false,
|
|
1680
|
-
timchars: [
|
|
1681
|
-
Buffer2.from(Buffer2.from([cr$1], "utf8").toString(), options.encoding),
|
|
1682
|
-
Buffer2.from(Buffer2.from([nl$1], "utf8").toString(), options.encoding),
|
|
1683
|
-
Buffer2.from(Buffer2.from([np], "utf8").toString(), options.encoding),
|
|
1684
|
-
Buffer2.from(Buffer2.from([space], "utf8").toString(), options.encoding),
|
|
1685
|
-
Buffer2.from(Buffer2.from([tab], "utf8").toString(), options.encoding)
|
|
1686
|
-
]
|
|
1687
|
-
};
|
|
1688
|
-
};
|
|
1689
|
-
var underscore = function(str) {
|
|
1690
|
-
return str.replace(/([A-Z])/g, function(_, match) {
|
|
1691
|
-
return "_" + match.toLowerCase();
|
|
1692
|
-
});
|
|
1693
|
-
};
|
|
1694
|
-
var normalize_options = function(opts) {
|
|
1695
|
-
const options = {};
|
|
1696
|
-
for (const opt in opts) {
|
|
1697
|
-
options[underscore(opt)] = opts[opt];
|
|
1698
|
-
}
|
|
1699
|
-
if (options.encoding === void 0 || options.encoding === true) {
|
|
1700
|
-
options.encoding = "utf8";
|
|
1701
|
-
} else if (options.encoding === null || options.encoding === false) {
|
|
1702
|
-
options.encoding = null;
|
|
1703
|
-
} else if (typeof options.encoding !== "string" && options.encoding !== null) {
|
|
1704
|
-
throw new CsvError(
|
|
1705
|
-
"CSV_INVALID_OPTION_ENCODING",
|
|
1706
|
-
[
|
|
1707
|
-
"Invalid option encoding:",
|
|
1708
|
-
"encoding must be a string or null to return a buffer,",
|
|
1709
|
-
`got ${JSON.stringify(options.encoding)}`
|
|
1710
|
-
],
|
|
1711
|
-
options
|
|
1712
|
-
);
|
|
1713
|
-
}
|
|
1714
|
-
if (options.bom === void 0 || options.bom === null || options.bom === false) {
|
|
1715
|
-
options.bom = false;
|
|
1716
|
-
} else if (options.bom !== true) {
|
|
1717
|
-
throw new CsvError(
|
|
1718
|
-
"CSV_INVALID_OPTION_BOM",
|
|
1719
|
-
[
|
|
1720
|
-
"Invalid option bom:",
|
|
1721
|
-
"bom must be true,",
|
|
1722
|
-
`got ${JSON.stringify(options.bom)}`
|
|
1723
|
-
],
|
|
1724
|
-
options
|
|
1725
|
-
);
|
|
1726
|
-
}
|
|
1727
|
-
options.cast_function = null;
|
|
1728
|
-
if (options.cast === void 0 || options.cast === null || options.cast === false || options.cast === "") {
|
|
1729
|
-
options.cast = void 0;
|
|
1730
|
-
} else if (typeof options.cast === "function") {
|
|
1731
|
-
options.cast_function = options.cast;
|
|
1732
|
-
options.cast = true;
|
|
1733
|
-
} else if (options.cast !== true) {
|
|
1734
|
-
throw new CsvError(
|
|
1735
|
-
"CSV_INVALID_OPTION_CAST",
|
|
1736
|
-
[
|
|
1737
|
-
"Invalid option cast:",
|
|
1738
|
-
"cast must be true or a function,",
|
|
1739
|
-
`got ${JSON.stringify(options.cast)}`
|
|
1740
|
-
],
|
|
1741
|
-
options
|
|
1742
|
-
);
|
|
1743
|
-
}
|
|
1744
|
-
if (options.cast_date === void 0 || options.cast_date === null || options.cast_date === false || options.cast_date === "") {
|
|
1745
|
-
options.cast_date = false;
|
|
1746
|
-
} else if (options.cast_date === true) {
|
|
1747
|
-
options.cast_date = function(value) {
|
|
1748
|
-
const date = Date.parse(value);
|
|
1749
|
-
return !isNaN(date) ? new Date(date) : value;
|
|
1750
|
-
};
|
|
1751
|
-
} else if (typeof options.cast_date !== "function") {
|
|
1752
|
-
throw new CsvError(
|
|
1753
|
-
"CSV_INVALID_OPTION_CAST_DATE",
|
|
1754
|
-
[
|
|
1755
|
-
"Invalid option cast_date:",
|
|
1756
|
-
"cast_date must be true or a function,",
|
|
1757
|
-
`got ${JSON.stringify(options.cast_date)}`
|
|
1758
|
-
],
|
|
1759
|
-
options
|
|
1760
|
-
);
|
|
1761
|
-
}
|
|
1762
|
-
options.cast_first_line_to_header = null;
|
|
1763
|
-
if (options.columns === true) {
|
|
1764
|
-
options.cast_first_line_to_header = void 0;
|
|
1765
|
-
} else if (typeof options.columns === "function") {
|
|
1766
|
-
options.cast_first_line_to_header = options.columns;
|
|
1767
|
-
options.columns = true;
|
|
1768
|
-
} else if (Array.isArray(options.columns)) {
|
|
1769
|
-
options.columns = normalize_columns_array(options.columns);
|
|
1770
|
-
} else if (options.columns === void 0 || options.columns === null || options.columns === false) {
|
|
1771
|
-
options.columns = false;
|
|
1772
|
-
} else {
|
|
1773
|
-
throw new CsvError(
|
|
1774
|
-
"CSV_INVALID_OPTION_COLUMNS",
|
|
1775
|
-
[
|
|
1776
|
-
"Invalid option columns:",
|
|
1777
|
-
"expect an array, a function or true,",
|
|
1778
|
-
`got ${JSON.stringify(options.columns)}`
|
|
1779
|
-
],
|
|
1780
|
-
options
|
|
1781
|
-
);
|
|
1782
|
-
}
|
|
1783
|
-
if (options.group_columns_by_name === void 0 || options.group_columns_by_name === null || options.group_columns_by_name === false) {
|
|
1784
|
-
options.group_columns_by_name = false;
|
|
1785
|
-
} else if (options.group_columns_by_name !== true) {
|
|
1786
|
-
throw new CsvError(
|
|
1787
|
-
"CSV_INVALID_OPTION_GROUP_COLUMNS_BY_NAME",
|
|
1788
|
-
[
|
|
1789
|
-
"Invalid option group_columns_by_name:",
|
|
1790
|
-
"expect an boolean,",
|
|
1791
|
-
`got ${JSON.stringify(options.group_columns_by_name)}`
|
|
1792
|
-
],
|
|
1793
|
-
options
|
|
1794
|
-
);
|
|
1795
|
-
} else if (options.columns === false) {
|
|
1796
|
-
throw new CsvError(
|
|
1797
|
-
"CSV_INVALID_OPTION_GROUP_COLUMNS_BY_NAME",
|
|
1798
|
-
[
|
|
1799
|
-
"Invalid option group_columns_by_name:",
|
|
1800
|
-
"the `columns` mode must be activated."
|
|
1801
|
-
],
|
|
1802
|
-
options
|
|
1803
|
-
);
|
|
1804
|
-
}
|
|
1805
|
-
if (options.comment === void 0 || options.comment === null || options.comment === false || options.comment === "") {
|
|
1806
|
-
options.comment = null;
|
|
1807
|
-
} else {
|
|
1808
|
-
if (typeof options.comment === "string") {
|
|
1809
|
-
options.comment = Buffer2.from(options.comment, options.encoding);
|
|
1810
|
-
}
|
|
1811
|
-
if (!isBuffer(options.comment)) {
|
|
1812
|
-
throw new CsvError(
|
|
1813
|
-
"CSV_INVALID_OPTION_COMMENT",
|
|
1814
|
-
[
|
|
1815
|
-
"Invalid option comment:",
|
|
1816
|
-
"comment must be a buffer or a string,",
|
|
1817
|
-
`got ${JSON.stringify(options.comment)}`
|
|
1818
|
-
],
|
|
1819
|
-
options
|
|
1820
|
-
);
|
|
1821
|
-
}
|
|
1822
|
-
}
|
|
1823
|
-
if (options.comment_no_infix === void 0 || options.comment_no_infix === null || options.comment_no_infix === false) {
|
|
1824
|
-
options.comment_no_infix = false;
|
|
1825
|
-
} else if (options.comment_no_infix !== true) {
|
|
1826
|
-
throw new CsvError(
|
|
1827
|
-
"CSV_INVALID_OPTION_COMMENT",
|
|
1828
|
-
[
|
|
1829
|
-
"Invalid option comment_no_infix:",
|
|
1830
|
-
"value must be a boolean,",
|
|
1831
|
-
`got ${JSON.stringify(options.comment_no_infix)}`
|
|
1832
|
-
],
|
|
1833
|
-
options
|
|
1834
|
-
);
|
|
1835
|
-
}
|
|
1836
|
-
const delimiter_json = JSON.stringify(options.delimiter);
|
|
1837
|
-
if (!Array.isArray(options.delimiter))
|
|
1838
|
-
options.delimiter = [options.delimiter];
|
|
1839
|
-
if (options.delimiter.length === 0) {
|
|
1840
|
-
throw new CsvError(
|
|
1841
|
-
"CSV_INVALID_OPTION_DELIMITER",
|
|
1842
|
-
[
|
|
1843
|
-
"Invalid option delimiter:",
|
|
1844
|
-
"delimiter must be a non empty string or buffer or array of string|buffer,",
|
|
1845
|
-
`got ${delimiter_json}`
|
|
1846
|
-
],
|
|
1847
|
-
options
|
|
1848
|
-
);
|
|
1849
|
-
}
|
|
1850
|
-
options.delimiter = options.delimiter.map(function(delimiter) {
|
|
1851
|
-
if (delimiter === void 0 || delimiter === null || delimiter === false) {
|
|
1852
|
-
return Buffer2.from(",", options.encoding);
|
|
1853
|
-
}
|
|
1854
|
-
if (typeof delimiter === "string") {
|
|
1855
|
-
delimiter = Buffer2.from(delimiter, options.encoding);
|
|
1856
|
-
}
|
|
1857
|
-
if (!isBuffer(delimiter) || delimiter.length === 0) {
|
|
1858
|
-
throw new CsvError(
|
|
1859
|
-
"CSV_INVALID_OPTION_DELIMITER",
|
|
1860
|
-
[
|
|
1861
|
-
"Invalid option delimiter:",
|
|
1862
|
-
"delimiter must be a non empty string or buffer or array of string|buffer,",
|
|
1863
|
-
`got ${delimiter_json}`
|
|
1864
|
-
],
|
|
1865
|
-
options
|
|
1866
|
-
);
|
|
1867
|
-
}
|
|
1868
|
-
return delimiter;
|
|
1869
|
-
});
|
|
1870
|
-
if (options.escape === void 0 || options.escape === true) {
|
|
1871
|
-
options.escape = Buffer2.from('"', options.encoding);
|
|
1872
|
-
} else if (typeof options.escape === "string") {
|
|
1873
|
-
options.escape = Buffer2.from(options.escape, options.encoding);
|
|
1874
|
-
} else if (options.escape === null || options.escape === false) {
|
|
1875
|
-
options.escape = null;
|
|
1876
|
-
}
|
|
1877
|
-
if (options.escape !== null) {
|
|
1878
|
-
if (!isBuffer(options.escape)) {
|
|
1879
|
-
throw new Error(
|
|
1880
|
-
`Invalid Option: escape must be a buffer, a string or a boolean, got ${JSON.stringify(options.escape)}`
|
|
1881
|
-
);
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
|
-
if (options.from === void 0 || options.from === null) {
|
|
1885
|
-
options.from = 1;
|
|
1886
|
-
} else {
|
|
1887
|
-
if (typeof options.from === "string" && /\d+/.test(options.from)) {
|
|
1888
|
-
options.from = parseInt(options.from);
|
|
1889
|
-
}
|
|
1890
|
-
if (Number.isInteger(options.from)) {
|
|
1891
|
-
if (options.from < 0) {
|
|
1892
|
-
throw new Error(
|
|
1893
|
-
`Invalid Option: from must be a positive integer, got ${JSON.stringify(opts.from)}`
|
|
1894
|
-
);
|
|
1895
|
-
}
|
|
1896
|
-
} else {
|
|
1897
|
-
throw new Error(
|
|
1898
|
-
`Invalid Option: from must be an integer, got ${JSON.stringify(options.from)}`
|
|
1899
|
-
);
|
|
1900
|
-
}
|
|
1901
|
-
}
|
|
1902
|
-
if (options.from_line === void 0 || options.from_line === null) {
|
|
1903
|
-
options.from_line = 1;
|
|
1904
|
-
} else {
|
|
1905
|
-
if (typeof options.from_line === "string" && /\d+/.test(options.from_line)) {
|
|
1906
|
-
options.from_line = parseInt(options.from_line);
|
|
1907
|
-
}
|
|
1908
|
-
if (Number.isInteger(options.from_line)) {
|
|
1909
|
-
if (options.from_line <= 0) {
|
|
1910
|
-
throw new Error(
|
|
1911
|
-
`Invalid Option: from_line must be a positive integer greater than 0, got ${JSON.stringify(opts.from_line)}`
|
|
1912
|
-
);
|
|
1913
|
-
}
|
|
1914
|
-
} else {
|
|
1915
|
-
throw new Error(
|
|
1916
|
-
`Invalid Option: from_line must be an integer, got ${JSON.stringify(opts.from_line)}`
|
|
1917
|
-
);
|
|
1918
|
-
}
|
|
1919
|
-
}
|
|
1920
|
-
if (options.ignore_last_delimiters === void 0 || options.ignore_last_delimiters === null) {
|
|
1921
|
-
options.ignore_last_delimiters = false;
|
|
1922
|
-
} else if (typeof options.ignore_last_delimiters === "number") {
|
|
1923
|
-
options.ignore_last_delimiters = Math.floor(options.ignore_last_delimiters);
|
|
1924
|
-
if (options.ignore_last_delimiters === 0) {
|
|
1925
|
-
options.ignore_last_delimiters = false;
|
|
1926
|
-
}
|
|
1927
|
-
} else if (typeof options.ignore_last_delimiters !== "boolean") {
|
|
1928
|
-
throw new CsvError(
|
|
1929
|
-
"CSV_INVALID_OPTION_IGNORE_LAST_DELIMITERS",
|
|
1930
|
-
[
|
|
1931
|
-
"Invalid option `ignore_last_delimiters`:",
|
|
1932
|
-
"the value must be a boolean value or an integer,",
|
|
1933
|
-
`got ${JSON.stringify(options.ignore_last_delimiters)}`
|
|
1934
|
-
],
|
|
1935
|
-
options
|
|
1936
|
-
);
|
|
1937
|
-
}
|
|
1938
|
-
if (options.ignore_last_delimiters === true && options.columns === false) {
|
|
1939
|
-
throw new CsvError(
|
|
1940
|
-
"CSV_IGNORE_LAST_DELIMITERS_REQUIRES_COLUMNS",
|
|
1941
|
-
[
|
|
1942
|
-
"The option `ignore_last_delimiters`",
|
|
1943
|
-
"requires the activation of the `columns` option"
|
|
1944
|
-
],
|
|
1945
|
-
options
|
|
1946
|
-
);
|
|
1947
|
-
}
|
|
1948
|
-
if (options.info === void 0 || options.info === null || options.info === false) {
|
|
1949
|
-
options.info = false;
|
|
1950
|
-
} else if (options.info !== true) {
|
|
1951
|
-
throw new Error(
|
|
1952
|
-
`Invalid Option: info must be true, got ${JSON.stringify(options.info)}`
|
|
1953
|
-
);
|
|
1954
|
-
}
|
|
1955
|
-
if (options.max_record_size === void 0 || options.max_record_size === null || options.max_record_size === false) {
|
|
1956
|
-
options.max_record_size = 0;
|
|
1957
|
-
} else if (Number.isInteger(options.max_record_size) && options.max_record_size >= 0) ;
|
|
1958
|
-
else if (typeof options.max_record_size === "string" && /\d+/.test(options.max_record_size)) {
|
|
1959
|
-
options.max_record_size = parseInt(options.max_record_size);
|
|
1960
|
-
} else {
|
|
1961
|
-
throw new Error(
|
|
1962
|
-
`Invalid Option: max_record_size must be a positive integer, got ${JSON.stringify(options.max_record_size)}`
|
|
1963
|
-
);
|
|
1964
|
-
}
|
|
1965
|
-
if (options.objname === void 0 || options.objname === null || options.objname === false) {
|
|
1966
|
-
options.objname = void 0;
|
|
1967
|
-
} else if (isBuffer(options.objname)) {
|
|
1968
|
-
if (options.objname.length === 0) {
|
|
1969
|
-
throw new Error(`Invalid Option: objname must be a non empty buffer`);
|
|
1970
|
-
}
|
|
1971
|
-
if (options.encoding === null) ;
|
|
1972
|
-
else {
|
|
1973
|
-
options.objname = options.objname.toString(options.encoding);
|
|
1974
|
-
}
|
|
1975
|
-
} else if (typeof options.objname === "string") {
|
|
1976
|
-
if (options.objname.length === 0) {
|
|
1977
|
-
throw new Error(`Invalid Option: objname must be a non empty string`);
|
|
1978
|
-
}
|
|
1979
|
-
} else if (typeof options.objname === "number") ;
|
|
1980
|
-
else {
|
|
1981
|
-
throw new Error(
|
|
1982
|
-
`Invalid Option: objname must be a string or a buffer, got ${options.objname}`
|
|
1983
|
-
);
|
|
1984
|
-
}
|
|
1985
|
-
if (options.objname !== void 0) {
|
|
1986
|
-
if (typeof options.objname === "number") {
|
|
1987
|
-
if (options.columns !== false) {
|
|
1988
|
-
throw Error(
|
|
1989
|
-
"Invalid Option: objname index cannot be combined with columns or be defined as a field"
|
|
1990
|
-
);
|
|
1991
|
-
}
|
|
1992
|
-
} else {
|
|
1993
|
-
if (options.columns === false) {
|
|
1994
|
-
throw Error(
|
|
1995
|
-
"Invalid Option: objname field must be combined with columns or be defined as an index"
|
|
1996
|
-
);
|
|
1997
|
-
}
|
|
1998
|
-
}
|
|
1999
|
-
}
|
|
2000
|
-
if (options.on_record === void 0 || options.on_record === null) {
|
|
2001
|
-
options.on_record = void 0;
|
|
2002
|
-
} else if (typeof options.on_record !== "function") {
|
|
2003
|
-
throw new CsvError(
|
|
2004
|
-
"CSV_INVALID_OPTION_ON_RECORD",
|
|
2005
|
-
[
|
|
2006
|
-
"Invalid option `on_record`:",
|
|
2007
|
-
"expect a function,",
|
|
2008
|
-
`got ${JSON.stringify(options.on_record)}`
|
|
2009
|
-
],
|
|
2010
|
-
options
|
|
2011
|
-
);
|
|
2012
|
-
}
|
|
2013
|
-
if (options.on_skip !== void 0 && options.on_skip !== null && typeof options.on_skip !== "function") {
|
|
2014
|
-
throw new Error(
|
|
2015
|
-
`Invalid Option: on_skip must be a function, got ${JSON.stringify(options.on_skip)}`
|
|
2016
|
-
);
|
|
2017
|
-
}
|
|
2018
|
-
if (options.quote === null || options.quote === false || options.quote === "") {
|
|
2019
|
-
options.quote = null;
|
|
2020
|
-
} else {
|
|
2021
|
-
if (options.quote === void 0 || options.quote === true) {
|
|
2022
|
-
options.quote = Buffer2.from('"', options.encoding);
|
|
2023
|
-
} else if (typeof options.quote === "string") {
|
|
2024
|
-
options.quote = Buffer2.from(options.quote, options.encoding);
|
|
2025
|
-
}
|
|
2026
|
-
if (!isBuffer(options.quote)) {
|
|
2027
|
-
throw new Error(
|
|
2028
|
-
`Invalid Option: quote must be a buffer or a string, got ${JSON.stringify(options.quote)}`
|
|
2029
|
-
);
|
|
2030
|
-
}
|
|
2031
|
-
}
|
|
2032
|
-
if (options.raw === void 0 || options.raw === null || options.raw === false) {
|
|
2033
|
-
options.raw = false;
|
|
2034
|
-
} else if (options.raw !== true) {
|
|
2035
|
-
throw new Error(
|
|
2036
|
-
`Invalid Option: raw must be true, got ${JSON.stringify(options.raw)}`
|
|
2037
|
-
);
|
|
2038
|
-
}
|
|
2039
|
-
if (options.record_delimiter === void 0) {
|
|
2040
|
-
options.record_delimiter = [];
|
|
2041
|
-
} else if (typeof options.record_delimiter === "string" || isBuffer(options.record_delimiter)) {
|
|
2042
|
-
if (options.record_delimiter.length === 0) {
|
|
2043
|
-
throw new CsvError(
|
|
2044
|
-
"CSV_INVALID_OPTION_RECORD_DELIMITER",
|
|
2045
|
-
[
|
|
2046
|
-
"Invalid option `record_delimiter`:",
|
|
2047
|
-
"value must be a non empty string or buffer,",
|
|
2048
|
-
`got ${JSON.stringify(options.record_delimiter)}`
|
|
2049
|
-
],
|
|
2050
|
-
options
|
|
2051
|
-
);
|
|
2052
|
-
}
|
|
2053
|
-
options.record_delimiter = [options.record_delimiter];
|
|
2054
|
-
} else if (!Array.isArray(options.record_delimiter)) {
|
|
2055
|
-
throw new CsvError(
|
|
2056
|
-
"CSV_INVALID_OPTION_RECORD_DELIMITER",
|
|
2057
|
-
[
|
|
2058
|
-
"Invalid option `record_delimiter`:",
|
|
2059
|
-
"value must be a string, a buffer or array of string|buffer,",
|
|
2060
|
-
`got ${JSON.stringify(options.record_delimiter)}`
|
|
2061
|
-
],
|
|
2062
|
-
options
|
|
2063
|
-
);
|
|
2064
|
-
}
|
|
2065
|
-
options.record_delimiter = options.record_delimiter.map(function(rd, i) {
|
|
2066
|
-
if (typeof rd !== "string" && !isBuffer(rd)) {
|
|
2067
|
-
throw new CsvError(
|
|
2068
|
-
"CSV_INVALID_OPTION_RECORD_DELIMITER",
|
|
2069
|
-
[
|
|
2070
|
-
"Invalid option `record_delimiter`:",
|
|
2071
|
-
"value must be a string, a buffer or array of string|buffer",
|
|
2072
|
-
`at index ${i},`,
|
|
2073
|
-
`got ${JSON.stringify(rd)}`
|
|
2074
|
-
],
|
|
2075
|
-
options
|
|
2076
|
-
);
|
|
2077
|
-
} else if (rd.length === 0) {
|
|
2078
|
-
throw new CsvError(
|
|
2079
|
-
"CSV_INVALID_OPTION_RECORD_DELIMITER",
|
|
2080
|
-
[
|
|
2081
|
-
"Invalid option `record_delimiter`:",
|
|
2082
|
-
"value must be a non empty string or buffer",
|
|
2083
|
-
`at index ${i},`,
|
|
2084
|
-
`got ${JSON.stringify(rd)}`
|
|
2085
|
-
],
|
|
2086
|
-
options
|
|
2087
|
-
);
|
|
2088
|
-
}
|
|
2089
|
-
if (typeof rd === "string") {
|
|
2090
|
-
rd = Buffer2.from(rd, options.encoding);
|
|
2091
|
-
}
|
|
2092
|
-
return rd;
|
|
2093
|
-
});
|
|
2094
|
-
if (typeof options.relax_column_count === "boolean") ;
|
|
2095
|
-
else if (options.relax_column_count === void 0 || options.relax_column_count === null) {
|
|
2096
|
-
options.relax_column_count = false;
|
|
2097
|
-
} else {
|
|
2098
|
-
throw new Error(
|
|
2099
|
-
`Invalid Option: relax_column_count must be a boolean, got ${JSON.stringify(options.relax_column_count)}`
|
|
2100
|
-
);
|
|
2101
|
-
}
|
|
2102
|
-
if (typeof options.relax_column_count_less === "boolean") ;
|
|
2103
|
-
else if (options.relax_column_count_less === void 0 || options.relax_column_count_less === null) {
|
|
2104
|
-
options.relax_column_count_less = false;
|
|
2105
|
-
} else {
|
|
2106
|
-
throw new Error(
|
|
2107
|
-
`Invalid Option: relax_column_count_less must be a boolean, got ${JSON.stringify(options.relax_column_count_less)}`
|
|
2108
|
-
);
|
|
2109
|
-
}
|
|
2110
|
-
if (typeof options.relax_column_count_more === "boolean") ;
|
|
2111
|
-
else if (options.relax_column_count_more === void 0 || options.relax_column_count_more === null) {
|
|
2112
|
-
options.relax_column_count_more = false;
|
|
2113
|
-
} else {
|
|
2114
|
-
throw new Error(
|
|
2115
|
-
`Invalid Option: relax_column_count_more must be a boolean, got ${JSON.stringify(options.relax_column_count_more)}`
|
|
2116
|
-
);
|
|
2117
|
-
}
|
|
2118
|
-
if (typeof options.relax_quotes === "boolean") ;
|
|
2119
|
-
else if (options.relax_quotes === void 0 || options.relax_quotes === null) {
|
|
2120
|
-
options.relax_quotes = false;
|
|
2121
|
-
} else {
|
|
2122
|
-
throw new Error(
|
|
2123
|
-
`Invalid Option: relax_quotes must be a boolean, got ${JSON.stringify(options.relax_quotes)}`
|
|
2124
|
-
);
|
|
2125
|
-
}
|
|
2126
|
-
if (typeof options.skip_empty_lines === "boolean") ;
|
|
2127
|
-
else if (options.skip_empty_lines === void 0 || options.skip_empty_lines === null) {
|
|
2128
|
-
options.skip_empty_lines = false;
|
|
2129
|
-
} else {
|
|
2130
|
-
throw new Error(
|
|
2131
|
-
`Invalid Option: skip_empty_lines must be a boolean, got ${JSON.stringify(options.skip_empty_lines)}`
|
|
2132
|
-
);
|
|
2133
|
-
}
|
|
2134
|
-
if (typeof options.skip_records_with_empty_values === "boolean") ;
|
|
2135
|
-
else if (options.skip_records_with_empty_values === void 0 || options.skip_records_with_empty_values === null) {
|
|
2136
|
-
options.skip_records_with_empty_values = false;
|
|
2137
|
-
} else {
|
|
2138
|
-
throw new Error(
|
|
2139
|
-
`Invalid Option: skip_records_with_empty_values must be a boolean, got ${JSON.stringify(options.skip_records_with_empty_values)}`
|
|
2140
|
-
);
|
|
2141
|
-
}
|
|
2142
|
-
if (typeof options.skip_records_with_error === "boolean") ;
|
|
2143
|
-
else if (options.skip_records_with_error === void 0 || options.skip_records_with_error === null) {
|
|
2144
|
-
options.skip_records_with_error = false;
|
|
2145
|
-
} else {
|
|
2146
|
-
throw new Error(
|
|
2147
|
-
`Invalid Option: skip_records_with_error must be a boolean, got ${JSON.stringify(options.skip_records_with_error)}`
|
|
2148
|
-
);
|
|
2149
|
-
}
|
|
2150
|
-
if (options.rtrim === void 0 || options.rtrim === null || options.rtrim === false) {
|
|
2151
|
-
options.rtrim = false;
|
|
2152
|
-
} else if (options.rtrim !== true) {
|
|
2153
|
-
throw new Error(
|
|
2154
|
-
`Invalid Option: rtrim must be a boolean, got ${JSON.stringify(options.rtrim)}`
|
|
2155
|
-
);
|
|
2156
|
-
}
|
|
2157
|
-
if (options.ltrim === void 0 || options.ltrim === null || options.ltrim === false) {
|
|
2158
|
-
options.ltrim = false;
|
|
2159
|
-
} else if (options.ltrim !== true) {
|
|
2160
|
-
throw new Error(
|
|
2161
|
-
`Invalid Option: ltrim must be a boolean, got ${JSON.stringify(options.ltrim)}`
|
|
2162
|
-
);
|
|
2163
|
-
}
|
|
2164
|
-
if (options.trim === void 0 || options.trim === null || options.trim === false) {
|
|
2165
|
-
options.trim = false;
|
|
2166
|
-
} else if (options.trim !== true) {
|
|
2167
|
-
throw new Error(
|
|
2168
|
-
`Invalid Option: trim must be a boolean, got ${JSON.stringify(options.trim)}`
|
|
2169
|
-
);
|
|
2170
|
-
}
|
|
2171
|
-
if (options.trim === true && opts.ltrim !== false) {
|
|
2172
|
-
options.ltrim = true;
|
|
2173
|
-
} else if (options.ltrim !== true) {
|
|
2174
|
-
options.ltrim = false;
|
|
2175
|
-
}
|
|
2176
|
-
if (options.trim === true && opts.rtrim !== false) {
|
|
2177
|
-
options.rtrim = true;
|
|
2178
|
-
} else if (options.rtrim !== true) {
|
|
2179
|
-
options.rtrim = false;
|
|
2180
|
-
}
|
|
2181
|
-
if (options.to === void 0 || options.to === null) {
|
|
2182
|
-
options.to = -1;
|
|
2183
|
-
} else {
|
|
2184
|
-
if (typeof options.to === "string" && /\d+/.test(options.to)) {
|
|
2185
|
-
options.to = parseInt(options.to);
|
|
2186
|
-
}
|
|
2187
|
-
if (Number.isInteger(options.to)) {
|
|
2188
|
-
if (options.to <= 0) {
|
|
2189
|
-
throw new Error(
|
|
2190
|
-
`Invalid Option: to must be a positive integer greater than 0, got ${JSON.stringify(opts.to)}`
|
|
2191
|
-
);
|
|
2192
|
-
}
|
|
2193
|
-
} else {
|
|
2194
|
-
throw new Error(
|
|
2195
|
-
`Invalid Option: to must be an integer, got ${JSON.stringify(opts.to)}`
|
|
2196
|
-
);
|
|
2197
|
-
}
|
|
2198
|
-
}
|
|
2199
|
-
if (options.to_line === void 0 || options.to_line === null) {
|
|
2200
|
-
options.to_line = -1;
|
|
2201
|
-
} else {
|
|
2202
|
-
if (typeof options.to_line === "string" && /\d+/.test(options.to_line)) {
|
|
2203
|
-
options.to_line = parseInt(options.to_line);
|
|
2204
|
-
}
|
|
2205
|
-
if (Number.isInteger(options.to_line)) {
|
|
2206
|
-
if (options.to_line <= 0) {
|
|
2207
|
-
throw new Error(
|
|
2208
|
-
`Invalid Option: to_line must be a positive integer greater than 0, got ${JSON.stringify(opts.to_line)}`
|
|
2209
|
-
);
|
|
2210
|
-
}
|
|
2211
|
-
} else {
|
|
2212
|
-
throw new Error(
|
|
2213
|
-
`Invalid Option: to_line must be an integer, got ${JSON.stringify(opts.to_line)}`
|
|
2214
|
-
);
|
|
2215
|
-
}
|
|
2216
|
-
}
|
|
2217
|
-
return options;
|
|
2218
|
-
};
|
|
2219
|
-
var isRecordEmpty = function(record) {
|
|
2220
|
-
return record.every(
|
|
2221
|
-
(field) => field == null || field.toString && field.toString().trim() === ""
|
|
2222
|
-
);
|
|
2223
|
-
};
|
|
2224
|
-
var cr = 13;
|
|
2225
|
-
var nl = 10;
|
|
2226
|
-
var boms = {
|
|
2227
|
-
// Note, the following are equals:
|
|
2228
|
-
// Buffer.from("\ufeff")
|
|
2229
|
-
// Buffer.from([239, 187, 191])
|
|
2230
|
-
// Buffer.from('EFBBBF', 'hex')
|
|
2231
|
-
utf8: Buffer2.from([239, 187, 191]),
|
|
2232
|
-
// Note, the following are equals:
|
|
2233
|
-
// Buffer.from "\ufeff", 'utf16le
|
|
2234
|
-
// Buffer.from([255, 254])
|
|
2235
|
-
utf16le: Buffer2.from([255, 254])
|
|
2236
|
-
};
|
|
2237
|
-
var transform = function(original_options = {}) {
|
|
2238
|
-
const info = {
|
|
2239
|
-
bytes: 0,
|
|
2240
|
-
comment_lines: 0,
|
|
2241
|
-
empty_lines: 0,
|
|
2242
|
-
invalid_field_length: 0,
|
|
2243
|
-
lines: 1,
|
|
2244
|
-
records: 0
|
|
2245
|
-
};
|
|
2246
|
-
const options = normalize_options(original_options);
|
|
2247
|
-
return {
|
|
2248
|
-
info,
|
|
2249
|
-
original_options,
|
|
2250
|
-
options,
|
|
2251
|
-
state: init_state(options),
|
|
2252
|
-
__needMoreData: function(i, bufLen, end) {
|
|
2253
|
-
if (end) return false;
|
|
2254
|
-
const { encoding, escape, quote } = this.options;
|
|
2255
|
-
const { quoting, needMoreDataSize, recordDelimiterMaxLength } = this.state;
|
|
2256
|
-
const numOfCharLeft = bufLen - i - 1;
|
|
2257
|
-
const requiredLength = Math.max(
|
|
2258
|
-
needMoreDataSize,
|
|
2259
|
-
// Skip if the remaining buffer smaller than record delimiter
|
|
2260
|
-
// If "record_delimiter" is yet to be discovered:
|
|
2261
|
-
// 1. It is equals to `[]` and "recordDelimiterMaxLength" equals `0`
|
|
2262
|
-
// 2. We set the length to windows line ending in the current encoding
|
|
2263
|
-
// Note, that encoding is known from user or bom discovery at that point
|
|
2264
|
-
// recordDelimiterMaxLength,
|
|
2265
|
-
recordDelimiterMaxLength === 0 ? Buffer2.from("\r\n", encoding).length : recordDelimiterMaxLength,
|
|
2266
|
-
// Skip if remaining buffer can be an escaped quote
|
|
2267
|
-
quoting ? (escape === null ? 0 : escape.length) + quote.length : 0,
|
|
2268
|
-
// Skip if remaining buffer can be record delimiter following the closing quote
|
|
2269
|
-
quoting ? quote.length + recordDelimiterMaxLength : 0
|
|
2270
|
-
);
|
|
2271
|
-
return numOfCharLeft < requiredLength;
|
|
2272
|
-
},
|
|
2273
|
-
// Central parser implementation
|
|
2274
|
-
parse: function(nextBuf, end, push, close) {
|
|
2275
|
-
const {
|
|
2276
|
-
bom,
|
|
2277
|
-
comment_no_infix,
|
|
2278
|
-
encoding,
|
|
2279
|
-
from_line,
|
|
2280
|
-
ltrim,
|
|
2281
|
-
max_record_size,
|
|
2282
|
-
raw,
|
|
2283
|
-
relax_quotes,
|
|
2284
|
-
rtrim,
|
|
2285
|
-
skip_empty_lines,
|
|
2286
|
-
to,
|
|
2287
|
-
to_line
|
|
2288
|
-
} = this.options;
|
|
2289
|
-
let { comment, escape, quote, record_delimiter } = this.options;
|
|
2290
|
-
const { bomSkipped, previousBuf, rawBuffer, escapeIsQuote } = this.state;
|
|
2291
|
-
let buf;
|
|
2292
|
-
if (previousBuf === void 0) {
|
|
2293
|
-
if (nextBuf === void 0) {
|
|
2294
|
-
close();
|
|
2295
|
-
return;
|
|
2296
|
-
} else {
|
|
2297
|
-
buf = nextBuf;
|
|
2298
|
-
}
|
|
2299
|
-
} else if (previousBuf !== void 0 && nextBuf === void 0) {
|
|
2300
|
-
buf = previousBuf;
|
|
2301
|
-
} else {
|
|
2302
|
-
buf = Buffer2.concat([previousBuf, nextBuf]);
|
|
2303
|
-
}
|
|
2304
|
-
if (bomSkipped === false) {
|
|
2305
|
-
if (bom === false) {
|
|
2306
|
-
this.state.bomSkipped = true;
|
|
2307
|
-
} else if (buf.length < 3) {
|
|
2308
|
-
if (end === false) {
|
|
2309
|
-
this.state.previousBuf = buf;
|
|
2310
|
-
return;
|
|
2311
|
-
}
|
|
2312
|
-
} else {
|
|
2313
|
-
for (const encoding2 in boms) {
|
|
2314
|
-
if (boms[encoding2].compare(buf, 0, boms[encoding2].length) === 0) {
|
|
2315
|
-
const bomLength = boms[encoding2].length;
|
|
2316
|
-
this.state.bufBytesStart += bomLength;
|
|
2317
|
-
buf = buf.slice(bomLength);
|
|
2318
|
-
this.options = normalize_options({
|
|
2319
|
-
...this.original_options,
|
|
2320
|
-
encoding: encoding2
|
|
2321
|
-
});
|
|
2322
|
-
({ comment, escape, quote } = this.options);
|
|
2323
|
-
break;
|
|
2324
|
-
}
|
|
2325
|
-
}
|
|
2326
|
-
this.state.bomSkipped = true;
|
|
2327
|
-
}
|
|
2328
|
-
}
|
|
2329
|
-
const bufLen = buf.length;
|
|
2330
|
-
let pos;
|
|
2331
|
-
for (pos = 0; pos < bufLen; pos++) {
|
|
2332
|
-
if (this.__needMoreData(pos, bufLen, end)) {
|
|
2333
|
-
break;
|
|
2334
|
-
}
|
|
2335
|
-
if (this.state.wasRowDelimiter === true) {
|
|
2336
|
-
this.info.lines++;
|
|
2337
|
-
this.state.wasRowDelimiter = false;
|
|
2338
|
-
}
|
|
2339
|
-
if (to_line !== -1 && this.info.lines > to_line) {
|
|
2340
|
-
this.state.stop = true;
|
|
2341
|
-
close();
|
|
2342
|
-
return;
|
|
2343
|
-
}
|
|
2344
|
-
if (this.state.quoting === false && record_delimiter.length === 0) {
|
|
2345
|
-
const record_delimiterCount = this.__autoDiscoverRecordDelimiter(
|
|
2346
|
-
buf,
|
|
2347
|
-
pos
|
|
2348
|
-
);
|
|
2349
|
-
if (record_delimiterCount) {
|
|
2350
|
-
record_delimiter = this.options.record_delimiter;
|
|
2351
|
-
}
|
|
2352
|
-
}
|
|
2353
|
-
const chr = buf[pos];
|
|
2354
|
-
if (raw === true) {
|
|
2355
|
-
rawBuffer.append(chr);
|
|
2356
|
-
}
|
|
2357
|
-
if ((chr === cr || chr === nl) && this.state.wasRowDelimiter === false) {
|
|
2358
|
-
this.state.wasRowDelimiter = true;
|
|
2359
|
-
}
|
|
2360
|
-
if (this.state.escaping === true) {
|
|
2361
|
-
this.state.escaping = false;
|
|
2362
|
-
} else {
|
|
2363
|
-
if (escape !== null && this.state.quoting === true && this.__isEscape(buf, pos, chr) && pos + escape.length < bufLen) {
|
|
2364
|
-
if (escapeIsQuote) {
|
|
2365
|
-
if (this.__isQuote(buf, pos + escape.length)) {
|
|
2366
|
-
this.state.escaping = true;
|
|
2367
|
-
pos += escape.length - 1;
|
|
2368
|
-
continue;
|
|
2369
|
-
}
|
|
2370
|
-
} else {
|
|
2371
|
-
this.state.escaping = true;
|
|
2372
|
-
pos += escape.length - 1;
|
|
2373
|
-
continue;
|
|
2374
|
-
}
|
|
2375
|
-
}
|
|
2376
|
-
if (this.state.commenting === false && this.__isQuote(buf, pos)) {
|
|
2377
|
-
if (this.state.quoting === true) {
|
|
2378
|
-
const nextChr = buf[pos + quote.length];
|
|
2379
|
-
const isNextChrTrimable = rtrim && this.__isCharTrimable(buf, pos + quote.length);
|
|
2380
|
-
const isNextChrComment = comment !== null && this.__compareBytes(comment, buf, pos + quote.length, nextChr);
|
|
2381
|
-
const isNextChrDelimiter = this.__isDelimiter(
|
|
2382
|
-
buf,
|
|
2383
|
-
pos + quote.length,
|
|
2384
|
-
nextChr
|
|
2385
|
-
);
|
|
2386
|
-
const isNextChrRecordDelimiter = record_delimiter.length === 0 ? this.__autoDiscoverRecordDelimiter(buf, pos + quote.length) : this.__isRecordDelimiter(nextChr, buf, pos + quote.length);
|
|
2387
|
-
if (escape !== null && this.__isEscape(buf, pos, chr) && this.__isQuote(buf, pos + escape.length)) {
|
|
2388
|
-
pos += escape.length - 1;
|
|
2389
|
-
} else if (!nextChr || isNextChrDelimiter || isNextChrRecordDelimiter || isNextChrComment || isNextChrTrimable) {
|
|
2390
|
-
this.state.quoting = false;
|
|
2391
|
-
this.state.wasQuoting = true;
|
|
2392
|
-
pos += quote.length - 1;
|
|
2393
|
-
continue;
|
|
2394
|
-
} else if (relax_quotes === false) {
|
|
2395
|
-
const err = this.__error(
|
|
2396
|
-
new CsvError(
|
|
2397
|
-
"CSV_INVALID_CLOSING_QUOTE",
|
|
2398
|
-
[
|
|
2399
|
-
"Invalid Closing Quote:",
|
|
2400
|
-
`got "${String.fromCharCode(nextChr)}"`,
|
|
2401
|
-
`at line ${this.info.lines}`,
|
|
2402
|
-
"instead of delimiter, record delimiter, trimable character",
|
|
2403
|
-
"(if activated) or comment"
|
|
2404
|
-
],
|
|
2405
|
-
this.options,
|
|
2406
|
-
this.__infoField()
|
|
2407
|
-
)
|
|
2408
|
-
);
|
|
2409
|
-
if (err !== void 0) return err;
|
|
2410
|
-
} else {
|
|
2411
|
-
this.state.quoting = false;
|
|
2412
|
-
this.state.wasQuoting = true;
|
|
2413
|
-
this.state.field.prepend(quote);
|
|
2414
|
-
pos += quote.length - 1;
|
|
2415
|
-
}
|
|
2416
|
-
} else {
|
|
2417
|
-
if (this.state.field.length !== 0) {
|
|
2418
|
-
if (relax_quotes === false) {
|
|
2419
|
-
const info2 = this.__infoField();
|
|
2420
|
-
const bom2 = Object.keys(boms).map(
|
|
2421
|
-
(b) => boms[b].equals(this.state.field.toString()) ? b : false
|
|
2422
|
-
).filter(Boolean)[0];
|
|
2423
|
-
const err = this.__error(
|
|
2424
|
-
new CsvError(
|
|
2425
|
-
"INVALID_OPENING_QUOTE",
|
|
2426
|
-
[
|
|
2427
|
-
"Invalid Opening Quote:",
|
|
2428
|
-
`a quote is found on field ${JSON.stringify(info2.column)} at line ${info2.lines}, value is ${JSON.stringify(this.state.field.toString(encoding))}`,
|
|
2429
|
-
bom2 ? `(${bom2} bom)` : void 0
|
|
2430
|
-
],
|
|
2431
|
-
this.options,
|
|
2432
|
-
info2,
|
|
2433
|
-
{
|
|
2434
|
-
field: this.state.field
|
|
2435
|
-
}
|
|
2436
|
-
)
|
|
2437
|
-
);
|
|
2438
|
-
if (err !== void 0) return err;
|
|
2439
|
-
}
|
|
2440
|
-
} else {
|
|
2441
|
-
this.state.quoting = true;
|
|
2442
|
-
pos += quote.length - 1;
|
|
2443
|
-
continue;
|
|
2444
|
-
}
|
|
2445
|
-
}
|
|
2446
|
-
}
|
|
2447
|
-
if (this.state.quoting === false) {
|
|
2448
|
-
const recordDelimiterLength = this.__isRecordDelimiter(
|
|
2449
|
-
chr,
|
|
2450
|
-
buf,
|
|
2451
|
-
pos
|
|
2452
|
-
);
|
|
2453
|
-
if (recordDelimiterLength !== 0) {
|
|
2454
|
-
const skipCommentLine = this.state.commenting && this.state.wasQuoting === false && this.state.record.length === 0 && this.state.field.length === 0;
|
|
2455
|
-
if (skipCommentLine) {
|
|
2456
|
-
this.info.comment_lines++;
|
|
2457
|
-
} else {
|
|
2458
|
-
if (this.state.enabled === false && this.info.lines + (this.state.wasRowDelimiter === true ? 1 : 0) >= from_line) {
|
|
2459
|
-
this.state.enabled = true;
|
|
2460
|
-
this.__resetField();
|
|
2461
|
-
this.__resetRecord();
|
|
2462
|
-
pos += recordDelimiterLength - 1;
|
|
2463
|
-
continue;
|
|
2464
|
-
}
|
|
2465
|
-
if (skip_empty_lines === true && this.state.wasQuoting === false && this.state.record.length === 0 && this.state.field.length === 0) {
|
|
2466
|
-
this.info.empty_lines++;
|
|
2467
|
-
pos += recordDelimiterLength - 1;
|
|
2468
|
-
continue;
|
|
2469
|
-
}
|
|
2470
|
-
this.info.bytes = this.state.bufBytesStart + pos;
|
|
2471
|
-
const errField = this.__onField();
|
|
2472
|
-
if (errField !== void 0) return errField;
|
|
2473
|
-
this.info.bytes = this.state.bufBytesStart + pos + recordDelimiterLength;
|
|
2474
|
-
const errRecord = this.__onRecord(push);
|
|
2475
|
-
if (errRecord !== void 0) return errRecord;
|
|
2476
|
-
if (to !== -1 && this.info.records >= to) {
|
|
2477
|
-
this.state.stop = true;
|
|
2478
|
-
close();
|
|
2479
|
-
return;
|
|
2480
|
-
}
|
|
2481
|
-
}
|
|
2482
|
-
this.state.commenting = false;
|
|
2483
|
-
pos += recordDelimiterLength - 1;
|
|
2484
|
-
continue;
|
|
2485
|
-
}
|
|
2486
|
-
if (this.state.commenting) {
|
|
2487
|
-
continue;
|
|
2488
|
-
}
|
|
2489
|
-
if (comment !== null && (comment_no_infix === false || this.state.record.length === 0 && this.state.field.length === 0)) {
|
|
2490
|
-
const commentCount = this.__compareBytes(comment, buf, pos, chr);
|
|
2491
|
-
if (commentCount !== 0) {
|
|
2492
|
-
this.state.commenting = true;
|
|
2493
|
-
continue;
|
|
2494
|
-
}
|
|
2495
|
-
}
|
|
2496
|
-
const delimiterLength = this.__isDelimiter(buf, pos, chr);
|
|
2497
|
-
if (delimiterLength !== 0) {
|
|
2498
|
-
this.info.bytes = this.state.bufBytesStart + pos;
|
|
2499
|
-
const errField = this.__onField();
|
|
2500
|
-
if (errField !== void 0) return errField;
|
|
2501
|
-
pos += delimiterLength - 1;
|
|
2502
|
-
continue;
|
|
2503
|
-
}
|
|
2504
|
-
}
|
|
2505
|
-
}
|
|
2506
|
-
if (this.state.commenting === false) {
|
|
2507
|
-
if (max_record_size !== 0 && this.state.record_length + this.state.field.length > max_record_size) {
|
|
2508
|
-
return this.__error(
|
|
2509
|
-
new CsvError(
|
|
2510
|
-
"CSV_MAX_RECORD_SIZE",
|
|
2511
|
-
[
|
|
2512
|
-
"Max Record Size:",
|
|
2513
|
-
"record exceed the maximum number of tolerated bytes",
|
|
2514
|
-
`of ${max_record_size}`,
|
|
2515
|
-
`at line ${this.info.lines}`
|
|
2516
|
-
],
|
|
2517
|
-
this.options,
|
|
2518
|
-
this.__infoField()
|
|
2519
|
-
)
|
|
2520
|
-
);
|
|
2521
|
-
}
|
|
2522
|
-
}
|
|
2523
|
-
const lappend = ltrim === false || this.state.quoting === true || this.state.field.length !== 0 || !this.__isCharTrimable(buf, pos);
|
|
2524
|
-
const rappend = rtrim === false || this.state.wasQuoting === false;
|
|
2525
|
-
if (lappend === true && rappend === true) {
|
|
2526
|
-
this.state.field.append(chr);
|
|
2527
|
-
} else if (rtrim === true && !this.__isCharTrimable(buf, pos)) {
|
|
2528
|
-
return this.__error(
|
|
2529
|
-
new CsvError(
|
|
2530
|
-
"CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE",
|
|
2531
|
-
[
|
|
2532
|
-
"Invalid Closing Quote:",
|
|
2533
|
-
"found non trimable byte after quote",
|
|
2534
|
-
`at line ${this.info.lines}`
|
|
2535
|
-
],
|
|
2536
|
-
this.options,
|
|
2537
|
-
this.__infoField()
|
|
2538
|
-
)
|
|
2539
|
-
);
|
|
2540
|
-
} else {
|
|
2541
|
-
if (lappend === false) {
|
|
2542
|
-
pos += this.__isCharTrimable(buf, pos) - 1;
|
|
2543
|
-
}
|
|
2544
|
-
continue;
|
|
2545
|
-
}
|
|
2546
|
-
}
|
|
2547
|
-
if (end === true) {
|
|
2548
|
-
if (this.state.quoting === true) {
|
|
2549
|
-
const err = this.__error(
|
|
2550
|
-
new CsvError(
|
|
2551
|
-
"CSV_QUOTE_NOT_CLOSED",
|
|
2552
|
-
[
|
|
2553
|
-
"Quote Not Closed:",
|
|
2554
|
-
`the parsing is finished with an opening quote at line ${this.info.lines}`
|
|
2555
|
-
],
|
|
2556
|
-
this.options,
|
|
2557
|
-
this.__infoField()
|
|
2558
|
-
)
|
|
2559
|
-
);
|
|
2560
|
-
if (err !== void 0) return err;
|
|
2561
|
-
} else {
|
|
2562
|
-
if (this.state.wasQuoting === true || this.state.record.length !== 0 || this.state.field.length !== 0) {
|
|
2563
|
-
this.info.bytes = this.state.bufBytesStart + pos;
|
|
2564
|
-
const errField = this.__onField();
|
|
2565
|
-
if (errField !== void 0) return errField;
|
|
2566
|
-
const errRecord = this.__onRecord(push);
|
|
2567
|
-
if (errRecord !== void 0) return errRecord;
|
|
2568
|
-
} else if (this.state.wasRowDelimiter === true) {
|
|
2569
|
-
this.info.empty_lines++;
|
|
2570
|
-
} else if (this.state.commenting === true) {
|
|
2571
|
-
this.info.comment_lines++;
|
|
2572
|
-
}
|
|
2573
|
-
}
|
|
2574
|
-
} else {
|
|
2575
|
-
this.state.bufBytesStart += pos;
|
|
2576
|
-
this.state.previousBuf = buf.slice(pos);
|
|
2577
|
-
}
|
|
2578
|
-
if (this.state.wasRowDelimiter === true) {
|
|
2579
|
-
this.info.lines++;
|
|
2580
|
-
this.state.wasRowDelimiter = false;
|
|
2581
|
-
}
|
|
2582
|
-
},
|
|
2583
|
-
__onRecord: function(push) {
|
|
2584
|
-
const {
|
|
2585
|
-
columns,
|
|
2586
|
-
group_columns_by_name,
|
|
2587
|
-
encoding,
|
|
2588
|
-
info: info2,
|
|
2589
|
-
from: from2,
|
|
2590
|
-
relax_column_count,
|
|
2591
|
-
relax_column_count_less,
|
|
2592
|
-
relax_column_count_more,
|
|
2593
|
-
raw,
|
|
2594
|
-
skip_records_with_empty_values
|
|
2595
|
-
} = this.options;
|
|
2596
|
-
const { enabled, record } = this.state;
|
|
2597
|
-
if (enabled === false) {
|
|
2598
|
-
return this.__resetRecord();
|
|
2599
|
-
}
|
|
2600
|
-
const recordLength = record.length;
|
|
2601
|
-
if (columns === true) {
|
|
2602
|
-
if (skip_records_with_empty_values === true && isRecordEmpty(record)) {
|
|
2603
|
-
this.__resetRecord();
|
|
2604
|
-
return;
|
|
2605
|
-
}
|
|
2606
|
-
return this.__firstLineToColumns(record);
|
|
2607
|
-
}
|
|
2608
|
-
if (columns === false && this.info.records === 0) {
|
|
2609
|
-
this.state.expectedRecordLength = recordLength;
|
|
2610
|
-
}
|
|
2611
|
-
if (recordLength !== this.state.expectedRecordLength) {
|
|
2612
|
-
const err = columns === false ? new CsvError(
|
|
2613
|
-
"CSV_RECORD_INCONSISTENT_FIELDS_LENGTH",
|
|
2614
|
-
[
|
|
2615
|
-
"Invalid Record Length:",
|
|
2616
|
-
`expect ${this.state.expectedRecordLength},`,
|
|
2617
|
-
`got ${recordLength} on line ${this.info.lines}`
|
|
2618
|
-
],
|
|
2619
|
-
this.options,
|
|
2620
|
-
this.__infoField(),
|
|
2621
|
-
{
|
|
2622
|
-
record
|
|
2623
|
-
}
|
|
2624
|
-
) : new CsvError(
|
|
2625
|
-
"CSV_RECORD_INCONSISTENT_COLUMNS",
|
|
2626
|
-
[
|
|
2627
|
-
"Invalid Record Length:",
|
|
2628
|
-
`columns length is ${columns.length},`,
|
|
2629
|
-
// rename columns
|
|
2630
|
-
`got ${recordLength} on line ${this.info.lines}`
|
|
2631
|
-
],
|
|
2632
|
-
this.options,
|
|
2633
|
-
this.__infoField(),
|
|
2634
|
-
{
|
|
2635
|
-
record
|
|
2636
|
-
}
|
|
2637
|
-
);
|
|
2638
|
-
if (relax_column_count === true || relax_column_count_less === true && recordLength < this.state.expectedRecordLength || relax_column_count_more === true && recordLength > this.state.expectedRecordLength) {
|
|
2639
|
-
this.info.invalid_field_length++;
|
|
2640
|
-
this.state.error = err;
|
|
2641
|
-
} else {
|
|
2642
|
-
const finalErr = this.__error(err);
|
|
2643
|
-
if (finalErr) return finalErr;
|
|
2644
|
-
}
|
|
2645
|
-
}
|
|
2646
|
-
if (skip_records_with_empty_values === true && isRecordEmpty(record)) {
|
|
2647
|
-
this.__resetRecord();
|
|
2648
|
-
return;
|
|
2649
|
-
}
|
|
2650
|
-
if (this.state.recordHasError === true) {
|
|
2651
|
-
this.__resetRecord();
|
|
2652
|
-
this.state.recordHasError = false;
|
|
2653
|
-
return;
|
|
2654
|
-
}
|
|
2655
|
-
this.info.records++;
|
|
2656
|
-
if (from2 === 1 || this.info.records >= from2) {
|
|
2657
|
-
const { objname } = this.options;
|
|
2658
|
-
if (columns !== false) {
|
|
2659
|
-
const obj = {};
|
|
2660
|
-
for (let i = 0, l = record.length; i < l; i++) {
|
|
2661
|
-
if (columns[i] === void 0 || columns[i].disabled) continue;
|
|
2662
|
-
if (group_columns_by_name === true && obj[columns[i].name] !== void 0) {
|
|
2663
|
-
if (Array.isArray(obj[columns[i].name])) {
|
|
2664
|
-
obj[columns[i].name] = obj[columns[i].name].concat(record[i]);
|
|
2665
|
-
} else {
|
|
2666
|
-
obj[columns[i].name] = [obj[columns[i].name], record[i]];
|
|
2667
|
-
}
|
|
2668
|
-
} else {
|
|
2669
|
-
obj[columns[i].name] = record[i];
|
|
2670
|
-
}
|
|
2671
|
-
}
|
|
2672
|
-
if (raw === true || info2 === true) {
|
|
2673
|
-
const extRecord = Object.assign(
|
|
2674
|
-
{ record: obj },
|
|
2675
|
-
raw === true ? { raw: this.state.rawBuffer.toString(encoding) } : {},
|
|
2676
|
-
info2 === true ? { info: this.__infoRecord() } : {}
|
|
2677
|
-
);
|
|
2678
|
-
const err = this.__push(
|
|
2679
|
-
objname === void 0 ? extRecord : [obj[objname], extRecord],
|
|
2680
|
-
push
|
|
2681
|
-
);
|
|
2682
|
-
if (err) {
|
|
2683
|
-
return err;
|
|
2684
|
-
}
|
|
2685
|
-
} else {
|
|
2686
|
-
const err = this.__push(
|
|
2687
|
-
objname === void 0 ? obj : [obj[objname], obj],
|
|
2688
|
-
push
|
|
2689
|
-
);
|
|
2690
|
-
if (err) {
|
|
2691
|
-
return err;
|
|
2692
|
-
}
|
|
2693
|
-
}
|
|
2694
|
-
} else {
|
|
2695
|
-
if (raw === true || info2 === true) {
|
|
2696
|
-
const extRecord = Object.assign(
|
|
2697
|
-
{ record },
|
|
2698
|
-
raw === true ? { raw: this.state.rawBuffer.toString(encoding) } : {},
|
|
2699
|
-
info2 === true ? { info: this.__infoRecord() } : {}
|
|
2700
|
-
);
|
|
2701
|
-
const err = this.__push(
|
|
2702
|
-
objname === void 0 ? extRecord : [record[objname], extRecord],
|
|
2703
|
-
push
|
|
2704
|
-
);
|
|
2705
|
-
if (err) {
|
|
2706
|
-
return err;
|
|
2707
|
-
}
|
|
2708
|
-
} else {
|
|
2709
|
-
const err = this.__push(
|
|
2710
|
-
objname === void 0 ? record : [record[objname], record],
|
|
2711
|
-
push
|
|
2712
|
-
);
|
|
2713
|
-
if (err) {
|
|
2714
|
-
return err;
|
|
2715
|
-
}
|
|
2716
|
-
}
|
|
2717
|
-
}
|
|
2718
|
-
}
|
|
2719
|
-
this.__resetRecord();
|
|
2720
|
-
},
|
|
2721
|
-
__firstLineToColumns: function(record) {
|
|
2722
|
-
const { firstLineToHeaders } = this.state;
|
|
2723
|
-
try {
|
|
2724
|
-
const headers = firstLineToHeaders === void 0 ? record : firstLineToHeaders.call(null, record);
|
|
2725
|
-
if (!Array.isArray(headers)) {
|
|
2726
|
-
return this.__error(
|
|
2727
|
-
new CsvError(
|
|
2728
|
-
"CSV_INVALID_COLUMN_MAPPING",
|
|
2729
|
-
[
|
|
2730
|
-
"Invalid Column Mapping:",
|
|
2731
|
-
"expect an array from column function,",
|
|
2732
|
-
`got ${JSON.stringify(headers)}`
|
|
2733
|
-
],
|
|
2734
|
-
this.options,
|
|
2735
|
-
this.__infoField(),
|
|
2736
|
-
{
|
|
2737
|
-
headers
|
|
2738
|
-
}
|
|
2739
|
-
)
|
|
2740
|
-
);
|
|
2741
|
-
}
|
|
2742
|
-
const normalizedHeaders = normalize_columns_array(headers);
|
|
2743
|
-
this.state.expectedRecordLength = normalizedHeaders.length;
|
|
2744
|
-
this.options.columns = normalizedHeaders;
|
|
2745
|
-
this.__resetRecord();
|
|
2746
|
-
return;
|
|
2747
|
-
} catch (err) {
|
|
2748
|
-
return err;
|
|
2749
|
-
}
|
|
2750
|
-
},
|
|
2751
|
-
__resetRecord: function() {
|
|
2752
|
-
if (this.options.raw === true) {
|
|
2753
|
-
this.state.rawBuffer.reset();
|
|
2754
|
-
}
|
|
2755
|
-
this.state.error = void 0;
|
|
2756
|
-
this.state.record = [];
|
|
2757
|
-
this.state.record_length = 0;
|
|
2758
|
-
},
|
|
2759
|
-
__onField: function() {
|
|
2760
|
-
const { cast, encoding, rtrim, max_record_size } = this.options;
|
|
2761
|
-
const { enabled, wasQuoting } = this.state;
|
|
2762
|
-
if (enabled === false) {
|
|
2763
|
-
return this.__resetField();
|
|
2764
|
-
}
|
|
2765
|
-
let field = this.state.field.toString(encoding);
|
|
2766
|
-
if (rtrim === true && wasQuoting === false) {
|
|
2767
|
-
field = field.trimRight();
|
|
2768
|
-
}
|
|
2769
|
-
if (cast === true) {
|
|
2770
|
-
const [err, f] = this.__cast(field);
|
|
2771
|
-
if (err !== void 0) return err;
|
|
2772
|
-
field = f;
|
|
2773
|
-
}
|
|
2774
|
-
this.state.record.push(field);
|
|
2775
|
-
if (max_record_size !== 0 && typeof field === "string") {
|
|
2776
|
-
this.state.record_length += field.length;
|
|
2777
|
-
}
|
|
2778
|
-
this.__resetField();
|
|
2779
|
-
},
|
|
2780
|
-
__resetField: function() {
|
|
2781
|
-
this.state.field.reset();
|
|
2782
|
-
this.state.wasQuoting = false;
|
|
2783
|
-
},
|
|
2784
|
-
__push: function(record, push) {
|
|
2785
|
-
const { on_record } = this.options;
|
|
2786
|
-
if (on_record !== void 0) {
|
|
2787
|
-
const info2 = this.__infoRecord();
|
|
2788
|
-
try {
|
|
2789
|
-
record = on_record.call(null, record, info2);
|
|
2790
|
-
} catch (err) {
|
|
2791
|
-
return err;
|
|
2792
|
-
}
|
|
2793
|
-
if (record === void 0 || record === null) {
|
|
2794
|
-
return;
|
|
2795
|
-
}
|
|
2796
|
-
}
|
|
2797
|
-
push(record);
|
|
2798
|
-
},
|
|
2799
|
-
// Return a tuple with the error and the casted value
|
|
2800
|
-
__cast: function(field) {
|
|
2801
|
-
const { columns, relax_column_count } = this.options;
|
|
2802
|
-
const isColumns = Array.isArray(columns);
|
|
2803
|
-
if (isColumns === true && relax_column_count && this.options.columns.length <= this.state.record.length) {
|
|
2804
|
-
return [void 0, void 0];
|
|
2805
|
-
}
|
|
2806
|
-
if (this.state.castField !== null) {
|
|
2807
|
-
try {
|
|
2808
|
-
const info2 = this.__infoField();
|
|
2809
|
-
return [void 0, this.state.castField.call(null, field, info2)];
|
|
2810
|
-
} catch (err) {
|
|
2811
|
-
return [err];
|
|
2812
|
-
}
|
|
2813
|
-
}
|
|
2814
|
-
if (this.__isFloat(field)) {
|
|
2815
|
-
return [void 0, parseFloat(field)];
|
|
2816
|
-
} else if (this.options.cast_date !== false) {
|
|
2817
|
-
const info2 = this.__infoField();
|
|
2818
|
-
return [void 0, this.options.cast_date.call(null, field, info2)];
|
|
2819
|
-
}
|
|
2820
|
-
return [void 0, field];
|
|
2821
|
-
},
|
|
2822
|
-
// Helper to test if a character is a space or a line delimiter
|
|
2823
|
-
__isCharTrimable: function(buf, pos) {
|
|
2824
|
-
const isTrim = (buf2, pos2) => {
|
|
2825
|
-
const { timchars } = this.state;
|
|
2826
|
-
loop1: for (let i = 0; i < timchars.length; i++) {
|
|
2827
|
-
const timchar = timchars[i];
|
|
2828
|
-
for (let j = 0; j < timchar.length; j++) {
|
|
2829
|
-
if (timchar[j] !== buf2[pos2 + j]) continue loop1;
|
|
2830
|
-
}
|
|
2831
|
-
return timchar.length;
|
|
2832
|
-
}
|
|
2833
|
-
return 0;
|
|
2834
|
-
};
|
|
2835
|
-
return isTrim(buf, pos);
|
|
2836
|
-
},
|
|
2837
|
-
// Keep it in case we implement the `cast_int` option
|
|
2838
|
-
// __isInt(value){
|
|
2839
|
-
// // return Number.isInteger(parseInt(value))
|
|
2840
|
-
// // return !isNaN( parseInt( obj ) );
|
|
2841
|
-
// return /^(\-|\+)?[1-9][0-9]*$/.test(value)
|
|
2842
|
-
// }
|
|
2843
|
-
__isFloat: function(value) {
|
|
2844
|
-
return value - parseFloat(value) + 1 >= 0;
|
|
2845
|
-
},
|
|
2846
|
-
__compareBytes: function(sourceBuf, targetBuf, targetPos, firstByte) {
|
|
2847
|
-
if (sourceBuf[0] !== firstByte) return 0;
|
|
2848
|
-
const sourceLength = sourceBuf.length;
|
|
2849
|
-
for (let i = 1; i < sourceLength; i++) {
|
|
2850
|
-
if (sourceBuf[i] !== targetBuf[targetPos + i]) return 0;
|
|
2851
|
-
}
|
|
2852
|
-
return sourceLength;
|
|
2853
|
-
},
|
|
2854
|
-
__isDelimiter: function(buf, pos, chr) {
|
|
2855
|
-
const { delimiter, ignore_last_delimiters } = this.options;
|
|
2856
|
-
if (ignore_last_delimiters === true && this.state.record.length === this.options.columns.length - 1) {
|
|
2857
|
-
return 0;
|
|
2858
|
-
} else if (ignore_last_delimiters !== false && typeof ignore_last_delimiters === "number" && this.state.record.length === ignore_last_delimiters - 1) {
|
|
2859
|
-
return 0;
|
|
2860
|
-
}
|
|
2861
|
-
loop1: for (let i = 0; i < delimiter.length; i++) {
|
|
2862
|
-
const del = delimiter[i];
|
|
2863
|
-
if (del[0] === chr) {
|
|
2864
|
-
for (let j = 1; j < del.length; j++) {
|
|
2865
|
-
if (del[j] !== buf[pos + j]) continue loop1;
|
|
2866
|
-
}
|
|
2867
|
-
return del.length;
|
|
2868
|
-
}
|
|
2869
|
-
}
|
|
2870
|
-
return 0;
|
|
2871
|
-
},
|
|
2872
|
-
__isRecordDelimiter: function(chr, buf, pos) {
|
|
2873
|
-
const { record_delimiter } = this.options;
|
|
2874
|
-
const recordDelimiterLength = record_delimiter.length;
|
|
2875
|
-
loop1: for (let i = 0; i < recordDelimiterLength; i++) {
|
|
2876
|
-
const rd = record_delimiter[i];
|
|
2877
|
-
const rdLength = rd.length;
|
|
2878
|
-
if (rd[0] !== chr) {
|
|
2879
|
-
continue;
|
|
2880
|
-
}
|
|
2881
|
-
for (let j = 1; j < rdLength; j++) {
|
|
2882
|
-
if (rd[j] !== buf[pos + j]) {
|
|
2883
|
-
continue loop1;
|
|
2884
|
-
}
|
|
2885
|
-
}
|
|
2886
|
-
return rd.length;
|
|
2887
|
-
}
|
|
2888
|
-
return 0;
|
|
2889
|
-
},
|
|
2890
|
-
__isEscape: function(buf, pos, chr) {
|
|
2891
|
-
const { escape } = this.options;
|
|
2892
|
-
if (escape === null) return false;
|
|
2893
|
-
const l = escape.length;
|
|
2894
|
-
if (escape[0] === chr) {
|
|
2895
|
-
for (let i = 0; i < l; i++) {
|
|
2896
|
-
if (escape[i] !== buf[pos + i]) {
|
|
2897
|
-
return false;
|
|
2898
|
-
}
|
|
2899
|
-
}
|
|
2900
|
-
return true;
|
|
2901
|
-
}
|
|
2902
|
-
return false;
|
|
2903
|
-
},
|
|
2904
|
-
__isQuote: function(buf, pos) {
|
|
2905
|
-
const { quote } = this.options;
|
|
2906
|
-
if (quote === null) return false;
|
|
2907
|
-
const l = quote.length;
|
|
2908
|
-
for (let i = 0; i < l; i++) {
|
|
2909
|
-
if (quote[i] !== buf[pos + i]) {
|
|
2910
|
-
return false;
|
|
2911
|
-
}
|
|
2912
|
-
}
|
|
2913
|
-
return true;
|
|
2914
|
-
},
|
|
2915
|
-
__autoDiscoverRecordDelimiter: function(buf, pos) {
|
|
2916
|
-
const { encoding } = this.options;
|
|
2917
|
-
const rds = [
|
|
2918
|
-
// Important, the windows line ending must be before mac os 9
|
|
2919
|
-
Buffer2.from("\r\n", encoding),
|
|
2920
|
-
Buffer2.from("\n", encoding),
|
|
2921
|
-
Buffer2.from("\r", encoding)
|
|
2922
|
-
];
|
|
2923
|
-
loop: for (let i = 0; i < rds.length; i++) {
|
|
2924
|
-
const l = rds[i].length;
|
|
2925
|
-
for (let j = 0; j < l; j++) {
|
|
2926
|
-
if (rds[i][j] !== buf[pos + j]) {
|
|
2927
|
-
continue loop;
|
|
2928
|
-
}
|
|
2929
|
-
}
|
|
2930
|
-
this.options.record_delimiter.push(rds[i]);
|
|
2931
|
-
this.state.recordDelimiterMaxLength = rds[i].length;
|
|
2932
|
-
return rds[i].length;
|
|
2933
|
-
}
|
|
2934
|
-
return 0;
|
|
2935
|
-
},
|
|
2936
|
-
__error: function(msg) {
|
|
2937
|
-
const { encoding, raw, skip_records_with_error } = this.options;
|
|
2938
|
-
const err = typeof msg === "string" ? new Error(msg) : msg;
|
|
2939
|
-
if (skip_records_with_error) {
|
|
2940
|
-
this.state.recordHasError = true;
|
|
2941
|
-
if (this.options.on_skip !== void 0) {
|
|
2942
|
-
this.options.on_skip(
|
|
2943
|
-
err,
|
|
2944
|
-
raw ? this.state.rawBuffer.toString(encoding) : void 0
|
|
2945
|
-
);
|
|
2946
|
-
}
|
|
2947
|
-
return void 0;
|
|
2948
|
-
} else {
|
|
2949
|
-
return err;
|
|
2950
|
-
}
|
|
2951
|
-
},
|
|
2952
|
-
__infoDataSet: function() {
|
|
2953
|
-
return {
|
|
2954
|
-
...this.info,
|
|
2955
|
-
columns: this.options.columns
|
|
2956
|
-
};
|
|
2957
|
-
},
|
|
2958
|
-
__infoRecord: function() {
|
|
2959
|
-
const { columns, raw, encoding } = this.options;
|
|
2960
|
-
return {
|
|
2961
|
-
...this.__infoDataSet(),
|
|
2962
|
-
error: this.state.error,
|
|
2963
|
-
header: columns === true,
|
|
2964
|
-
index: this.state.record.length,
|
|
2965
|
-
raw: raw ? this.state.rawBuffer.toString(encoding) : void 0
|
|
2966
|
-
};
|
|
2967
|
-
},
|
|
2968
|
-
__infoField: function() {
|
|
2969
|
-
const { columns } = this.options;
|
|
2970
|
-
const isColumns = Array.isArray(columns);
|
|
2971
|
-
return {
|
|
2972
|
-
...this.__infoRecord(),
|
|
2973
|
-
column: isColumns === true ? columns.length > this.state.record.length ? columns[this.state.record.length].name : null : this.state.record.length,
|
|
2974
|
-
quoting: this.state.wasQuoting
|
|
2975
|
-
};
|
|
2976
|
-
}
|
|
2977
|
-
};
|
|
2978
|
-
};
|
|
2979
|
-
var parse = function(data, opts = {}) {
|
|
2980
|
-
if (typeof data === "string") {
|
|
2981
|
-
data = Buffer2.from(data);
|
|
2982
|
-
}
|
|
2983
|
-
const records = opts && opts.objname ? {} : [];
|
|
2984
|
-
const parser = transform(opts);
|
|
2985
|
-
const push = (record) => {
|
|
2986
|
-
if (parser.options.objname === void 0) records.push(record);
|
|
2987
|
-
else {
|
|
2988
|
-
records[record[0]] = record[1];
|
|
2989
|
-
}
|
|
2990
|
-
};
|
|
2991
|
-
const close = () => {
|
|
2992
|
-
};
|
|
2993
|
-
const err1 = parser.parse(data, false, push, close);
|
|
2994
|
-
if (err1 !== void 0) throw err1;
|
|
2995
|
-
const err2 = parser.parse(void 0, true, push, close);
|
|
2996
|
-
if (err2 !== void 0) throw err2;
|
|
2997
|
-
return records;
|
|
2998
|
-
};
|
|
2999
7
|
|
|
3000
|
-
|
|
3001
|
-
var DEEPLINE_ERROR_BRAND = Symbol.for("deepline.error.v1");
|
|
3002
|
-
var TOOL_EXECUTION_ERROR_BRAND = Symbol.for(
|
|
3003
|
-
"deepline.tool-execution-error.v1"
|
|
3004
|
-
);
|
|
3005
|
-
var PROVIDER_TRANSIENT_ERROR_BRAND = Symbol.for(
|
|
3006
|
-
"deepline.provider-transient-error.v1"
|
|
3007
|
-
);
|
|
3008
|
-
function nativeInstanceOf(constructor, value) {
|
|
3009
|
-
return Reflect.apply(Function.prototype[Symbol.hasInstance], constructor, [
|
|
3010
|
-
value
|
|
3011
|
-
]);
|
|
3012
|
-
}
|
|
3013
|
-
function hasBrand(value, brand) {
|
|
3014
|
-
return typeof value === "object" && value !== null && value[brand] === true;
|
|
3015
|
-
}
|
|
3016
|
-
function applyBrand(value, brand) {
|
|
3017
|
-
if (hasBrand(value, brand)) return;
|
|
3018
|
-
Object.defineProperty(value, brand, {
|
|
3019
|
-
configurable: false,
|
|
3020
|
-
enumerable: false,
|
|
3021
|
-
writable: false,
|
|
3022
|
-
value: true
|
|
3023
|
-
});
|
|
3024
|
-
}
|
|
3025
|
-
var DeeplineError = class _DeeplineError extends Error {
|
|
3026
|
-
/** HTTP status when the failure crossed an HTTP boundary. */
|
|
3027
|
-
statusCode;
|
|
3028
|
-
/** Stable machine-readable error code when one exists. */
|
|
3029
|
-
code;
|
|
3030
|
-
/** Local diagnostic context; not a portable error contract. */
|
|
3031
|
-
details;
|
|
3032
|
-
/**
|
|
3033
|
-
* Construct a Deepline error.
|
|
3034
|
-
*
|
|
3035
|
-
* SDK and runtime code construct these errors. Application and Play code
|
|
3036
|
-
* normally catches the public subclasses instead.
|
|
3037
|
-
*
|
|
3038
|
-
* @param message Human-readable failure summary.
|
|
3039
|
-
* @param statusCode HTTP status when one exists.
|
|
3040
|
-
* @param code Stable machine-readable code when one exists.
|
|
3041
|
-
* @param details Local diagnostic context; never a portable error contract.
|
|
3042
|
-
*/
|
|
3043
|
-
constructor(message, statusCode, code, details) {
|
|
3044
|
-
super(message);
|
|
3045
|
-
this.name = "DeeplineError";
|
|
3046
|
-
this.statusCode = statusCode;
|
|
3047
|
-
this.code = code;
|
|
3048
|
-
this.details = details;
|
|
3049
|
-
applyBrand(this, DEEPLINE_ERROR_BRAND);
|
|
3050
|
-
}
|
|
3051
|
-
static [Symbol.hasInstance](value) {
|
|
3052
|
-
if (this !== _DeeplineError) return nativeInstanceOf(this, value);
|
|
3053
|
-
return hasBrand(value, DEEPLINE_ERROR_BRAND);
|
|
3054
|
-
}
|
|
3055
|
-
};
|
|
3056
|
-
|
|
3057
|
-
// src/plays/csv-data-input.ts
|
|
3058
|
-
function parseCsvDataInput(source, content, options = {}) {
|
|
3059
|
-
const onRecord = options.onRecord;
|
|
3060
|
-
let recordCount = 0;
|
|
3061
|
-
let records;
|
|
3062
|
-
try {
|
|
3063
|
-
records = parse(content, {
|
|
3064
|
-
bom: true,
|
|
3065
|
-
columns: false,
|
|
3066
|
-
skip_empty_lines: true,
|
|
3067
|
-
relax_column_count: true,
|
|
3068
|
-
// STRICT RFC quoting: an unclosed quote or ragged quoting is a hard
|
|
3069
|
-
// error rather than being swallowed into one giant field.
|
|
3070
|
-
relax_quotes: false,
|
|
3071
|
-
trim: true,
|
|
3072
|
-
...onRecord ? {
|
|
3073
|
-
on_record: (record) => {
|
|
3074
|
-
recordCount += 1;
|
|
3075
|
-
onRecord(recordCount);
|
|
3076
|
-
return record;
|
|
3077
|
-
}
|
|
3078
|
-
} : {}
|
|
3079
|
-
});
|
|
3080
|
-
} catch (error) {
|
|
3081
|
-
throw new DeeplineError(
|
|
3082
|
-
`Input ${source.inputPath} could not be parsed as CSV (${source.value}): ${error instanceof Error ? error.message : String(error)}. This usually means an unclosed quote or ragged quoting. No run was created.`,
|
|
3083
|
-
void 0,
|
|
3084
|
-
"PLAY_INPUT_FILE_PREFLIGHT",
|
|
3085
|
-
{ inputPath: source.inputPath, path: source.value }
|
|
3086
|
-
);
|
|
3087
|
-
}
|
|
3088
|
-
if (records.length === 0) {
|
|
3089
|
-
throw new DeeplineError(
|
|
3090
|
-
`${source.value} is empty: it has no header row and no data rows. No run was created.`,
|
|
3091
|
-
void 0,
|
|
3092
|
-
"PLAY_INPUT_FILE_PREFLIGHT",
|
|
3093
|
-
{ inputPath: source.inputPath, path: source.value }
|
|
3094
|
-
);
|
|
3095
|
-
}
|
|
3096
|
-
const header = records[0];
|
|
3097
|
-
const seen = /* @__PURE__ */ new Map();
|
|
3098
|
-
for (let i = 0; i < header.length; i++) {
|
|
3099
|
-
const raw = header[i] ?? "";
|
|
3100
|
-
const name = raw.trim();
|
|
3101
|
-
if (name.length === 0) continue;
|
|
3102
|
-
const prior = seen.get(name);
|
|
3103
|
-
if (prior) {
|
|
3104
|
-
throw new DeeplineError(
|
|
3105
|
-
`Input ${source.inputPath} (${source.value}) has a duplicate CSV header "${name}" (columns ${prior.index + 1} and ${i + 1}). The second column would silently overwrite the first. Rename one of them. No run was created.`,
|
|
3106
|
-
void 0,
|
|
3107
|
-
"PLAY_INPUT_FILE_PREFLIGHT",
|
|
3108
|
-
{
|
|
3109
|
-
inputPath: source.inputPath,
|
|
3110
|
-
path: source.value,
|
|
3111
|
-
duplicateHeader: name,
|
|
3112
|
-
columns: [prior.index + 1, i + 1],
|
|
3113
|
-
rawSpellings: [prior.raw, raw]
|
|
3114
|
-
}
|
|
3115
|
-
);
|
|
3116
|
-
}
|
|
3117
|
-
seen.set(name, { index: i, raw });
|
|
3118
|
-
}
|
|
3119
|
-
if (records.length - 1 < 1) {
|
|
3120
|
-
throw new DeeplineError(
|
|
3121
|
-
`${source.value} has a header row but no data rows. No run was created.`,
|
|
3122
|
-
void 0,
|
|
3123
|
-
"PLAY_INPUT_FILE_PREFLIGHT",
|
|
3124
|
-
{ inputPath: source.inputPath, path: source.value }
|
|
3125
|
-
);
|
|
3126
|
-
}
|
|
3127
|
-
return {
|
|
3128
|
-
headers: header.map((name) => name.trim()),
|
|
3129
|
-
records: records.slice(1)
|
|
3130
|
-
};
|
|
3131
|
-
}
|
|
3132
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
3133
|
-
0 && (module.exports = {
|
|
3134
|
-
parseCsvDataInput
|
|
3135
|
-
});
|
|
8
|
+
exports.parseCsvDataInput = _chunk5JLQPVNXjs.parseCsvDataInput;
|