mol_vary 0.0.89 → 0.0.91

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/node.mjs CHANGED
@@ -28,6 +28,16 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
28
28
  var $ = ( typeof module === 'object' ) ? ( module['export'+'s'] = globalThis ) : globalThis
29
29
  $.$$ = $
30
30
 
31
+ ;
32
+ "use strict";
33
+ var $;
34
+ (function ($) {
35
+ function $mol_fail(error) {
36
+ throw error;
37
+ }
38
+ $.$mol_fail = $mol_fail;
39
+ })($ || ($ = {}));
40
+
31
41
  ;
32
42
  "use strict";
33
43
  var $;
@@ -54,21 +64,21 @@ var $;
54
64
  "use strict";
55
65
  var $;
56
66
  (function ($) {
57
- function $mol_fail(error) {
58
- throw error;
67
+ let buf = new Uint8Array(2 ** 12);
68
+ function $mol_charset_buffer(size) {
69
+ if (buf.byteLength < size)
70
+ buf = new Uint8Array(size);
71
+ return buf;
59
72
  }
60
- $.$mol_fail = $mol_fail;
73
+ $.$mol_charset_buffer = $mol_charset_buffer;
61
74
  })($ || ($ = {}));
62
75
 
63
76
  ;
64
77
  "use strict";
65
78
  var $;
66
79
  (function ($) {
67
- let buf = new Uint8Array(2 ** 12);
68
80
  function $mol_charset_encode(str) {
69
- const capacity = str.length * 3;
70
- if (buf.byteLength < capacity)
71
- buf = new Uint8Array(capacity);
81
+ const buf = $mol_charset_buffer(str.length * 3);
72
82
  return buf.slice(0, $mol_charset_encode_to(str, buf));
73
83
  }
74
84
  $.$mol_charset_encode = $mol_charset_encode;
@@ -160,59 +170,6 @@ var $;
160
170
  $.$mol_charset_decode = $mol_charset_decode;
161
171
  })($ || ($ = {}));
162
172
 
163
- ;
164
- "use strict";
165
- var $;
166
- (function ($) {
167
- function $mol_charset_decode_from(buffer, from, count) {
168
- const codes = [];
169
- let pos = from;
170
- while (pos < buffer.length && codes.length < count) {
171
- const byte1 = buffer[pos++];
172
- if (byte1 <= 0x7F) {
173
- codes.push(byte1);
174
- }
175
- else if ((byte1 & 0xE0) === 0xC0) {
176
- if (pos >= buffer.length)
177
- break;
178
- const byte2 = buffer[pos++];
179
- const code = ((byte1 & 0x1F) << 6) | (byte2 & 0x3F);
180
- codes.push(code);
181
- }
182
- else if ((byte1 & 0xF0) === 0xE0) {
183
- if (pos + 1 >= buffer.length)
184
- break;
185
- const byte2 = buffer[pos++];
186
- const byte3 = buffer[pos++];
187
- const code = ((byte1 & 0x0F) << 12) | ((byte2 & 0x3F) << 6) | (byte3 & 0x3F);
188
- codes.push(code);
189
- }
190
- else if ((byte1 & 0xF8) === 0xF0) {
191
- if (pos + 2 >= buffer.length)
192
- break;
193
- const byte2 = buffer[pos++];
194
- const byte3 = buffer[pos++];
195
- const byte4 = buffer[pos++];
196
- let code = ((byte1 & 0x07) << 18) | ((byte2 & 0x3F) << 12) | ((byte3 & 0x3F) << 6) | (byte4 & 0x3F);
197
- if (code > 0xFFFF) {
198
- code -= 0x10000;
199
- const hi = 0xD800 + (code >> 10);
200
- const lo = 0xDC00 + (code & 0x3FF);
201
- codes.push(hi, lo);
202
- }
203
- else {
204
- codes.push(code);
205
- }
206
- }
207
- else {
208
- codes.push(0xFFFD);
209
- }
210
- }
211
- return [String.fromCharCode(...codes), pos - from];
212
- }
213
- $.$mol_charset_decode_from = $mol_charset_decode_from;
214
- })($ || ($ = {}));
215
-
216
173
  ;
217
174
  "use strict";
218
175
  var $;
@@ -549,6 +506,8 @@ var $;
549
506
  "use strict";
550
507
  var $;
551
508
  (function ($) {
509
+ if (!Symbol.dispose)
510
+ Symbol.dispose = Symbol('Symbol.dispose');
552
511
  class $mol_object2 {
553
512
  static $ = $;
554
513
  [Symbol.toStringTag];
@@ -581,6 +540,9 @@ var $;
581
540
  }
582
541
  destructor() { }
583
542
  static destructor() { }
543
+ [Symbol.dispose]() {
544
+ this.destructor();
545
+ }
584
546
  toString() {
585
547
  return this[Symbol.toStringTag] || this.constructor.name + '<>';
586
548
  }
@@ -2397,8 +2359,21 @@ var $;
2397
2359
  const release = (size) => {
2398
2360
  capacity -= size;
2399
2361
  };
2400
- const dump_unum = (tip, val) => {
2401
- if (val < $mol_vary_len.L1) {
2362
+ const calc_size = (val) => {
2363
+ if (val < $mol_vary_len.L1)
2364
+ return 1;
2365
+ if (val < 2 ** 8)
2366
+ return 2;
2367
+ if (val < 2 ** 16)
2368
+ return 3;
2369
+ if (val < 2 ** 32)
2370
+ return 5;
2371
+ if (val < 2n ** 64n)
2372
+ return 9;
2373
+ return $mol_fail(new Error('Too large number'));
2374
+ };
2375
+ const dump_unum = (tip, val, max = val) => {
2376
+ if (max < $mol_vary_len.L1) {
2402
2377
  this.array[pos++] = tip | Number(val);
2403
2378
  release(8);
2404
2379
  return;
@@ -2408,24 +2383,24 @@ var $;
2408
2383
  if (offset !== undefined)
2409
2384
  return dump_unum($mol_vary_tip.link, offset);
2410
2385
  }
2411
- if (val < 2 ** 8) {
2386
+ if (max < 2 ** 8) {
2412
2387
  this.array[pos++] = tip | $mol_vary_len.L1;
2413
2388
  this.array[pos++] = Number(val);
2414
2389
  release(7);
2415
2390
  }
2416
- else if (val < 2 ** 16) {
2391
+ else if (max < 2 ** 16) {
2417
2392
  this.array[pos++] = tip | $mol_vary_len.L2;
2418
2393
  this.buffer.setUint16(pos, Number(val), true);
2419
2394
  pos += 2;
2420
2395
  release(6);
2421
2396
  }
2422
- else if (val < 2 ** 32) {
2397
+ else if (max < 2 ** 32) {
2423
2398
  this.array[pos++] = tip | $mol_vary_len.L4;
2424
2399
  this.buffer.setUint32(pos, Number(val), true);
2425
2400
  pos += 4;
2426
2401
  release(4);
2427
2402
  }
2428
- else if (val < 2n ** 64n) {
2403
+ else if (max < 2n ** 64n) {
2429
2404
  this.array[pos++] = tip | $mol_vary_len.L8;
2430
2405
  this.buffer.setBigUint64(pos, BigInt(val), true);
2431
2406
  pos += 8;
@@ -2496,11 +2471,13 @@ var $;
2496
2471
  const offset = offsets.get(val);
2497
2472
  if (offset !== undefined)
2498
2473
  return dump_unum($mol_vary_tip.link, offset);
2499
- dump_unum($mol_vary_tip.text, val.length);
2500
- acquire(val.length * 3);
2501
- const len = $mol_charset_encode_to(val, this.array, pos);
2474
+ const len_max = val.length * 3;
2475
+ const len_size = calc_size(len_max);
2476
+ acquire(len_max);
2477
+ const len = $mol_charset_encode_to(val, this.array, pos + len_size);
2478
+ dump_unum($mol_vary_tip.text, len, len_max);
2502
2479
  pos += len;
2503
- release(val.length * 3 - len);
2480
+ release(len_max - len);
2504
2481
  offsets.set(val, offsets.size);
2505
2482
  return;
2506
2483
  };
@@ -2706,8 +2683,8 @@ var $;
2706
2683
  };
2707
2684
  const read_text = (kind) => {
2708
2685
  const len = read_unum(kind);
2709
- const [text, bytes] = $mol_charset_decode_from(array, pos, len);
2710
- pos += bytes;
2686
+ const text = $mol_charset_decode(new Uint8Array(array.buffer, array.byteOffset + pos, len));
2687
+ pos += len;
2711
2688
  stream.push(text);
2712
2689
  return text;
2713
2690
  };
package/node.test.js CHANGED
@@ -19,6 +19,16 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
19
19
  var $ = ( typeof module === 'object' ) ? ( module['export'+'s'] = globalThis ) : globalThis
20
20
  $.$$ = $
21
21
 
22
+ ;
23
+ "use strict";
24
+ var $;
25
+ (function ($) {
26
+ function $mol_fail(error) {
27
+ throw error;
28
+ }
29
+ $.$mol_fail = $mol_fail;
30
+ })($ || ($ = {}));
31
+
22
32
  ;
23
33
  "use strict";
24
34
  var $;
@@ -45,21 +55,21 @@ var $;
45
55
  "use strict";
46
56
  var $;
47
57
  (function ($) {
48
- function $mol_fail(error) {
49
- throw error;
58
+ let buf = new Uint8Array(2 ** 12);
59
+ function $mol_charset_buffer(size) {
60
+ if (buf.byteLength < size)
61
+ buf = new Uint8Array(size);
62
+ return buf;
50
63
  }
51
- $.$mol_fail = $mol_fail;
64
+ $.$mol_charset_buffer = $mol_charset_buffer;
52
65
  })($ || ($ = {}));
53
66
 
54
67
  ;
55
68
  "use strict";
56
69
  var $;
57
70
  (function ($) {
58
- let buf = new Uint8Array(2 ** 12);
59
71
  function $mol_charset_encode(str) {
60
- const capacity = str.length * 3;
61
- if (buf.byteLength < capacity)
62
- buf = new Uint8Array(capacity);
72
+ const buf = $mol_charset_buffer(str.length * 3);
63
73
  return buf.slice(0, $mol_charset_encode_to(str, buf));
64
74
  }
65
75
  $.$mol_charset_encode = $mol_charset_encode;
@@ -151,59 +161,6 @@ var $;
151
161
  $.$mol_charset_decode = $mol_charset_decode;
152
162
  })($ || ($ = {}));
153
163
 
154
- ;
155
- "use strict";
156
- var $;
157
- (function ($) {
158
- function $mol_charset_decode_from(buffer, from, count) {
159
- const codes = [];
160
- let pos = from;
161
- while (pos < buffer.length && codes.length < count) {
162
- const byte1 = buffer[pos++];
163
- if (byte1 <= 0x7F) {
164
- codes.push(byte1);
165
- }
166
- else if ((byte1 & 0xE0) === 0xC0) {
167
- if (pos >= buffer.length)
168
- break;
169
- const byte2 = buffer[pos++];
170
- const code = ((byte1 & 0x1F) << 6) | (byte2 & 0x3F);
171
- codes.push(code);
172
- }
173
- else if ((byte1 & 0xF0) === 0xE0) {
174
- if (pos + 1 >= buffer.length)
175
- break;
176
- const byte2 = buffer[pos++];
177
- const byte3 = buffer[pos++];
178
- const code = ((byte1 & 0x0F) << 12) | ((byte2 & 0x3F) << 6) | (byte3 & 0x3F);
179
- codes.push(code);
180
- }
181
- else if ((byte1 & 0xF8) === 0xF0) {
182
- if (pos + 2 >= buffer.length)
183
- break;
184
- const byte2 = buffer[pos++];
185
- const byte3 = buffer[pos++];
186
- const byte4 = buffer[pos++];
187
- let code = ((byte1 & 0x07) << 18) | ((byte2 & 0x3F) << 12) | ((byte3 & 0x3F) << 6) | (byte4 & 0x3F);
188
- if (code > 0xFFFF) {
189
- code -= 0x10000;
190
- const hi = 0xD800 + (code >> 10);
191
- const lo = 0xDC00 + (code & 0x3FF);
192
- codes.push(hi, lo);
193
- }
194
- else {
195
- codes.push(code);
196
- }
197
- }
198
- else {
199
- codes.push(0xFFFD);
200
- }
201
- }
202
- return [String.fromCharCode(...codes), pos - from];
203
- }
204
- $.$mol_charset_decode_from = $mol_charset_decode_from;
205
- })($ || ($ = {}));
206
-
207
164
  ;
208
165
  "use strict";
209
166
  var $;
@@ -540,6 +497,8 @@ var $;
540
497
  "use strict";
541
498
  var $;
542
499
  (function ($) {
500
+ if (!Symbol.dispose)
501
+ Symbol.dispose = Symbol('Symbol.dispose');
543
502
  class $mol_object2 {
544
503
  static $ = $;
545
504
  [Symbol.toStringTag];
@@ -572,6 +531,9 @@ var $;
572
531
  }
573
532
  destructor() { }
574
533
  static destructor() { }
534
+ [Symbol.dispose]() {
535
+ this.destructor();
536
+ }
575
537
  toString() {
576
538
  return this[Symbol.toStringTag] || this.constructor.name + '<>';
577
539
  }
@@ -2388,8 +2350,21 @@ var $;
2388
2350
  const release = (size) => {
2389
2351
  capacity -= size;
2390
2352
  };
2391
- const dump_unum = (tip, val) => {
2392
- if (val < $mol_vary_len.L1) {
2353
+ const calc_size = (val) => {
2354
+ if (val < $mol_vary_len.L1)
2355
+ return 1;
2356
+ if (val < 2 ** 8)
2357
+ return 2;
2358
+ if (val < 2 ** 16)
2359
+ return 3;
2360
+ if (val < 2 ** 32)
2361
+ return 5;
2362
+ if (val < 2n ** 64n)
2363
+ return 9;
2364
+ return $mol_fail(new Error('Too large number'));
2365
+ };
2366
+ const dump_unum = (tip, val, max = val) => {
2367
+ if (max < $mol_vary_len.L1) {
2393
2368
  this.array[pos++] = tip | Number(val);
2394
2369
  release(8);
2395
2370
  return;
@@ -2399,24 +2374,24 @@ var $;
2399
2374
  if (offset !== undefined)
2400
2375
  return dump_unum($mol_vary_tip.link, offset);
2401
2376
  }
2402
- if (val < 2 ** 8) {
2377
+ if (max < 2 ** 8) {
2403
2378
  this.array[pos++] = tip | $mol_vary_len.L1;
2404
2379
  this.array[pos++] = Number(val);
2405
2380
  release(7);
2406
2381
  }
2407
- else if (val < 2 ** 16) {
2382
+ else if (max < 2 ** 16) {
2408
2383
  this.array[pos++] = tip | $mol_vary_len.L2;
2409
2384
  this.buffer.setUint16(pos, Number(val), true);
2410
2385
  pos += 2;
2411
2386
  release(6);
2412
2387
  }
2413
- else if (val < 2 ** 32) {
2388
+ else if (max < 2 ** 32) {
2414
2389
  this.array[pos++] = tip | $mol_vary_len.L4;
2415
2390
  this.buffer.setUint32(pos, Number(val), true);
2416
2391
  pos += 4;
2417
2392
  release(4);
2418
2393
  }
2419
- else if (val < 2n ** 64n) {
2394
+ else if (max < 2n ** 64n) {
2420
2395
  this.array[pos++] = tip | $mol_vary_len.L8;
2421
2396
  this.buffer.setBigUint64(pos, BigInt(val), true);
2422
2397
  pos += 8;
@@ -2487,11 +2462,13 @@ var $;
2487
2462
  const offset = offsets.get(val);
2488
2463
  if (offset !== undefined)
2489
2464
  return dump_unum($mol_vary_tip.link, offset);
2490
- dump_unum($mol_vary_tip.text, val.length);
2491
- acquire(val.length * 3);
2492
- const len = $mol_charset_encode_to(val, this.array, pos);
2465
+ const len_max = val.length * 3;
2466
+ const len_size = calc_size(len_max);
2467
+ acquire(len_max);
2468
+ const len = $mol_charset_encode_to(val, this.array, pos + len_size);
2469
+ dump_unum($mol_vary_tip.text, len, len_max);
2493
2470
  pos += len;
2494
- release(val.length * 3 - len);
2471
+ release(len_max - len);
2495
2472
  offsets.set(val, offsets.size);
2496
2473
  return;
2497
2474
  };
@@ -2697,8 +2674,8 @@ var $;
2697
2674
  };
2698
2675
  const read_text = (kind) => {
2699
2676
  const len = read_unum(kind);
2700
- const [text, bytes] = $mol_charset_decode_from(array, pos, len);
2701
- pos += bytes;
2677
+ const text = $mol_charset_decode(new Uint8Array(array.buffer, array.byteOffset + pos, len));
2678
+ pos += len;
2702
2679
  stream.push(text);
2703
2680
  return text;
2704
2681
  };
@@ -4555,32 +4532,6 @@ var $;
4555
4532
  });
4556
4533
  })($ || ($ = {}));
4557
4534
 
4558
- ;
4559
- "use strict";
4560
- var $;
4561
- (function ($) {
4562
- $mol_test({
4563
- 'encode empty'() {
4564
- $mol_assert_equal($mol_charset_decode_from(new Uint8Array([]), 0, 0), ['', 0]);
4565
- },
4566
- 'encode 1 octet'() {
4567
- $mol_assert_equal($mol_charset_decode_from(new Uint8Array([0x46]), 0, 1), ['F', 1]);
4568
- },
4569
- 'encode 2 octet'() {
4570
- $mol_assert_equal($mol_charset_decode_from(new Uint8Array([0xd0, 0x91]), 0, 1), ['Б', 2]);
4571
- },
4572
- 'encode 3 octet'() {
4573
- $mol_assert_equal($mol_charset_decode_from(new Uint8Array([0xe0, 0xa4, 0xb9]), 0, 1), ['ह', 3]);
4574
- },
4575
- 'encode 4 octet'() {
4576
- $mol_assert_equal($mol_charset_decode_from(new Uint8Array([0xf0, 0x90, 0x8d, 0x88]), 0, 1), ['𐍈', 4]);
4577
- },
4578
- 'encode surrogate pair'() {
4579
- $mol_assert_equal($mol_charset_decode_from(new Uint8Array([0xf0, 0x9f, 0x98, 0x80]), 0, 2), ['😀', 4]);
4580
- },
4581
- });
4582
- })($ || ($ = {}));
4583
-
4584
4535
  ;
4585
4536
  "use strict";
4586
4537
  var $;
@@ -5025,8 +4976,11 @@ var $;
5025
4976
  },
5026
4977
  "vary pack text"($) {
5027
4978
  check(['foo'], [text | 3, ...str('foo')]);
5028
- const long = 'abcdefghijklmnopqrstuvwxyzЖЫ';
5029
- check([long], [text | L1, 28, ...str(long)]);
4979
+ check(['абв'], [text | 6, ...str('абв')]);
4980
+ const long_lat = 'abcdefghijklmnopqrst';
4981
+ check([long_lat], [text | L1, 20, ...str(long_lat)]);
4982
+ const long_cyr = 'абвгдеёжзийклмнопрст';
4983
+ check([long_cyr], [text | L1, 40, ...str(long_cyr)]);
5030
4984
  },
5031
4985
  "vary pack dedup text"($) {
5032
4986
  check([["f", "f"]], [list | 2, text | 1, ...str('f'), link | 0]);