@loaders.gl/netcdf 4.2.0-alpha.4 → 4.2.0-alpha.6
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/dist.dev.js +284 -9
- package/dist/dist.min.js +10 -0
- package/dist/index.cjs +48 -14
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/iobuffer/iobuffer.js +445 -266
- package/dist/netcdf-loader.d.ts +1 -1
- package/dist/netcdf-loader.d.ts.map +1 -1
- package/dist/netcdf-loader.js +37 -27
- package/dist/netcdfjs/netcdf-reader.d.ts +2 -2
- package/dist/netcdfjs/netcdf-reader.d.ts.map +1 -1
- package/dist/netcdfjs/netcdf-reader.js +156 -89
- package/dist/netcdfjs/netcdf-types.js +0 -1
- package/dist/netcdfjs/read-data.d.ts +2 -2
- package/dist/netcdfjs/read-data.d.ts.map +1 -1
- package/dist/netcdfjs/read-data.js +39 -19
- package/dist/netcdfjs/read-header.d.ts +2 -2
- package/dist/netcdfjs/read-header.d.ts.map +1 -1
- package/dist/netcdfjs/read-header.js +198 -134
- package/dist/netcdfjs/read-type.d.ts +1 -1
- package/dist/netcdfjs/read-type.d.ts.map +1 -1
- package/dist/netcdfjs/read-type.js +118 -82
- package/package.json +9 -5
- package/src/netcdfjs/netcdf-reader.ts +7 -1
- package/dist/index.js.map +0 -1
- package/dist/iobuffer/iobuffer.js.map +0 -1
- package/dist/netcdf-loader.js.map +0 -1
- package/dist/netcdfjs/LICENSE +0 -24
- package/dist/netcdfjs/netcdf-reader.js.map +0 -1
- package/dist/netcdfjs/netcdf-types.js.map +0 -1
- package/dist/netcdfjs/read-data.js.map +0 -1
- package/dist/netcdfjs/read-header.js.map +0 -1
- package/dist/netcdfjs/read-type.js.map +0 -1
package/dist/dist.dev.js
CHANGED
|
@@ -2,14 +2,19 @@
|
|
|
2
2
|
if (typeof exports === 'object' && typeof module === 'object')
|
|
3
3
|
module.exports = factory();
|
|
4
4
|
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
|
-
else if (typeof exports === 'object') exports['
|
|
6
|
-
else root['
|
|
5
|
+
else if (typeof exports === 'object') exports['loaders'] = factory();
|
|
6
|
+
else root['loaders'] = factory();})(globalThis, function () {
|
|
7
7
|
"use strict";
|
|
8
8
|
var __exports__ = (() => {
|
|
9
|
+
var __create = Object.create;
|
|
9
10
|
var __defProp = Object.defineProperty;
|
|
10
11
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
12
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
12
14
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
15
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
16
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
17
|
+
};
|
|
13
18
|
var __export = (target, all) => {
|
|
14
19
|
for (var name in all)
|
|
15
20
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -22,20 +27,70 @@ var __exports__ = (() => {
|
|
|
22
27
|
}
|
|
23
28
|
return to;
|
|
24
29
|
};
|
|
30
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
31
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
32
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
33
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
34
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
35
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
36
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
37
|
+
mod
|
|
38
|
+
));
|
|
25
39
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
40
|
|
|
27
|
-
//
|
|
28
|
-
var
|
|
29
|
-
|
|
41
|
+
// external-global-plugin:@loaders.gl/core
|
|
42
|
+
var require_core = __commonJS({
|
|
43
|
+
"external-global-plugin:@loaders.gl/core"(exports, module) {
|
|
44
|
+
module.exports = globalThis.loaders;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// bundle.ts
|
|
49
|
+
var bundle_exports = {};
|
|
50
|
+
__export(bundle_exports, {
|
|
30
51
|
NetCDFLoader: () => NetCDFLoader,
|
|
31
52
|
NetCDFReader: () => NetCDFReader
|
|
32
53
|
});
|
|
54
|
+
__reExport(bundle_exports, __toESM(require_core(), 1));
|
|
33
55
|
|
|
34
56
|
// src/iobuffer/iobuffer.ts
|
|
35
57
|
var DEFAULT_BYTE_LENGTH = 1024 * 8;
|
|
36
58
|
var IOBuffer = class {
|
|
59
|
+
/**
|
|
60
|
+
* Reference to the internal ArrayBuffer object.
|
|
61
|
+
*/
|
|
62
|
+
buffer;
|
|
63
|
+
/**
|
|
64
|
+
* Byte length of the internal ArrayBuffer.
|
|
65
|
+
*/
|
|
66
|
+
byteLength;
|
|
67
|
+
/**
|
|
68
|
+
* Byte offset of the internal ArrayBuffer.
|
|
69
|
+
*/
|
|
70
|
+
byteOffset;
|
|
71
|
+
/**
|
|
72
|
+
* Byte length of the internal ArrayBuffer.
|
|
73
|
+
*/
|
|
74
|
+
length;
|
|
75
|
+
/**
|
|
76
|
+
* The current offset of the buffer's pointer.
|
|
77
|
+
*/
|
|
78
|
+
offset;
|
|
79
|
+
lastWrittenByte;
|
|
80
|
+
littleEndian;
|
|
81
|
+
_data;
|
|
82
|
+
_mark;
|
|
83
|
+
_marks;
|
|
37
84
|
textDecoder = new TextDecoder();
|
|
38
85
|
textEncoder = new TextEncoder();
|
|
86
|
+
/**
|
|
87
|
+
* @param data - The data to construct the IOBuffer with.
|
|
88
|
+
* If data is a number, it will be the new buffer's length<br>
|
|
89
|
+
* If data is `undefined`, the buffer will be initialized with a default length of 8Kb<br>
|
|
90
|
+
* If data is an ArrayBuffer, SharedArrayBuffer, an ArrayBufferView (Typed Array), an IOBuffer instance,
|
|
91
|
+
* or a Node.js Buffer, a view will be created over the underlying ArrayBuffer.
|
|
92
|
+
* @param options
|
|
93
|
+
*/
|
|
39
94
|
constructor(data = DEFAULT_BYTE_LENGTH, options = {}) {
|
|
40
95
|
let dataIsGiven = false;
|
|
41
96
|
if (typeof data === "number") {
|
|
@@ -68,43 +123,89 @@ var __exports__ = (() => {
|
|
|
68
123
|
this._mark = 0;
|
|
69
124
|
this._marks = [];
|
|
70
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Checks if the memory allocated to the buffer is sufficient to store more
|
|
128
|
+
* bytes after the offset.
|
|
129
|
+
* @param byteLength - The needed memory in bytes.
|
|
130
|
+
* @returns `true` if there is sufficient space and `false` otherwise.
|
|
131
|
+
*/
|
|
71
132
|
available(byteLength = 1) {
|
|
72
133
|
return this.offset + byteLength <= this.length;
|
|
73
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Check if little-endian mode is used for reading and writing multi-byte
|
|
137
|
+
* values.
|
|
138
|
+
* @returns `true` if little-endian mode is used, `false` otherwise.
|
|
139
|
+
*/
|
|
74
140
|
isLittleEndian() {
|
|
75
141
|
return this.littleEndian;
|
|
76
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Set little-endian mode for reading and writing multi-byte values.
|
|
145
|
+
*/
|
|
77
146
|
setLittleEndian() {
|
|
78
147
|
this.littleEndian = true;
|
|
79
148
|
return this;
|
|
80
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Check if big-endian mode is used for reading and writing multi-byte values.
|
|
152
|
+
* @returns `true` if big-endian mode is used, `false` otherwise.
|
|
153
|
+
*/
|
|
81
154
|
isBigEndian() {
|
|
82
155
|
return !this.littleEndian;
|
|
83
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Switches to big-endian mode for reading and writing multi-byte values.
|
|
159
|
+
*/
|
|
84
160
|
setBigEndian() {
|
|
85
161
|
this.littleEndian = false;
|
|
86
162
|
return this;
|
|
87
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Move the pointer n bytes forward.
|
|
166
|
+
* @param n - Number of bytes to skip.
|
|
167
|
+
*/
|
|
88
168
|
skip(n = 1) {
|
|
89
169
|
this.offset += n;
|
|
90
170
|
return this;
|
|
91
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Move the pointer to the given offset.
|
|
174
|
+
* @param offset
|
|
175
|
+
*/
|
|
92
176
|
seek(offset) {
|
|
93
177
|
this.offset = offset;
|
|
94
178
|
return this;
|
|
95
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Store the current pointer offset.
|
|
182
|
+
* @see {@link IOBuffer#reset}
|
|
183
|
+
*/
|
|
96
184
|
mark() {
|
|
97
185
|
this._mark = this.offset;
|
|
98
186
|
return this;
|
|
99
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Move the pointer back to the last pointer offset set by mark.
|
|
190
|
+
* @see {@link IOBuffer#mark}
|
|
191
|
+
*/
|
|
100
192
|
reset() {
|
|
101
193
|
this.offset = this._mark;
|
|
102
194
|
return this;
|
|
103
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Push the current pointer offset to the mark stack.
|
|
198
|
+
* @see {@link IOBuffer#popMark}
|
|
199
|
+
*/
|
|
104
200
|
pushMark() {
|
|
105
201
|
this._marks.push(this.offset);
|
|
106
202
|
return this;
|
|
107
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* Pop the last pointer offset from the mark stack, and set the current
|
|
206
|
+
* pointer offset to the popped value.
|
|
207
|
+
* @see {@link IOBuffer#pushMark}
|
|
208
|
+
*/
|
|
108
209
|
popMark() {
|
|
109
210
|
const offset = this._marks.pop();
|
|
110
211
|
if (offset === void 0) {
|
|
@@ -113,10 +214,20 @@ var __exports__ = (() => {
|
|
|
113
214
|
this.seek(offset);
|
|
114
215
|
return this;
|
|
115
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Move the pointer offset back to 0.
|
|
219
|
+
*/
|
|
116
220
|
rewind() {
|
|
117
221
|
this.offset = 0;
|
|
118
222
|
return this;
|
|
119
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Make sure the buffer has sufficient memory to write a given byteLength at
|
|
226
|
+
* the current pointer offset.
|
|
227
|
+
* If the buffer's memory is insufficient, this method will create a new
|
|
228
|
+
* buffer (a copy) with a length that is twice (byteLength + current offset).
|
|
229
|
+
* @param byteLength
|
|
230
|
+
*/
|
|
120
231
|
ensureAvailable(byteLength = 1) {
|
|
121
232
|
if (!this.available(byteLength)) {
|
|
122
233
|
const lengthNeeded = this.offset + byteLength;
|
|
@@ -129,18 +240,34 @@ var __exports__ = (() => {
|
|
|
129
240
|
}
|
|
130
241
|
return this;
|
|
131
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* Read a byte and return false if the byte's value is 0, or true otherwise.
|
|
245
|
+
* Moves pointer forward by one byte.
|
|
246
|
+
*/
|
|
132
247
|
readBoolean() {
|
|
133
248
|
return this.readUint8() !== 0;
|
|
134
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* Read a signed 8-bit integer and move pointer forward by 1 byte.
|
|
252
|
+
*/
|
|
135
253
|
readInt8() {
|
|
136
254
|
return this._data.getInt8(this.offset++);
|
|
137
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Read an unsigned 8-bit integer and move pointer forward by 1 byte.
|
|
258
|
+
*/
|
|
138
259
|
readUint8() {
|
|
139
260
|
return this._data.getUint8(this.offset++);
|
|
140
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* Alias for {@link IOBuffer#readUint8}.
|
|
264
|
+
*/
|
|
141
265
|
readByte() {
|
|
142
266
|
return this.readUint8();
|
|
143
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* Read `n` bytes and move pointer forward by `n` bytes.
|
|
270
|
+
*/
|
|
144
271
|
readBytes(n = 1) {
|
|
145
272
|
const bytes = new Uint8Array(n);
|
|
146
273
|
for (let i = 0; i < n; i++) {
|
|
@@ -148,39 +275,63 @@ var __exports__ = (() => {
|
|
|
148
275
|
}
|
|
149
276
|
return bytes;
|
|
150
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* Read a 16-bit signed integer and move pointer forward by 2 bytes.
|
|
280
|
+
*/
|
|
151
281
|
readInt16() {
|
|
152
282
|
const value = this._data.getInt16(this.offset, this.littleEndian);
|
|
153
283
|
this.offset += 2;
|
|
154
284
|
return value;
|
|
155
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Read a 16-bit unsigned integer and move pointer forward by 2 bytes.
|
|
288
|
+
*/
|
|
156
289
|
readUint16() {
|
|
157
290
|
const value = this._data.getUint16(this.offset, this.littleEndian);
|
|
158
291
|
this.offset += 2;
|
|
159
292
|
return value;
|
|
160
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* Read a 32-bit signed integer and move pointer forward by 4 bytes.
|
|
296
|
+
*/
|
|
161
297
|
readInt32() {
|
|
162
298
|
const value = this._data.getInt32(this.offset, this.littleEndian);
|
|
163
299
|
this.offset += 4;
|
|
164
300
|
return value;
|
|
165
301
|
}
|
|
302
|
+
/**
|
|
303
|
+
* Read a 32-bit unsigned integer and move pointer forward by 4 bytes.
|
|
304
|
+
*/
|
|
166
305
|
readUint32() {
|
|
167
306
|
const value = this._data.getUint32(this.offset, this.littleEndian);
|
|
168
307
|
this.offset += 4;
|
|
169
308
|
return value;
|
|
170
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* Read a 32-bit floating number and move pointer forward by 4 bytes.
|
|
312
|
+
*/
|
|
171
313
|
readFloat32() {
|
|
172
314
|
const value = this._data.getFloat32(this.offset, this.littleEndian);
|
|
173
315
|
this.offset += 4;
|
|
174
316
|
return value;
|
|
175
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* Read a 64-bit floating number and move pointer forward by 8 bytes.
|
|
320
|
+
*/
|
|
176
321
|
readFloat64() {
|
|
177
322
|
const value = this._data.getFloat64(this.offset, this.littleEndian);
|
|
178
323
|
this.offset += 8;
|
|
179
324
|
return value;
|
|
180
325
|
}
|
|
326
|
+
/**
|
|
327
|
+
* Read a 1-byte ASCII character and move pointer forward by 1 byte.
|
|
328
|
+
*/
|
|
181
329
|
readChar() {
|
|
182
330
|
return String.fromCharCode(this.readInt8());
|
|
183
331
|
}
|
|
332
|
+
/**
|
|
333
|
+
* Read `n` 1-byte ASCII characters and move pointer forward by `n` bytes.
|
|
334
|
+
*/
|
|
184
335
|
readChars(n = 1) {
|
|
185
336
|
let result = "";
|
|
186
337
|
for (let i = 0; i < n; i++) {
|
|
@@ -188,28 +339,50 @@ var __exports__ = (() => {
|
|
|
188
339
|
}
|
|
189
340
|
return result;
|
|
190
341
|
}
|
|
342
|
+
/**
|
|
343
|
+
* Read the next `n` bytes, return a UTF-8 decoded string and move pointer
|
|
344
|
+
* forward by `n` bytes.
|
|
345
|
+
*/
|
|
191
346
|
readUtf8(n = 1) {
|
|
192
347
|
return this.textDecoder.decode(this.readBytes(n));
|
|
193
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* Write 0xff if the passed value is truthy, 0x00 otherwise and move pointer
|
|
351
|
+
* forward by 1 byte.
|
|
352
|
+
*/
|
|
194
353
|
writeBoolean(value) {
|
|
195
354
|
this.writeUint8(value ? 255 : 0);
|
|
196
355
|
return this;
|
|
197
356
|
}
|
|
357
|
+
/**
|
|
358
|
+
* Write `value` as an 8-bit signed integer and move pointer forward by 1 byte.
|
|
359
|
+
*/
|
|
198
360
|
writeInt8(value) {
|
|
199
361
|
this.ensureAvailable(1);
|
|
200
362
|
this._data.setInt8(this.offset++, value);
|
|
201
363
|
this._updateLastWrittenByte();
|
|
202
364
|
return this;
|
|
203
365
|
}
|
|
366
|
+
/**
|
|
367
|
+
* Write `value` as an 8-bit unsigned integer and move pointer forward by 1
|
|
368
|
+
* byte.
|
|
369
|
+
*/
|
|
204
370
|
writeUint8(value) {
|
|
205
371
|
this.ensureAvailable(1);
|
|
206
372
|
this._data.setUint8(this.offset++, value);
|
|
207
373
|
this._updateLastWrittenByte();
|
|
208
374
|
return this;
|
|
209
375
|
}
|
|
376
|
+
/**
|
|
377
|
+
* An alias for {@link IOBuffer#writeUint8}.
|
|
378
|
+
*/
|
|
210
379
|
writeByte(value) {
|
|
211
380
|
return this.writeUint8(value);
|
|
212
381
|
}
|
|
382
|
+
/**
|
|
383
|
+
* Write all elements of `bytes` as uint8 values and move pointer forward by
|
|
384
|
+
* `bytes.length` bytes.
|
|
385
|
+
*/
|
|
213
386
|
writeBytes(bytes) {
|
|
214
387
|
this.ensureAvailable(bytes.length);
|
|
215
388
|
for (let i = 0; i < bytes.length; i++) {
|
|
@@ -218,6 +391,10 @@ var __exports__ = (() => {
|
|
|
218
391
|
this._updateLastWrittenByte();
|
|
219
392
|
return this;
|
|
220
393
|
}
|
|
394
|
+
/**
|
|
395
|
+
* Write `value` as a 16-bit signed integer and move pointer forward by 2
|
|
396
|
+
* bytes.
|
|
397
|
+
*/
|
|
221
398
|
writeInt16(value) {
|
|
222
399
|
this.ensureAvailable(2);
|
|
223
400
|
this._data.setInt16(this.offset, value, this.littleEndian);
|
|
@@ -225,6 +402,10 @@ var __exports__ = (() => {
|
|
|
225
402
|
this._updateLastWrittenByte();
|
|
226
403
|
return this;
|
|
227
404
|
}
|
|
405
|
+
/**
|
|
406
|
+
* Write `value` as a 16-bit unsigned integer and move pointer forward by 2
|
|
407
|
+
* bytes.
|
|
408
|
+
*/
|
|
228
409
|
writeUint16(value) {
|
|
229
410
|
this.ensureAvailable(2);
|
|
230
411
|
this._data.setUint16(this.offset, value, this.littleEndian);
|
|
@@ -232,6 +413,10 @@ var __exports__ = (() => {
|
|
|
232
413
|
this._updateLastWrittenByte();
|
|
233
414
|
return this;
|
|
234
415
|
}
|
|
416
|
+
/**
|
|
417
|
+
* Write `value` as a 32-bit signed integer and move pointer forward by 4
|
|
418
|
+
* bytes.
|
|
419
|
+
*/
|
|
235
420
|
writeInt32(value) {
|
|
236
421
|
this.ensureAvailable(4);
|
|
237
422
|
this._data.setInt32(this.offset, value, this.littleEndian);
|
|
@@ -239,6 +424,10 @@ var __exports__ = (() => {
|
|
|
239
424
|
this._updateLastWrittenByte();
|
|
240
425
|
return this;
|
|
241
426
|
}
|
|
427
|
+
/**
|
|
428
|
+
* Write `value` as a 32-bit unsigned integer and move pointer forward by 4
|
|
429
|
+
* bytes.
|
|
430
|
+
*/
|
|
242
431
|
writeUint32(value) {
|
|
243
432
|
this.ensureAvailable(4);
|
|
244
433
|
this._data.setUint32(this.offset, value, this.littleEndian);
|
|
@@ -246,6 +435,10 @@ var __exports__ = (() => {
|
|
|
246
435
|
this._updateLastWrittenByte();
|
|
247
436
|
return this;
|
|
248
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
* Write `value` as a 32-bit floating number and move pointer forward by 4
|
|
440
|
+
* bytes.
|
|
441
|
+
*/
|
|
249
442
|
writeFloat32(value) {
|
|
250
443
|
this.ensureAvailable(4);
|
|
251
444
|
this._data.setFloat32(this.offset, value, this.littleEndian);
|
|
@@ -253,6 +446,10 @@ var __exports__ = (() => {
|
|
|
253
446
|
this._updateLastWrittenByte();
|
|
254
447
|
return this;
|
|
255
448
|
}
|
|
449
|
+
/**
|
|
450
|
+
* Write `value` as a 64-bit floating number and move pointer forward by 8
|
|
451
|
+
* bytes.
|
|
452
|
+
*/
|
|
256
453
|
writeFloat64(value) {
|
|
257
454
|
this.ensureAvailable(8);
|
|
258
455
|
this._data.setFloat64(this.offset, value, this.littleEndian);
|
|
@@ -260,22 +457,43 @@ var __exports__ = (() => {
|
|
|
260
457
|
this._updateLastWrittenByte();
|
|
261
458
|
return this;
|
|
262
459
|
}
|
|
460
|
+
/**
|
|
461
|
+
* Write the charCode of `str`'s first character as an 8-bit unsigned integer
|
|
462
|
+
* and move pointer forward by 1 byte.
|
|
463
|
+
*/
|
|
263
464
|
writeChar(str) {
|
|
264
465
|
return this.writeUint8(str.charCodeAt(0));
|
|
265
466
|
}
|
|
467
|
+
/**
|
|
468
|
+
* Write the charCodes of all `str`'s characters as 8-bit unsigned integers
|
|
469
|
+
* and move pointer forward by `str.length` bytes.
|
|
470
|
+
*/
|
|
266
471
|
writeChars(str) {
|
|
267
472
|
for (let i = 0; i < str.length; i++) {
|
|
268
473
|
this.writeUint8(str.charCodeAt(i));
|
|
269
474
|
}
|
|
270
475
|
return this;
|
|
271
476
|
}
|
|
477
|
+
/**
|
|
478
|
+
* UTF-8 encode and write `str` to the current pointer offset and move pointer
|
|
479
|
+
* forward according to the encoded length.
|
|
480
|
+
*/
|
|
272
481
|
writeUtf8(str) {
|
|
273
482
|
const bytes = this.textEncoder.encode(str);
|
|
274
483
|
return this.writeBytes(bytes);
|
|
275
484
|
}
|
|
485
|
+
/**
|
|
486
|
+
* Export a Uint8Array view of the internal buffer.
|
|
487
|
+
* The view starts at the byte offset and its length
|
|
488
|
+
* is calculated to stop at the last written byte or the original length.
|
|
489
|
+
*/
|
|
276
490
|
toArray() {
|
|
277
491
|
return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte);
|
|
278
492
|
}
|
|
493
|
+
/**
|
|
494
|
+
* Update the last written byte offset
|
|
495
|
+
* @private
|
|
496
|
+
*/
|
|
279
497
|
_updateLastWrittenByte() {
|
|
280
498
|
if (this.offset > this.lastWrittenByte) {
|
|
281
499
|
this.lastWrittenByte = this.offset;
|
|
@@ -397,7 +615,9 @@ var __exports__ = (() => {
|
|
|
397
615
|
recordDimension: {
|
|
398
616
|
length: recordDimensionLength,
|
|
399
617
|
id: dimList.recordId,
|
|
618
|
+
// id of the unlimited dimension
|
|
400
619
|
name: dimList.recordName,
|
|
620
|
+
// name of the unlimited dimension
|
|
401
621
|
recordStep: variableList.recordStep
|
|
402
622
|
},
|
|
403
623
|
dimensions: dimList.dimensions,
|
|
@@ -568,6 +788,8 @@ var __exports__ = (() => {
|
|
|
568
788
|
|
|
569
789
|
// src/netcdfjs/netcdf-reader.ts
|
|
570
790
|
var NetCDFReader = class {
|
|
791
|
+
header;
|
|
792
|
+
buffer;
|
|
571
793
|
constructor(data) {
|
|
572
794
|
const buffer = new IOBuffer(data);
|
|
573
795
|
buffer.setBigEndian();
|
|
@@ -582,46 +804,89 @@ var __exports__ = (() => {
|
|
|
582
804
|
this.header = readNetCDFHeader(buffer, version);
|
|
583
805
|
this.buffer = buffer;
|
|
584
806
|
}
|
|
807
|
+
/**
|
|
808
|
+
* @return {string} - Version for the NetCDF format
|
|
809
|
+
*/
|
|
585
810
|
get version() {
|
|
586
811
|
if (this.header.version === 1) {
|
|
587
812
|
return "classic format";
|
|
588
813
|
}
|
|
589
814
|
return "64-bit offset format";
|
|
590
815
|
}
|
|
816
|
+
/**
|
|
817
|
+
* Get metadata for the record dimension
|
|
818
|
+
*/
|
|
591
819
|
get recordDimension() {
|
|
592
820
|
return this.header.recordDimension;
|
|
593
821
|
}
|
|
822
|
+
/**
|
|
823
|
+
* Get list of dimensions (each with `name` and `size`)
|
|
824
|
+
*/
|
|
594
825
|
get dimensions() {
|
|
595
826
|
return this.header.dimensions;
|
|
596
827
|
}
|
|
828
|
+
/**
|
|
829
|
+
* Get list of global attributes with:
|
|
830
|
+
* * `name`: String with the name of the attribute
|
|
831
|
+
* * `type`: String with the type of the attribute
|
|
832
|
+
* * `value`: A number or string with the value of the attribute
|
|
833
|
+
*/
|
|
597
834
|
get attributes() {
|
|
598
835
|
return this.header.attributes;
|
|
599
836
|
}
|
|
837
|
+
/**
|
|
838
|
+
* Get list of variables
|
|
839
|
+
*/
|
|
600
840
|
get variables() {
|
|
601
841
|
return this.header.variables;
|
|
602
842
|
}
|
|
843
|
+
/**
|
|
844
|
+
* Check if an attribute exists
|
|
845
|
+
* @param attributeName - Name of the attribute to find
|
|
846
|
+
* @return
|
|
847
|
+
*/
|
|
603
848
|
attributeExists(attributeName) {
|
|
604
849
|
const attribute = this.attributes.find((val) => val.name === attributeName);
|
|
605
850
|
return attribute !== void 0;
|
|
606
851
|
}
|
|
852
|
+
/**
|
|
853
|
+
* Returns the value of an attribute
|
|
854
|
+
* @param attributeName
|
|
855
|
+
* @return Value of the attributeName or null
|
|
856
|
+
*/
|
|
607
857
|
getAttribute(attributeName) {
|
|
608
858
|
const attribute = this.attributes.find((val) => val.name === attributeName);
|
|
609
859
|
if (attribute)
|
|
610
860
|
return attribute.value;
|
|
611
861
|
return null;
|
|
612
862
|
}
|
|
863
|
+
/**
|
|
864
|
+
* Check if a dataVariable exists
|
|
865
|
+
* @param variableName - Name of the variable to find
|
|
866
|
+
* @return
|
|
867
|
+
*/
|
|
613
868
|
dataVariableExists(variableName) {
|
|
614
869
|
const variable = this.header.variables.find(function(val) {
|
|
615
870
|
return val.name === variableName;
|
|
616
871
|
});
|
|
617
872
|
return variable !== void 0;
|
|
618
873
|
}
|
|
874
|
+
/**
|
|
875
|
+
* Returns the value of a variable as a string
|
|
876
|
+
* @param variableName
|
|
877
|
+
* @return Value of the variable as a string or null
|
|
878
|
+
*/
|
|
619
879
|
getDataVariableAsString(variableName) {
|
|
620
880
|
const variable = this.getDataVariable(variableName);
|
|
621
881
|
if (variable)
|
|
622
882
|
return variable.join("");
|
|
623
883
|
return null;
|
|
624
884
|
}
|
|
885
|
+
/**
|
|
886
|
+
* Retrieves the data for a given variable
|
|
887
|
+
* @param variableName - Name of the variable to search or variable object
|
|
888
|
+
* @return List with the variable values
|
|
889
|
+
*/
|
|
625
890
|
getDataVariable(variableName) {
|
|
626
891
|
let variable;
|
|
627
892
|
if (typeof variableName === "string") {
|
|
@@ -632,7 +897,13 @@ var __exports__ = (() => {
|
|
|
632
897
|
variable = variableName;
|
|
633
898
|
}
|
|
634
899
|
if (variable === void 0) {
|
|
635
|
-
|
|
900
|
+
let errorOutput;
|
|
901
|
+
if (typeof variableName === "string") {
|
|
902
|
+
errorOutput = variableName;
|
|
903
|
+
} else if (typeof variableName === "object") {
|
|
904
|
+
errorOutput = JSON.stringify(variableName);
|
|
905
|
+
}
|
|
906
|
+
throw new Error(`NetCDF: variable not found: ${errorOutput}`);
|
|
636
907
|
}
|
|
637
908
|
this.buffer.seek(variable.offset);
|
|
638
909
|
if (variable.record) {
|
|
@@ -669,14 +940,18 @@ var __exports__ = (() => {
|
|
|
669
940
|
};
|
|
670
941
|
|
|
671
942
|
// src/netcdf-loader.ts
|
|
672
|
-
var VERSION =
|
|
943
|
+
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
673
944
|
var NetCDFWorkerLoader = {
|
|
674
945
|
name: "NetCDF",
|
|
675
946
|
id: "mvt",
|
|
676
947
|
module: "mvt",
|
|
677
948
|
version: VERSION,
|
|
678
949
|
extensions: ["cdf", "nc"],
|
|
679
|
-
mimeTypes: [
|
|
950
|
+
mimeTypes: [
|
|
951
|
+
"application/netcdf",
|
|
952
|
+
"application/x-netcdf"
|
|
953
|
+
// 'application/octet-stream'
|
|
954
|
+
],
|
|
680
955
|
category: "image",
|
|
681
956
|
options: {
|
|
682
957
|
netcdf: {
|
|
@@ -702,7 +977,7 @@ var __exports__ = (() => {
|
|
|
702
977
|
data: variables
|
|
703
978
|
};
|
|
704
979
|
}
|
|
705
|
-
return __toCommonJS(
|
|
980
|
+
return __toCommonJS(bundle_exports);
|
|
706
981
|
})();
|
|
707
982
|
return __exports__;
|
|
708
983
|
});
|
package/dist/dist.min.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
+
if (typeof exports === 'object' && typeof module === 'object')
|
|
3
|
+
module.exports = factory();
|
|
4
|
+
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
|
+
else if (typeof exports === 'object') exports['loaders'] = factory();
|
|
6
|
+
else root['loaders'] = factory();})(globalThis, function () {
|
|
7
|
+
"use strict";var __exports__=(()=>{var H=Object.create;var g=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var Y=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var M=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),G=(e,t)=>{for(var r in t)g(e,r,{get:t[r],enumerable:!0})},w=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of $(t))!z.call(e,n)&&n!==r&&g(e,n,{get:()=>t[n],enumerable:!(i=V(t,n))||i.enumerable});return e},E=(e,t,r)=>(w(e,t,"default"),r&&w(r,t,"default")),J=(e,t,r)=>(r=e!=null?H(Y(e)):{},w(t||!e||!e.__esModule?g(r,"default",{value:e,enumerable:!0}):r,e)),j=e=>w(g({},"__esModule",{value:!0}),e);var F=M((st,T)=>{T.exports=globalThis.loaders});var p={};G(p,{NetCDFLoader:()=>R,NetCDFReader:()=>u});E(p,J(F(),1));var f=class{buffer;byteLength;byteOffset;length;offset;lastWrittenByte;littleEndian;_data;_mark;_marks;textDecoder=new TextDecoder;textEncoder=new TextEncoder;constructor(t=8192,r={}){let i=!1;typeof t=="number"?t=new ArrayBuffer(t):(i=!0,this.lastWrittenByte=t.byteLength);let n=r.offset?r.offset>>>0:0,a=t.byteLength-n,o=n;(ArrayBuffer.isView(t)||t instanceof f)&&(t.byteLength!==t.buffer.byteLength&&(o=t.byteOffset+n),t=t.buffer),i?this.lastWrittenByte=a:this.lastWrittenByte=0,this.buffer=t,this.length=a,this.byteLength=a,this.byteOffset=o,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,o,a),this._mark=0,this._marks=[]}available(t=1){return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(t=1){return this.offset+=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){let t=this._marks.pop();if(t===void 0)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(t=1){if(!this.available(t)){let i=(this.offset+t)*2,n=new Uint8Array(i);n.set(new Uint8Array(this.buffer)),this.buffer=n.buffer,this.length=this.byteLength=i,this._data=new DataView(this.buffer)}return this}readBoolean(){return this.readUint8()!==0}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(t=1){let r=new Uint8Array(t);for(let i=0;i<t;i++)r[i]=this.readByte();return r}readInt16(){let t=this._data.getInt16(this.offset,this.littleEndian);return this.offset+=2,t}readUint16(){let t=this._data.getUint16(this.offset,this.littleEndian);return this.offset+=2,t}readInt32(){let t=this._data.getInt32(this.offset,this.littleEndian);return this.offset+=4,t}readUint32(){let t=this._data.getUint32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat32(){let t=this._data.getFloat32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat64(){let t=this._data.getFloat64(this.offset,this.littleEndian);return this.offset+=8,t}readChar(){return String.fromCharCode(this.readInt8())}readChars(t=1){let r="";for(let i=0;i<t;i++)r+=this.readChar();return r}readUtf8(t=1){return this.textDecoder.decode(this.readBytes(t))}writeBoolean(t){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(let r=0;r<t.length;r++)this._data.setUint8(this.offset++,t[r]);return this._updateLastWrittenByte(),this}writeInt16(t){return this.ensureAvailable(2),this._data.setInt16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeUint16(t){return this.ensureAvailable(2),this._data.setUint16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeInt32(t){return this.ensureAvailable(4),this._data.setInt32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeUint32(t){return this.ensureAvailable(4),this._data.setUint32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat32(t){return this.ensureAvailable(4),this._data.setFloat32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat64(t){return this.ensureAvailable(8),this._data.setFloat64(this.offset,t,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeChar(t){return this.writeUint8(t.charCodeAt(0))}writeChars(t){for(let r=0;r<t.length;r++)this.writeUint8(t.charCodeAt(r));return this}writeUtf8(t){let r=this.textEncoder.encode(t);return this.writeBytes(r)}toArray(){return new Uint8Array(this.buffer,this.byteOffset,this.lastWrittenByte)}_updateLastWrittenByte(){this.offset>this.lastWrittenByte&&(this.lastWrittenByte=this.offset)}};var s={BYTE:1,CHAR:2,SHORT:3,INT:4,FLOAT:5,DOUBLE:6};function c(e,t,r){switch(t){case s.BYTE:return e.readBytes(r);case s.CHAR:return P(e.readChars(r));case s.SHORT:return b(r,e.readInt16.bind(e));case s.INT:return b(r,e.readInt32.bind(e));case s.FLOAT:return b(r,e.readFloat32.bind(e));case s.DOUBLE:return b(r,e.readFloat64.bind(e));default:throw new Error(`NetCDF: non valid type ${t}`)}}function B(e){switch(Number(e)){case s.BYTE:return"byte";case s.CHAR:return"char";case s.SHORT:return"short";case s.INT:return"int";case s.FLOAT:return"float";case s.DOUBLE:return"double";default:return"undefined"}}function D(e){switch(Number(e)){case s.BYTE:return 1;case s.CHAR:return 1;case s.SHORT:return 2;case s.INT:return 4;case s.FLOAT:return 4;case s.DOUBLE:return 8;default:return-1}}function N(e){switch(String(e)){case"byte":return s.BYTE;case"char":return s.CHAR;case"short":return s.SHORT;case"int":return s.INT;case"float":return s.FLOAT;case"double":return s.DOUBLE;default:return-1}}function b(e,t){if(e!==1){let r=new Array(e);for(let i=0;i<e;i++)r[i]=t();return r}return t()}function P(e){return e.charCodeAt(e.length-1)===0?e.substring(0,e.length-1):e}var l=0,Z=10,q=11,K=12,Q=0;function I(e,t){let r=e.readUint32(),i=X(e),n=x(e),a=tt(e,i.recordId,t);return{version:t,recordDimension:{length:r,id:i.recordId,name:i.recordName,recordStep:a.recordStep},dimensions:i.dimensions,variables:a.variables,attributes:n}}function X(e){let t=e.readUint32();if(t===l){if(e.readUint32()!==l)throw new Error("NetCDF: wrong empty tag for list of dimensions");return{recordId:0,recordName:"",dimensions:[]}}if(t!==Z)throw new Error("NetCDF: wrong tag for list of dimensions");let r=e.readUint32(),i=new Array(r),n,a;for(let o=0;o<r;o++){let h=v(e),d=e.readUint32();d===Q&&(n=o,a=h),i[o]={name:h,size:d}}return{dimensions:i,recordId:n,recordName:a}}function x(e){let t=e.readUint32();if(t===l){if(e.readUint32()!==l)throw new Error("NetCDF: wrong empty tag for list of attributes");return[]}if(t!==K)throw new Error("NetCDF: wrong tag for list of attributes");let r=e.readUint32(),i=new Array(r);for(let n=0;n<r;n++){let a=v(e),o=e.readUint32();if(o<1||o>6)throw new Error(`NetCDF: non valid type ${o}`);let h=e.readUint32(),d=c(e,o,h);O(e),i[n]={name:a,type:B(o),value:d}}return i}function tt(e,t,r){let i=e.readUint32(),n=0;if(i===l){if(e.readUint32()!==l)throw new Error("NetCDF: wrong empty tag for list of variables");return{recordStep:n,variables:[]}}if(i!==q)throw new Error("NetCDF: wrong tag for list of variables");let a=e.readUint32(),o=new Array(a);for(let h=0;h<a;h++){let d=v(e),y=e.readUint32(),U=new Array(y);for(let L=0;L<y;L++)U[L]=e.readUint32();let W=x(e),m=e.readUint32();if(m<1&&m>6)throw new Error(`NetCDF: non valid type ${m}`);let C=e.readUint32(),A=e.readUint32();if(r===2){if(A>0)throw new Error("NetCDF: offsets larger than 4GB not supported");A=e.readUint32()}let _=!1;typeof t<"u"&&U[0]===t&&(n+=C,_=!0),o[h]={name:d,dimensions:U,attributes:W,type:B(m),size:C,offset:A,record:_}}return{variables:o,recordStep:n}}function v(e){let t=e.readUint32(),r=e.readChars(t);return O(e),r}function O(e){e.offset%4!==0&&e.skip(4-e.offset%4)}function S(e,t){let r=N(t.type),i=t.size/D(r),n=new Array(i);for(let a=0;a<i;a++)n[a]=c(e,r,1);return n}function k(e,t,r){let i=N(t.type),n=t.size?t.size/D(i):1,a=r.length,o=new Array(a),h=r.recordStep;for(let d=0;d<a;d++){let y=e.offset;o[d]=c(e,i,n),e.seek(y+h)}return o}var u=class{header;buffer;constructor(t){let r=new f(t);r.setBigEndian();let i=r.readChars(3);if(i!=="CDF")throw new Error(`NetCDF: file should start with 'CDF', found ${i}`);let n=r.readByte();if(n>2)throw new Error(`NetCDF: unsupported version ${n}`);this.header=I(r,n),this.buffer=r}get version(){return this.header.version===1?"classic format":"64-bit offset format"}get recordDimension(){return this.header.recordDimension}get dimensions(){return this.header.dimensions}get attributes(){return this.header.attributes}get variables(){return this.header.variables}attributeExists(t){return this.attributes.find(i=>i.name===t)!==void 0}getAttribute(t){let r=this.attributes.find(i=>i.name===t);return r?r.value:null}dataVariableExists(t){return this.header.variables.find(function(i){return i.name===t})!==void 0}getDataVariableAsString(t){let r=this.getDataVariable(t);return r?r.join(""):null}getDataVariable(t){let r;if(typeof t=="string"?r=this.header.variables.find(function(i){return i.name===t}):r=t,r===void 0){let i;throw typeof t=="string"?i=t:typeof t=="object"&&(i=JSON.stringify(t)),new Error(`NetCDF: variable not found: ${i}`)}return this.buffer.seek(r.offset),r.record?k(this.buffer,r,this.header.recordDimension):S(this.buffer,r)}toString(){let t=[];t.push("DIMENSIONS");for(let i of this.dimensions)t.push(` ${i.name.padEnd(30)} = size: ${i.size}`);t.push(""),t.push("GLOBAL ATTRIBUTES");for(let i of this.attributes)t.push(` ${i.name.padEnd(30)} = ${i.value}`);let r=JSON.parse(JSON.stringify(this.variables));t.push(""),t.push("VARIABLES:");for(let i of r){i.value=this.getDataVariable(i);let n=JSON.stringify(i.value);n.length>50&&(n=n.substring(0,50)),isNaN(i.value.length)||(n+=` (length: ${i.value.length})`),t.push(` ${i.name.padEnd(30)} = ${n}`)}return t.join(`
|
|
8
|
+
`)}};var et="4.2.0-alpha.5",rt={name:"NetCDF",id:"mvt",module:"mvt",version:et,extensions:["cdf","nc"],mimeTypes:["application/netcdf","application/x-netcdf"],category:"image",options:{netcdf:{loadVariables:!1}}},R={...rt,parse:async(e,t)=>it(e,t),binary:!0};function it(e,t){let r=new u(e),i={};if(t?.netcdf?.loadData)for(let n of r.variables)i[n.name]=r.getDataVariable(n);return{loaderData:r.header,data:i}}return j(p);})();
|
|
9
|
+
return __exports__;
|
|
10
|
+
});
|