@loaders.gl/parquet 4.4.2 → 5.0.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 (267) hide show
  1. package/dist/bundled.d.ts +6 -0
  2. package/dist/bundled.d.ts.map +1 -0
  3. package/dist/bundled.js +7 -0
  4. package/dist/bundled.js.map +1 -0
  5. package/dist/geoparquet-loader-with-parser.d.ts +34 -0
  6. package/dist/geoparquet-loader-with-parser.d.ts.map +1 -0
  7. package/dist/geoparquet-loader-with-parser.js +52 -0
  8. package/dist/geoparquet-loader-with-parser.js.map +1 -0
  9. package/dist/geoparquet-loader.d.ts +61 -0
  10. package/dist/geoparquet-loader.d.ts.map +1 -0
  11. package/dist/geoparquet-loader.js +30 -0
  12. package/dist/geoparquet-loader.js.map +1 -0
  13. package/dist/index.cjs +5879 -5643
  14. package/dist/index.cjs.map +4 -4
  15. package/dist/index.d.ts +7 -7
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +5 -11
  18. package/dist/index.js.map +1 -1
  19. package/dist/lib/constants.d.ts +1 -1
  20. package/dist/lib/constants.js +2 -2
  21. package/dist/lib/constants.js.map +1 -1
  22. package/dist/lib/encoders/encode-arrow-to-parquet.d.ts +2 -2
  23. package/dist/lib/encoders/encode-arrow-to-parquet.d.ts.map +1 -1
  24. package/dist/lib/encoders/encode-arrow-to-parquet.js +3 -10
  25. package/dist/lib/encoders/encode-arrow-to-parquet.js.map +1 -1
  26. package/dist/lib/encoders/encode-table-to-parquet-js.d.ts +5 -0
  27. package/dist/lib/encoders/encode-table-to-parquet-js.d.ts.map +1 -0
  28. package/dist/lib/encoders/encode-table-to-parquet-js.js +149 -0
  29. package/dist/lib/encoders/encode-table-to-parquet-js.js.map +1 -0
  30. package/dist/lib/geo/geospatial-metadata.d.ts +67 -0
  31. package/dist/lib/geo/geospatial-metadata.d.ts.map +1 -0
  32. package/dist/lib/geo/geospatial-metadata.js +357 -0
  33. package/dist/lib/geo/geospatial-metadata.js.map +1 -0
  34. package/dist/lib/parsers/get-parquet-schema.d.ts.map +1 -1
  35. package/dist/lib/parsers/get-parquet-schema.js +3 -1
  36. package/dist/lib/parsers/get-parquet-schema.js.map +1 -1
  37. package/dist/lib/parsers/parse-geoparquet-to-geojson.d.ts +4 -4
  38. package/dist/lib/parsers/parse-geoparquet-to-geojson.d.ts.map +1 -1
  39. package/dist/lib/parsers/parse-geoparquet-to-geojson.js +19 -6
  40. package/dist/lib/parsers/parse-geoparquet-to-geojson.js.map +1 -1
  41. package/dist/lib/parsers/parse-parquet-tables.d.ts +50 -0
  42. package/dist/lib/parsers/parse-parquet-tables.d.ts.map +1 -0
  43. package/dist/lib/parsers/parse-parquet-tables.js +101 -0
  44. package/dist/lib/parsers/parse-parquet-tables.js.map +1 -0
  45. package/dist/lib/parsers/parse-parquet-to-arrow-js.d.ts +6 -0
  46. package/dist/lib/parsers/parse-parquet-to-arrow-js.d.ts.map +1 -0
  47. package/dist/lib/parsers/parse-parquet-to-arrow-js.js +23 -0
  48. package/dist/lib/parsers/parse-parquet-to-arrow-js.js.map +1 -0
  49. package/dist/lib/parsers/parse-parquet-to-arrow.d.ts +7 -7
  50. package/dist/lib/parsers/parse-parquet-to-arrow.d.ts.map +1 -1
  51. package/dist/lib/parsers/parse-parquet-to-arrow.js +45 -32
  52. package/dist/lib/parsers/parse-parquet-to-arrow.js.map +1 -1
  53. package/dist/lib/parsers/parse-parquet-to-columns.d.ts +3 -3
  54. package/dist/lib/parsers/parse-parquet-to-columns.d.ts.map +1 -1
  55. package/dist/lib/parsers/parse-parquet-to-columns.js +1 -4
  56. package/dist/lib/parsers/parse-parquet-to-columns.js.map +1 -1
  57. package/dist/lib/parsers/parse-parquet-to-json.d.ts +3 -3
  58. package/dist/lib/parsers/parse-parquet-to-json.d.ts.map +1 -1
  59. package/dist/lib/parsers/parse-parquet-to-json.js +77 -26
  60. package/dist/lib/parsers/parse-parquet-to-json.js.map +1 -1
  61. package/dist/lib/utils/load-wasm.d.ts +2 -2
  62. package/dist/lib/utils/load-wasm.d.ts.map +1 -1
  63. package/dist/lib/utils/load-wasm.js +7 -7
  64. package/dist/lib/utils/load-wasm.js.map +1 -1
  65. package/dist/lib/utils/make-stream-iterator.js +1 -1
  66. package/dist/lib/utils/make-stream-iterator.js.map +1 -1
  67. package/dist/lib/utils/normalize-parquet-options.d.ts +5 -0
  68. package/dist/lib/utils/normalize-parquet-options.d.ts.map +1 -0
  69. package/dist/lib/utils/normalize-parquet-options.js +11 -0
  70. package/dist/lib/utils/normalize-parquet-options.js.map +1 -0
  71. package/dist/parquet-format.d.ts +2 -0
  72. package/dist/parquet-format.d.ts.map +1 -1
  73. package/dist/parquet-format.js +2 -0
  74. package/dist/parquet-format.js.map +1 -1
  75. package/dist/parquet-js-loader.d.ts +57 -0
  76. package/dist/parquet-js-loader.d.ts.map +1 -0
  77. package/dist/parquet-js-loader.js +33 -0
  78. package/dist/parquet-js-loader.js.map +1 -0
  79. package/dist/parquet-js-writer.d.ts +34 -0
  80. package/dist/parquet-js-writer.d.ts.map +1 -0
  81. package/dist/parquet-js-writer.js +28 -0
  82. package/dist/parquet-js-writer.js.map +1 -0
  83. package/dist/parquet-loader-options.d.ts +56 -0
  84. package/dist/parquet-loader-options.d.ts.map +1 -0
  85. package/dist/parquet-loader-options.js +11 -0
  86. package/dist/parquet-loader-options.js.map +1 -0
  87. package/dist/parquet-loader-with-parser.d.ts +33 -0
  88. package/dist/parquet-loader-with-parser.d.ts.map +1 -0
  89. package/dist/parquet-loader-with-parser.js +40 -0
  90. package/dist/parquet-loader-with-parser.js.map +1 -0
  91. package/dist/parquet-loader.d.ts +62 -0
  92. package/dist/parquet-loader.d.ts.map +1 -0
  93. package/dist/parquet-loader.js +53 -0
  94. package/dist/parquet-loader.js.map +1 -0
  95. package/dist/parquet-wasm-loader-with-parser.d.ts +40 -0
  96. package/dist/parquet-wasm-loader-with-parser.d.ts.map +1 -0
  97. package/dist/parquet-wasm-loader-with-parser.js +68 -0
  98. package/dist/parquet-wasm-loader-with-parser.js.map +1 -0
  99. package/dist/parquet-writer.d.ts +10 -0
  100. package/dist/parquet-writer.d.ts.map +1 -0
  101. package/dist/parquet-writer.js +29 -0
  102. package/dist/parquet-writer.js.map +1 -0
  103. package/dist/parquet_wasm_bg.wasm +0 -0
  104. package/dist/parquetjs/codecs/declare.d.ts +2 -2
  105. package/dist/parquetjs/codecs/declare.d.ts.map +1 -1
  106. package/dist/parquetjs/codecs/dictionary.js +1 -1
  107. package/dist/parquetjs/codecs/dictionary.js.map +1 -1
  108. package/dist/parquetjs/codecs/plain.d.ts +1 -1
  109. package/dist/parquetjs/codecs/plain.d.ts.map +1 -1
  110. package/dist/parquetjs/codecs/plain.js +36 -41
  111. package/dist/parquetjs/codecs/plain.js.map +1 -1
  112. package/dist/parquetjs/codecs/rle.d.ts +1 -1
  113. package/dist/parquetjs/codecs/rle.d.ts.map +1 -1
  114. package/dist/parquetjs/codecs/rle.js +16 -21
  115. package/dist/parquetjs/codecs/rle.js.map +1 -1
  116. package/dist/parquetjs/compression.d.ts +2 -3
  117. package/dist/parquetjs/compression.d.ts.map +1 -1
  118. package/dist/parquetjs/compression.js +4 -105
  119. package/dist/parquetjs/compression.js.map +1 -1
  120. package/dist/parquetjs/encoder/parquet-encoder.d.ts +4 -4
  121. package/dist/parquetjs/encoder/parquet-encoder.d.ts.map +1 -1
  122. package/dist/parquetjs/encoder/parquet-encoder.js +38 -33
  123. package/dist/parquetjs/encoder/parquet-encoder.js.map +1 -1
  124. package/dist/parquetjs/parquet-thrift/ColumnIndex.js +1 -1
  125. package/dist/parquetjs/parquet-thrift/ColumnIndex.js.map +1 -1
  126. package/dist/parquetjs/parquet-thrift/index.d.ts +0 -1
  127. package/dist/parquetjs/parquet-thrift/index.d.ts.map +1 -1
  128. package/dist/parquetjs/parquet-thrift/index.js +0 -1
  129. package/dist/parquetjs/parquet-thrift/index.js.map +1 -1
  130. package/dist/parquetjs/parser/decoders.d.ts +1 -1
  131. package/dist/parquetjs/parser/decoders.d.ts.map +1 -1
  132. package/dist/parquetjs/parser/decoders.js +4 -22
  133. package/dist/parquetjs/parser/decoders.js.map +1 -1
  134. package/dist/parquetjs/parser/parquet-reader.d.ts +1 -1
  135. package/dist/parquetjs/parser/parquet-reader.d.ts.map +1 -1
  136. package/dist/parquetjs/parser/parquet-reader.js +9 -9
  137. package/dist/parquetjs/parser/parquet-reader.js.map +1 -1
  138. package/dist/parquetjs/schema/declare.d.ts +1 -1
  139. package/dist/parquetjs/schema/declare.d.ts.map +1 -1
  140. package/dist/parquetjs/schema/types.d.ts.map +1 -1
  141. package/dist/parquetjs/schema/types.js +36 -35
  142. package/dist/parquetjs/schema/types.js.map +1 -1
  143. package/dist/parquetjs/utils/binary-utils.d.ts +39 -0
  144. package/dist/parquetjs/utils/binary-utils.d.ts.map +1 -0
  145. package/dist/parquetjs/utils/binary-utils.js +102 -0
  146. package/dist/parquetjs/utils/binary-utils.js.map +1 -0
  147. package/dist/parquetjs/utils/file-utils.d.ts +1 -1
  148. package/dist/parquetjs/utils/file-utils.d.ts.map +1 -1
  149. package/dist/parquetjs/utils/file-utils.js +3 -3
  150. package/dist/parquetjs/utils/file-utils.js.map +1 -1
  151. package/dist/parquetjs/utils/read-utils.d.ts +4 -4
  152. package/dist/parquetjs/utils/read-utils.d.ts.map +1 -1
  153. package/dist/parquetjs/utils/read-utils.js +12 -17
  154. package/dist/parquetjs/utils/read-utils.js.map +1 -1
  155. package/dist/parquetjs/utils/uint8-array-compact-protocol-writer.d.ts +78 -0
  156. package/dist/parquetjs/utils/uint8-array-compact-protocol-writer.d.ts.map +1 -0
  157. package/dist/parquetjs/utils/uint8-array-compact-protocol-writer.js +213 -0
  158. package/dist/parquetjs/utils/uint8-array-compact-protocol-writer.js.map +1 -0
  159. package/dist/parquetjs/utils/uint8-array-compact-protocol.d.ts +78 -0
  160. package/dist/parquetjs/utils/uint8-array-compact-protocol.d.ts.map +1 -0
  161. package/dist/parquetjs/utils/uint8-array-compact-protocol.js +276 -0
  162. package/dist/parquetjs/utils/uint8-array-compact-protocol.js.map +1 -0
  163. package/dist/parquetjs/utils/uint8-array-transport.d.ts +25 -0
  164. package/dist/parquetjs/utils/uint8-array-transport.d.ts.map +1 -0
  165. package/dist/parquetjs/utils/uint8-array-transport.js +62 -0
  166. package/dist/parquetjs/utils/uint8-array-transport.js.map +1 -0
  167. package/dist/unbundled.d.ts +6 -0
  168. package/dist/unbundled.d.ts.map +1 -0
  169. package/dist/unbundled.js +7 -0
  170. package/dist/unbundled.js.map +1 -0
  171. package/package.json +21 -25
  172. package/src/bundled.ts +9 -0
  173. package/src/geoparquet-loader-with-parser.ts +95 -0
  174. package/src/geoparquet-loader.ts +54 -0
  175. package/src/index.ts +7 -25
  176. package/src/lib/constants.ts +1 -1
  177. package/src/lib/encoders/encode-arrow-to-parquet.ts +9 -15
  178. package/src/lib/encoders/encode-table-to-parquet-js.ts +199 -0
  179. package/src/lib/geo/geospatial-metadata.ts +507 -0
  180. package/src/lib/parsers/get-parquet-schema.ts +3 -1
  181. package/src/lib/parsers/parse-geoparquet-to-geojson.ts +27 -14
  182. package/src/lib/parsers/parse-parquet-tables.ts +137 -0
  183. package/src/lib/parsers/parse-parquet-to-arrow-js.ts +36 -0
  184. package/src/lib/parsers/parse-parquet-to-arrow.ts +63 -36
  185. package/src/lib/parsers/parse-parquet-to-columns.ts +6 -7
  186. package/src/lib/parsers/parse-parquet-to-json.ts +101 -33
  187. package/src/lib/utils/load-wasm.ts +16 -9
  188. package/src/lib/utils/make-stream-iterator.ts +1 -1
  189. package/src/lib/utils/normalize-parquet-options.ts +14 -0
  190. package/src/parquet-format.ts +2 -0
  191. package/src/parquet-js-loader.ts +43 -0
  192. package/src/parquet-js-writer.ts +52 -0
  193. package/src/parquet-loader-options.ts +63 -0
  194. package/src/parquet-loader-with-parser.ts +68 -0
  195. package/src/parquet-loader.ts +79 -0
  196. package/src/parquet-wasm-loader-with-parser.ts +115 -0
  197. package/src/parquet-writer.ts +44 -0
  198. package/src/parquetjs/codecs/declare.ts +2 -2
  199. package/src/parquetjs/codecs/dictionary.ts +1 -1
  200. package/src/parquetjs/codecs/plain.ts +67 -53
  201. package/src/parquetjs/codecs/rle.ts +20 -26
  202. package/src/parquetjs/compression.ts +7 -114
  203. package/src/parquetjs/encoder/parquet-encoder.ts +49 -43
  204. package/src/parquetjs/parquet-thrift/ColumnIndex.ts +1 -1
  205. package/src/parquetjs/parquet-thrift/index.ts +0 -2
  206. package/src/parquetjs/parser/decoders.ts +5 -23
  207. package/src/parquetjs/parser/parquet-reader.ts +10 -12
  208. package/src/parquetjs/schema/declare.ts +1 -1
  209. package/src/parquetjs/schema/types.ts +48 -40
  210. package/src/parquetjs/utils/binary-utils.ts +127 -0
  211. package/src/parquetjs/utils/file-utils.ts +4 -4
  212. package/src/parquetjs/utils/read-utils.ts +19 -34
  213. package/src/parquetjs/utils/uint8-array-compact-protocol-writer.ts +254 -0
  214. package/src/parquetjs/utils/uint8-array-compact-protocol.ts +322 -0
  215. package/src/parquetjs/utils/uint8-array-transport.ts +79 -0
  216. package/src/unbundled.ts +9 -0
  217. package/dist/parquet-arrow-loader.d.ts +0 -43
  218. package/dist/parquet-arrow-loader.d.ts.map +0 -1
  219. package/dist/parquet-arrow-loader.js +0 -49
  220. package/dist/parquet-arrow-loader.js.map +0 -1
  221. package/dist/parquet-arrow-writer.d.ts +0 -9
  222. package/dist/parquet-arrow-writer.d.ts.map +0 -1
  223. package/dist/parquet-arrow-writer.js +0 -23
  224. package/dist/parquet-arrow-writer.js.map +0 -1
  225. package/dist/parquet-json-loader.d.ts +0 -148
  226. package/dist/parquet-json-loader.d.ts.map +0 -1
  227. package/dist/parquet-json-loader.js +0 -106
  228. package/dist/parquet-json-loader.js.map +0 -1
  229. package/dist/parquet-json-writer.d.ts +0 -19
  230. package/dist/parquet-json-writer.d.ts.map +0 -1
  231. package/dist/parquet-json-writer.js +0 -20
  232. package/dist/parquet-json-writer.js.map +0 -1
  233. package/dist/polyfills/buffer/buffer-polyfill.browser.d.ts +0 -3
  234. package/dist/polyfills/buffer/buffer-polyfill.browser.d.ts.map +0 -1
  235. package/dist/polyfills/buffer/buffer-polyfill.browser.js +0 -12
  236. package/dist/polyfills/buffer/buffer-polyfill.browser.js.map +0 -1
  237. package/dist/polyfills/buffer/buffer-polyfill.node.d.ts +0 -3
  238. package/dist/polyfills/buffer/buffer-polyfill.node.d.ts.map +0 -1
  239. package/dist/polyfills/buffer/buffer-polyfill.node.js +0 -17
  240. package/dist/polyfills/buffer/buffer-polyfill.node.js.map +0 -1
  241. package/dist/polyfills/buffer/buffer.d.ts +0 -222
  242. package/dist/polyfills/buffer/buffer.d.ts.map +0 -1
  243. package/dist/polyfills/buffer/buffer.js +0 -1868
  244. package/dist/polyfills/buffer/buffer.js.map +0 -1
  245. package/dist/polyfills/buffer/index.d.ts +0 -4
  246. package/dist/polyfills/buffer/index.d.ts.map +0 -1
  247. package/dist/polyfills/buffer/index.js +0 -9
  248. package/dist/polyfills/buffer/index.js.map +0 -1
  249. package/dist/polyfills/buffer/install-buffer-polyfill.d.ts +0 -2
  250. package/dist/polyfills/buffer/install-buffer-polyfill.d.ts.map +0 -1
  251. package/dist/polyfills/buffer/install-buffer-polyfill.js +0 -10
  252. package/dist/polyfills/buffer/install-buffer-polyfill.js.map +0 -1
  253. package/dist/workers/parquet-json-worker.d.ts +0 -2
  254. package/dist/workers/parquet-json-worker.d.ts.map +0 -1
  255. package/dist/workers/parquet-json-worker.js +0 -7
  256. package/dist/workers/parquet-json-worker.js.map +0 -1
  257. package/src/parquet-arrow-loader.ts +0 -74
  258. package/src/parquet-arrow-writer.ts +0 -33
  259. package/src/parquet-json-loader.ts +0 -160
  260. package/src/parquet-json-writer.ts +0 -27
  261. package/src/parquetjs/modules.d.ts +0 -25
  262. package/src/polyfills/buffer/buffer-polyfill.browser.ts +0 -14
  263. package/src/polyfills/buffer/buffer-polyfill.node.ts +0 -19
  264. package/src/polyfills/buffer/buffer.ts +0 -2205
  265. package/src/polyfills/buffer/index.ts +0 -11
  266. package/src/polyfills/buffer/install-buffer-polyfill.ts +0 -12
  267. package/src/workers/parquet-json-worker.ts +0 -8
@@ -5,8 +5,16 @@
5
5
  // Forked from https://github.com/kbajalc/parquets under MIT license
6
6
 
7
7
  /* eslint-disable camelcase */
8
- import {BSONLoader, BSONWriter} from '@loaders.gl/bson';
8
+ import {BSONWriter, parseBSONSync} from '@loaders.gl/bson';
9
9
  import {OriginalType, ParquetField, ParquetType, PrimitiveType} from './declare';
10
+ import {
11
+ decodeUtf8,
12
+ encodeUtf8,
13
+ readUInt32LE,
14
+ toArrayBuffer,
15
+ toUint8Array,
16
+ writeUInt32LE
17
+ } from '../utils/binary-utils';
10
18
 
11
19
  export interface ParquetTypeKit {
12
20
  primitiveType: PrimitiveType;
@@ -207,7 +215,7 @@ function fromPrimitive_BOOLEAN(value: any): boolean {
207
215
 
208
216
  function toPrimitive_FLOAT(value: any): number {
209
217
  const v = parseFloat(value);
210
- if (isNaN(v)) {
218
+ if (Number.isNaN(v)) {
211
219
  throw new Error(`invalid value for FLOAT: ${value}`);
212
220
  }
213
221
  return v;
@@ -215,7 +223,7 @@ function toPrimitive_FLOAT(value: any): number {
215
223
 
216
224
  function toPrimitive_DOUBLE(value: any): number {
217
225
  const v = parseFloat(value);
218
- if (isNaN(v)) {
226
+ if (Number.isNaN(v)) {
219
227
  throw new Error(`invalid value for DOUBLE: ${value}`);
220
228
  }
221
229
  return v;
@@ -223,7 +231,7 @@ function toPrimitive_DOUBLE(value: any): number {
223
231
 
224
232
  function toPrimitive_INT8(value: any) {
225
233
  const v = parseInt(value, 10);
226
- if (v < -0x80 || v > 0x7f || isNaN(v)) {
234
+ if (v < -0x80 || v > 0x7f || Number.isNaN(v)) {
227
235
  throw new Error(`invalid value for INT8: ${value}`);
228
236
  }
229
237
 
@@ -232,7 +240,7 @@ function toPrimitive_INT8(value: any) {
232
240
 
233
241
  function toPrimitive_UINT8(value: any) {
234
242
  const v = parseInt(value, 10);
235
- if (v < 0 || v > 0xff || isNaN(v)) {
243
+ if (v < 0 || v > 0xff || Number.isNaN(v)) {
236
244
  throw new Error(`invalid value for UINT8: ${value}`);
237
245
  }
238
246
 
@@ -241,7 +249,7 @@ function toPrimitive_UINT8(value: any) {
241
249
 
242
250
  function toPrimitive_INT16(value: any) {
243
251
  const v = parseInt(value, 10);
244
- if (v < -0x8000 || v > 0x7fff || isNaN(v)) {
252
+ if (v < -0x8000 || v > 0x7fff || Number.isNaN(v)) {
245
253
  throw new Error(`invalid value for INT16: ${value}`);
246
254
  }
247
255
 
@@ -250,7 +258,7 @@ function toPrimitive_INT16(value: any) {
250
258
 
251
259
  function toPrimitive_UINT16(value: any) {
252
260
  const v = parseInt(value, 10);
253
- if (v < 0 || v > 0xffff || isNaN(v)) {
261
+ if (v < 0 || v > 0xffff || Number.isNaN(v)) {
254
262
  throw new Error(`invalid value for UINT16: ${value}`);
255
263
  }
256
264
 
@@ -259,7 +267,7 @@ function toPrimitive_UINT16(value: any) {
259
267
 
260
268
  function toPrimitive_INT32(value: any) {
261
269
  const v = parseInt(value, 10);
262
- if (v < -0x80000000 || v > 0x7fffffff || isNaN(v)) {
270
+ if (v < -0x80000000 || v > 0x7fffffff || Number.isNaN(v)) {
263
271
  throw new Error(`invalid value for INT32: ${value}`);
264
272
  }
265
273
 
@@ -269,7 +277,7 @@ function toPrimitive_INT32(value: any) {
269
277
  function decimalToPrimitive_INT32(value: number, field: ParquetField): number {
270
278
  const primitiveValue = value * 10 ** (field.scale || 0);
271
279
  const v = Math.round(((primitiveValue * 10 ** -field.presision!) % 1) * 10 ** field.presision!);
272
- if (v < -0x80000000 || v > 0x7fffffff || isNaN(v)) {
280
+ if (v < -0x80000000 || v > 0x7fffffff || Number.isNaN(v)) {
273
281
  throw new Error(`invalid value for INT32: ${value}`);
274
282
  }
275
283
  return v;
@@ -277,7 +285,7 @@ function decimalToPrimitive_INT32(value: number, field: ParquetField): number {
277
285
 
278
286
  function toPrimitive_UINT32(value: any): number {
279
287
  const v = parseInt(value, 10);
280
- if (v < 0 || v > 0xffffffffffff || isNaN(v)) {
288
+ if (v < 0 || v > 0xffffffffffff || Number.isNaN(v)) {
281
289
  throw new Error(`invalid value for UINT32: ${value}`);
282
290
  }
283
291
  return v;
@@ -285,7 +293,7 @@ function toPrimitive_UINT32(value: any): number {
285
293
 
286
294
  function toPrimitive_INT64(value: any): number {
287
295
  const v = parseInt(value, 10);
288
- if (isNaN(v)) {
296
+ if (Number.isNaN(v)) {
289
297
  throw new Error(`invalid value for INT64: ${value}`);
290
298
  }
291
299
  return v;
@@ -294,7 +302,7 @@ function toPrimitive_INT64(value: any): number {
294
302
  function decimalToPrimitive_INT64(value: number, field: ParquetField) {
295
303
  const primitiveValue = value * 10 ** (field.scale || 0);
296
304
  const v = Math.round(((primitiveValue * 10 ** -field.presision!) % 1) * 10 ** field.presision!);
297
- if (isNaN(v)) {
305
+ if (Number.isNaN(v)) {
298
306
  throw new Error(`invalid value for INT64: ${value}`);
299
307
  }
300
308
 
@@ -303,7 +311,7 @@ function decimalToPrimitive_INT64(value: number, field: ParquetField) {
303
311
 
304
312
  function toPrimitive_UINT64(value: any) {
305
313
  const v = parseInt(value, 10);
306
- if (v < 0 || isNaN(v)) {
314
+ if (v < 0 || Number.isNaN(v)) {
307
315
  throw new Error(`invalid value for UINT64: ${value}`);
308
316
  }
309
317
 
@@ -312,52 +320,52 @@ function toPrimitive_UINT64(value: any) {
312
320
 
313
321
  function toPrimitive_INT96(value: any) {
314
322
  const v = parseInt(value, 10);
315
- if (isNaN(v)) {
323
+ if (Number.isNaN(v)) {
316
324
  throw new Error(`invalid value for INT96: ${value}`);
317
325
  }
318
326
 
319
327
  return v;
320
328
  }
321
329
 
322
- function toPrimitive_BYTE_ARRAY(value: any): Buffer {
323
- return Buffer.from(value);
330
+ function toPrimitive_BYTE_ARRAY(value: any): Uint8Array {
331
+ return typeof value === 'string' ? encodeUtf8(value) : toUint8Array(value);
324
332
  }
325
333
 
326
- function decimalToPrimitive_BYTE_ARRAY(value: any): Buffer {
334
+ function decimalToPrimitive_BYTE_ARRAY(value: any): Uint8Array {
327
335
  // TBD
328
- return Buffer.from(value);
336
+ return typeof value === 'string' ? encodeUtf8(value) : toUint8Array(value);
329
337
  }
330
338
 
331
- function toPrimitive_UTF8(value: any): Buffer {
332
- return Buffer.from(value, 'utf8');
339
+ function toPrimitive_UTF8(value: any): Uint8Array {
340
+ return encodeUtf8(String(value));
333
341
  }
334
342
 
335
343
  function fromPrimitive_UTF8(value: any): string {
336
- return value.toString();
344
+ return decodeUtf8(toUint8Array(value));
337
345
  }
338
346
 
339
- function toPrimitive_JSON(value: any): Buffer {
340
- return Buffer.from(JSON.stringify(value));
347
+ function toPrimitive_JSON(value: any): Uint8Array {
348
+ return encodeUtf8(JSON.stringify(value));
341
349
  }
342
350
 
343
351
  function fromPrimitive_JSON(value: any): unknown {
344
- return JSON.parse(value);
352
+ return JSON.parse(decodeUtf8(toUint8Array(value)));
345
353
  }
346
354
 
347
- function toPrimitive_BSON(value: any): Buffer {
355
+ function toPrimitive_BSON(value: any): Uint8Array {
348
356
  // @ts-ignore
349
357
  const arrayBuffer: ArrayBuffer = BSONWriter.encodeSync?.(value);
350
- return Buffer.from(arrayBuffer);
358
+ return toUint8Array(arrayBuffer);
351
359
  }
352
360
 
353
361
  function fromPrimitive_BSON(value: any) {
354
- return BSONLoader.parseSync?.(value);
362
+ return parseBSONSync(toArrayBuffer(value));
355
363
  }
356
364
 
357
365
  function toPrimitive_TIME_MILLIS(value: any) {
358
366
  const v = parseInt(value, 10);
359
367
  // eslint-disable-next-line @typescript-eslint/no-loss-of-precision
360
- if (v < 0 || v > 0xffffffffffffffff || isNaN(v)) {
368
+ if (v < 0 || v > 0xffffffffffffffff || Number.isNaN(v)) {
361
369
  throw new Error(`invalid value for TIME_MILLIS: ${value}`);
362
370
  }
363
371
 
@@ -366,7 +374,7 @@ function toPrimitive_TIME_MILLIS(value: any) {
366
374
 
367
375
  function toPrimitive_TIME_MICROS(value: any): number {
368
376
  const v = parseInt(value, 10);
369
- if (v < 0 || isNaN(v)) {
377
+ if (v < 0 || Number.isNaN(v)) {
370
378
  throw new Error(`invalid value for TIME_MICROS: ${value}`);
371
379
  }
372
380
  return v;
@@ -383,7 +391,7 @@ function toPrimitive_DATE(value: any): number {
383
391
  /* convert from integer */
384
392
  {
385
393
  const v = parseInt(value, 10);
386
- if (v < 0 || isNaN(v)) {
394
+ if (v < 0 || Number.isNaN(v)) {
387
395
  throw new Error(`invalid value for DATE: ${value}`);
388
396
  }
389
397
 
@@ -404,7 +412,7 @@ function toPrimitive_TIMESTAMP_MILLIS(value: any): number {
404
412
  /* convert from integer */
405
413
  {
406
414
  const v = parseInt(value, 10);
407
- if (v < 0 || isNaN(v)) {
415
+ if (v < 0 || Number.isNaN(v)) {
408
416
  throw new Error(`invalid value for TIMESTAMP_MILLIS: ${value}`);
409
417
  }
410
418
 
@@ -425,7 +433,7 @@ function toPrimitive_TIMESTAMP_MICROS(value: any) {
425
433
  /* convert from integer */
426
434
  {
427
435
  const v = parseInt(value, 10);
428
- if (v < 0 || isNaN(v)) {
436
+ if (v < 0 || Number.isNaN(v)) {
429
437
  throw new Error(`invalid value for TIMESTAMP_MICROS: ${value}`);
430
438
  }
431
439
 
@@ -444,19 +452,19 @@ function toPrimitive_INTERVAL(value: any) {
444
452
  );
445
453
  }
446
454
 
447
- const buf = Buffer.alloc(12);
455
+ const buf = new Uint8Array(12);
448
456
 
449
- buf.writeUInt32LE(value.months, 0);
450
- buf.writeUInt32LE(value.days, 4);
451
- buf.writeUInt32LE(value.milliseconds, 8);
457
+ writeUInt32LE(buf, value.months, 0);
458
+ writeUInt32LE(buf, value.days, 4);
459
+ writeUInt32LE(buf, value.milliseconds, 8);
452
460
  return buf;
453
461
  }
454
462
 
455
463
  function fromPrimitive_INTERVAL(value: any) {
456
- const buf = Buffer.from(value);
457
- const months = buf.readUInt32LE(0);
458
- const days = buf.readUInt32LE(4);
459
- const millis = buf.readUInt32LE(8);
464
+ const bytes = toUint8Array(value);
465
+ const months = readUInt32LE(bytes, 0);
466
+ const days = readUInt32LE(bytes, 4);
467
+ const millis = readUInt32LE(bytes, 8);
460
468
 
461
469
  return {months, days, milliseconds: millis};
462
470
  }
@@ -0,0 +1,127 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ const TEXT_DECODER = new TextDecoder();
6
+ const TEXT_ENCODER = new TextEncoder();
7
+
8
+ /** Returns bytes as an exact Uint8Array view. */
9
+ export function toUint8Array(binary: ArrayBuffer | ArrayBufferView): Uint8Array {
10
+ if (binary instanceof Uint8Array) {
11
+ return binary;
12
+ }
13
+ if (ArrayBuffer.isView(binary)) {
14
+ return new Uint8Array(binary.buffer, binary.byteOffset, binary.byteLength);
15
+ }
16
+ return new Uint8Array(binary);
17
+ }
18
+
19
+ /** Returns bytes as a copied ArrayBuffer with no extra prefix/suffix bytes. */
20
+ export function toArrayBuffer(binary: ArrayBuffer | ArrayBufferView): ArrayBuffer {
21
+ const bytes = toUint8Array(binary);
22
+ return bytes.slice().buffer;
23
+ }
24
+
25
+ /** Returns a copied Uint8Array. */
26
+ export function copyUint8Array(binary: Uint8Array): Uint8Array {
27
+ return binary.slice();
28
+ }
29
+
30
+ /** Decode UTF-8 bytes. */
31
+ export function decodeUtf8(binary: Uint8Array): string {
32
+ return TEXT_DECODER.decode(binary);
33
+ }
34
+
35
+ /** Encode text as UTF-8 bytes. */
36
+ export function encodeUtf8(text: string): Uint8Array {
37
+ return TEXT_ENCODER.encode(text);
38
+ }
39
+
40
+ /** Decode an ASCII/UTF-8 range from bytes. */
41
+ export function decodeString(
42
+ binary: Uint8Array,
43
+ start: number = 0,
44
+ end: number = binary.length
45
+ ): string {
46
+ return decodeUtf8(binary.subarray(start, end));
47
+ }
48
+
49
+ function getDataView(binary: Uint8Array): DataView {
50
+ return new DataView(binary.buffer, binary.byteOffset, binary.byteLength);
51
+ }
52
+
53
+ /** Read signed little-endian 32-bit integer. */
54
+ export function readInt32LE(binary: Uint8Array, offset: number): number {
55
+ return getDataView(binary).getInt32(offset, true);
56
+ }
57
+
58
+ /** Read unsigned little-endian 32-bit integer. */
59
+ export function readUInt32LE(binary: Uint8Array, offset: number): number {
60
+ return getDataView(binary).getUint32(offset, true);
61
+ }
62
+
63
+ /** Read signed little-endian 64-bit integer as number. */
64
+ export function readInt64LE(binary: Uint8Array, offset: number): number {
65
+ return Number(getDataView(binary).getBigInt64(offset, true));
66
+ }
67
+
68
+ /** Read little-endian 32-bit float. */
69
+ export function readFloatLE(binary: Uint8Array, offset: number): number {
70
+ return getDataView(binary).getFloat32(offset, true);
71
+ }
72
+
73
+ /** Read little-endian 64-bit float. */
74
+ export function readDoubleLE(binary: Uint8Array, offset: number): number {
75
+ return getDataView(binary).getFloat64(offset, true);
76
+ }
77
+
78
+ /** Concatenate bytes into one exact Uint8Array. */
79
+ export function concatUint8Arrays(chunks: Uint8Array[]): Uint8Array {
80
+ let byteLength = 0;
81
+ for (const chunk of chunks) {
82
+ byteLength += chunk.length;
83
+ }
84
+
85
+ const result = new Uint8Array(byteLength);
86
+ let offset = 0;
87
+ for (const chunk of chunks) {
88
+ result.set(chunk, offset);
89
+ offset += chunk.length;
90
+ }
91
+ return result;
92
+ }
93
+
94
+ /** Write signed little-endian 16-bit integer. */
95
+ export function writeInt16LE(binary: Uint8Array, value: number, offset: number): void {
96
+ getDataView(binary).setInt16(offset, value, true);
97
+ }
98
+
99
+ /** Write unsigned little-endian 16-bit integer. */
100
+ export function writeUInt16LE(binary: Uint8Array, value: number, offset: number): void {
101
+ getDataView(binary).setUint16(offset, value, true);
102
+ }
103
+
104
+ /** Write signed little-endian 32-bit integer. */
105
+ export function writeInt32LE(binary: Uint8Array, value: number, offset: number): void {
106
+ getDataView(binary).setInt32(offset, value, true);
107
+ }
108
+
109
+ /** Write unsigned little-endian 32-bit integer. */
110
+ export function writeUInt32LE(binary: Uint8Array, value: number, offset: number): void {
111
+ getDataView(binary).setUint32(offset, value, true);
112
+ }
113
+
114
+ /** Write signed little-endian 64-bit integer. */
115
+ export function writeInt64LE(binary: Uint8Array, value: number | bigint, offset: number): void {
116
+ getDataView(binary).setBigInt64(offset, BigInt(value), true);
117
+ }
118
+
119
+ /** Write little-endian 32-bit float. */
120
+ export function writeFloatLE(binary: Uint8Array, value: number, offset: number): void {
121
+ getDataView(binary).setFloat32(offset, value, true);
122
+ }
123
+
124
+ /** Write little-endian 64-bit float. */
125
+ export function writeDoubleLE(binary: Uint8Array, value: number, offset: number): void {
126
+ getDataView(binary).setFloat64(offset, value, true);
127
+ }
@@ -19,9 +19,9 @@ export interface WriteStreamOptions {
19
19
  start?: number;
20
20
  }
21
21
 
22
- export function oswrite(os: stream.Writable, buf: Buffer): Promise<void> {
22
+ export function oswrite(os: stream.Writable, buf: Uint8Array): Promise<void> {
23
23
  return new Promise((resolve, reject) => {
24
- os.write(buf, (err) => {
24
+ os.write(buf, err => {
25
25
  if (err) {
26
26
  reject(err);
27
27
  } else {
@@ -46,7 +46,7 @@ export function osclose(os: stream.Writable): Promise<void> {
46
46
  export function osopen(path: string, opts?: WriteStreamOptions): Promise<fs.WriteStream> {
47
47
  return new Promise((resolve, reject) => {
48
48
  const outputStream = fs.createWriteStream(path, opts as any);
49
- outputStream.once('open', (fd) => resolve(outputStream));
50
- outputStream.once('error', (err) => reject(err));
49
+ outputStream.once('open', _fd => resolve(outputStream));
50
+ outputStream.once('error', err => reject(err));
51
51
  });
52
52
  }
@@ -4,44 +4,29 @@
4
4
  // Copyright (c) 2017 ironSource Ltd.
5
5
  // Forked from https://github.com/kbajalc/parquets under MIT license
6
6
 
7
- import {
8
- TBufferedTransport,
9
- TCompactProtocol,
10
- TFramedTransport,
11
- FileMetaData,
12
- PageHeader
13
- } from '../parquet-thrift/index';
14
-
15
- class UFramedTransport extends TFramedTransport {
16
- public readPos: number = 0;
17
- }
7
+ import {FileMetaData, PageHeader} from '../parquet-thrift/index';
8
+ import {Uint8ArrayCompactProtocol} from './uint8-array-compact-protocol';
9
+ import {Uint8ArrayCompactProtocolWriter} from './uint8-array-compact-protocol-writer';
10
+ import {Uint8ArrayTransport} from './uint8-array-transport';
18
11
 
19
12
  /**
20
13
  * Helper function that serializes a thrift object into a buffer
21
14
  */
22
- export function serializeThrift(obj: any): Buffer {
23
- const output: Buffer[] = [];
24
-
25
- const transport = new TBufferedTransport(undefined, (buf) => {
26
- output.push(buf as unknown as Buffer);
27
- });
28
-
29
- const protocol = new TCompactProtocol(transport);
30
- obj.write(protocol);
31
- transport.flush();
32
-
33
- return Buffer.concat(output as Uint8Array[]);
15
+ export function serializeThrift(obj: any): Uint8Array {
16
+ const protocol = new Uint8ArrayCompactProtocolWriter();
17
+ obj.write(protocol as any);
18
+ return protocol.getBytes();
34
19
  }
35
20
 
36
- export function decodeThrift(obj: any, buf: Buffer, offset?: number) {
21
+ export function decodeThrift(obj: any, buf: Uint8Array, offset?: number) {
37
22
  if (!offset) {
38
23
  // tslint:disable-next-line:no-parameter-reassignment
39
24
  offset = 0;
40
25
  }
41
26
 
42
- const transport = new UFramedTransport(buf);
27
+ const transport = new Uint8ArrayTransport(buf);
43
28
  transport.readPos = offset;
44
- const protocol = new TCompactProtocol(transport);
29
+ const protocol = new Uint8ArrayCompactProtocol(transport);
45
30
  obj.read(protocol);
46
31
  return transport.readPos - offset;
47
32
  }
@@ -58,29 +43,29 @@ export function getThriftEnum(klass: any, value: number | string): string {
58
43
  throw new Error('Invalid ENUM value');
59
44
  }
60
45
 
61
- export function decodeFileMetadata(buf: Buffer, offset?: number) {
46
+ export function decodeFileMetadata(buf: Uint8Array, offset?: number) {
62
47
  if (!offset) {
63
48
  // tslint:disable-next-line:no-parameter-reassignment
64
49
  offset = 0;
65
50
  }
66
51
 
67
- const transport = new UFramedTransport(buf);
52
+ const transport = new Uint8ArrayTransport(buf);
68
53
  transport.readPos = offset;
69
- const protocol = new TCompactProtocol(transport);
70
- const metadata = FileMetaData.read(protocol);
54
+ const protocol = new Uint8ArrayCompactProtocol(transport);
55
+ const metadata = FileMetaData.read(protocol as any);
71
56
  return {length: transport.readPos - offset, metadata};
72
57
  }
73
58
 
74
- export function decodePageHeader(buf: Buffer, offset?: number) {
59
+ export function decodePageHeader(buf: Uint8Array, offset?: number) {
75
60
  if (!offset) {
76
61
  // tslint:disable-next-line:no-parameter-reassignment
77
62
  offset = 0;
78
63
  }
79
64
 
80
- const transport = new UFramedTransport(buf);
65
+ const transport = new Uint8ArrayTransport(buf);
81
66
  transport.readPos = offset;
82
- const protocol = new TCompactProtocol(transport);
83
- const pageHeader = PageHeader.read(protocol);
67
+ const protocol = new Uint8ArrayCompactProtocol(transport);
68
+ const pageHeader = PageHeader.read(protocol as any);
84
69
  return {length: transport.readPos - offset, pageHeader};
85
70
  }
86
71