@loaders.gl/wkt 4.0.0-alpha.5 → 4.0.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.
Files changed (93) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/dist.min.js +9 -3
  3. package/dist/es5/bundle.js +6 -0
  4. package/dist/es5/bundle.js.map +1 -0
  5. package/dist/es5/index.js +46 -0
  6. package/dist/es5/index.js.map +1 -0
  7. package/dist/es5/lib/encode-wkb.js +373 -0
  8. package/dist/es5/lib/encode-wkb.js.map +1 -0
  9. package/dist/es5/lib/encode-wkt.js +45 -0
  10. package/dist/es5/lib/encode-wkt.js.map +1 -0
  11. package/dist/es5/lib/parse-wkb.js +290 -0
  12. package/dist/es5/lib/parse-wkb.js.map +1 -0
  13. package/dist/es5/lib/parse-wkt.js +176 -0
  14. package/dist/es5/lib/parse-wkt.js.map +1 -0
  15. package/dist/es5/lib/utils/binary-writer.js +161 -0
  16. package/dist/es5/lib/utils/binary-writer.js.map +1 -0
  17. package/dist/es5/lib/utils/version.js +9 -0
  18. package/dist/es5/lib/utils/version.js.map +1 -0
  19. package/dist/es5/wkb-loader.js +54 -0
  20. package/dist/es5/wkb-loader.js.map +1 -0
  21. package/dist/es5/wkb-writer.js +25 -0
  22. package/dist/es5/wkb-writer.js.map +1 -0
  23. package/dist/es5/wkt-loader.js +51 -0
  24. package/dist/es5/wkt-loader.js.map +1 -0
  25. package/dist/es5/wkt-writer.js +22 -0
  26. package/dist/es5/wkt-writer.js.map +1 -0
  27. package/dist/es5/workers/wkb-worker.js +6 -0
  28. package/dist/es5/workers/wkb-worker.js.map +1 -0
  29. package/dist/es5/workers/wkt-worker.js +6 -0
  30. package/dist/es5/workers/wkt-worker.js.map +1 -0
  31. package/dist/esm/bundle.js +4 -0
  32. package/dist/esm/bundle.js.map +1 -0
  33. package/dist/esm/index.js +5 -0
  34. package/dist/esm/index.js.map +1 -0
  35. package/dist/esm/lib/encode-wkb.js +252 -0
  36. package/dist/esm/lib/encode-wkb.js.map +1 -0
  37. package/dist/esm/lib/encode-wkt.js +39 -0
  38. package/dist/esm/lib/encode-wkt.js.map +1 -0
  39. package/dist/esm/lib/parse-wkb.js +255 -0
  40. package/dist/esm/lib/parse-wkb.js.map +1 -0
  41. package/dist/esm/lib/parse-wkt.js +170 -0
  42. package/dist/esm/lib/parse-wkt.js.map +1 -0
  43. package/dist/esm/lib/utils/binary-writer.js +114 -0
  44. package/dist/esm/lib/utils/binary-writer.js.map +1 -0
  45. package/dist/esm/lib/utils/version.js +2 -0
  46. package/dist/esm/lib/utils/version.js.map +1 -0
  47. package/dist/esm/wkb-loader.js +23 -0
  48. package/dist/esm/wkb-loader.js.map +1 -0
  49. package/dist/esm/wkb-writer.js +17 -0
  50. package/dist/esm/wkb-writer.js.map +1 -0
  51. package/dist/esm/wkt-loader.js +22 -0
  52. package/dist/esm/wkt-loader.js.map +1 -0
  53. package/dist/esm/wkt-writer.js +14 -0
  54. package/dist/esm/wkt-writer.js.map +1 -0
  55. package/dist/esm/workers/wkb-worker.js +4 -0
  56. package/dist/esm/workers/wkb-worker.js.map +1 -0
  57. package/dist/esm/workers/wkt-worker.js +4 -0
  58. package/dist/esm/workers/wkt-worker.js.map +1 -0
  59. package/dist/index.js +13 -5
  60. package/dist/lib/encode-wkb.d.ts +6 -1
  61. package/dist/lib/encode-wkb.d.ts.map +1 -1
  62. package/dist/lib/encode-wkb.js +250 -278
  63. package/dist/lib/encode-wkt.js +35 -41
  64. package/dist/lib/parse-wkb.js +208 -276
  65. package/dist/lib/parse-wkt.js +218 -189
  66. package/dist/lib/utils/binary-writer.js +117 -150
  67. package/dist/lib/utils/version.js +7 -2
  68. package/dist/wkb-loader.js +32 -20
  69. package/dist/wkb-writer.d.ts +1 -1
  70. package/dist/wkb-writer.d.ts.map +1 -1
  71. package/dist/wkb-writer.js +25 -13
  72. package/dist/wkt-loader.js +31 -19
  73. package/dist/wkt-worker.js +48 -16
  74. package/dist/wkt-writer.js +22 -13
  75. package/dist/workers/wkb-worker.js +5 -4
  76. package/dist/workers/wkt-worker.js +5 -4
  77. package/package.json +6 -6
  78. package/src/lib/encode-wkb.ts +12 -1
  79. package/src/wkb-writer.ts +6 -3
  80. package/dist/bundle.js.map +0 -1
  81. package/dist/index.js.map +0 -1
  82. package/dist/lib/encode-wkb.js.map +0 -1
  83. package/dist/lib/encode-wkt.js.map +0 -1
  84. package/dist/lib/parse-wkb.js.map +0 -1
  85. package/dist/lib/parse-wkt.js.map +0 -1
  86. package/dist/lib/utils/binary-writer.js.map +0 -1
  87. package/dist/lib/utils/version.js.map +0 -1
  88. package/dist/wkb-loader.js.map +0 -1
  89. package/dist/wkb-writer.js.map +0 -1
  90. package/dist/wkt-loader.js.map +0 -1
  91. package/dist/wkt-writer.js.map +0 -1
  92. package/dist/workers/wkb-worker.js.map +0 -1
  93. package/dist/workers/wkt-worker.js.map +0 -1
@@ -1,198 +1,227 @@
1
+ "use strict";
2
+ // Fork of https://github.com/mapbox/wellknown under ISC license (MIT/BSD-2-clause equivalent)
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ /* eslint-disable */
5
+ // @ts-nocheck
1
6
  const numberRegexp = /[-+]?([0-9]*\.[0-9]+|[0-9]+)([eE][-+]?[0-9]+)?/;
7
+ // Matches sequences like '100 100' or '100 100 100'.
2
8
  const tuples = new RegExp('^' + numberRegexp.source + '(\\s' + numberRegexp.source + '){1,}');
3
- export default function parseWKT(input) {
4
- const parts = input.split(';');
5
-
6
- let _ = parts.pop();
7
-
8
- const srid = (parts.shift() || '').split('=').pop();
9
- let i = 0;
10
-
11
- function $(re) {
12
- const match = _.substring(i).match(re);
13
-
14
- if (!match) return null;else {
15
- i += match[0].length;
16
- return match[0];
9
+ /**
10
+ * Parse WKT and return GeoJSON.
11
+ *
12
+ * @param {string} _ A WKT geometry
13
+ * @return {?Object} A GeoJSON geometry object
14
+ **/
15
+ function parseWKT(input) {
16
+ const parts = input.split(';');
17
+ let _ = parts.pop();
18
+ const srid = (parts.shift() || '').split('=').pop();
19
+ let i = 0;
20
+ function $(re) {
21
+ const match = _.substring(i).match(re);
22
+ if (!match)
23
+ return null;
24
+ else {
25
+ i += match[0].length;
26
+ return match[0];
27
+ }
28
+ }
29
+ function crs(obj) {
30
+ if (obj && srid.match(/\d+/)) {
31
+ obj.crs = {
32
+ type: 'name',
33
+ properties: {
34
+ name: 'urn:ogc:def:crs:EPSG::' + srid
35
+ }
36
+ };
37
+ }
38
+ return obj;
39
+ }
40
+ function white() {
41
+ $(/^\s*/);
42
+ }
43
+ function multicoords() {
44
+ white();
45
+ let depth = 0;
46
+ const rings = [];
47
+ const stack = [rings];
48
+ let pointer = rings;
49
+ let elem;
50
+ while ((elem = $(/^(\()/) || $(/^(\))/) || $(/^(,)/) || $(tuples))) {
51
+ if (elem === '(') {
52
+ stack.push(pointer);
53
+ pointer = [];
54
+ stack[stack.length - 1].push(pointer);
55
+ depth++;
56
+ }
57
+ else if (elem === ')') {
58
+ // For the case: Polygon(), ...
59
+ if (pointer.length === 0)
60
+ return null;
61
+ // @ts-ignore
62
+ pointer = stack.pop();
63
+ // the stack was empty, input was malformed
64
+ if (!pointer)
65
+ return null;
66
+ depth--;
67
+ if (depth === 0)
68
+ break;
69
+ }
70
+ else if (elem === ',') {
71
+ pointer = [];
72
+ stack[stack.length - 1].push(pointer);
73
+ }
74
+ else if (!elem.split(/\s/g).some(isNaN)) {
75
+ Array.prototype.push.apply(pointer, elem.split(/\s/g).map(parseFloat));
76
+ }
77
+ else {
78
+ return null;
79
+ }
80
+ white();
81
+ }
82
+ if (depth !== 0)
83
+ return null;
84
+ return rings;
17
85
  }
18
- }
19
-
20
- function crs(obj) {
21
- if (obj && srid.match(/\d+/)) {
22
- obj.crs = {
23
- type: 'name',
24
- properties: {
25
- name: 'urn:ogc:def:crs:EPSG::' + srid
86
+ function coords() {
87
+ const list = [];
88
+ let item;
89
+ let pt;
90
+ while ((pt = $(tuples) || $(/^(,)/))) {
91
+ if (pt === ',') {
92
+ list.push(item);
93
+ item = [];
94
+ }
95
+ else if (!pt.split(/\s/g).some(isNaN)) {
96
+ if (!item)
97
+ item = [];
98
+ Array.prototype.push.apply(item, pt.split(/\s/g).map(parseFloat));
99
+ }
100
+ white();
26
101
  }
27
- };
102
+ if (item)
103
+ list.push(item);
104
+ else
105
+ return null;
106
+ return list.length ? list : null;
28
107
  }
29
-
30
- return obj;
31
- }
32
-
33
- function white() {
34
- $(/^\s*/);
35
- }
36
-
37
- function multicoords() {
38
- white();
39
- let depth = 0;
40
- const rings = [];
41
- const stack = [rings];
42
- let pointer = rings;
43
- let elem;
44
-
45
- while (elem = $(/^(\()/) || $(/^(\))/) || $(/^(,)/) || $(tuples)) {
46
- if (elem === '(') {
47
- stack.push(pointer);
48
- pointer = [];
49
- stack[stack.length - 1].push(pointer);
50
- depth++;
51
- } else if (elem === ')') {
52
- if (pointer.length === 0) return null;
53
- pointer = stack.pop();
54
- if (!pointer) return null;
55
- depth--;
56
- if (depth === 0) break;
57
- } else if (elem === ',') {
58
- pointer = [];
59
- stack[stack.length - 1].push(pointer);
60
- } else if (!elem.split(/\s/g).some(isNaN)) {
61
- Array.prototype.push.apply(pointer, elem.split(/\s/g).map(parseFloat));
62
- } else {
63
- return null;
64
- }
65
-
66
- white();
108
+ function point() {
109
+ if (!$(/^(point(\sz)?)/i))
110
+ return null;
111
+ white();
112
+ if (!$(/^(\()/))
113
+ return null;
114
+ const c = coords();
115
+ if (!c)
116
+ return null;
117
+ white();
118
+ if (!$(/^(\))/))
119
+ return null;
120
+ return {
121
+ type: 'Point',
122
+ coordinates: c[0]
123
+ };
67
124
  }
68
-
69
- if (depth !== 0) return null;
70
- return rings;
71
- }
72
-
73
- function coords() {
74
- const list = [];
75
- let item;
76
- let pt;
77
-
78
- while (pt = $(tuples) || $(/^(,)/)) {
79
- if (pt === ',') {
80
- list.push(item);
81
- item = [];
82
- } else if (!pt.split(/\s/g).some(isNaN)) {
83
- if (!item) item = [];
84
- Array.prototype.push.apply(item, pt.split(/\s/g).map(parseFloat));
85
- }
86
-
87
- white();
125
+ function multipoint() {
126
+ if (!$(/^(multipoint)/i))
127
+ return null;
128
+ white();
129
+ const newCoordsFormat = _.substring(_.indexOf('(') + 1, _.length - 1)
130
+ .replace(/\(/g, '')
131
+ .replace(/\)/g, '');
132
+ _ = 'MULTIPOINT (' + newCoordsFormat + ')';
133
+ const c = multicoords();
134
+ if (!c)
135
+ return null;
136
+ white();
137
+ return {
138
+ type: 'MultiPoint',
139
+ coordinates: c
140
+ };
141
+ }
142
+ function multilinestring() {
143
+ if (!$(/^(multilinestring)/i))
144
+ return null;
145
+ white();
146
+ const c = multicoords();
147
+ if (!c)
148
+ return null;
149
+ white();
150
+ return {
151
+ type: 'MultiLineString',
152
+ coordinates: c
153
+ };
154
+ }
155
+ function linestring() {
156
+ if (!$(/^(linestring(\sz)?)/i))
157
+ return null;
158
+ white();
159
+ if (!$(/^(\()/))
160
+ return null;
161
+ const c = coords();
162
+ if (!c)
163
+ return null;
164
+ if (!$(/^(\))/))
165
+ return null;
166
+ return {
167
+ type: 'LineString',
168
+ coordinates: c
169
+ };
170
+ }
171
+ function polygon() {
172
+ if (!$(/^(polygon(\sz)?)/i))
173
+ return null;
174
+ white();
175
+ const c = multicoords();
176
+ if (!c)
177
+ return null;
178
+ return {
179
+ type: 'Polygon',
180
+ coordinates: c
181
+ };
182
+ }
183
+ function multipolygon() {
184
+ if (!$(/^(multipolygon)/i))
185
+ return null;
186
+ white();
187
+ const c = multicoords();
188
+ if (!c)
189
+ return null;
190
+ return {
191
+ type: 'MultiPolygon',
192
+ coordinates: c
193
+ };
194
+ }
195
+ function geometrycollection() {
196
+ const geometries = [];
197
+ let geometry;
198
+ if (!$(/^(geometrycollection)/i))
199
+ return null;
200
+ white();
201
+ if (!$(/^(\()/))
202
+ return null;
203
+ while ((geometry = root())) {
204
+ geometries.push(geometry);
205
+ white();
206
+ $(/^(,)/);
207
+ white();
208
+ }
209
+ if (!$(/^(\))/))
210
+ return null;
211
+ return {
212
+ type: 'GeometryCollection',
213
+ geometries: geometries
214
+ };
88
215
  }
89
-
90
- if (item) list.push(item);else return null;
91
- return list.length ? list : null;
92
- }
93
-
94
- function point() {
95
- if (!$(/^(point(\sz)?)/i)) return null;
96
- white();
97
- if (!$(/^(\()/)) return null;
98
- const c = coords();
99
- if (!c) return null;
100
- white();
101
- if (!$(/^(\))/)) return null;
102
- return {
103
- type: 'Point',
104
- coordinates: c[0]
105
- };
106
- }
107
-
108
- function multipoint() {
109
- if (!$(/^(multipoint)/i)) return null;
110
- white();
111
-
112
- const newCoordsFormat = _.substring(_.indexOf('(') + 1, _.length - 1).replace(/\(/g, '').replace(/\)/g, '');
113
-
114
- _ = 'MULTIPOINT (' + newCoordsFormat + ')';
115
- const c = multicoords();
116
- if (!c) return null;
117
- white();
118
- return {
119
- type: 'MultiPoint',
120
- coordinates: c
121
- };
122
- }
123
-
124
- function multilinestring() {
125
- if (!$(/^(multilinestring)/i)) return null;
126
- white();
127
- const c = multicoords();
128
- if (!c) return null;
129
- white();
130
- return {
131
- type: 'MultiLineString',
132
- coordinates: c
133
- };
134
- }
135
-
136
- function linestring() {
137
- if (!$(/^(linestring(\sz)?)/i)) return null;
138
- white();
139
- if (!$(/^(\()/)) return null;
140
- const c = coords();
141
- if (!c) return null;
142
- if (!$(/^(\))/)) return null;
143
- return {
144
- type: 'LineString',
145
- coordinates: c
146
- };
147
- }
148
-
149
- function polygon() {
150
- if (!$(/^(polygon(\sz)?)/i)) return null;
151
- white();
152
- const c = multicoords();
153
- if (!c) return null;
154
- return {
155
- type: 'Polygon',
156
- coordinates: c
157
- };
158
- }
159
-
160
- function multipolygon() {
161
- if (!$(/^(multipolygon)/i)) return null;
162
- white();
163
- const c = multicoords();
164
- if (!c) return null;
165
- return {
166
- type: 'MultiPolygon',
167
- coordinates: c
168
- };
169
- }
170
-
171
- function geometrycollection() {
172
- const geometries = [];
173
- let geometry;
174
- if (!$(/^(geometrycollection)/i)) return null;
175
- white();
176
- if (!$(/^(\()/)) return null;
177
-
178
- while (geometry = root()) {
179
- geometries.push(geometry);
180
- white();
181
- $(/^(,)/);
182
- white();
216
+ function root() {
217
+ return (point() ||
218
+ linestring() ||
219
+ polygon() ||
220
+ multipoint() ||
221
+ multilinestring() ||
222
+ multipolygon() ||
223
+ geometrycollection());
183
224
  }
184
-
185
- if (!$(/^(\))/)) return null;
186
- return {
187
- type: 'GeometryCollection',
188
- geometries: geometries
189
- };
190
- }
191
-
192
- function root() {
193
- return point() || linestring() || polygon() || multipoint() || multilinestring() || multipolygon() || geometrycollection();
194
- }
195
-
196
- return crs(root());
225
+ return crs(root());
197
226
  }
198
- //# sourceMappingURL=parse-wkt.js.map
227
+ exports.default = parseWKT;
@@ -1,153 +1,120 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
1
+ "use strict";
2
+ // loaders.gl, MIT license
3
+ // Forked from https://github.com/cschwarz/wkx under MIT license, Copyright (c) 2013 Christian Schwarz
4
+ Object.defineProperty(exports, "__esModule", { value: true });
2
5
  const LE = true;
3
6
  const BE = false;
4
- export default class BinaryWriter {
5
- constructor(size, allowResize) {
6
- _defineProperty(this, "arrayBuffer", void 0);
7
-
8
- _defineProperty(this, "dataView", void 0);
9
-
10
- _defineProperty(this, "byteOffset", 0);
11
-
12
- _defineProperty(this, "allowResize", false);
13
-
14
- this.arrayBuffer = new ArrayBuffer(size);
15
- this.dataView = new DataView(this.arrayBuffer);
16
- this.byteOffset = 0;
17
- this.allowResize = allowResize || false;
18
- }
19
-
20
- writeUInt8(value) {
21
- this._ensureSize(1);
22
-
23
- this.dataView.setUint8(this.byteOffset, value);
24
- this.byteOffset += 1;
25
- }
26
-
27
- writeUInt16LE(value) {
28
- this._ensureSize(2);
29
-
30
- this.dataView.setUint16(this.byteOffset, value, LE);
31
- this.byteOffset += 2;
32
- }
33
-
34
- writeUInt16BE(value) {
35
- this._ensureSize(2);
36
-
37
- this.dataView.setUint16(this.byteOffset, value, BE);
38
- this.byteOffset += 2;
39
- }
40
-
41
- writeUInt32LE(value) {
42
- this._ensureSize(4);
43
-
44
- this.dataView.setUint32(this.byteOffset, value, LE);
45
- this.byteOffset += 4;
46
- }
47
-
48
- writeUInt32BE(value) {
49
- this._ensureSize(4);
50
-
51
- this.dataView.setUint32(this.byteOffset, value, BE);
52
- this.byteOffset += 4;
53
- }
54
-
55
- writeInt8(value) {
56
- this._ensureSize(1);
57
-
58
- this.dataView.setInt8(this.byteOffset, value);
59
- this.byteOffset += 1;
60
- }
61
-
62
- writeInt16LE(value) {
63
- this._ensureSize(2);
64
-
65
- this.dataView.setInt16(this.byteOffset, value, LE);
66
- this.byteOffset += 2;
67
- }
68
-
69
- writeInt16BE(value) {
70
- this._ensureSize(2);
71
-
72
- this.dataView.setInt16(this.byteOffset, value, BE);
73
- this.byteOffset += 2;
74
- }
75
-
76
- writeInt32LE(value) {
77
- this._ensureSize(4);
78
-
79
- this.dataView.setInt32(this.byteOffset, value, LE);
80
- this.byteOffset += 4;
81
- }
82
-
83
- writeInt32BE(value) {
84
- this._ensureSize(4);
85
-
86
- this.dataView.setInt32(this.byteOffset, value, BE);
87
- this.byteOffset += 4;
88
- }
89
-
90
- writeFloatLE(value) {
91
- this._ensureSize(4);
92
-
93
- this.dataView.setFloat32(this.byteOffset, value, LE);
94
- this.byteOffset += 4;
95
- }
96
-
97
- writeFloatBE(value) {
98
- this._ensureSize(4);
99
-
100
- this.dataView.setFloat32(this.byteOffset, value, BE);
101
- this.byteOffset += 4;
102
- }
103
-
104
- writeDoubleLE(value) {
105
- this._ensureSize(8);
106
-
107
- this.dataView.setFloat64(this.byteOffset, value, LE);
108
- this.byteOffset += 8;
109
- }
110
-
111
- writeDoubleBE(value) {
112
- this._ensureSize(8);
113
-
114
- this.dataView.setFloat64(this.byteOffset, value, BE);
115
- this.byteOffset += 8;
116
- }
117
-
118
- writeVarInt(value) {
119
- let length = 1;
120
-
121
- while ((value & 0xffffff80) !== 0) {
122
- this.writeUInt8(value & 0x7f | 0x80);
123
- value >>>= 7;
124
- length++;
125
- }
126
-
127
- this.writeUInt8(value & 0x7f);
128
- return length;
129
- }
130
-
131
- writeBuffer(arrayBuffer) {
132
- this._ensureSize(arrayBuffer.byteLength);
133
-
134
- const tempArray = new Uint8Array(this.arrayBuffer);
135
- tempArray.set(new Uint8Array(arrayBuffer), this.byteOffset);
136
- this.byteOffset += arrayBuffer.byteLength;
137
- }
138
-
139
- _ensureSize(size) {
140
- if (this.arrayBuffer.byteLength < this.byteOffset + size) {
141
- if (this.allowResize) {
142
- const newArrayBuffer = new ArrayBuffer(this.byteOffset + size);
143
- const tempArray = new Uint8Array(newArrayBuffer);
144
- tempArray.set(new Uint8Array(this.arrayBuffer));
145
- this.arrayBuffer = newArrayBuffer;
146
- } else {
147
- throw new Error('BinaryWriter overflow');
148
- }
149
- }
150
- }
151
-
7
+ class BinaryWriter {
8
+ constructor(size, allowResize) {
9
+ this.byteOffset = 0;
10
+ this.allowResize = false;
11
+ this.arrayBuffer = new ArrayBuffer(size);
12
+ this.dataView = new DataView(this.arrayBuffer);
13
+ this.byteOffset = 0;
14
+ this.allowResize = allowResize || false;
15
+ }
16
+ writeUInt8(value) {
17
+ this._ensureSize(1);
18
+ this.dataView.setUint8(this.byteOffset, value);
19
+ this.byteOffset += 1;
20
+ }
21
+ writeUInt16LE(value) {
22
+ this._ensureSize(2);
23
+ this.dataView.setUint16(this.byteOffset, value, LE);
24
+ this.byteOffset += 2;
25
+ }
26
+ writeUInt16BE(value) {
27
+ this._ensureSize(2);
28
+ this.dataView.setUint16(this.byteOffset, value, BE);
29
+ this.byteOffset += 2;
30
+ }
31
+ writeUInt32LE(value) {
32
+ this._ensureSize(4);
33
+ this.dataView.setUint32(this.byteOffset, value, LE);
34
+ this.byteOffset += 4;
35
+ }
36
+ writeUInt32BE(value) {
37
+ this._ensureSize(4);
38
+ this.dataView.setUint32(this.byteOffset, value, BE);
39
+ this.byteOffset += 4;
40
+ }
41
+ writeInt8(value) {
42
+ this._ensureSize(1);
43
+ this.dataView.setInt8(this.byteOffset, value);
44
+ this.byteOffset += 1;
45
+ }
46
+ writeInt16LE(value) {
47
+ this._ensureSize(2);
48
+ this.dataView.setInt16(this.byteOffset, value, LE);
49
+ this.byteOffset += 2;
50
+ }
51
+ writeInt16BE(value) {
52
+ this._ensureSize(2);
53
+ this.dataView.setInt16(this.byteOffset, value, BE);
54
+ this.byteOffset += 2;
55
+ }
56
+ writeInt32LE(value) {
57
+ this._ensureSize(4);
58
+ this.dataView.setInt32(this.byteOffset, value, LE);
59
+ this.byteOffset += 4;
60
+ }
61
+ writeInt32BE(value) {
62
+ this._ensureSize(4);
63
+ this.dataView.setInt32(this.byteOffset, value, BE);
64
+ this.byteOffset += 4;
65
+ }
66
+ writeFloatLE(value) {
67
+ this._ensureSize(4);
68
+ this.dataView.setFloat32(this.byteOffset, value, LE);
69
+ this.byteOffset += 4;
70
+ }
71
+ writeFloatBE(value) {
72
+ this._ensureSize(4);
73
+ this.dataView.setFloat32(this.byteOffset, value, BE);
74
+ this.byteOffset += 4;
75
+ }
76
+ writeDoubleLE(value) {
77
+ this._ensureSize(8);
78
+ this.dataView.setFloat64(this.byteOffset, value, LE);
79
+ this.byteOffset += 8;
80
+ }
81
+ writeDoubleBE(value) {
82
+ this._ensureSize(8);
83
+ this.dataView.setFloat64(this.byteOffset, value, BE);
84
+ this.byteOffset += 8;
85
+ }
86
+ /** A varint uses a variable number of bytes */
87
+ writeVarInt(value) {
88
+ // TODO - ensure size?
89
+ let length = 1;
90
+ while ((value & 0xffffff80) !== 0) {
91
+ this.writeUInt8((value & 0x7f) | 0x80);
92
+ value >>>= 7;
93
+ length++;
94
+ }
95
+ this.writeUInt8(value & 0x7f);
96
+ return length;
97
+ }
98
+ /** Append another ArrayBuffer to this ArrayBuffer */
99
+ writeBuffer(arrayBuffer) {
100
+ this._ensureSize(arrayBuffer.byteLength);
101
+ const tempArray = new Uint8Array(this.arrayBuffer);
102
+ tempArray.set(new Uint8Array(arrayBuffer), this.byteOffset);
103
+ this.byteOffset += arrayBuffer.byteLength;
104
+ }
105
+ /** Resizes this.arrayBuffer if not enough space */
106
+ _ensureSize(size) {
107
+ if (this.arrayBuffer.byteLength < this.byteOffset + size) {
108
+ if (this.allowResize) {
109
+ const newArrayBuffer = new ArrayBuffer(this.byteOffset + size);
110
+ const tempArray = new Uint8Array(newArrayBuffer);
111
+ tempArray.set(new Uint8Array(this.arrayBuffer));
112
+ this.arrayBuffer = newArrayBuffer;
113
+ }
114
+ else {
115
+ throw new Error('BinaryWriter overflow');
116
+ }
117
+ }
118
+ }
152
119
  }
153
- //# sourceMappingURL=binary-writer.js.map
120
+ exports.default = BinaryWriter;