@loaders.gl/netcdf 3.1.0-beta.5 → 3.1.2

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