@loaders.gl/netcdf 3.1.0-alpha.4 → 3.1.0-beta.3

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 (46) hide show
  1. package/dist/es5/index.js +2 -2
  2. package/dist/es5/iobuffer/iobuffer.js +259 -318
  3. package/dist/es5/iobuffer/iobuffer.js.map +1 -1
  4. package/dist/es5/netcdf-loader.js +11 -62
  5. package/dist/es5/netcdf-loader.js.map +1 -1
  6. package/dist/es5/netcdfjs/netcdf-reader.js +97 -155
  7. package/dist/es5/netcdfjs/netcdf-reader.js.map +1 -1
  8. package/dist/es5/netcdfjs/read-data.js +12 -12
  9. package/dist/es5/netcdfjs/read-data.js.map +1 -1
  10. package/dist/es5/netcdfjs/read-header.js +58 -58
  11. package/dist/es5/netcdfjs/read-header.js.map +1 -1
  12. package/dist/es5/netcdfjs/read-type.js +3 -3
  13. package/dist/es5/netcdfjs/read-type.js.map +1 -1
  14. package/dist/esm/netcdf-loader.js +1 -1
  15. package/dist/esm/netcdf-loader.js.map +1 -1
  16. package/dist/esm/netcdfjs/netcdf-reader.js +7 -7
  17. package/dist/esm/netcdfjs/netcdf-reader.js.map +1 -1
  18. package/dist/esm/netcdfjs/read-header.js +2 -2
  19. package/dist/esm/netcdfjs/read-header.js.map +1 -1
  20. package/dist/esm/netcdfjs/read-type.js +1 -1
  21. package/dist/esm/netcdfjs/read-type.js.map +1 -1
  22. package/dist/index.d.ts +3 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +7 -0
  25. package/dist/iobuffer/iobuffer.d.ts +254 -0
  26. package/dist/iobuffer/iobuffer.d.ts.map +1 -0
  27. package/dist/iobuffer/iobuffer.js +427 -0
  28. package/dist/netcdf-loader.d.ts +52 -0
  29. package/dist/netcdf-loader.d.ts.map +1 -0
  30. package/dist/netcdf-loader.js +52 -0
  31. package/dist/netcdfjs/netcdf-reader.d.ts +68 -0
  32. package/dist/netcdfjs/netcdf-reader.d.ts.map +1 -0
  33. package/dist/netcdfjs/netcdf-reader.js +165 -0
  34. package/dist/netcdfjs/netcdf-types.d.ts +70 -0
  35. package/dist/netcdfjs/netcdf-types.d.ts.map +1 -0
  36. package/dist/netcdfjs/netcdf-types.js +2 -0
  37. package/dist/netcdfjs/read-data.d.ts +18 -0
  38. package/dist/netcdfjs/read-data.d.ts.map +1 -0
  39. package/dist/netcdfjs/read-data.js +49 -0
  40. package/dist/netcdfjs/read-header.d.ts +16 -0
  41. package/dist/netcdfjs/read-header.d.ts.map +1 -0
  42. package/dist/netcdfjs/read-header.js +230 -0
  43. package/dist/netcdfjs/read-type.d.ts +36 -0
  44. package/dist/netcdfjs/read-type.d.ts.map +1 -0
  45. package/dist/netcdfjs/read-type.js +140 -0
  46. package/package.json +7 -8
package/dist/es5/index.js CHANGED
@@ -5,13 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  Object.defineProperty(exports, "NetCDFReader", {
7
7
  enumerable: true,
8
- get: function get() {
8
+ get: function () {
9
9
  return _netcdfReader.NetCDFReader;
10
10
  }
11
11
  });
12
12
  Object.defineProperty(exports, "NetCDFLoader", {
13
13
  enumerable: true,
14
- get: function get() {
14
+ get: function () {
15
15
  return _netcdfLoader.NetCDFLoader;
16
16
  }
17
17
  });
@@ -7,19 +7,12 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.IOBuffer = void 0;
9
9
 
10
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
-
12
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
-
14
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
11
 
16
- var DEFAULT_BYTE_LENGTH = 1024 * 8;
12
+ const DEFAULT_BYTE_LENGTH = 1024 * 8;
17
13
 
18
- var IOBuffer = function () {
19
- function IOBuffer() {
20
- var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_BYTE_LENGTH;
21
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
22
- (0, _classCallCheck2.default)(this, IOBuffer);
14
+ class IOBuffer {
15
+ constructor(data = DEFAULT_BYTE_LENGTH, options = {}) {
23
16
  (0, _defineProperty2.default)(this, "buffer", void 0);
24
17
  (0, _defineProperty2.default)(this, "byteLength", void 0);
25
18
  (0, _defineProperty2.default)(this, "byteOffset", void 0);
@@ -32,7 +25,7 @@ var IOBuffer = function () {
32
25
  (0, _defineProperty2.default)(this, "_marks", void 0);
33
26
  (0, _defineProperty2.default)(this, "textDecoder", new TextDecoder());
34
27
  (0, _defineProperty2.default)(this, "textEncoder", new TextEncoder());
35
- var dataIsGiven = false;
28
+ let dataIsGiven = false;
36
29
 
37
30
  if (typeof data === 'number') {
38
31
  data = new ArrayBuffer(data);
@@ -41,9 +34,9 @@ var IOBuffer = function () {
41
34
  this.lastWrittenByte = data.byteLength;
42
35
  }
43
36
 
44
- var offset = options.offset ? options.offset >>> 0 : 0;
45
- var byteLength = data.byteLength - offset;
46
- var dvOffset = offset;
37
+ const offset = options.offset ? options.offset >>> 0 : 0;
38
+ const byteLength = data.byteLength - offset;
39
+ let dvOffset = offset;
47
40
 
48
41
  if (ArrayBuffer.isView(data) || data instanceof IOBuffer) {
49
42
  if (data.byteLength !== data.buffer.byteLength) {
@@ -70,363 +63,311 @@ var IOBuffer = function () {
70
63
  this._marks = [];
71
64
  }
72
65
 
73
- (0, _createClass2.default)(IOBuffer, [{
74
- key: "available",
75
- value: function available() {
76
- var byteLength = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
77
- return this.offset + byteLength <= this.length;
78
- }
79
- }, {
80
- key: "isLittleEndian",
81
- value: function isLittleEndian() {
82
- return this.littleEndian;
83
- }
84
- }, {
85
- key: "setLittleEndian",
86
- value: function setLittleEndian() {
87
- this.littleEndian = true;
88
- return this;
89
- }
90
- }, {
91
- key: "isBigEndian",
92
- value: function isBigEndian() {
93
- return !this.littleEndian;
94
- }
95
- }, {
96
- key: "setBigEndian",
97
- value: function setBigEndian() {
98
- this.littleEndian = false;
99
- return this;
100
- }
101
- }, {
102
- key: "skip",
103
- value: function skip() {
104
- var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
105
- this.offset += n;
106
- return this;
107
- }
108
- }, {
109
- key: "seek",
110
- value: function seek(offset) {
111
- this.offset = offset;
112
- return this;
113
- }
114
- }, {
115
- key: "mark",
116
- value: function mark() {
117
- this._mark = this.offset;
118
- return this;
119
- }
120
- }, {
121
- key: "reset",
122
- value: function reset() {
123
- this.offset = this._mark;
124
- return this;
125
- }
126
- }, {
127
- key: "pushMark",
128
- value: function pushMark() {
129
- this._marks.push(this.offset);
66
+ available(byteLength = 1) {
67
+ return this.offset + byteLength <= this.length;
68
+ }
130
69
 
131
- return this;
132
- }
133
- }, {
134
- key: "popMark",
135
- value: function popMark() {
136
- var offset = this._marks.pop();
70
+ isLittleEndian() {
71
+ return this.littleEndian;
72
+ }
137
73
 
138
- if (offset === undefined) {
139
- throw new Error('Mark stack empty');
140
- }
74
+ setLittleEndian() {
75
+ this.littleEndian = true;
76
+ return this;
77
+ }
141
78
 
142
- this.seek(offset);
143
- return this;
144
- }
145
- }, {
146
- key: "rewind",
147
- value: function rewind() {
148
- this.offset = 0;
149
- return this;
150
- }
151
- }, {
152
- key: "ensureAvailable",
153
- value: function ensureAvailable() {
154
- var byteLength = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
155
-
156
- if (!this.available(byteLength)) {
157
- var lengthNeeded = this.offset + byteLength;
158
- var newLength = lengthNeeded * 2;
159
- var newArray = new Uint8Array(newLength);
160
- newArray.set(new Uint8Array(this.buffer));
161
- this.buffer = newArray.buffer;
162
- this.length = this.byteLength = newLength;
163
- this._data = new DataView(this.buffer);
164
- }
79
+ isBigEndian() {
80
+ return !this.littleEndian;
81
+ }
165
82
 
166
- return this;
167
- }
168
- }, {
169
- key: "readBoolean",
170
- value: function readBoolean() {
171
- return this.readUint8() !== 0;
172
- }
173
- }, {
174
- key: "readInt8",
175
- value: function readInt8() {
176
- return this._data.getInt8(this.offset++);
177
- }
178
- }, {
179
- key: "readUint8",
180
- value: function readUint8() {
181
- return this._data.getUint8(this.offset++);
182
- }
183
- }, {
184
- key: "readByte",
185
- value: function readByte() {
186
- return this.readUint8();
187
- }
188
- }, {
189
- key: "readBytes",
190
- value: function readBytes() {
191
- var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
192
- var bytes = new Uint8Array(n);
193
-
194
- for (var i = 0; i < n; i++) {
195
- bytes[i] = this.readByte();
196
- }
83
+ setBigEndian() {
84
+ this.littleEndian = false;
85
+ return this;
86
+ }
197
87
 
198
- return bytes;
199
- }
200
- }, {
201
- key: "readInt16",
202
- value: function readInt16() {
203
- var value = this._data.getInt16(this.offset, this.littleEndian);
88
+ skip(n = 1) {
89
+ this.offset += n;
90
+ return this;
91
+ }
204
92
 
205
- this.offset += 2;
206
- return value;
207
- }
208
- }, {
209
- key: "readUint16",
210
- value: function readUint16() {
211
- var value = this._data.getUint16(this.offset, this.littleEndian);
93
+ seek(offset) {
94
+ this.offset = offset;
95
+ return this;
96
+ }
212
97
 
213
- this.offset += 2;
214
- return value;
215
- }
216
- }, {
217
- key: "readInt32",
218
- value: function readInt32() {
219
- var value = this._data.getInt32(this.offset, this.littleEndian);
98
+ mark() {
99
+ this._mark = this.offset;
100
+ return this;
101
+ }
220
102
 
221
- this.offset += 4;
222
- return value;
223
- }
224
- }, {
225
- key: "readUint32",
226
- value: function readUint32() {
227
- var value = this._data.getUint32(this.offset, this.littleEndian);
103
+ reset() {
104
+ this.offset = this._mark;
105
+ return this;
106
+ }
228
107
 
229
- this.offset += 4;
230
- return value;
231
- }
232
- }, {
233
- key: "readFloat32",
234
- value: function readFloat32() {
235
- var value = this._data.getFloat32(this.offset, this.littleEndian);
108
+ pushMark() {
109
+ this._marks.push(this.offset);
236
110
 
237
- this.offset += 4;
238
- return value;
239
- }
240
- }, {
241
- key: "readFloat64",
242
- value: function readFloat64() {
243
- var value = this._data.getFloat64(this.offset, this.littleEndian);
111
+ return this;
112
+ }
244
113
 
245
- this.offset += 8;
246
- return value;
247
- }
248
- }, {
249
- key: "readChar",
250
- value: function readChar() {
251
- return String.fromCharCode(this.readInt8());
252
- }
253
- }, {
254
- key: "readChars",
255
- value: function readChars() {
256
- var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
257
- var result = '';
258
-
259
- for (var i = 0; i < n; i++) {
260
- result += this.readChar();
261
- }
114
+ popMark() {
115
+ const offset = this._marks.pop();
262
116
 
263
- return result;
264
- }
265
- }, {
266
- key: "readUtf8",
267
- value: function readUtf8() {
268
- var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
269
- return this.textDecoder.decode(this.readBytes(n));
117
+ if (offset === undefined) {
118
+ throw new Error('Mark stack empty');
270
119
  }
271
- }, {
272
- key: "writeBoolean",
273
- value: function writeBoolean(value) {
274
- this.writeUint8(value ? 0xff : 0x00);
275
- return this;
276
- }
277
- }, {
278
- key: "writeInt8",
279
- value: function writeInt8(value) {
280
- this.ensureAvailable(1);
281
120
 
282
- this._data.setInt8(this.offset++, value);
121
+ this.seek(offset);
122
+ return this;
123
+ }
283
124
 
284
- this._updateLastWrittenByte();
125
+ rewind() {
126
+ this.offset = 0;
127
+ return this;
128
+ }
285
129
 
286
- return this;
130
+ ensureAvailable(byteLength = 1) {
131
+ if (!this.available(byteLength)) {
132
+ const lengthNeeded = this.offset + byteLength;
133
+ const newLength = lengthNeeded * 2;
134
+ const newArray = new Uint8Array(newLength);
135
+ newArray.set(new Uint8Array(this.buffer));
136
+ this.buffer = newArray.buffer;
137
+ this.length = this.byteLength = newLength;
138
+ this._data = new DataView(this.buffer);
287
139
  }
288
- }, {
289
- key: "writeUint8",
290
- value: function writeUint8(value) {
291
- this.ensureAvailable(1);
292
140
 
293
- this._data.setUint8(this.offset++, value);
141
+ return this;
142
+ }
294
143
 
295
- this._updateLastWrittenByte();
144
+ readBoolean() {
145
+ return this.readUint8() !== 0;
146
+ }
296
147
 
297
- return this;
298
- }
299
- }, {
300
- key: "writeByte",
301
- value: function writeByte(value) {
302
- return this.writeUint8(value);
303
- }
304
- }, {
305
- key: "writeBytes",
306
- value: function writeBytes(bytes) {
307
- this.ensureAvailable(bytes.length);
148
+ readInt8() {
149
+ return this._data.getInt8(this.offset++);
150
+ }
308
151
 
309
- for (var i = 0; i < bytes.length; i++) {
310
- this._data.setUint8(this.offset++, bytes[i]);
311
- }
152
+ readUint8() {
153
+ return this._data.getUint8(this.offset++);
154
+ }
155
+
156
+ readByte() {
157
+ return this.readUint8();
158
+ }
312
159
 
313
- this._updateLastWrittenByte();
160
+ readBytes(n = 1) {
161
+ const bytes = new Uint8Array(n);
314
162
 
315
- return this;
163
+ for (let i = 0; i < n; i++) {
164
+ bytes[i] = this.readByte();
316
165
  }
317
- }, {
318
- key: "writeInt16",
319
- value: function writeInt16(value) {
320
- this.ensureAvailable(2);
321
166
 
322
- this._data.setInt16(this.offset, value, this.littleEndian);
167
+ return bytes;
168
+ }
323
169
 
324
- this.offset += 2;
170
+ readInt16() {
171
+ const value = this._data.getInt16(this.offset, this.littleEndian);
325
172
 
326
- this._updateLastWrittenByte();
173
+ this.offset += 2;
174
+ return value;
175
+ }
327
176
 
328
- return this;
329
- }
330
- }, {
331
- key: "writeUint16",
332
- value: function writeUint16(value) {
333
- this.ensureAvailable(2);
177
+ readUint16() {
178
+ const value = this._data.getUint16(this.offset, this.littleEndian);
334
179
 
335
- this._data.setUint16(this.offset, value, this.littleEndian);
180
+ this.offset += 2;
181
+ return value;
182
+ }
336
183
 
337
- this.offset += 2;
184
+ readInt32() {
185
+ const value = this._data.getInt32(this.offset, this.littleEndian);
338
186
 
339
- this._updateLastWrittenByte();
187
+ this.offset += 4;
188
+ return value;
189
+ }
340
190
 
341
- return this;
342
- }
343
- }, {
344
- key: "writeInt32",
345
- value: function writeInt32(value) {
346
- this.ensureAvailable(4);
191
+ readUint32() {
192
+ const value = this._data.getUint32(this.offset, this.littleEndian);
347
193
 
348
- this._data.setInt32(this.offset, value, this.littleEndian);
194
+ this.offset += 4;
195
+ return value;
196
+ }
349
197
 
350
- this.offset += 4;
198
+ readFloat32() {
199
+ const value = this._data.getFloat32(this.offset, this.littleEndian);
351
200
 
352
- this._updateLastWrittenByte();
201
+ this.offset += 4;
202
+ return value;
203
+ }
353
204
 
354
- return this;
355
- }
356
- }, {
357
- key: "writeUint32",
358
- value: function writeUint32(value) {
359
- this.ensureAvailable(4);
205
+ readFloat64() {
206
+ const value = this._data.getFloat64(this.offset, this.littleEndian);
360
207
 
361
- this._data.setUint32(this.offset, value, this.littleEndian);
208
+ this.offset += 8;
209
+ return value;
210
+ }
362
211
 
363
- this.offset += 4;
212
+ readChar() {
213
+ return String.fromCharCode(this.readInt8());
214
+ }
364
215
 
365
- this._updateLastWrittenByte();
216
+ readChars(n = 1) {
217
+ let result = '';
366
218
 
367
- return this;
219
+ for (let i = 0; i < n; i++) {
220
+ result += this.readChar();
368
221
  }
369
- }, {
370
- key: "writeFloat32",
371
- value: function writeFloat32(value) {
372
- this.ensureAvailable(4);
373
222
 
374
- this._data.setFloat32(this.offset, value, this.littleEndian);
223
+ return result;
224
+ }
375
225
 
376
- this.offset += 4;
226
+ readUtf8(n = 1) {
227
+ return this.textDecoder.decode(this.readBytes(n));
228
+ }
377
229
 
378
- this._updateLastWrittenByte();
230
+ writeBoolean(value) {
231
+ this.writeUint8(value ? 0xff : 0x00);
232
+ return this;
233
+ }
379
234
 
380
- return this;
381
- }
382
- }, {
383
- key: "writeFloat64",
384
- value: function writeFloat64(value) {
385
- this.ensureAvailable(8);
235
+ writeInt8(value) {
236
+ this.ensureAvailable(1);
386
237
 
387
- this._data.setFloat64(this.offset, value, this.littleEndian);
238
+ this._data.setInt8(this.offset++, value);
388
239
 
389
- this.offset += 8;
240
+ this._updateLastWrittenByte();
390
241
 
391
- this._updateLastWrittenByte();
242
+ return this;
243
+ }
392
244
 
393
- return this;
394
- }
395
- }, {
396
- key: "writeChar",
397
- value: function writeChar(str) {
398
- return this.writeUint8(str.charCodeAt(0));
399
- }
400
- }, {
401
- key: "writeChars",
402
- value: function writeChars(str) {
403
- for (var i = 0; i < str.length; i++) {
404
- this.writeUint8(str.charCodeAt(i));
405
- }
245
+ writeUint8(value) {
246
+ this.ensureAvailable(1);
406
247
 
407
- return this;
408
- }
409
- }, {
410
- key: "writeUtf8",
411
- value: function writeUtf8(str) {
412
- var bytes = this.textEncoder.encode(str);
413
- return this.writeBytes(bytes);
248
+ this._data.setUint8(this.offset++, value);
249
+
250
+ this._updateLastWrittenByte();
251
+
252
+ return this;
253
+ }
254
+
255
+ writeByte(value) {
256
+ return this.writeUint8(value);
257
+ }
258
+
259
+ writeBytes(bytes) {
260
+ this.ensureAvailable(bytes.length);
261
+
262
+ for (let i = 0; i < bytes.length; i++) {
263
+ this._data.setUint8(this.offset++, bytes[i]);
414
264
  }
415
- }, {
416
- key: "toArray",
417
- value: function toArray() {
418
- return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte);
265
+
266
+ this._updateLastWrittenByte();
267
+
268
+ return this;
269
+ }
270
+
271
+ writeInt16(value) {
272
+ this.ensureAvailable(2);
273
+
274
+ this._data.setInt16(this.offset, value, this.littleEndian);
275
+
276
+ this.offset += 2;
277
+
278
+ this._updateLastWrittenByte();
279
+
280
+ return this;
281
+ }
282
+
283
+ writeUint16(value) {
284
+ this.ensureAvailable(2);
285
+
286
+ this._data.setUint16(this.offset, value, this.littleEndian);
287
+
288
+ this.offset += 2;
289
+
290
+ this._updateLastWrittenByte();
291
+
292
+ return this;
293
+ }
294
+
295
+ writeInt32(value) {
296
+ this.ensureAvailable(4);
297
+
298
+ this._data.setInt32(this.offset, value, this.littleEndian);
299
+
300
+ this.offset += 4;
301
+
302
+ this._updateLastWrittenByte();
303
+
304
+ return this;
305
+ }
306
+
307
+ writeUint32(value) {
308
+ this.ensureAvailable(4);
309
+
310
+ this._data.setUint32(this.offset, value, this.littleEndian);
311
+
312
+ this.offset += 4;
313
+
314
+ this._updateLastWrittenByte();
315
+
316
+ return this;
317
+ }
318
+
319
+ writeFloat32(value) {
320
+ this.ensureAvailable(4);
321
+
322
+ this._data.setFloat32(this.offset, value, this.littleEndian);
323
+
324
+ this.offset += 4;
325
+
326
+ this._updateLastWrittenByte();
327
+
328
+ return this;
329
+ }
330
+
331
+ writeFloat64(value) {
332
+ this.ensureAvailable(8);
333
+
334
+ this._data.setFloat64(this.offset, value, this.littleEndian);
335
+
336
+ this.offset += 8;
337
+
338
+ this._updateLastWrittenByte();
339
+
340
+ return this;
341
+ }
342
+
343
+ writeChar(str) {
344
+ return this.writeUint8(str.charCodeAt(0));
345
+ }
346
+
347
+ writeChars(str) {
348
+ for (let i = 0; i < str.length; i++) {
349
+ this.writeUint8(str.charCodeAt(i));
419
350
  }
420
- }, {
421
- key: "_updateLastWrittenByte",
422
- value: function _updateLastWrittenByte() {
423
- if (this.offset > this.lastWrittenByte) {
424
- this.lastWrittenByte = this.offset;
425
- }
351
+
352
+ return this;
353
+ }
354
+
355
+ writeUtf8(str) {
356
+ const bytes = this.textEncoder.encode(str);
357
+ return this.writeBytes(bytes);
358
+ }
359
+
360
+ toArray() {
361
+ return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte);
362
+ }
363
+
364
+ _updateLastWrittenByte() {
365
+ if (this.offset > this.lastWrittenByte) {
366
+ this.lastWrittenByte = this.offset;
426
367
  }
427
- }]);
428
- return IOBuffer;
429
- }();
368
+ }
369
+
370
+ }
430
371
 
431
372
  exports.IOBuffer = IOBuffer;
432
373
  //# sourceMappingURL=iobuffer.js.map