@gscdump/lakehouse 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/THIRD-PARTY-LICENSES.md +474 -0
- package/dist/_chunks/catalog.d.mts +236 -0
- package/dist/_chunks/catalog.mjs +331 -0
- package/dist/_chunks/libs/@netlify/blobs.d.mts +6 -0
- package/dist/_chunks/libs/chokidar.d.mts +1 -0
- package/dist/_chunks/libs/db0.d.mts +1 -0
- package/dist/_chunks/libs/denque.d.mts +1 -0
- package/dist/_chunks/libs/fzstd.mjs +545 -0
- package/dist/_chunks/libs/hyparquet-compressors.mjs +2796 -0
- package/dist/_chunks/libs/hyparquet-writer.mjs +2516 -0
- package/dist/_chunks/libs/hyparquet.d.mts +10 -0
- package/dist/_chunks/libs/hyparquet.mjs +460 -0
- package/dist/_chunks/libs/icebird.d.mts +549 -0
- package/dist/_chunks/libs/icebird.mjs +3723 -0
- package/dist/_chunks/libs/ioredis.d.mts +1 -0
- package/dist/_chunks/libs/lru-cache.d.mts +1 -0
- package/dist/_chunks/libs/unstorage.d.mts +120 -0
- package/dist/_chunks/schema.d.mts +74 -0
- package/dist/index.d.mts +159 -0
- package/dist/index.mjs +356 -0
- package/dist/provisioning/index.d.mts +124 -0
- package/dist/provisioning/index.mjs +141 -0
- package/dist/unsafe-raw.d.mts +3 -0
- package/dist/unsafe-raw.mjs +3 -0
- package/dist/vendor/hysnappy-purejs.d.mts +29 -0
- package/dist/vendor/hysnappy-purejs.mjs +2 -0
- package/package.json +61 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File-like object that can read slices of a file asynchronously.
|
|
3
|
+
*/
|
|
4
|
+
interface AsyncBuffer$1 {
|
|
5
|
+
byteLength: number;
|
|
6
|
+
slice(start: number, end?: number): Awaitable<ArrayBuffer>;
|
|
7
|
+
}
|
|
8
|
+
type Awaitable<T> = T | Promise<T>;
|
|
9
|
+
type AsyncBuffer = AsyncBuffer$1;
|
|
10
|
+
export { AsyncBuffer };
|
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
const ParquetTypes = [
|
|
2
|
+
"BOOLEAN",
|
|
3
|
+
"INT32",
|
|
4
|
+
"INT64",
|
|
5
|
+
"INT96",
|
|
6
|
+
"FLOAT",
|
|
7
|
+
"DOUBLE",
|
|
8
|
+
"BYTE_ARRAY",
|
|
9
|
+
"FIXED_LEN_BYTE_ARRAY"
|
|
10
|
+
];
|
|
11
|
+
const Encodings = [
|
|
12
|
+
"PLAIN",
|
|
13
|
+
"GROUP_VAR_INT",
|
|
14
|
+
"PLAIN_DICTIONARY",
|
|
15
|
+
"RLE",
|
|
16
|
+
"BIT_PACKED",
|
|
17
|
+
"DELTA_BINARY_PACKED",
|
|
18
|
+
"DELTA_LENGTH_BYTE_ARRAY",
|
|
19
|
+
"DELTA_BYTE_ARRAY",
|
|
20
|
+
"RLE_DICTIONARY",
|
|
21
|
+
"BYTE_STREAM_SPLIT"
|
|
22
|
+
];
|
|
23
|
+
const FieldRepetitionTypes = [
|
|
24
|
+
"REQUIRED",
|
|
25
|
+
"OPTIONAL",
|
|
26
|
+
"REPEATED"
|
|
27
|
+
];
|
|
28
|
+
const ConvertedTypes = [
|
|
29
|
+
"UTF8",
|
|
30
|
+
"MAP",
|
|
31
|
+
"MAP_KEY_VALUE",
|
|
32
|
+
"LIST",
|
|
33
|
+
"ENUM",
|
|
34
|
+
"DECIMAL",
|
|
35
|
+
"DATE",
|
|
36
|
+
"TIME_MILLIS",
|
|
37
|
+
"TIME_MICROS",
|
|
38
|
+
"TIMESTAMP_MILLIS",
|
|
39
|
+
"TIMESTAMP_MICROS",
|
|
40
|
+
"UINT_8",
|
|
41
|
+
"UINT_16",
|
|
42
|
+
"UINT_32",
|
|
43
|
+
"UINT_64",
|
|
44
|
+
"INT_8",
|
|
45
|
+
"INT_16",
|
|
46
|
+
"INT_32",
|
|
47
|
+
"INT_64",
|
|
48
|
+
"JSON",
|
|
49
|
+
"BSON",
|
|
50
|
+
"INTERVAL"
|
|
51
|
+
];
|
|
52
|
+
const CompressionCodecs = [
|
|
53
|
+
"UNCOMPRESSED",
|
|
54
|
+
"SNAPPY",
|
|
55
|
+
"GZIP",
|
|
56
|
+
"LZO",
|
|
57
|
+
"BROTLI",
|
|
58
|
+
"LZ4",
|
|
59
|
+
"ZSTD",
|
|
60
|
+
"LZ4_RAW"
|
|
61
|
+
];
|
|
62
|
+
const PageTypes = [
|
|
63
|
+
"DATA_PAGE",
|
|
64
|
+
"INDEX_PAGE",
|
|
65
|
+
"DICTIONARY_PAGE",
|
|
66
|
+
"DATA_PAGE_V2"
|
|
67
|
+
];
|
|
68
|
+
const BoundaryOrders = [
|
|
69
|
+
"UNORDERED",
|
|
70
|
+
"ASCENDING",
|
|
71
|
+
"DESCENDING"
|
|
72
|
+
];
|
|
73
|
+
const EdgeInterpolationAlgorithms = [
|
|
74
|
+
"SPHERICAL",
|
|
75
|
+
"VINCENTY",
|
|
76
|
+
"THOMAS",
|
|
77
|
+
"ANDOYER",
|
|
78
|
+
"KARNEY"
|
|
79
|
+
];
|
|
80
|
+
new TextDecoder();
|
|
81
|
+
function parseDecimal(bytes) {
|
|
82
|
+
if (!bytes.length) return 0;
|
|
83
|
+
let value = 0n;
|
|
84
|
+
for (const byte of bytes) value = value * 256n + BigInt(byte);
|
|
85
|
+
const bits = bytes.length * 8;
|
|
86
|
+
if (value >= 2n ** BigInt(bits - 1)) value -= 2n ** BigInt(bits);
|
|
87
|
+
return Number(value);
|
|
88
|
+
}
|
|
89
|
+
function schemaTree(schema, rootIndex, path) {
|
|
90
|
+
const element = schema[rootIndex];
|
|
91
|
+
const children = [];
|
|
92
|
+
let count = 1;
|
|
93
|
+
if (element.num_children) while (children.length < element.num_children) {
|
|
94
|
+
const childElement = schema[rootIndex + count];
|
|
95
|
+
const child = schemaTree(schema, rootIndex + count, [...path, childElement.name]);
|
|
96
|
+
count += child.count;
|
|
97
|
+
children.push(child);
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
count,
|
|
101
|
+
element,
|
|
102
|
+
children,
|
|
103
|
+
path
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function getSchemaPath(schema, name) {
|
|
107
|
+
let tree = schemaTree(schema, 0, []);
|
|
108
|
+
const path = [tree];
|
|
109
|
+
for (const part of name) {
|
|
110
|
+
const child = tree.children.find((child) => child.element.name === part);
|
|
111
|
+
if (!child) throw new Error(`parquet schema element not found: ${name}`);
|
|
112
|
+
path.push(child);
|
|
113
|
+
tree = child;
|
|
114
|
+
}
|
|
115
|
+
return path;
|
|
116
|
+
}
|
|
117
|
+
function getMaxDefinitionLevel(schemaPath) {
|
|
118
|
+
let maxLevel = 0;
|
|
119
|
+
for (const { element } of schemaPath.slice(1)) if (element.repetition_type !== "REQUIRED") maxLevel++;
|
|
120
|
+
return maxLevel;
|
|
121
|
+
}
|
|
122
|
+
function isListLike(schema) {
|
|
123
|
+
if (!schema) return false;
|
|
124
|
+
if (schema.element.converted_type !== "LIST") return false;
|
|
125
|
+
if (schema.children.length > 1) return false;
|
|
126
|
+
const firstChild = schema.children[0];
|
|
127
|
+
if (firstChild.children.length > 1) return false;
|
|
128
|
+
if (firstChild.element.repetition_type !== "REPEATED") return false;
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
function isMapLike(schema) {
|
|
132
|
+
if (!schema) return false;
|
|
133
|
+
if (schema.element.converted_type !== "MAP") return false;
|
|
134
|
+
if (schema.children.length > 1) return false;
|
|
135
|
+
const firstChild = schema.children[0];
|
|
136
|
+
if (firstChild.children.length !== 2) return false;
|
|
137
|
+
if (firstChild.element.repetition_type !== "REPEATED") return false;
|
|
138
|
+
if (firstChild.children.find((child) => child.element.name === "key")?.element.repetition_type === "REPEATED") return false;
|
|
139
|
+
if (firstChild.children.find((child) => child.element.name === "value")?.element.repetition_type === "REPEATED") return false;
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
const defaultInitialFetchSize = 1 << 19;
|
|
143
|
+
new TextDecoder();
|
|
144
|
+
const MASK = 18446744073709551615n;
|
|
145
|
+
const PRIME1 = 11400714785074694791n;
|
|
146
|
+
const PRIME2 = 14029467366897019727n;
|
|
147
|
+
const PRIME3 = 1609587929392839161n;
|
|
148
|
+
const PRIME4 = 9650029242287828579n;
|
|
149
|
+
const PRIME5 = 2870177450012600261n;
|
|
150
|
+
function rotl64(x, r) {
|
|
151
|
+
return (x << r | x >> 64n - r) & MASK;
|
|
152
|
+
}
|
|
153
|
+
function round(acc, val) {
|
|
154
|
+
acc = acc + val * PRIME2 & MASK;
|
|
155
|
+
acc = rotl64(acc, 31n);
|
|
156
|
+
return acc * PRIME1 & MASK;
|
|
157
|
+
}
|
|
158
|
+
function mergeRound(acc, val) {
|
|
159
|
+
acc ^= round(0n, val);
|
|
160
|
+
return acc * PRIME1 + PRIME4 & MASK;
|
|
161
|
+
}
|
|
162
|
+
function xxhash64(input, seed = 0n) {
|
|
163
|
+
const view = new DataView(input.buffer, input.byteOffset, input.byteLength);
|
|
164
|
+
const len = input.byteLength;
|
|
165
|
+
let offset = 0;
|
|
166
|
+
let h64;
|
|
167
|
+
if (len >= 32) {
|
|
168
|
+
let v1 = seed + PRIME1 + PRIME2 & MASK;
|
|
169
|
+
let v2 = seed + PRIME2 & MASK;
|
|
170
|
+
let v3 = seed;
|
|
171
|
+
let v4 = seed - PRIME1 & MASK;
|
|
172
|
+
while (offset + 32 <= len) {
|
|
173
|
+
v1 = round(v1, view.getBigUint64(offset, true));
|
|
174
|
+
offset += 8;
|
|
175
|
+
v2 = round(v2, view.getBigUint64(offset, true));
|
|
176
|
+
offset += 8;
|
|
177
|
+
v3 = round(v3, view.getBigUint64(offset, true));
|
|
178
|
+
offset += 8;
|
|
179
|
+
v4 = round(v4, view.getBigUint64(offset, true));
|
|
180
|
+
offset += 8;
|
|
181
|
+
}
|
|
182
|
+
h64 = rotl64(v1, 1n) + rotl64(v2, 7n) + rotl64(v3, 12n) + rotl64(v4, 18n) & MASK;
|
|
183
|
+
h64 = mergeRound(h64, v1);
|
|
184
|
+
h64 = mergeRound(h64, v2);
|
|
185
|
+
h64 = mergeRound(h64, v3);
|
|
186
|
+
h64 = mergeRound(h64, v4);
|
|
187
|
+
} else h64 = seed + PRIME5 & MASK;
|
|
188
|
+
h64 = h64 + BigInt(len) & MASK;
|
|
189
|
+
while (offset + 8 <= len) {
|
|
190
|
+
h64 ^= round(0n, view.getBigUint64(offset, true));
|
|
191
|
+
h64 = rotl64(h64, 27n) * PRIME1 + PRIME4 & MASK;
|
|
192
|
+
offset += 8;
|
|
193
|
+
}
|
|
194
|
+
if (offset + 4 <= len) {
|
|
195
|
+
h64 ^= BigInt(view.getUint32(offset, true)) * PRIME1 & MASK;
|
|
196
|
+
h64 = rotl64(h64, 23n) * PRIME2 + PRIME3 & MASK;
|
|
197
|
+
offset += 4;
|
|
198
|
+
}
|
|
199
|
+
while (offset < len) {
|
|
200
|
+
h64 ^= BigInt(view.getUint8(offset)) * PRIME5 & MASK;
|
|
201
|
+
h64 = rotl64(h64, 11n) * PRIME1 & MASK;
|
|
202
|
+
offset += 1;
|
|
203
|
+
}
|
|
204
|
+
h64 ^= h64 >> 33n;
|
|
205
|
+
h64 = h64 * PRIME2 & MASK;
|
|
206
|
+
h64 ^= h64 >> 29n;
|
|
207
|
+
h64 = h64 * PRIME3 & MASK;
|
|
208
|
+
h64 ^= h64 >> 32n;
|
|
209
|
+
return h64;
|
|
210
|
+
}
|
|
211
|
+
const textEncoder = new TextEncoder();
|
|
212
|
+
new Uint32Array([
|
|
213
|
+
1203114875,
|
|
214
|
+
1150766481,
|
|
215
|
+
2284105051,
|
|
216
|
+
2729912477,
|
|
217
|
+
1884591559,
|
|
218
|
+
770785867,
|
|
219
|
+
2667333959,
|
|
220
|
+
1550580529
|
|
221
|
+
]);
|
|
222
|
+
function hashParquetValue(value, element) {
|
|
223
|
+
if (value === null || value === void 0) return void 0;
|
|
224
|
+
const { type, converted_type, logical_type } = element;
|
|
225
|
+
if (type === "BOOLEAN") {
|
|
226
|
+
if (typeof value !== "boolean") return void 0;
|
|
227
|
+
return xxhash64(new Uint8Array([value ? 1 : 0]));
|
|
228
|
+
}
|
|
229
|
+
if (type === "FLOAT") {
|
|
230
|
+
if (typeof value !== "number") return void 0;
|
|
231
|
+
const buf = /* @__PURE__ */ new ArrayBuffer(4);
|
|
232
|
+
new DataView(buf).setFloat32(0, value, true);
|
|
233
|
+
return xxhash64(new Uint8Array(buf));
|
|
234
|
+
}
|
|
235
|
+
if (type === "DOUBLE") {
|
|
236
|
+
if (typeof value !== "number") return void 0;
|
|
237
|
+
const buf = /* @__PURE__ */ new ArrayBuffer(8);
|
|
238
|
+
new DataView(buf).setFloat64(0, value, true);
|
|
239
|
+
return xxhash64(new Uint8Array(buf));
|
|
240
|
+
}
|
|
241
|
+
if (type === "INT32") {
|
|
242
|
+
if (converted_type === "DATE" || converted_type === "DECIMAL" || converted_type === "TIME_MILLIS") return void 0;
|
|
243
|
+
if (logical_type?.type === "DATE" || logical_type?.type === "TIME" || logical_type?.type === "DECIMAL") return void 0;
|
|
244
|
+
if (typeof value !== "number" || !Number.isInteger(value)) return void 0;
|
|
245
|
+
const buf = /* @__PURE__ */ new ArrayBuffer(4);
|
|
246
|
+
new DataView(buf).setInt32(0, value | 0, true);
|
|
247
|
+
return xxhash64(new Uint8Array(buf));
|
|
248
|
+
}
|
|
249
|
+
if (type === "INT64") {
|
|
250
|
+
if (converted_type === "TIMESTAMP_MILLIS" || converted_type === "TIMESTAMP_MICROS") return void 0;
|
|
251
|
+
if (converted_type === "TIME_MICROS" || converted_type === "DECIMAL") return void 0;
|
|
252
|
+
if (logical_type?.type === "TIMESTAMP" || logical_type?.type === "TIME" || logical_type?.type === "DECIMAL") return void 0;
|
|
253
|
+
let bigValue;
|
|
254
|
+
if (typeof value === "bigint") bigValue = value;
|
|
255
|
+
else if (typeof value === "number" && Number.isSafeInteger(value)) bigValue = BigInt(value);
|
|
256
|
+
else return void 0;
|
|
257
|
+
const buf = /* @__PURE__ */ new ArrayBuffer(8);
|
|
258
|
+
new DataView(buf).setBigUint64(0, BigInt.asUintN(64, bigValue), true);
|
|
259
|
+
return xxhash64(new Uint8Array(buf));
|
|
260
|
+
}
|
|
261
|
+
if (type === "BYTE_ARRAY") {
|
|
262
|
+
if (converted_type === "JSON" || converted_type === "BSON" || converted_type === "DECIMAL") return void 0;
|
|
263
|
+
if (logical_type?.type === "JSON" || logical_type?.type === "BSON" || logical_type?.type === "VARIANT") return void 0;
|
|
264
|
+
if (logical_type?.type === "GEOMETRY" || logical_type?.type === "GEOGRAPHY") return void 0;
|
|
265
|
+
if (typeof value === "string") return xxhash64(textEncoder.encode(value));
|
|
266
|
+
if (value instanceof Uint8Array) return xxhash64(value);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
if (type === "FIXED_LEN_BYTE_ARRAY") {
|
|
270
|
+
if (converted_type === "DECIMAL" || converted_type === "INTERVAL") return void 0;
|
|
271
|
+
if (logical_type?.type === "DECIMAL" || logical_type?.type === "UUID" || logical_type?.type === "FLOAT16") return void 0;
|
|
272
|
+
if (logical_type?.type === "GEOMETRY" || logical_type?.type === "GEOGRAPHY") return void 0;
|
|
273
|
+
if (value instanceof Uint8Array) return xxhash64(value);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
function toJson(obj) {
|
|
278
|
+
if (obj === void 0) return null;
|
|
279
|
+
if (typeof obj === "bigint") return Number(obj);
|
|
280
|
+
if (Object.is(obj, -0)) return 0;
|
|
281
|
+
if (Array.isArray(obj)) return obj.map(toJson);
|
|
282
|
+
if (obj instanceof Uint8Array) return Array.from(obj);
|
|
283
|
+
if (obj instanceof Date) return obj.toISOString();
|
|
284
|
+
if (obj instanceof Object) {
|
|
285
|
+
const newObj = {};
|
|
286
|
+
for (const key of Object.keys(obj)) {
|
|
287
|
+
if (obj[key] === void 0) continue;
|
|
288
|
+
newObj[key] = toJson(obj[key]);
|
|
289
|
+
}
|
|
290
|
+
return newObj;
|
|
291
|
+
}
|
|
292
|
+
return obj;
|
|
293
|
+
}
|
|
294
|
+
async function byteLengthFromUrlUsingGet(url, requestInit = {}, fetchFn = globalThis.fetch) {
|
|
295
|
+
const controller = new AbortController();
|
|
296
|
+
const headers = new Headers(requestInit.headers);
|
|
297
|
+
headers.set("Range", "bytes=0-0");
|
|
298
|
+
const res = await fetchFn(url, {
|
|
299
|
+
...requestInit,
|
|
300
|
+
headers,
|
|
301
|
+
signal: controller.signal
|
|
302
|
+
});
|
|
303
|
+
if (!res.ok) throw new Error(`fetch with range failed ${res.status}`);
|
|
304
|
+
if (res.status === 206) {
|
|
305
|
+
const contentRange = res.headers.get("Content-Range");
|
|
306
|
+
if (!contentRange) throw new Error("missing content-range header");
|
|
307
|
+
const match = contentRange.match(/bytes \d+-\d+\/(\d+)/);
|
|
308
|
+
if (!match) throw new Error(`invalid content-range header: ${contentRange}`);
|
|
309
|
+
return parseInt(match[1]);
|
|
310
|
+
}
|
|
311
|
+
if (res.status === 200) {
|
|
312
|
+
const contentLength = res.headers.get("Content-Length");
|
|
313
|
+
controller.abort();
|
|
314
|
+
if (contentLength) return parseInt(contentLength);
|
|
315
|
+
}
|
|
316
|
+
throw new Error("server does not support range requests and missing content-length");
|
|
317
|
+
}
|
|
318
|
+
async function byteLengthFromUrl(url, requestInit, customFetch) {
|
|
319
|
+
const fetch = customFetch ?? globalThis.fetch;
|
|
320
|
+
const res = await fetch(url, {
|
|
321
|
+
...requestInit,
|
|
322
|
+
method: "HEAD"
|
|
323
|
+
});
|
|
324
|
+
if (res.status === 403) return byteLengthFromUrlUsingGet(url, requestInit, fetch);
|
|
325
|
+
if (!res.ok) throw new Error(`fetch head failed ${res.status}`);
|
|
326
|
+
const length = res.headers.get("Content-Length");
|
|
327
|
+
if (!length) return byteLengthFromUrlUsingGet(url, requestInit, fetch);
|
|
328
|
+
return parseInt(length);
|
|
329
|
+
}
|
|
330
|
+
async function asyncBufferFromUrl({ url, byteLength, requestInit, fetch: customFetch }) {
|
|
331
|
+
if (!url) throw new Error("missing url");
|
|
332
|
+
const fetch = customFetch ?? globalThis.fetch;
|
|
333
|
+
byteLength ??= await byteLengthFromUrl(url, requestInit, fetch);
|
|
334
|
+
let buffer = void 0;
|
|
335
|
+
const init = requestInit || {};
|
|
336
|
+
return {
|
|
337
|
+
byteLength,
|
|
338
|
+
async slice(start, end) {
|
|
339
|
+
if (buffer) return buffer.then((buffer) => buffer.slice(start, end));
|
|
340
|
+
const headers = new Headers(init.headers);
|
|
341
|
+
const endStr = end === void 0 ? "" : end - 1;
|
|
342
|
+
headers.set("Range", `bytes=${start}-${endStr}`);
|
|
343
|
+
const res = await fetch(url, {
|
|
344
|
+
...init,
|
|
345
|
+
headers
|
|
346
|
+
});
|
|
347
|
+
if (!res.ok || !res.body) throw new Error(`fetch failed ${res.status}`);
|
|
348
|
+
if (res.status === 200) {
|
|
349
|
+
buffer = res.arrayBuffer();
|
|
350
|
+
return buffer.then((buffer) => buffer.slice(start, end));
|
|
351
|
+
} else if (res.status === 206) return res.arrayBuffer();
|
|
352
|
+
else throw new Error(`fetch received unexpected status code ${res.status}`);
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
function cachedAsyncBuffer({ byteLength, slice }, { minSize = defaultInitialFetchSize } = {}) {
|
|
357
|
+
if (byteLength < minSize) {
|
|
358
|
+
const buffer = slice(0, byteLength);
|
|
359
|
+
return {
|
|
360
|
+
byteLength,
|
|
361
|
+
async slice(start, end) {
|
|
362
|
+
return (await buffer).slice(start, end);
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
const cache = /* @__PURE__ */ new Map();
|
|
367
|
+
return {
|
|
368
|
+
byteLength,
|
|
369
|
+
slice(start, end) {
|
|
370
|
+
const key = cacheKey(start, end, byteLength);
|
|
371
|
+
const cached = cache.get(key);
|
|
372
|
+
if (cached) return cached;
|
|
373
|
+
const promise = slice(start, end);
|
|
374
|
+
cache.set(key, promise);
|
|
375
|
+
return promise;
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
function cacheKey(start, end, size) {
|
|
380
|
+
if (start < 0) {
|
|
381
|
+
if (end !== void 0) throw new Error(`invalid suffix range [${start}, ${end}]`);
|
|
382
|
+
if (size === void 0) return `${start},`;
|
|
383
|
+
return `${size + start},${size}`;
|
|
384
|
+
} else if (end !== void 0) {
|
|
385
|
+
if (start > end) throw new Error(`invalid empty range [${start}, ${end}]`);
|
|
386
|
+
return `${start},${end}`;
|
|
387
|
+
} else if (size === void 0) return `${start},`;
|
|
388
|
+
else return `${start},${size}`;
|
|
389
|
+
}
|
|
390
|
+
new TextDecoder();
|
|
391
|
+
const WORD_MASK = [
|
|
392
|
+
0,
|
|
393
|
+
255,
|
|
394
|
+
65535,
|
|
395
|
+
16777215,
|
|
396
|
+
4294967295
|
|
397
|
+
];
|
|
398
|
+
function copyBytes(fromArray, fromPos, toArray, toPos, length) {
|
|
399
|
+
for (let i = 0; i < length; i++) toArray[toPos + i] = fromArray[fromPos + i];
|
|
400
|
+
}
|
|
401
|
+
function snappyUncompress(input, output) {
|
|
402
|
+
const inputLength = input.byteLength;
|
|
403
|
+
const outputLength = output.byteLength;
|
|
404
|
+
let pos = 0;
|
|
405
|
+
let outPos = 0;
|
|
406
|
+
while (pos < inputLength) {
|
|
407
|
+
const c = input[pos];
|
|
408
|
+
pos++;
|
|
409
|
+
if (c < 128) break;
|
|
410
|
+
}
|
|
411
|
+
if (outputLength && pos >= inputLength) throw new Error("invalid snappy length header");
|
|
412
|
+
while (pos < inputLength) {
|
|
413
|
+
const c = input[pos];
|
|
414
|
+
let len = 0;
|
|
415
|
+
pos++;
|
|
416
|
+
if (pos >= inputLength) throw new Error("missing eof marker");
|
|
417
|
+
if ((c & 3) === 0) {
|
|
418
|
+
let len = (c >>> 2) + 1;
|
|
419
|
+
if (len > 60) {
|
|
420
|
+
if (pos + 3 >= inputLength) throw new Error("snappy error literal pos + 3 >= inputLength");
|
|
421
|
+
const lengthSize = len - 60;
|
|
422
|
+
len = input[pos] + (input[pos + 1] << 8) + (input[pos + 2] << 16) + (input[pos + 3] << 24);
|
|
423
|
+
len = (len & WORD_MASK[lengthSize]) + 1;
|
|
424
|
+
pos += lengthSize;
|
|
425
|
+
}
|
|
426
|
+
if (pos + len > inputLength) throw new Error("snappy error literal exceeds input length");
|
|
427
|
+
copyBytes(input, pos, output, outPos, len);
|
|
428
|
+
pos += len;
|
|
429
|
+
outPos += len;
|
|
430
|
+
} else {
|
|
431
|
+
let offset = 0;
|
|
432
|
+
switch (c & 3) {
|
|
433
|
+
case 1:
|
|
434
|
+
len = (c >>> 2 & 7) + 4;
|
|
435
|
+
offset = input[pos] + (c >>> 5 << 8);
|
|
436
|
+
pos++;
|
|
437
|
+
break;
|
|
438
|
+
case 2:
|
|
439
|
+
if (inputLength <= pos + 1) throw new Error("snappy error end of input");
|
|
440
|
+
len = (c >>> 2) + 1;
|
|
441
|
+
offset = input[pos] + (input[pos + 1] << 8);
|
|
442
|
+
pos += 2;
|
|
443
|
+
break;
|
|
444
|
+
case 3:
|
|
445
|
+
if (inputLength <= pos + 3) throw new Error("snappy error end of input");
|
|
446
|
+
len = (c >>> 2) + 1;
|
|
447
|
+
offset = input[pos] + (input[pos + 1] << 8) + (input[pos + 2] << 16) + (input[pos + 3] << 24);
|
|
448
|
+
pos += 4;
|
|
449
|
+
break;
|
|
450
|
+
default: break;
|
|
451
|
+
}
|
|
452
|
+
if (offset === 0 || isNaN(offset)) throw new Error(`invalid offset ${offset} pos ${pos} inputLength ${inputLength}`);
|
|
453
|
+
if (offset > outPos) throw new Error("cannot copy from before start of buffer");
|
|
454
|
+
copyBytes(output, outPos - offset, output, outPos, len);
|
|
455
|
+
outPos += len;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
if (outPos !== outputLength) throw new Error("premature end of input");
|
|
459
|
+
}
|
|
460
|
+
export { BoundaryOrders, CompressionCodecs, ConvertedTypes, EdgeInterpolationAlgorithms, Encodings, FieldRepetitionTypes, PageTypes, ParquetTypes, asyncBufferFromUrl, cachedAsyncBuffer, getMaxDefinitionLevel, getSchemaPath, hashParquetValue, isListLike, isMapLike, parseDecimal, snappyUncompress, toJson };
|