@konstit/csv 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +152 -463
- package/THIRD_PARTY_NOTICES.md +7 -1
- package/dist/api.d.ts +169 -44
- package/dist/api.js +75 -368
- package/dist/batches.d.ts +250 -7
- package/dist/batches.js +135 -83
- package/dist/cli-command.d.ts +7 -0
- package/dist/cli-command.js +350 -0
- package/dist/cli-schema.d.ts +111 -0
- package/dist/cli-schema.js +219 -0
- package/dist/cli.js +2 -604
- package/dist/file-stream.d.ts +57 -2
- package/dist/file-stream.js +244 -36
- package/dist/files.d.ts +149 -3
- package/dist/files.js +37 -29
- package/dist/filter.d.ts +80 -0
- package/dist/format-bytes.d.ts +1 -0
- package/dist/format-bytes.js +11 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -14
- package/dist/inspect-file.d.ts +12 -0
- package/dist/inspect-file.js +88 -0
- package/dist/latin1-rows.d.ts +5 -0
- package/dist/latin1-rows.js +122 -0
- package/dist/materialize-field.d.ts +3 -0
- package/dist/materialize-field.js +31 -0
- package/dist/native.d.ts +51 -2
- package/dist/native.js +43 -4
- package/dist/normalize.d.ts +32 -2
- package/dist/normalize.js +51 -2
- package/dist/options-snapshot.d.ts +3 -0
- package/dist/options-snapshot.js +51 -0
- package/dist/options.d.ts +25 -10
- package/dist/options.js +0 -6
- package/dist/parser.d.ts +309 -4
- package/dist/parser.js +128 -31
- package/dist/strict-schema.d.ts +5 -3
- package/dist/strict-schema.js +4 -1
- package/dist/types.d.ts +355 -121
- package/dist/zip-reader.d.ts +11 -1
- package/dist/zip-reader.js +12 -3
- package/package.json +44 -29
- package/prebuilds/darwin-arm64/libcsv_native.dylib +0 -0
- package/prebuilds/darwin-x64/libcsv_native.dylib +0 -0
- package/prebuilds/linux-x64/libcsv_native.so +0 -0
- package/prebuilds/manifest.json +9 -8
- package/prebuilds/provenance/darwin-arm64.json +1 -1
- package/prebuilds/provenance/darwin-x64.json +1 -1
- package/prebuilds/provenance/linux-x64.json +1 -1
- package/dist/worker-count.d.ts +0 -2
- package/dist/worker-count.js +0 -96
- package/dist/worker-factory.d.ts +0 -3
- package/dist/worker-factory.js +0 -9
- package/dist/worker-filter.d.ts +0 -29
- package/dist/worker-filter.js +0 -46
- package/dist/worker-module.d.ts +0 -1
- package/dist/worker-module.js +0 -4
- package/dist/worker-pool.d.ts +0 -17
- package/dist/worker-pool.js +0 -290
- package/dist/worker-rows.d.ts +0 -8
- package/dist/worker-rows.js +0 -118
- package/dist/workers/count.worker.d.ts +0 -1
- package/dist/workers/count.worker.js +0 -49
- package/dist/workers/rows.worker.d.ts +0 -1
- package/dist/workers/rows.worker.js +0 -85
package/dist/batches.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { read } from "bun:ffi";
|
|
2
|
+
import { decodeMaterializedField } from "./materialize-field.js";
|
|
1
3
|
import {
|
|
2
4
|
EMPTY_BUFFER,
|
|
3
5
|
native,
|
|
@@ -9,19 +11,24 @@ import {
|
|
|
9
11
|
normalizeColumns,
|
|
10
12
|
normalizeFilterColumn
|
|
11
13
|
} from "./normalize.js";
|
|
14
|
+
const visitBatchRows = Symbol("visitBatchRows");
|
|
12
15
|
|
|
13
16
|
export class NativeCsvRowView {
|
|
14
17
|
#data;
|
|
15
|
-
#
|
|
18
|
+
#rowOffsetWords;
|
|
16
19
|
#fieldOffsets;
|
|
20
|
+
#fieldOffsetWords;
|
|
17
21
|
#rowIndex;
|
|
22
|
+
#owner;
|
|
18
23
|
constructor(data, rowOffsets, fieldOffsets, rowIndex = 0) {
|
|
19
24
|
this.#data = data;
|
|
20
|
-
this.#
|
|
25
|
+
this.#rowOffsetWords = offsetWords(rowOffsets);
|
|
21
26
|
this.#fieldOffsets = fieldOffsets;
|
|
27
|
+
this.#fieldOffsetWords = offsetWords(fieldOffsets);
|
|
22
28
|
this.#rowIndex = rowIndex;
|
|
23
29
|
}
|
|
24
30
|
get rowIndex() {
|
|
31
|
+
this.#requireActive();
|
|
25
32
|
return this.#rowIndex;
|
|
26
33
|
}
|
|
27
34
|
get fieldCount() {
|
|
@@ -33,75 +40,82 @@ export class NativeCsvRowView {
|
|
|
33
40
|
this.#rowIndex = rowIndex;
|
|
34
41
|
return this;
|
|
35
42
|
}
|
|
36
|
-
|
|
43
|
+
range(columnIndex) {
|
|
37
44
|
const [rowStart, rowEnd] = this.#rowRange(this.#rowIndex);
|
|
38
45
|
const fieldIndex = rowStart + columnIndex;
|
|
39
46
|
if (fieldIndex < rowStart || fieldIndex >= rowEnd)
|
|
40
47
|
return null;
|
|
41
48
|
return {
|
|
42
|
-
start: offsetAt(this.#
|
|
43
|
-
end: offsetAt(this.#
|
|
49
|
+
start: offsetAt(this.#fieldOffsetWords, fieldIndex, "field offset", this.#data.byteLength),
|
|
50
|
+
end: offsetAt(this.#fieldOffsetWords, fieldIndex + 1, "field offset", this.#data.byteLength)
|
|
44
51
|
};
|
|
45
52
|
}
|
|
46
|
-
range(columnIndex) {
|
|
47
|
-
return this.fieldRange(columnIndex);
|
|
48
|
-
}
|
|
49
|
-
fieldBytes(columnIndex) {
|
|
50
|
-
const range = this.fieldRange(columnIndex);
|
|
51
|
-
if (range === null)
|
|
52
|
-
return null;
|
|
53
|
-
return this.#data.subarray(range.start, range.end);
|
|
54
|
-
}
|
|
55
53
|
bytes(columnIndex) {
|
|
56
|
-
return this.
|
|
54
|
+
return this.buffer(columnIndex);
|
|
57
55
|
}
|
|
58
|
-
|
|
59
|
-
const range = this.
|
|
56
|
+
buffer(columnIndex) {
|
|
57
|
+
const range = this.range(columnIndex);
|
|
60
58
|
if (range === null)
|
|
61
59
|
return null;
|
|
62
60
|
return this.#data.subarray(range.start, range.end);
|
|
63
61
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
fieldString(columnIndex) {
|
|
68
|
-
const range = this.fieldRange(columnIndex);
|
|
62
|
+
get(columnIndex) {
|
|
63
|
+
const range = this.range(columnIndex);
|
|
69
64
|
if (range === null)
|
|
70
65
|
return null;
|
|
71
66
|
return this.#data.toString("utf8", range.start, range.end);
|
|
72
67
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
get(columnIndex) {
|
|
77
|
-
return this.getPhysical(columnIndex);
|
|
78
|
-
}
|
|
79
|
-
pickPhysical(columns) {
|
|
68
|
+
pick(columns) {
|
|
69
|
+
this.#requireActive();
|
|
80
70
|
const values = [];
|
|
81
71
|
values.length = columns.length;
|
|
82
72
|
for (let index = 0;index < columns.length; ++index)
|
|
83
|
-
values[index] = this.
|
|
73
|
+
values[index] = this.get(columns[index] ?? 0) ?? "";
|
|
84
74
|
return values;
|
|
85
75
|
}
|
|
86
|
-
pick(columns) {
|
|
87
|
-
return this.pickPhysical(columns);
|
|
88
|
-
}
|
|
89
76
|
#rowRange(rowIndex) {
|
|
77
|
+
this.#requireActive();
|
|
90
78
|
const maxFieldIndex = this.#fieldOffsets.length - 1;
|
|
91
|
-
const rowStart = offsetAt(this.#
|
|
92
|
-
const rowEnd = offsetAt(this.#
|
|
79
|
+
const rowStart = offsetAt(this.#rowOffsetWords, rowIndex, `row ${rowIndex} offset`, maxFieldIndex);
|
|
80
|
+
const rowEnd = offsetAt(this.#rowOffsetWords, rowIndex + 1, `row ${rowIndex} offset`, maxFieldIndex);
|
|
93
81
|
if (rowEnd < rowStart)
|
|
94
82
|
throw RangeError(`row ${rowIndex} offsets are not monotonic`);
|
|
95
83
|
return [rowStart, rowEnd];
|
|
96
84
|
}
|
|
85
|
+
#requireActive() {
|
|
86
|
+
if (this.#owner === null)
|
|
87
|
+
throw Error("row view is only valid during row view callback");
|
|
88
|
+
if (this.#owner?.closed)
|
|
89
|
+
throw Error("native CSV batch is closed");
|
|
90
|
+
}
|
|
91
|
+
static [visitBatchRows](batch, callback) {
|
|
92
|
+
const rowCount = batch.rowCount;
|
|
93
|
+
const view = new NativeCsvRowView(batch.data(), batch.rowOffsets(), batch.fieldOffsets());
|
|
94
|
+
for (let index = 0;index < rowCount; ++index) {
|
|
95
|
+
view.#owner = batch;
|
|
96
|
+
let result;
|
|
97
|
+
try {
|
|
98
|
+
result = callback(view.moveTo(index), index);
|
|
99
|
+
} finally {
|
|
100
|
+
view.#owner = null;
|
|
101
|
+
}
|
|
102
|
+
if (result !== null && (typeof result === "object" || typeof result === "function") && "then" in result && typeof result.then === "function") {
|
|
103
|
+
void Promise.resolve(result).catch(() => {});
|
|
104
|
+
throw TypeError("row view callback must be synchronous");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
97
108
|
}
|
|
98
109
|
|
|
99
110
|
export class NativeCsvBatch {
|
|
100
111
|
#handle;
|
|
101
112
|
#data;
|
|
102
113
|
#dataView;
|
|
114
|
+
#rowOffsetLimit;
|
|
103
115
|
#rowOffsets;
|
|
116
|
+
#rowOffsetWords;
|
|
104
117
|
#fieldOffsets;
|
|
118
|
+
#fieldOffsetWords;
|
|
105
119
|
constructor(handle) {
|
|
106
120
|
this.#handle = handle;
|
|
107
121
|
}
|
|
@@ -121,23 +135,20 @@ export class NativeCsvBatch {
|
|
|
121
135
|
return this.rowsInto([]);
|
|
122
136
|
}
|
|
123
137
|
forEachRow(callback) {
|
|
124
|
-
|
|
125
|
-
const rowView = new NativeCsvRowView(this.data(), this.rowOffsets(), this.fieldOffsets());
|
|
126
|
-
for (let rowIndex = 0;rowIndex < rowCount; ++rowIndex)
|
|
127
|
-
callback(rowView.moveTo(rowIndex), rowIndex);
|
|
138
|
+
NativeCsvRowView[visitBatchRows](this, callback);
|
|
128
139
|
}
|
|
129
140
|
rowsInto(target, columns) {
|
|
130
141
|
normalizeColumns(columns);
|
|
131
142
|
const rowCount = this.rowCount;
|
|
132
143
|
const totalFields = this.totalFields;
|
|
133
|
-
const
|
|
134
|
-
const
|
|
144
|
+
const rowOffsetWords = this.#rowOffsetWordsView();
|
|
145
|
+
const fieldOffsetWords = this.#fieldOffsetWordsView();
|
|
135
146
|
const data = this.data();
|
|
136
147
|
target.length = rowCount;
|
|
137
148
|
if (columns !== void 0) {
|
|
138
149
|
for (let rowIndex = 0;rowIndex < rowCount; ++rowIndex) {
|
|
139
|
-
const fieldStart = offsetAt(
|
|
140
|
-
const fieldEnd = offsetAt(
|
|
150
|
+
const fieldStart = offsetAt(rowOffsetWords, rowIndex, `row ${rowIndex} offset`, totalFields);
|
|
151
|
+
const fieldEnd = offsetAt(rowOffsetWords, rowIndex + 1, `row ${rowIndex} offset`, totalFields);
|
|
141
152
|
const existing = target[rowIndex];
|
|
142
153
|
const row = existing === void 0 ? [] : existing;
|
|
143
154
|
row.length = columns.length;
|
|
@@ -148,25 +159,25 @@ export class NativeCsvBatch {
|
|
|
148
159
|
row[outputIndex] = "";
|
|
149
160
|
continue;
|
|
150
161
|
}
|
|
151
|
-
const start = offsetAt(
|
|
152
|
-
const end = offsetAt(
|
|
153
|
-
row[outputIndex] = data
|
|
162
|
+
const start = offsetAt(fieldOffsetWords, fieldIndex, "field offset", data.byteLength);
|
|
163
|
+
const end = offsetAt(fieldOffsetWords, fieldIndex + 1, "field offset", data.byteLength);
|
|
164
|
+
row[outputIndex] = decodeMaterializedField(data, start, end, "utf8");
|
|
154
165
|
}
|
|
155
166
|
target[rowIndex] = row;
|
|
156
167
|
}
|
|
157
168
|
return target;
|
|
158
169
|
}
|
|
159
170
|
for (let rowIndex = 0;rowIndex < rowCount; ++rowIndex) {
|
|
160
|
-
const fieldStart = offsetAt(
|
|
161
|
-
const fieldEnd = offsetAt(
|
|
171
|
+
const fieldStart = offsetAt(rowOffsetWords, rowIndex, `row ${rowIndex} offset`, totalFields);
|
|
172
|
+
const fieldEnd = offsetAt(rowOffsetWords, rowIndex + 1, `row ${rowIndex} offset`, totalFields);
|
|
162
173
|
const existing = target[rowIndex];
|
|
163
174
|
const row = existing === void 0 ? [] : existing;
|
|
164
175
|
row.length = fieldEnd - fieldStart;
|
|
165
176
|
for (let fieldIndex = fieldStart;fieldIndex < fieldEnd; ++fieldIndex) {
|
|
166
|
-
const start = offsetAt(
|
|
167
|
-
const end = offsetAt(
|
|
177
|
+
const start = offsetAt(fieldOffsetWords, fieldIndex, "field offset", data.byteLength);
|
|
178
|
+
const end = offsetAt(fieldOffsetWords, fieldIndex + 1, "field offset", data.byteLength);
|
|
168
179
|
const column = fieldIndex - fieldStart;
|
|
169
|
-
row[column] = data
|
|
180
|
+
row[column] = decodeMaterializedField(data, start, end, "utf8");
|
|
170
181
|
}
|
|
171
182
|
target[rowIndex] = row;
|
|
172
183
|
}
|
|
@@ -192,10 +203,7 @@ export class NativeCsvBatch {
|
|
|
192
203
|
if (this.#rowOffsets !== void 0)
|
|
193
204
|
return this.#rowOffsets;
|
|
194
205
|
const rowCount = this.rowCount;
|
|
195
|
-
|
|
196
|
-
if (ptr === null)
|
|
197
|
-
throw Error("native CSV batch row offsets are null");
|
|
198
|
-
this.#rowOffsets = new BigUint64Array(toArrayBuffer(ptr, 0, (rowCount + 1) * BigUint64Array.BYTES_PER_ELEMENT));
|
|
206
|
+
this.#rowOffsets = new BigUint64Array(toArrayBuffer(this.#rowOffsetsPointer(), 0, (rowCount + 1) * BigUint64Array.BYTES_PER_ELEMENT));
|
|
199
207
|
return this.#rowOffsets;
|
|
200
208
|
}
|
|
201
209
|
fieldOffsets() {
|
|
@@ -209,24 +217,37 @@ export class NativeCsvBatch {
|
|
|
209
217
|
return this.#fieldOffsets;
|
|
210
218
|
}
|
|
211
219
|
rowFieldCount(rowIndex) {
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
const
|
|
220
|
+
const firstLookupWithoutView = this.#rowOffsetLimit === void 0 && this.#rowOffsets === void 0;
|
|
221
|
+
this.#rowOffsetLimit ??= this.totalFields;
|
|
222
|
+
const totalFields = this.#rowOffsetLimit;
|
|
223
|
+
if (!Number.isInteger(rowIndex) || rowIndex < 0)
|
|
224
|
+
throw RangeError(`row ${rowIndex} offset index out of range: ${rowIndex}`);
|
|
225
|
+
if (firstLookupWithoutView && rowIndex < MAX_DIRECT_ROW_INDEX_EXCLUSIVE && rowIndex < native.symbols.csv_batch_row_count(this.#requireHandle())) {
|
|
226
|
+
const ptr = this.#rowOffsetsPointer();
|
|
227
|
+
const byteOffset = rowIndex * BigUint64Array.BYTES_PER_ELEMENT;
|
|
228
|
+
const start = Number(read.u64(ptr, byteOffset));
|
|
229
|
+
const end = Number(read.u64(ptr, byteOffset + BigUint64Array.BYTES_PER_ELEMENT));
|
|
230
|
+
if (start <= totalFields && end <= totalFields)
|
|
231
|
+
return end - start;
|
|
232
|
+
}
|
|
233
|
+
const rowOffsetWords = this.#rowOffsetWords ?? this.#rowOffsetWordsView();
|
|
234
|
+
const start = offsetAt(rowOffsetWords, rowIndex, `row ${rowIndex} offset`, totalFields);
|
|
235
|
+
const end = offsetAt(rowOffsetWords, rowIndex + 1, `row ${rowIndex} offset`, totalFields);
|
|
215
236
|
return end - start;
|
|
216
237
|
}
|
|
217
238
|
fieldRange(rowIndex, columnIndex) {
|
|
218
|
-
const
|
|
219
|
-
const
|
|
239
|
+
const rowOffsetWords = this.#rowOffsetWordsView();
|
|
240
|
+
const fieldOffsetWords = this.#fieldOffsetWordsView();
|
|
220
241
|
const totalFields = this.totalFields;
|
|
221
242
|
const dataLength = this.dataLength;
|
|
222
|
-
const rowStart = offsetAt(
|
|
223
|
-
const rowEnd = offsetAt(
|
|
243
|
+
const rowStart = offsetAt(rowOffsetWords, rowIndex, `row ${rowIndex} offset`, totalFields);
|
|
244
|
+
const rowEnd = offsetAt(rowOffsetWords, rowIndex + 1, `row ${rowIndex} offset`, totalFields);
|
|
224
245
|
const fieldIndex = rowStart + columnIndex;
|
|
225
246
|
if (fieldIndex < rowStart || fieldIndex >= rowEnd)
|
|
226
247
|
return null;
|
|
227
248
|
return {
|
|
228
|
-
start: offsetAt(
|
|
229
|
-
end: offsetAt(
|
|
249
|
+
start: offsetAt(fieldOffsetWords, fieldIndex, "field offset", dataLength),
|
|
250
|
+
end: offsetAt(fieldOffsetWords, fieldIndex + 1, "field offset", dataLength)
|
|
230
251
|
};
|
|
231
252
|
}
|
|
232
253
|
fieldBuffer(rowIndex, columnIndex) {
|
|
@@ -248,19 +269,20 @@ export class NativeCsvBatch {
|
|
|
248
269
|
return this.data().toString("utf8", range.start, range.end);
|
|
249
270
|
}
|
|
250
271
|
forEachColumnRange(columnIndex, callback, startRow = 0, endRow = this.rowCount) {
|
|
251
|
-
const
|
|
252
|
-
const
|
|
272
|
+
const rowOffsetWords = this.#rowOffsetWordsView();
|
|
273
|
+
const fieldOffsetWords = this.#fieldOffsetWordsView();
|
|
253
274
|
const totalFields = this.totalFields;
|
|
254
275
|
const dataLength = this.dataLength;
|
|
255
276
|
const resolvedEndRow = this.#resolveEndRow(endRow);
|
|
256
277
|
this.#validateRowRange(startRow, resolvedEndRow);
|
|
257
278
|
for (let rowIndex = startRow;rowIndex < resolvedEndRow; ++rowIndex) {
|
|
258
|
-
|
|
259
|
-
const
|
|
279
|
+
this.#requireHandle();
|
|
280
|
+
const rowStart = offsetAt(rowOffsetWords, rowIndex, `row ${rowIndex} offset`, totalFields);
|
|
281
|
+
const rowEnd = offsetAt(rowOffsetWords, rowIndex + 1, `row ${rowIndex} offset`, totalFields);
|
|
260
282
|
const fieldIndex = rowStart + columnIndex;
|
|
261
283
|
if (fieldIndex < rowStart || fieldIndex >= rowEnd)
|
|
262
284
|
continue;
|
|
263
|
-
callback(rowIndex, offsetAt(
|
|
285
|
+
callback(rowIndex, offsetAt(fieldOffsetWords, fieldIndex, "field offset", dataLength), offsetAt(fieldOffsetWords, fieldIndex + 1, "field offset", dataLength));
|
|
264
286
|
}
|
|
265
287
|
}
|
|
266
288
|
forEachColumnBytes(columnIndex, callback, startRow = 0, endRow = this.rowCount) {
|
|
@@ -272,14 +294,15 @@ export class NativeCsvBatch {
|
|
|
272
294
|
scanColumns(columns, callback, startRow = 0, endRow = this.rowCount) {
|
|
273
295
|
const resolvedEndRow = this.#resolveEndRow(endRow);
|
|
274
296
|
this.#validateRowRange(startRow, resolvedEndRow);
|
|
275
|
-
const
|
|
276
|
-
const
|
|
297
|
+
const rowOffsetWords = this.#rowOffsetWordsView();
|
|
298
|
+
const fieldOffsetWords = this.#fieldOffsetWordsView();
|
|
277
299
|
const data = this.data();
|
|
278
300
|
const totalFields = this.totalFields;
|
|
279
301
|
const ranges = new Float64Array(columns.length * 2);
|
|
280
302
|
for (let rowIndex = startRow;rowIndex < resolvedEndRow; ++rowIndex) {
|
|
281
|
-
|
|
282
|
-
const
|
|
303
|
+
this.#requireHandle();
|
|
304
|
+
const rowStart = offsetAt(rowOffsetWords, rowIndex, `row ${rowIndex} offset`, totalFields);
|
|
305
|
+
const rowEnd = offsetAt(rowOffsetWords, rowIndex + 1, `row ${rowIndex} offset`, totalFields);
|
|
283
306
|
for (let columnOffset = 0;columnOffset < columns.length; ++columnOffset) {
|
|
284
307
|
const columnIndex = columns[columnOffset] ?? 0;
|
|
285
308
|
const fieldIndex = rowStart + columnIndex;
|
|
@@ -289,8 +312,8 @@ export class NativeCsvBatch {
|
|
|
289
312
|
ranges[rangeIndex + 1] = -1;
|
|
290
313
|
continue;
|
|
291
314
|
}
|
|
292
|
-
ranges[rangeIndex] = offsetAt(
|
|
293
|
-
ranges[rangeIndex + 1] = offsetAt(
|
|
315
|
+
ranges[rangeIndex] = offsetAt(fieldOffsetWords, fieldIndex, "field offset", data.byteLength);
|
|
316
|
+
ranges[rangeIndex + 1] = offsetAt(fieldOffsetWords, fieldIndex + 1, "field offset", data.byteLength);
|
|
294
317
|
}
|
|
295
318
|
callback(rowIndex, ranges, data);
|
|
296
319
|
}
|
|
@@ -307,13 +330,13 @@ export class NativeCsvBatch {
|
|
|
307
330
|
this.#handle = null;
|
|
308
331
|
this.#data = void 0;
|
|
309
332
|
this.#dataView = void 0;
|
|
333
|
+
this.#rowOffsetLimit = void 0;
|
|
310
334
|
this.#rowOffsets = void 0;
|
|
335
|
+
this.#rowOffsetWords = void 0;
|
|
311
336
|
this.#fieldOffsets = void 0;
|
|
337
|
+
this.#fieldOffsetWords = void 0;
|
|
312
338
|
}
|
|
313
339
|
}
|
|
314
|
-
dispose() {
|
|
315
|
-
this.close();
|
|
316
|
-
}
|
|
317
340
|
[Symbol.dispose]() {
|
|
318
341
|
this.close();
|
|
319
342
|
}
|
|
@@ -322,6 +345,24 @@ export class NativeCsvBatch {
|
|
|
322
345
|
throw Error("native CSV batch is closed");
|
|
323
346
|
return this.#handle;
|
|
324
347
|
}
|
|
348
|
+
#rowOffsetWordsView() {
|
|
349
|
+
const rowOffsets = this.rowOffsets();
|
|
350
|
+
if (this.#rowOffsetWords === void 0)
|
|
351
|
+
this.#rowOffsetWords = offsetWords(rowOffsets);
|
|
352
|
+
return this.#rowOffsetWords;
|
|
353
|
+
}
|
|
354
|
+
#rowOffsetsPointer() {
|
|
355
|
+
const ptr = native.symbols.csv_batch_row_offsets_ptr(this.#requireHandle());
|
|
356
|
+
if (ptr === null)
|
|
357
|
+
throw Error("native CSV batch row offsets are null");
|
|
358
|
+
return ptr;
|
|
359
|
+
}
|
|
360
|
+
#fieldOffsetWordsView() {
|
|
361
|
+
const fieldOffsets = this.fieldOffsets();
|
|
362
|
+
if (this.#fieldOffsetWords === void 0)
|
|
363
|
+
this.#fieldOffsetWords = offsetWords(fieldOffsets);
|
|
364
|
+
return this.#fieldOffsetWords;
|
|
365
|
+
}
|
|
325
366
|
#resolveEndRow(endRow) {
|
|
326
367
|
if (Number.isNaN(endRow))
|
|
327
368
|
throw RangeError(`row index out of range: ${endRow}`);
|
|
@@ -335,14 +376,25 @@ export class NativeCsvBatch {
|
|
|
335
376
|
throw RangeError(`row index out of range: ${endRow}`);
|
|
336
377
|
}
|
|
337
378
|
}
|
|
379
|
+
const UINT32_BASE = 4294967296;
|
|
380
|
+
const UINT32_BASE_BIGINT = 0x100000000n;
|
|
381
|
+
const MAX_SAFE_OFFSET_HIGH_WORD = 2097151;
|
|
382
|
+
const MAX_DIRECT_ROW_INDEX_EXCLUSIVE = Math.floor(2147483647 / BigUint64Array.BYTES_PER_ELEMENT);
|
|
383
|
+
function offsetWords(offsets) {
|
|
384
|
+
return new Uint32Array(offsets.buffer, offsets.byteOffset, offsets.length * 2);
|
|
385
|
+
}
|
|
338
386
|
function offsetAt(offsets, index, label, upperBound) {
|
|
339
|
-
const
|
|
340
|
-
|
|
387
|
+
const wordIndex = index * 2;
|
|
388
|
+
const low = offsets[wordIndex];
|
|
389
|
+
const high = offsets[wordIndex + 1];
|
|
390
|
+
if (low === void 0 || high === void 0 || wordIndex % 2 !== 0)
|
|
341
391
|
throw RangeError(`${label} index out of range: ${index}`);
|
|
342
|
-
if (
|
|
392
|
+
if (high > MAX_SAFE_OFFSET_HIGH_WORD) {
|
|
393
|
+
const value = BigInt(high) * UINT32_BASE_BIGINT + BigInt(low);
|
|
343
394
|
throw RangeError(`${label} exceeds Number.MAX_SAFE_INTEGER: ${value}`);
|
|
344
|
-
|
|
395
|
+
}
|
|
396
|
+
const offset = low + high * UINT32_BASE;
|
|
345
397
|
if (offset > upperBound)
|
|
346
|
-
throw RangeError(`${label} exceeds backing storage: ${
|
|
398
|
+
throw RangeError(`${label} exceeds backing storage: ${offset}`);
|
|
347
399
|
return offset;
|
|
348
400
|
}
|