@loaders.gl/parquet 3.3.0 → 3.4.0-alpha.1

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.
Files changed (131) hide show
  1. package/dist/dist.min.js +26 -17
  2. package/dist/dist.min.js.map +3 -3
  3. package/dist/es5/index.js +3 -3
  4. package/dist/es5/index.js.map +1 -1
  5. package/dist/es5/lib/parse-parquet.js +25 -49
  6. package/dist/es5/lib/parse-parquet.js.map +1 -1
  7. package/dist/es5/parquet-loader.js +2 -3
  8. package/dist/es5/parquet-loader.js.map +1 -1
  9. package/dist/es5/parquet-wasm-loader.js +1 -1
  10. package/dist/es5/parquet-wasm-loader.js.map +1 -1
  11. package/dist/es5/parquet-wasm-writer.js +1 -1
  12. package/dist/es5/parquet-wasm-writer.js.map +1 -1
  13. package/dist/es5/parquet-writer.js +1 -1
  14. package/dist/es5/parquet-writer.js.map +1 -1
  15. package/dist/es5/parquetjs/compression.js +5 -15
  16. package/dist/es5/parquetjs/compression.js.map +1 -1
  17. package/dist/es5/parquetjs/encoder/{parquet-encoder.js → writer.js} +158 -70
  18. package/dist/es5/parquetjs/encoder/writer.js.map +1 -0
  19. package/dist/es5/parquetjs/file.js +94 -0
  20. package/dist/es5/parquetjs/file.js.map +1 -0
  21. package/dist/es5/parquetjs/parser/parquet-cursor.js +183 -0
  22. package/dist/es5/parquetjs/parser/parquet-cursor.js.map +1 -0
  23. package/dist/es5/parquetjs/parser/parquet-envelope-reader.js +327 -0
  24. package/dist/es5/parquetjs/parser/parquet-envelope-reader.js.map +1 -0
  25. package/dist/es5/parquetjs/parser/parquet-reader.js +222 -553
  26. package/dist/es5/parquetjs/parser/parquet-reader.js.map +1 -1
  27. package/dist/es5/parquetjs/schema/declare.js +1 -3
  28. package/dist/es5/parquetjs/schema/declare.js.map +1 -1
  29. package/dist/es5/parquetjs/schema/shred.js +33 -39
  30. package/dist/es5/parquetjs/schema/shred.js.map +1 -1
  31. package/dist/es5/parquetjs/schema/types.js.map +1 -1
  32. package/dist/es5/parquetjs/utils/buffer-utils.js +19 -0
  33. package/dist/es5/parquetjs/utils/buffer-utils.js.map +1 -0
  34. package/dist/es5/parquetjs/utils/file-utils.js +3 -2
  35. package/dist/es5/parquetjs/utils/file-utils.js.map +1 -1
  36. package/dist/esm/index.js +1 -1
  37. package/dist/esm/index.js.map +1 -1
  38. package/dist/esm/lib/parse-parquet.js +12 -6
  39. package/dist/esm/lib/parse-parquet.js.map +1 -1
  40. package/dist/esm/parquet-loader.js +2 -3
  41. package/dist/esm/parquet-loader.js.map +1 -1
  42. package/dist/esm/parquet-wasm-loader.js +1 -1
  43. package/dist/esm/parquet-wasm-loader.js.map +1 -1
  44. package/dist/esm/parquet-wasm-writer.js +1 -1
  45. package/dist/esm/parquet-wasm-writer.js.map +1 -1
  46. package/dist/esm/parquet-writer.js +1 -1
  47. package/dist/esm/parquet-writer.js.map +1 -1
  48. package/dist/esm/parquetjs/compression.js +1 -10
  49. package/dist/esm/parquetjs/compression.js.map +1 -1
  50. package/dist/esm/parquetjs/encoder/{parquet-encoder.js → writer.js} +37 -7
  51. package/dist/esm/parquetjs/encoder/writer.js.map +1 -0
  52. package/dist/esm/parquetjs/file.js +81 -0
  53. package/dist/esm/parquetjs/file.js.map +1 -0
  54. package/dist/esm/parquetjs/parser/parquet-cursor.js +78 -0
  55. package/dist/esm/parquetjs/parser/parquet-cursor.js.map +1 -0
  56. package/dist/esm/parquetjs/parser/parquet-envelope-reader.js +129 -0
  57. package/dist/esm/parquetjs/parser/parquet-envelope-reader.js.map +1 -0
  58. package/dist/esm/parquetjs/parser/parquet-reader.js +72 -158
  59. package/dist/esm/parquetjs/parser/parquet-reader.js.map +1 -1
  60. package/dist/esm/parquetjs/schema/declare.js +0 -1
  61. package/dist/esm/parquetjs/schema/declare.js.map +1 -1
  62. package/dist/esm/parquetjs/schema/shred.js +34 -42
  63. package/dist/esm/parquetjs/schema/shred.js.map +1 -1
  64. package/dist/esm/parquetjs/schema/types.js.map +1 -1
  65. package/dist/esm/parquetjs/utils/buffer-utils.js +13 -0
  66. package/dist/esm/parquetjs/utils/buffer-utils.js.map +1 -0
  67. package/dist/esm/parquetjs/utils/file-utils.js +1 -1
  68. package/dist/esm/parquetjs/utils/file-utils.js.map +1 -1
  69. package/dist/index.d.ts +1 -1
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/index.js +4 -3
  72. package/dist/lib/parse-parquet.d.ts +2 -2
  73. package/dist/lib/parse-parquet.d.ts.map +1 -1
  74. package/dist/lib/parse-parquet.js +12 -24
  75. package/dist/parquet-loader.d.ts +0 -1
  76. package/dist/parquet-loader.d.ts.map +1 -1
  77. package/dist/parquet-loader.js +1 -2
  78. package/dist/parquet-worker.js +24 -15
  79. package/dist/parquet-worker.js.map +3 -3
  80. package/dist/parquetjs/compression.d.ts.map +1 -1
  81. package/dist/parquetjs/compression.js +5 -16
  82. package/dist/parquetjs/encoder/{parquet-encoder.d.ts → writer.d.ts} +19 -10
  83. package/dist/parquetjs/encoder/writer.d.ts.map +1 -0
  84. package/dist/parquetjs/encoder/{parquet-encoder.js → writer.js} +37 -39
  85. package/dist/parquetjs/file.d.ts +10 -0
  86. package/dist/parquetjs/file.d.ts.map +1 -0
  87. package/dist/parquetjs/file.js +99 -0
  88. package/dist/parquetjs/parser/parquet-cursor.d.ts +36 -0
  89. package/dist/parquetjs/parser/parquet-cursor.d.ts.map +1 -0
  90. package/dist/parquetjs/parser/parquet-cursor.js +74 -0
  91. package/dist/parquetjs/parser/parquet-envelope-reader.d.ts +40 -0
  92. package/dist/parquetjs/parser/parquet-envelope-reader.d.ts.map +1 -0
  93. package/dist/parquetjs/parser/parquet-envelope-reader.js +136 -0
  94. package/dist/parquetjs/parser/parquet-reader.d.ts +57 -47
  95. package/dist/parquetjs/parser/parquet-reader.d.ts.map +1 -1
  96. package/dist/parquetjs/parser/parquet-reader.js +102 -168
  97. package/dist/parquetjs/schema/declare.d.ts +7 -14
  98. package/dist/parquetjs/schema/declare.d.ts.map +1 -1
  99. package/dist/parquetjs/schema/declare.js +0 -2
  100. package/dist/parquetjs/schema/shred.d.ts +0 -115
  101. package/dist/parquetjs/schema/shred.d.ts.map +1 -1
  102. package/dist/parquetjs/schema/shred.js +43 -161
  103. package/dist/parquetjs/schema/types.d.ts +2 -2
  104. package/dist/parquetjs/schema/types.d.ts.map +1 -1
  105. package/dist/parquetjs/utils/buffer-utils.d.ts +10 -0
  106. package/dist/parquetjs/utils/buffer-utils.d.ts.map +1 -0
  107. package/dist/parquetjs/utils/buffer-utils.js +22 -0
  108. package/dist/parquetjs/utils/file-utils.d.ts +4 -3
  109. package/dist/parquetjs/utils/file-utils.d.ts.map +1 -1
  110. package/dist/parquetjs/utils/file-utils.js +5 -2
  111. package/package.json +5 -7
  112. package/src/index.ts +2 -2
  113. package/src/lib/parse-parquet.ts +12 -25
  114. package/src/parquet-loader.ts +1 -3
  115. package/src/parquetjs/compression.ts +1 -14
  116. package/src/parquetjs/encoder/{parquet-encoder.ts → writer.ts} +28 -22
  117. package/src/parquetjs/file.ts +90 -0
  118. package/src/parquetjs/parser/parquet-cursor.ts +94 -0
  119. package/src/parquetjs/parser/parquet-envelope-reader.ts +199 -0
  120. package/src/parquetjs/parser/parquet-reader.ts +122 -239
  121. package/src/parquetjs/schema/declare.ts +9 -17
  122. package/src/parquetjs/schema/shred.ts +28 -157
  123. package/src/parquetjs/schema/types.ts +27 -21
  124. package/src/parquetjs/utils/buffer-utils.ts +18 -0
  125. package/src/parquetjs/utils/file-utils.ts +4 -3
  126. package/dist/es5/lib/convert-schema-deep.ts.disabled +0 -910
  127. package/dist/es5/parquetjs/encoder/parquet-encoder.js.map +0 -1
  128. package/dist/esm/lib/convert-schema-deep.ts.disabled +0 -910
  129. package/dist/esm/parquetjs/encoder/parquet-encoder.js.map +0 -1
  130. package/dist/parquetjs/encoder/parquet-encoder.d.ts.map +0 -1
  131. package/src/lib/convert-schema-deep.ts.disabled +0 -910
@@ -146,14 +146,9 @@ function shredRecordFields(
146
146
  */
147
147
  export function materializeRecords(schema: ParquetSchema, buffer: ParquetBuffer): ParquetRecord[] {
148
148
  const records: ParquetRecord[] = [];
149
- for (let i = 0; i < buffer.rowCount; i++) {
150
- records.push({});
151
- }
149
+ for (let i = 0; i < buffer.rowCount; i++) records.push({});
152
150
  for (const key in buffer.columnData) {
153
- const columnData = buffer.columnData[key];
154
- if (columnData.count) {
155
- materializeColumn(schema, columnData, key, records);
156
- }
151
+ materializeColumn(schema, buffer, key, records);
157
152
  }
158
153
  return records;
159
154
  }
@@ -161,151 +156,33 @@ export function materializeRecords(schema: ParquetSchema, buffer: ParquetBuffer)
161
156
  // eslint-disable-next-line max-statements, complexity
162
157
  function materializeColumn(
163
158
  schema: ParquetSchema,
164
- columnData: ParquetData,
159
+ buffer: ParquetBuffer,
165
160
  key: string,
166
161
  records: ParquetRecord[]
167
- ): void {
162
+ ) {
163
+ const data = buffer.columnData[key];
164
+ if (!data.count) return;
165
+
168
166
  const field = schema.findField(key);
169
167
  const branch = schema.findFieldBranch(key);
170
168
 
171
169
  // tslint:disable-next-line:prefer-array-literal
172
170
  const rLevels: number[] = new Array(field.rLevelMax + 1).fill(0);
173
171
  let vIndex = 0;
174
- for (let i = 0; i < columnData.count; i++) {
175
- const dLevel = columnData.dlevels[i];
176
- const rLevel = columnData.rlevels[i];
172
+ for (let i = 0; i < data.count; i++) {
173
+ const dLevel = data.dlevels[i];
174
+ const rLevel = data.rlevels[i];
177
175
  rLevels[rLevel]++;
178
176
  rLevels.fill(0, rLevel + 1);
179
177
 
180
178
  let rIndex = 0;
181
179
  let record = records[rLevels[rIndex++] - 1];
182
180
 
183
- // Internal nodes - Build a nested row object
181
+ // Internal nodes
184
182
  for (const step of branch) {
185
- if (step === field || dLevel < step.dLevelMax) {
186
- break;
187
- }
188
-
189
- switch (step.repetitionType) {
190
- case 'REPEATED':
191
- if (!(step.name in record)) {
192
- // eslint-disable max-depth
193
- record[step.name] = [];
194
- }
195
- const ix = rLevels[rIndex++];
196
- while (record[step.name].length <= ix) {
197
- // eslint-disable max-depth
198
- record[step.name].push({});
199
- }
200
- record = record[step.name][ix];
201
- break;
202
-
203
- default:
204
- record[step.name] = record[step.name] || {};
205
- record = record[step.name];
206
- }
207
- }
208
-
209
- // Leaf node - Add the value
210
- if (dLevel === field.dLevelMax) {
211
- const value = Types.fromPrimitive(
212
- // @ts-ignore
213
- field.originalType || field.primitiveType,
214
- columnData.values[vIndex],
215
- field
216
- );
217
- vIndex++;
218
-
219
- switch (field.repetitionType) {
220
- case 'REPEATED':
221
- if (!(field.name in record)) {
222
- // eslint-disable max-depth
223
- record[field.name] = [];
224
- }
225
- const ix = rLevels[rIndex];
226
- while (record[field.name].length <= ix) {
227
- // eslint-disable max-depth
228
- record[field.name].push(null);
229
- }
230
- record[field.name][ix] = value;
231
- break;
232
-
233
- default:
234
- record[field.name] = value;
235
- }
236
- }
237
- }
238
- }
239
-
240
- // Columnar export
241
-
242
- /**
243
- * 'Materialize' a list of <value, repetition_level, definition_level>
244
- * tuples back to nested records (objects/arrays) using the Google Dremel
245
- * Algorithm..
246
- *
247
- * The buffer argument must point to an object with the following structure (i.e.
248
- * the same structure that is returned by shredRecords):
249
- *
250
- * buffer = {
251
- * columnData: [
252
- * 'my_col': {
253
- * dlevels: [d1, d2, .. dN],
254
- * rlevels: [r1, r2, .. rN],
255
- * values: [v1, v2, .. vN],
256
- * }, ...
257
- * ],
258
- * rowCount: X,
259
- * }
260
- *
261
- export function extractColumns(schema: ParquetSchema, buffer: ParquetBuffer): Record<string, unknown> {
262
- const columns: ParquetRecord = {};
263
- for (const key in buffer.columnData) {
264
- const columnData = buffer.columnData[key];
265
- if (columnData.count) {
266
- extractColumn(schema, columnData, key, columns);
267
- }
268
- }
269
- return columns;
270
- }
271
-
272
- // eslint-disable-next-line max-statements, complexity
273
- function extractColumn(
274
- schema: ParquetSchema,
275
- columnData: ParquetData,
276
- key: string,
277
- columns: Record<string, unknown>
278
- ) {
279
- if (columnData.count <= 0) {
280
- return;
281
- }
282
-
283
- const record = columns;
284
-
285
- const field = schema.findField(key);
286
- const branch = schema.findFieldBranch(key);
287
-
288
- // tslint:disable-next-line:prefer-array-literal
289
- const rLevels: number[] = new Array(field.rLevelMax + 1).fill(0);
290
- let vIndex = 0;
291
-
292
- let i = 0;
293
- const dLevel = columnData.dlevels[i];
294
- const rLevel = columnData.rlevels[i];
295
- rLevels[rLevel]++;
296
- rLevels.fill(0, rLevel + 1);
297
-
298
- let rIndex = 0;
299
- let record = records[rLevels[rIndex++] - 1];
300
-
301
- // Internal nodes
302
- for (const step of branch) {
303
- if (step === field || dLevel < step.dLevelMax) {
304
- break;
305
- }
306
-
307
- switch (step.repetitionType) {
308
- case 'REPEATED':
183
+ if (step === field) break;
184
+ if (dLevel < step.dLevelMax) break;
185
+ if (step.repetitionType === 'REPEATED') {
309
186
  if (!(step.name in record)) {
310
187
  // eslint-disable max-depth
311
188
  record[step.name] = [];
@@ -316,26 +193,22 @@ function extractColumn(
316
193
  record[step.name].push({});
317
194
  }
318
195
  record = record[step.name][ix];
319
- break;
320
-
321
- default:
196
+ } else {
322
197
  record[step.name] = record[step.name] || {};
323
198
  record = record[step.name];
199
+ }
324
200
  }
325
- }
326
-
327
- // Leaf node
328
- if (dLevel === field.dLevelMax) {
329
- const value = Types.fromPrimitive(
330
- // @ts-ignore
331
- field.originalType || field.primitiveType,
332
- columnData.values[vIndex],
333
- field
334
- );
335
- vIndex++;
336
201
 
337
- switch (field.repetitionType) {
338
- case 'REPEATED':
202
+ // Leaf node
203
+ if (dLevel === field.dLevelMax) {
204
+ const value = Types.fromPrimitive(
205
+ // @ts-ignore
206
+ field.originalType || field.primitiveType,
207
+ data.values[vIndex],
208
+ field
209
+ );
210
+ vIndex++;
211
+ if (field.repetitionType === 'REPEATED') {
339
212
  if (!(field.name in record)) {
340
213
  // eslint-disable max-depth
341
214
  record[field.name] = [];
@@ -346,11 +219,9 @@ function extractColumn(
346
219
  record[field.name].push(null);
347
220
  }
348
221
  record[field.name][ix] = value;
349
- break;
350
-
351
- default:
222
+ } else {
352
223
  record[field.name] = value;
224
+ }
353
225
  }
354
226
  }
355
227
  }
356
- */
@@ -168,7 +168,7 @@ export const PARQUET_LOGICAL_TYPES: Record<ParquetType, ParquetTypeKit> = {
168
168
  * Convert a value from it's native representation to the internal/underlying
169
169
  * primitive type
170
170
  */
171
- export function toPrimitive(type: ParquetType, value: unknown, field?: ParquetField): unknown {
171
+ export function toPrimitive(type: ParquetType, value: any, field?: ParquetField) {
172
172
  if (!(type in PARQUET_LOGICAL_TYPES)) {
173
173
  throw new Error(`invalid type: ${type}`);
174
174
  }
@@ -180,7 +180,7 @@ export function toPrimitive(type: ParquetType, value: unknown, field?: ParquetFi
180
180
  * Convert a value from it's internal/underlying primitive representation to
181
181
  * the native representation
182
182
  */
183
- export function fromPrimitive(type: ParquetType, value: unknown, field?: ParquetField) {
183
+ export function fromPrimitive(type: ParquetType, value: any, field?: ParquetField) {
184
184
  if (!(type in PARQUET_LOGICAL_TYPES)) {
185
185
  throw new Error(`invalid type: ${type}`);
186
186
  }
@@ -192,27 +192,29 @@ export function fromPrimitive(type: ParquetType, value: unknown, field?: Parquet
192
192
  return value;
193
193
  }
194
194
 
195
- function toPrimitive_BOOLEAN(value: unknown): boolean {
195
+ function toPrimitive_BOOLEAN(value: any) {
196
196
  return Boolean(value);
197
197
  }
198
198
 
199
- function fromPrimitive_BOOLEAN(value: any): boolean {
199
+ function fromPrimitive_BOOLEAN(value: any) {
200
200
  return Boolean(value);
201
201
  }
202
202
 
203
- function toPrimitive_FLOAT(value: any): number {
203
+ function toPrimitive_FLOAT(value: any) {
204
204
  const v = parseFloat(value);
205
205
  if (isNaN(v)) {
206
206
  throw new Error(`invalid value for FLOAT: ${value}`);
207
207
  }
208
+
208
209
  return v;
209
210
  }
210
211
 
211
- function toPrimitive_DOUBLE(value: any): number {
212
+ function toPrimitive_DOUBLE(value: any) {
212
213
  const v = parseFloat(value);
213
214
  if (isNaN(v)) {
214
215
  throw new Error(`invalid value for DOUBLE: ${value}`);
215
216
  }
217
+
216
218
  return v;
217
219
  }
218
220
 
@@ -261,28 +263,31 @@ function toPrimitive_INT32(value: any) {
261
263
  return v;
262
264
  }
263
265
 
264
- function decimalToPrimitive_INT32(value: number, field: ParquetField): number {
266
+ function decimalToPrimitive_INT32(value: number, field: ParquetField) {
265
267
  const primitiveValue = value * 10 ** (field.scale || 0);
266
268
  const v = Math.round(((primitiveValue * 10 ** -field.presision!) % 1) * 10 ** field.presision!);
267
269
  if (v < -0x80000000 || v > 0x7fffffff || isNaN(v)) {
268
270
  throw new Error(`invalid value for INT32: ${value}`);
269
271
  }
272
+
270
273
  return v;
271
274
  }
272
275
 
273
- function toPrimitive_UINT32(value: any): number {
276
+ function toPrimitive_UINT32(value: any) {
274
277
  const v = parseInt(value, 10);
275
278
  if (v < 0 || v > 0xffffffffffff || isNaN(v)) {
276
279
  throw new Error(`invalid value for UINT32: ${value}`);
277
280
  }
281
+
278
282
  return v;
279
283
  }
280
284
 
281
- function toPrimitive_INT64(value: any): number {
285
+ function toPrimitive_INT64(value: any) {
282
286
  const v = parseInt(value, 10);
283
287
  if (isNaN(v)) {
284
288
  throw new Error(`invalid value for INT64: ${value}`);
285
289
  }
290
+
286
291
  return v;
287
292
  }
288
293
 
@@ -314,32 +319,32 @@ function toPrimitive_INT96(value: any) {
314
319
  return v;
315
320
  }
316
321
 
317
- function toPrimitive_BYTE_ARRAY(value: any): Buffer {
322
+ function toPrimitive_BYTE_ARRAY(value: any) {
318
323
  return Buffer.from(value);
319
324
  }
320
325
 
321
- function decimalToPrimitive_BYTE_ARRAY(value: any): Buffer {
326
+ function decimalToPrimitive_BYTE_ARRAY(value: any) {
322
327
  // TBD
323
328
  return Buffer.from(value);
324
329
  }
325
330
 
326
- function toPrimitive_UTF8(value: any): Buffer {
331
+ function toPrimitive_UTF8(value: any) {
327
332
  return Buffer.from(value, 'utf8');
328
333
  }
329
334
 
330
- function fromPrimitive_UTF8(value: any): string {
335
+ function fromPrimitive_UTF8(value: any) {
331
336
  return value.toString();
332
337
  }
333
338
 
334
- function toPrimitive_JSON(value: any): Buffer {
339
+ function toPrimitive_JSON(value: any) {
335
340
  return Buffer.from(JSON.stringify(value));
336
341
  }
337
342
 
338
- function fromPrimitive_JSON(value: any): unknown {
343
+ function fromPrimitive_JSON(value: any) {
339
344
  return JSON.parse(value);
340
345
  }
341
346
 
342
- function toPrimitive_BSON(value: any): Buffer {
347
+ function toPrimitive_BSON(value: any) {
343
348
  return Buffer.from(BSON.serialize(value));
344
349
  }
345
350
 
@@ -356,17 +361,18 @@ function toPrimitive_TIME_MILLIS(value: any) {
356
361
  return v;
357
362
  }
358
363
 
359
- function toPrimitive_TIME_MICROS(value: any): number {
364
+ function toPrimitive_TIME_MICROS(value: any) {
360
365
  const v = parseInt(value, 10);
361
366
  if (v < 0 || isNaN(v)) {
362
367
  throw new Error(`invalid value for TIME_MICROS: ${value}`);
363
368
  }
369
+
364
370
  return v;
365
371
  }
366
372
 
367
373
  const kMillisPerDay = 86400000;
368
374
 
369
- function toPrimitive_DATE(value: any): number {
375
+ function toPrimitive_DATE(value: any) {
370
376
  /* convert from date */
371
377
  if (value instanceof Date) {
372
378
  return value.getTime() / kMillisPerDay;
@@ -383,11 +389,11 @@ function toPrimitive_DATE(value: any): number {
383
389
  }
384
390
  }
385
391
 
386
- function fromPrimitive_DATE(value: any): Date {
392
+ function fromPrimitive_DATE(value: any) {
387
393
  return new Date(value * kMillisPerDay);
388
394
  }
389
395
 
390
- function toPrimitive_TIMESTAMP_MILLIS(value: any): number {
396
+ function toPrimitive_TIMESTAMP_MILLIS(value: any) {
391
397
  /* convert from date */
392
398
  if (value instanceof Date) {
393
399
  return value.getTime();
@@ -404,7 +410,7 @@ function toPrimitive_TIMESTAMP_MILLIS(value: any): number {
404
410
  }
405
411
  }
406
412
 
407
- function fromPrimitive_TIMESTAMP_MILLIS(value: any): Date {
413
+ function fromPrimitive_TIMESTAMP_MILLIS(value: any) {
408
414
  return new Date(value);
409
415
  }
410
416
 
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Convert Buffer to ArrayBuffer
3
+ */
4
+ export function toArrayBuffer(buffer: Buffer): ArrayBuffer {
5
+ // TODO - per docs we should just be able to call buffer.buffer, but there are issues
6
+ if (Buffer.isBuffer(buffer)) {
7
+ const typedArray = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.length);
8
+ return typedArray.slice().buffer;
9
+ }
10
+ return buffer;
11
+ }
12
+
13
+ /**
14
+ * Convert (copy) ArrayBuffer to Buffer
15
+ */
16
+ export function toBuffer(arrayBuffer: ArrayBuffer): Buffer {
17
+ return Buffer.from(arrayBuffer);
18
+ }
@@ -1,5 +1,6 @@
1
1
  // Forked from https://github.com/kbajalc/parquets under MIT license (Copyright (c) 2017 ironSource Ltd.)
2
- import {fs, stream} from '@loaders.gl/loader-utils';
2
+ import fs from 'fs';
3
+ import {Writable} from 'stream';
3
4
 
4
5
  export function load(name: string): any {
5
6
  return (module || (global as any)).require(name);
@@ -13,7 +14,7 @@ export interface WriteStreamOptions {
13
14
  start?: number;
14
15
  }
15
16
 
16
- export function oswrite(os: stream.Writable, buf: Buffer): Promise<void> {
17
+ export function oswrite(os: Writable, buf: Buffer): Promise<void> {
17
18
  return new Promise((resolve, reject) => {
18
19
  os.write(buf, (err) => {
19
20
  if (err) {
@@ -25,7 +26,7 @@ export function oswrite(os: stream.Writable, buf: Buffer): Promise<void> {
25
26
  });
26
27
  }
27
28
 
28
- export function osclose(os: stream.Writable): Promise<void> {
29
+ export function osclose(os: Writable): Promise<void> {
29
30
  return new Promise((resolve, reject) => {
30
31
  (os as any).close((err: any) => {
31
32
  if (err) {