bare-buffer 3.3.0 → 3.4.0
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/binding.c +49 -32
- package/global.d.ts +3 -0
- package/global.js +6 -1
- package/index.d.ts +19 -0
- package/index.js +294 -8
- package/package.json +1 -1
- package/prebuilds/android-arm/bare-buffer.bare +0 -0
- package/prebuilds/android-arm64/bare-buffer.bare +0 -0
- package/prebuilds/android-ia32/bare-buffer.bare +0 -0
- package/prebuilds/android-x64/bare-buffer.bare +0 -0
- package/prebuilds/darwin-arm64/bare-buffer.bare +0 -0
- package/prebuilds/darwin-x64/bare-buffer.bare +0 -0
- package/prebuilds/ios-arm64/bare-buffer.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare-buffer.bare +0 -0
- package/prebuilds/ios-x64-simulator/bare-buffer.bare +0 -0
- package/prebuilds/linux-arm64/bare-buffer.bare +0 -0
- package/prebuilds/linux-x64/bare-buffer.bare +0 -0
- package/prebuilds/win32-arm64/bare-buffer.bare +0 -0
- package/prebuilds/win32-x64/bare-buffer.bare +0 -0
package/binding.c
CHANGED
|
@@ -7,22 +7,26 @@
|
|
|
7
7
|
#include <string.h>
|
|
8
8
|
#include <utf.h>
|
|
9
9
|
|
|
10
|
+
static void
|
|
11
|
+
bare_buffer__on_finalize_string(js_env_t *env, void *data, void *finalize_hint) {
|
|
12
|
+
free(data);
|
|
13
|
+
}
|
|
14
|
+
|
|
10
15
|
static inline int
|
|
11
|
-
|
|
12
|
-
int
|
|
16
|
+
bare_buffer__get_info(js_env_t *env, js_value_t *buffer, void **data, size_t *len) {
|
|
17
|
+
int err;
|
|
13
18
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
bool is_shared;
|
|
20
|
+
err = js_is_sharedarraybuffer(env, buffer, &is_shared);
|
|
21
|
+
if (err < 0) return err;
|
|
22
|
+
|
|
23
|
+
if (is_shared) {
|
|
24
|
+
err = js_get_sharedarraybuffer_info(env, buffer, data, len);
|
|
25
|
+
} else {
|
|
26
|
+
err = js_get_arraybuffer_info(env, buffer, data, len);
|
|
18
27
|
}
|
|
19
28
|
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
static void
|
|
24
|
-
bare_buffer__on_finalize_string(js_env_t *env, void *data, void *finalize_hint) {
|
|
25
|
-
free(data);
|
|
29
|
+
return err;
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
static js_value_t *
|
|
@@ -122,7 +126,7 @@ bare_buffer_to_string_utf8(js_env_t *env, js_callback_info_t *info) {
|
|
|
122
126
|
assert(argc == 3);
|
|
123
127
|
|
|
124
128
|
utf8_t *buf;
|
|
125
|
-
err =
|
|
129
|
+
err = bare_buffer__get_info(env, argv[0], (void **) &buf, NULL);
|
|
126
130
|
assert(err == 0);
|
|
127
131
|
|
|
128
132
|
int64_t offset;
|
|
@@ -156,7 +160,7 @@ bare_buffer_typed_write_utf8(
|
|
|
156
160
|
assert(err == 0);
|
|
157
161
|
|
|
158
162
|
utf8_t *buf;
|
|
159
|
-
err =
|
|
163
|
+
err = bare_buffer__get_info(env, handle, (void **) &buf, NULL);
|
|
160
164
|
assert(err == 0);
|
|
161
165
|
|
|
162
166
|
size_t str_len;
|
|
@@ -179,7 +183,7 @@ bare_buffer_write_utf8(js_env_t *env, js_callback_info_t *info) {
|
|
|
179
183
|
assert(argc == 4);
|
|
180
184
|
|
|
181
185
|
utf8_t *buf;
|
|
182
|
-
err =
|
|
186
|
+
err = bare_buffer__get_info(env, argv[0], (void **) &buf, NULL);
|
|
183
187
|
assert(err == 0);
|
|
184
188
|
|
|
185
189
|
int64_t offset;
|
|
@@ -214,7 +218,7 @@ bare_buffer_to_string_utf16le(js_env_t *env, js_callback_info_t *info) {
|
|
|
214
218
|
assert(argc == 3);
|
|
215
219
|
|
|
216
220
|
utf16_t *buf;
|
|
217
|
-
err =
|
|
221
|
+
err = bare_buffer__get_info(env, argv[0], (void **) &buf, NULL);
|
|
218
222
|
assert(err == 0);
|
|
219
223
|
|
|
220
224
|
int64_t offset;
|
|
@@ -251,7 +255,7 @@ bare_buffer_typed_write_utf16le(
|
|
|
251
255
|
assert(err == 0);
|
|
252
256
|
|
|
253
257
|
utf16_t *buf;
|
|
254
|
-
err =
|
|
258
|
+
err = bare_buffer__get_info(env, handle, (void **) &buf, NULL);
|
|
255
259
|
assert(err == 0);
|
|
256
260
|
|
|
257
261
|
offset /= sizeof(utf16_t);
|
|
@@ -279,7 +283,7 @@ bare_buffer_write_utf16le(js_env_t *env, js_callback_info_t *info) {
|
|
|
279
283
|
assert(argc == 4);
|
|
280
284
|
|
|
281
285
|
utf16_t *buf;
|
|
282
|
-
err =
|
|
286
|
+
err = bare_buffer__get_info(env, argv[0], (void **) &buf, NULL);
|
|
283
287
|
assert(err == 0);
|
|
284
288
|
|
|
285
289
|
int64_t offset;
|
|
@@ -319,7 +323,7 @@ bare_buffer_to_string_latin1(js_env_t *env, js_callback_info_t *info) {
|
|
|
319
323
|
assert(argc == 3);
|
|
320
324
|
|
|
321
325
|
latin1_t *buf;
|
|
322
|
-
err =
|
|
326
|
+
err = bare_buffer__get_info(env, argv[0], (void **) &buf, NULL);
|
|
323
327
|
assert(err == 0);
|
|
324
328
|
|
|
325
329
|
int64_t offset;
|
|
@@ -353,7 +357,7 @@ bare_buffer_typed_write_latin1(
|
|
|
353
357
|
assert(err == 0);
|
|
354
358
|
|
|
355
359
|
latin1_t *buf;
|
|
356
|
-
err =
|
|
360
|
+
err = bare_buffer__get_info(env, handle, (void **) &buf, NULL);
|
|
357
361
|
assert(err == 0);
|
|
358
362
|
|
|
359
363
|
size_t str_len;
|
|
@@ -376,7 +380,7 @@ bare_buffer_write_latin1(js_env_t *env, js_callback_info_t *info) {
|
|
|
376
380
|
assert(argc == 4);
|
|
377
381
|
|
|
378
382
|
latin1_t *buf;
|
|
379
|
-
err =
|
|
383
|
+
err = bare_buffer__get_info(env, argv[0], (void **) &buf, NULL);
|
|
380
384
|
assert(err == 0);
|
|
381
385
|
|
|
382
386
|
int64_t offset;
|
|
@@ -411,7 +415,7 @@ bare_buffer_to_string_base64(js_env_t *env, js_callback_info_t *info) {
|
|
|
411
415
|
assert(argc == 3);
|
|
412
416
|
|
|
413
417
|
utf8_t *buf;
|
|
414
|
-
err =
|
|
418
|
+
err = bare_buffer__get_info(env, argv[0], (void **) &buf, NULL);
|
|
415
419
|
assert(err == 0);
|
|
416
420
|
|
|
417
421
|
int64_t offset;
|
|
@@ -450,7 +454,7 @@ bare_buffer_to_string_base64url(js_env_t *env, js_callback_info_t *info) {
|
|
|
450
454
|
assert(argc == 3);
|
|
451
455
|
|
|
452
456
|
utf8_t *buf;
|
|
453
|
-
err =
|
|
457
|
+
err = bare_buffer__get_info(env, argv[0], (void **) &buf, NULL);
|
|
454
458
|
assert(err == 0);
|
|
455
459
|
|
|
456
460
|
int64_t offset;
|
|
@@ -492,7 +496,7 @@ bare_buffer_typed_write_base64(
|
|
|
492
496
|
assert(err == 0);
|
|
493
497
|
|
|
494
498
|
utf8_t *buf;
|
|
495
|
-
err =
|
|
499
|
+
err = bare_buffer__get_info(env, handle, (void **) &buf, NULL);
|
|
496
500
|
assert(err == 0);
|
|
497
501
|
|
|
498
502
|
js_string_encoding_t encoding;
|
|
@@ -540,7 +544,7 @@ bare_buffer_write_base64(js_env_t *env, js_callback_info_t *info) {
|
|
|
540
544
|
assert(argc == 4);
|
|
541
545
|
|
|
542
546
|
utf8_t *buf;
|
|
543
|
-
err =
|
|
547
|
+
err = bare_buffer__get_info(env, argv[0], (void **) &buf, NULL);
|
|
544
548
|
assert(err == 0);
|
|
545
549
|
|
|
546
550
|
int64_t offset;
|
|
@@ -600,7 +604,7 @@ bare_buffer_to_string_hex(js_env_t *env, js_callback_info_t *info) {
|
|
|
600
604
|
assert(argc == 3);
|
|
601
605
|
|
|
602
606
|
utf8_t *buf;
|
|
603
|
-
err =
|
|
607
|
+
err = bare_buffer__get_info(env, argv[0], (void **) &buf, NULL);
|
|
604
608
|
assert(err == 0);
|
|
605
609
|
|
|
606
610
|
int64_t offset;
|
|
@@ -642,7 +646,7 @@ bare_buffer_typed_write_hex(
|
|
|
642
646
|
assert(err == 0);
|
|
643
647
|
|
|
644
648
|
utf8_t *buf;
|
|
645
|
-
err =
|
|
649
|
+
err = bare_buffer__get_info(env, handle, (void **) &buf, NULL);
|
|
646
650
|
assert(err == 0);
|
|
647
651
|
|
|
648
652
|
js_string_encoding_t encoding;
|
|
@@ -690,7 +694,7 @@ bare_buffer_write_hex(js_env_t *env, js_callback_info_t *info) {
|
|
|
690
694
|
assert(argc == 4);
|
|
691
695
|
|
|
692
696
|
utf8_t *buf;
|
|
693
|
-
err =
|
|
697
|
+
err = bare_buffer__get_info(env, argv[0], (void **) &buf, NULL);
|
|
694
698
|
assert(err == 0);
|
|
695
699
|
|
|
696
700
|
int64_t offset;
|
|
@@ -737,6 +741,19 @@ bare_buffer_write_hex(js_env_t *env, js_callback_info_t *info) {
|
|
|
737
741
|
return result;
|
|
738
742
|
}
|
|
739
743
|
|
|
744
|
+
static inline int
|
|
745
|
+
bare_buffer__memcmp(void *a, size_t a_len, void *b, size_t b_len) {
|
|
746
|
+
int r = memcmp(a, b, a_len < b_len ? a_len : b_len);
|
|
747
|
+
|
|
748
|
+
if (r == 0) {
|
|
749
|
+
if (a_len < b_len) return -1;
|
|
750
|
+
if (a_len > b_len) return 1;
|
|
751
|
+
return 0;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
return r < 0 ? -1 : 1;
|
|
755
|
+
}
|
|
756
|
+
|
|
740
757
|
static int32_t
|
|
741
758
|
bare_buffer_typed_compare(
|
|
742
759
|
js_value_t *receiver,
|
|
@@ -755,11 +772,11 @@ bare_buffer_typed_compare(
|
|
|
755
772
|
assert(err == 0);
|
|
756
773
|
|
|
757
774
|
uint8_t *a;
|
|
758
|
-
err =
|
|
775
|
+
err = bare_buffer__get_info(env, a_handle, (void **) &a, NULL);
|
|
759
776
|
assert(err == 0);
|
|
760
777
|
|
|
761
778
|
uint8_t *b;
|
|
762
|
-
err =
|
|
779
|
+
err = bare_buffer__get_info(env, b_handle, (void **) &b, NULL);
|
|
763
780
|
assert(err == 0);
|
|
764
781
|
|
|
765
782
|
return bare_buffer__memcmp(&a[a_offset], a_len, &b[b_offset], b_len);
|
|
@@ -778,7 +795,7 @@ bare_buffer_compare(js_env_t *env, js_callback_info_t *info) {
|
|
|
778
795
|
assert(argc == 6);
|
|
779
796
|
|
|
780
797
|
uint8_t *a;
|
|
781
|
-
err =
|
|
798
|
+
err = bare_buffer__get_info(env, argv[0], (void **) &a, NULL);
|
|
782
799
|
assert(err == 0);
|
|
783
800
|
|
|
784
801
|
int64_t a_offset;
|
|
@@ -790,7 +807,7 @@ bare_buffer_compare(js_env_t *env, js_callback_info_t *info) {
|
|
|
790
807
|
assert(err == 0);
|
|
791
808
|
|
|
792
809
|
uint8_t *b;
|
|
793
|
-
err =
|
|
810
|
+
err = bare_buffer__get_info(env, argv[3], (void **) &b, NULL);
|
|
794
811
|
assert(err == 0);
|
|
795
812
|
|
|
796
813
|
int64_t b_offset;
|
package/global.d.ts
CHANGED
package/global.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -73,6 +73,9 @@ interface Buffer extends Uint8Array {
|
|
|
73
73
|
readInt32BE(offset?: number): number
|
|
74
74
|
readInt32LE(offset?: number): number
|
|
75
75
|
|
|
76
|
+
readIntBE(offset: number, byteLength: number): number
|
|
77
|
+
readIntLE(offset: number, byteLength: number): number
|
|
78
|
+
|
|
76
79
|
readBigInt64BE(offset?: number): bigint
|
|
77
80
|
readBigInt64LE(offset?: number): bigint
|
|
78
81
|
|
|
@@ -89,6 +92,11 @@ interface Buffer extends Uint8Array {
|
|
|
89
92
|
readUInt32LE(offset?: number): number
|
|
90
93
|
readUint32LE(offset?: number): number
|
|
91
94
|
|
|
95
|
+
readUIntBE(offset: number, byteLength: number): number
|
|
96
|
+
readUintBE(offset: number, byteLength: number): number
|
|
97
|
+
readUIntLE(offset: number, byteLength: number): number
|
|
98
|
+
readUintLE(offset: number, byteLength: number): number
|
|
99
|
+
|
|
92
100
|
readBigUInt64BE(offset?: number): bigint
|
|
93
101
|
readBigUint64BE(offset?: number): bigint
|
|
94
102
|
readBigUInt64LE(offset?: number): bigint
|
|
@@ -117,6 +125,9 @@ interface Buffer extends Uint8Array {
|
|
|
117
125
|
writeInt32BE(value: number, offset?: number): number
|
|
118
126
|
writeInt32LE(value: number, offset?: number): number
|
|
119
127
|
|
|
128
|
+
writeIntBE(value: number, offset: number, byteLength: number): number
|
|
129
|
+
writeIntLE(value: number, offset: number, byteLength: number): number
|
|
130
|
+
|
|
120
131
|
writeBigInt64BE(value: bigint, offset?: number): number
|
|
121
132
|
writeBigInt64LE(value: bigint, offset?: number): number
|
|
122
133
|
|
|
@@ -133,6 +144,11 @@ interface Buffer extends Uint8Array {
|
|
|
133
144
|
writeUInt32LE(value: number, offset?: number): number
|
|
134
145
|
writeUint32LE(value: number, offset?: number): number
|
|
135
146
|
|
|
147
|
+
writeUIntBE(value: number, offset: number, byteLength: number): number
|
|
148
|
+
writeUintBE(value: number, offset: number, byteLength: number): number
|
|
149
|
+
writeUIntLE(value: number, offset: number, byteLength: number): number
|
|
150
|
+
writeUintLE(value: number, offset: number, byteLength: number): number
|
|
151
|
+
|
|
136
152
|
writeBigUint64BE(value: bigint, offset?: number): number
|
|
137
153
|
writeBigUInt64BE(value: bigint, offset?: number): number
|
|
138
154
|
writeBigUint64LE(value: bigint, offset?: number): number
|
|
@@ -181,6 +197,9 @@ declare namespace Buffer {
|
|
|
181
197
|
length?: number
|
|
182
198
|
): Buffer
|
|
183
199
|
|
|
200
|
+
export function atob(data: unknown): string
|
|
201
|
+
export function btoa(data: unknown): string
|
|
202
|
+
|
|
184
203
|
export { Buffer, type BufferEncoding, constants }
|
|
185
204
|
}
|
|
186
205
|
|
package/index.js
CHANGED
|
@@ -104,7 +104,6 @@ module.exports = exports = class Buffer extends Uint8Array {
|
|
|
104
104
|
const source = this
|
|
105
105
|
|
|
106
106
|
if (source === target) return true
|
|
107
|
-
|
|
108
107
|
if (source.byteLength !== target.byteLength) return false
|
|
109
108
|
|
|
110
109
|
return (
|
|
@@ -164,14 +163,13 @@ module.exports = exports = class Buffer extends Uint8Array {
|
|
|
164
163
|
|
|
165
164
|
fill(value, offset = 0, end = this.byteLength, encoding = 'utf8') {
|
|
166
165
|
if (typeof value === 'string') {
|
|
167
|
-
// fill(string, encoding)
|
|
168
166
|
if (typeof offset === 'string') {
|
|
167
|
+
// fill(string, encoding)
|
|
169
168
|
encoding = offset
|
|
170
169
|
offset = 0
|
|
171
170
|
end = this.byteLength
|
|
172
|
-
|
|
173
|
-
// fill(string, offset, encoding)
|
|
174
171
|
} else if (typeof end === 'string') {
|
|
172
|
+
// fill(string, offset, encoding)
|
|
175
173
|
encoding = end
|
|
176
174
|
end = this.byteLength
|
|
177
175
|
}
|
|
@@ -299,14 +297,13 @@ module.exports = exports = class Buffer extends Uint8Array {
|
|
|
299
297
|
// write(string)
|
|
300
298
|
if (arguments.length === 1) return utf8.write(this, string)
|
|
301
299
|
|
|
302
|
-
// write(string, encoding)
|
|
303
300
|
if (typeof offset === 'string') {
|
|
301
|
+
// write(string, encoding)
|
|
304
302
|
encoding = offset
|
|
305
303
|
offset = 0
|
|
306
304
|
length = this.byteLength
|
|
307
|
-
|
|
308
|
-
// write(string, offset, encoding)
|
|
309
305
|
} else if (typeof length === 'string') {
|
|
306
|
+
// write(string, offset, encoding)
|
|
310
307
|
encoding = length
|
|
311
308
|
length = this.byteLength - offset
|
|
312
309
|
}
|
|
@@ -376,6 +373,26 @@ module.exports = exports = class Buffer extends Uint8Array {
|
|
|
376
373
|
return viewOf(this).getInt32(offset, true)
|
|
377
374
|
}
|
|
378
375
|
|
|
376
|
+
readIntBE(offset, byteLength) {
|
|
377
|
+
if (byteLength === 6) return readInt48BE(viewOf(this), offset)
|
|
378
|
+
if (byteLength === 5) return readInt40BE(viewOf(this), offset)
|
|
379
|
+
if (byteLength === 3) return readInt24BE(viewOf(this), offset)
|
|
380
|
+
if (byteLength === 4) return this.readInt32BE(offset)
|
|
381
|
+
if (byteLength === 2) return this.readInt16BE(offset)
|
|
382
|
+
if (byteLength === 1) return this.readInt8(offset)
|
|
383
|
+
throw new RangeError(`Byte length must be between 1 and 6`)
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
readIntLE(offset, byteLength) {
|
|
387
|
+
if (byteLength === 6) return readInt48LE(viewOf(this), offset)
|
|
388
|
+
if (byteLength === 5) return readInt40LE(viewOf(this), offset)
|
|
389
|
+
if (byteLength === 3) return readInt24LE(viewOf(this), offset)
|
|
390
|
+
if (byteLength === 4) return this.readInt32LE(offset)
|
|
391
|
+
if (byteLength === 2) return this.readInt16LE(offset)
|
|
392
|
+
if (byteLength === 1) return this.readInt8(offset)
|
|
393
|
+
throw new RangeError(`Byte length must be between 1 and 6`)
|
|
394
|
+
}
|
|
395
|
+
|
|
379
396
|
readUint8(offset = 0) {
|
|
380
397
|
return viewOf(this).getUint8(offset)
|
|
381
398
|
}
|
|
@@ -394,6 +411,26 @@ module.exports = exports = class Buffer extends Uint8Array {
|
|
|
394
411
|
return viewOf(this).getUint32(offset, true)
|
|
395
412
|
}
|
|
396
413
|
|
|
414
|
+
readUintBE(offset, byteLength) {
|
|
415
|
+
if (byteLength === 6) return readUint48BE(viewOf(this), offset)
|
|
416
|
+
if (byteLength === 5) return readUint40BE(viewOf(this), offset)
|
|
417
|
+
if (byteLength === 3) return readUint24BE(viewOf(this), offset)
|
|
418
|
+
if (byteLength === 4) return this.readUint32BE(offset)
|
|
419
|
+
if (byteLength === 2) return this.readUint16BE(offset)
|
|
420
|
+
if (byteLength === 1) return this.readUint8(offset)
|
|
421
|
+
throw new RangeError(`Byte length must be between 1 and 6`)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
readUintLE(offset, byteLength) {
|
|
425
|
+
if (byteLength === 6) return readUint48LE(viewOf(this), offset)
|
|
426
|
+
if (byteLength === 5) return readUint40LE(viewOf(this), offset)
|
|
427
|
+
if (byteLength === 3) return readUint24LE(viewOf(this), offset)
|
|
428
|
+
if (byteLength === 4) return this.readUint32LE(offset)
|
|
429
|
+
if (byteLength === 2) return this.readUint16LE(offset)
|
|
430
|
+
if (byteLength === 1) return this.readUint8(offset)
|
|
431
|
+
throw new RangeError(`Byte length must be between 1 and 6`)
|
|
432
|
+
}
|
|
433
|
+
|
|
397
434
|
readBigUInt64BE(...args) {
|
|
398
435
|
return this.readBigUint64BE(...args)
|
|
399
436
|
}
|
|
@@ -419,6 +456,13 @@ module.exports = exports = class Buffer extends Uint8Array {
|
|
|
419
456
|
return this.readUint32LE(...args)
|
|
420
457
|
}
|
|
421
458
|
|
|
459
|
+
readUIntBE(...args) {
|
|
460
|
+
return this.readUintBE(...args)
|
|
461
|
+
}
|
|
462
|
+
readUIntLE(...args) {
|
|
463
|
+
return this.readUintLE(...args)
|
|
464
|
+
}
|
|
465
|
+
|
|
422
466
|
writeBigInt64BE(value, offset = 0) {
|
|
423
467
|
viewOf(this).setBigInt64(offset, value, false)
|
|
424
468
|
return offset + 8
|
|
@@ -478,6 +522,26 @@ module.exports = exports = class Buffer extends Uint8Array {
|
|
|
478
522
|
return offset + 4
|
|
479
523
|
}
|
|
480
524
|
|
|
525
|
+
writeIntBE(value, offset, byteLength) {
|
|
526
|
+
if (byteLength === 6) return writeInt48BE(value, viewOf(this), offset)
|
|
527
|
+
if (byteLength === 5) return writeInt40BE(value, viewOf(this), offset)
|
|
528
|
+
if (byteLength === 3) return writeInt24BE(value, viewOf(this), offset)
|
|
529
|
+
if (byteLength === 4) return this.writeInt32BE(value, offset)
|
|
530
|
+
if (byteLength === 2) return this.writeInt16BE(value, offset)
|
|
531
|
+
if (byteLength === 1) return this.writeInt8(value, offset)
|
|
532
|
+
throw new RangeError(`Byte length must be between 1 and 6`)
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
writeIntLE(value, offset, byteLength) {
|
|
536
|
+
if (byteLength === 6) return writeInt48LE(value, viewOf(this), offset)
|
|
537
|
+
if (byteLength === 5) return writeInt40LE(value, viewOf(this), offset)
|
|
538
|
+
if (byteLength === 3) return writeInt24LE(value, viewOf(this), offset)
|
|
539
|
+
if (byteLength === 4) return this.writeInt32LE(value, offset)
|
|
540
|
+
if (byteLength === 2) return this.writeInt16LE(value, offset)
|
|
541
|
+
if (byteLength === 1) return this.writeInt8(value, offset)
|
|
542
|
+
throw new RangeError(`Byte length must be between 1 and 6`)
|
|
543
|
+
}
|
|
544
|
+
|
|
481
545
|
writeUint8(value, offset = 0) {
|
|
482
546
|
viewOf(this).setUint8(offset, value, true)
|
|
483
547
|
return offset + 1
|
|
@@ -501,6 +565,26 @@ module.exports = exports = class Buffer extends Uint8Array {
|
|
|
501
565
|
return offset + 4
|
|
502
566
|
}
|
|
503
567
|
|
|
568
|
+
writeUintBE(value, offset, byteLength) {
|
|
569
|
+
if (byteLength === 6) return writeUint48BE(value, viewOf(this), offset)
|
|
570
|
+
if (byteLength === 5) return writeUint40BE(value, viewOf(this), offset)
|
|
571
|
+
if (byteLength === 3) return writeUint24BE(value, viewOf(this), offset)
|
|
572
|
+
if (byteLength === 4) return this.writeUint32BE(value, offset)
|
|
573
|
+
if (byteLength === 2) return this.writeUint16BE(value, offset)
|
|
574
|
+
if (byteLength === 1) return this.writeUint8(value, offset)
|
|
575
|
+
throw new RangeError(`Byte length must be between 1 and 6`)
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
writeUintLE(value, offset, byteLength) {
|
|
579
|
+
if (byteLength === 6) return writeUint48LE(value, viewOf(this), offset)
|
|
580
|
+
if (byteLength === 5) return writeUint40LE(value, viewOf(this), offset)
|
|
581
|
+
if (byteLength === 3) return writeUint24LE(value, viewOf(this), offset)
|
|
582
|
+
if (byteLength === 4) return this.writeUint32LE(value, offset)
|
|
583
|
+
if (byteLength === 2) return this.writeUint16LE(value, offset)
|
|
584
|
+
if (byteLength === 1) return this.writeUint8(value, offset)
|
|
585
|
+
throw new RangeError(`Byte length must be between 1 and 6`)
|
|
586
|
+
}
|
|
587
|
+
|
|
504
588
|
writeBigUInt64BE(...args) {
|
|
505
589
|
return this.writeBigUint64BE(...args)
|
|
506
590
|
}
|
|
@@ -525,6 +609,13 @@ module.exports = exports = class Buffer extends Uint8Array {
|
|
|
525
609
|
writeUInt32LE(...args) {
|
|
526
610
|
return this.writeUint32LE(...args)
|
|
527
611
|
}
|
|
612
|
+
|
|
613
|
+
writeUIntBE(...args) {
|
|
614
|
+
return this.writeUintBE(...args)
|
|
615
|
+
}
|
|
616
|
+
writeUIntLE(...args) {
|
|
617
|
+
return this.writeUintLE(...args)
|
|
618
|
+
}
|
|
528
619
|
}
|
|
529
620
|
|
|
530
621
|
const Buffer = exports
|
|
@@ -630,7 +721,6 @@ exports.concat = function concat(buffers, length) {
|
|
|
630
721
|
}
|
|
631
722
|
|
|
632
723
|
result.set(buffer, offset)
|
|
633
|
-
|
|
634
724
|
offset += buffer.byteLength
|
|
635
725
|
}
|
|
636
726
|
|
|
@@ -742,3 +832,199 @@ function swap(buffer, n, m) {
|
|
|
742
832
|
buffer[n] = buffer[m]
|
|
743
833
|
buffer[m] = i
|
|
744
834
|
}
|
|
835
|
+
|
|
836
|
+
exports.atob = function atob(data) {
|
|
837
|
+
return Buffer.from(data, 'base64').toString('latin1')
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
exports.btoa = function btoa(data) {
|
|
841
|
+
if (typeof data !== 'string') data = String(data)
|
|
842
|
+
|
|
843
|
+
return Buffer.from(data, 'latin1').toString('base64')
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
function readInt48BE(view, offset) {
|
|
847
|
+
const hi = view.getUint16(offset, false)
|
|
848
|
+
const lo = view.getUint32(offset + 2, false)
|
|
849
|
+
let value = lo + hi * 0x100000000
|
|
850
|
+
if (hi & 0x8000) value -= 0x1000000000000
|
|
851
|
+
return value
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
function readInt48LE(view, offset) {
|
|
855
|
+
const lo = view.getUint32(offset, true)
|
|
856
|
+
const hi = view.getUint16(offset + 4, true)
|
|
857
|
+
let value = lo + hi * 0x100000000
|
|
858
|
+
if (hi & 0x8000) value -= 0x1000000000000
|
|
859
|
+
return value
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
function readInt40BE(view, offset) {
|
|
863
|
+
const hi = view.getUint8(offset)
|
|
864
|
+
const lo = view.getUint32(offset + 1, false)
|
|
865
|
+
let value = lo + hi * 0x100000000
|
|
866
|
+
if (hi & 0x80) value -= 0x10000000000
|
|
867
|
+
return value
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
function readInt40LE(view, offset) {
|
|
871
|
+
const lo = view.getUint32(offset, true)
|
|
872
|
+
const hi = view.getUint8(offset + 4)
|
|
873
|
+
let value = lo + hi * 0x100000000
|
|
874
|
+
if (hi & 0x80) value -= 0x10000000000
|
|
875
|
+
return value
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
function readInt24BE(view, offset) {
|
|
879
|
+
const value =
|
|
880
|
+
(view.getUint8(offset) << 16) |
|
|
881
|
+
(view.getUint8(offset + 1) << 8) |
|
|
882
|
+
view.getUint8(offset + 2)
|
|
883
|
+
return value & 0x800000 ? value - 0x1000000 : value
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
function readInt24LE(view, offset) {
|
|
887
|
+
const value =
|
|
888
|
+
view.getUint8(offset) |
|
|
889
|
+
(view.getUint8(offset + 1) << 8) |
|
|
890
|
+
(view.getUint8(offset + 2) << 16)
|
|
891
|
+
return value & 0x800000 ? value - 0x1000000 : value
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
function readUint48BE(view, offset) {
|
|
895
|
+
const hi = view.getUint16(offset, false)
|
|
896
|
+
const lo = view.getUint32(offset + 2, false)
|
|
897
|
+
return lo + hi * 0x100000000
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
function readUint48LE(view, offset) {
|
|
901
|
+
const lo = view.getUint32(offset, true)
|
|
902
|
+
const hi = view.getUint16(offset + 4, true)
|
|
903
|
+
return lo + hi * 0x100000000
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
function readUint40BE(view, offset) {
|
|
907
|
+
const hi = view.getUint8(offset)
|
|
908
|
+
const lo = view.getUint32(offset + 1, false)
|
|
909
|
+
return lo + hi * 0x100000000
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
function readUint40LE(view, offset) {
|
|
913
|
+
const lo = view.getUint32(offset, true)
|
|
914
|
+
const hi = view.getUint8(offset + 4)
|
|
915
|
+
return lo + hi * 0x100000000
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
function readUint24BE(view, offset) {
|
|
919
|
+
return (
|
|
920
|
+
(view.getUint8(offset) << 16) |
|
|
921
|
+
(view.getUint8(offset + 1) << 8) |
|
|
922
|
+
view.getUint8(offset + 2)
|
|
923
|
+
)
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
function readUint24LE(view, offset) {
|
|
927
|
+
return (
|
|
928
|
+
view.getUint8(offset) |
|
|
929
|
+
(view.getUint8(offset + 1) << 8) |
|
|
930
|
+
(view.getUint8(offset + 2) << 16)
|
|
931
|
+
)
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
function writeInt48BE(value, view, offset) {
|
|
935
|
+
if (value < 0) value += 0x1000000000000
|
|
936
|
+
const hi = Math.floor(value / 0x100000000)
|
|
937
|
+
const lo = value >>> 0
|
|
938
|
+
view.setUint16(offset, hi, false)
|
|
939
|
+
view.setUint32(offset + 2, lo, false)
|
|
940
|
+
return offset + 6
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
function writeInt48LE(value, view, offset) {
|
|
944
|
+
if (value < 0) value += 0x1000000000000
|
|
945
|
+
const hi = Math.floor(value / 0x100000000)
|
|
946
|
+
const lo = value >>> 0
|
|
947
|
+
view.setUint32(offset, lo, true)
|
|
948
|
+
view.setUint16(offset + 4, hi, true)
|
|
949
|
+
return offset + 6
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
function writeInt40BE(value, view, offset) {
|
|
953
|
+
if (value < 0) value += 0x10000000000
|
|
954
|
+
const hi = Math.floor(value / 0x100000000)
|
|
955
|
+
const lo = value >>> 0
|
|
956
|
+
view.setUint8(offset, hi)
|
|
957
|
+
view.setUint32(offset + 1, lo, false)
|
|
958
|
+
return offset + 5
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
function writeInt40LE(value, view, offset) {
|
|
962
|
+
if (value < 0) value += 0x10000000000
|
|
963
|
+
const hi = Math.floor(value / 0x100000000)
|
|
964
|
+
const lo = value >>> 0
|
|
965
|
+
view.setUint32(offset, lo, true)
|
|
966
|
+
view.setUint8(offset + 4, hi)
|
|
967
|
+
return offset + 5
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
function writeInt24BE(value, view, offset) {
|
|
971
|
+
if (value < 0) value += 0x1000000
|
|
972
|
+
view.setUint8(offset, (value >> 16) & 0xff)
|
|
973
|
+
view.setUint8(offset + 1, (value >> 8) & 0xff)
|
|
974
|
+
view.setUint8(offset + 2, value & 0xff)
|
|
975
|
+
return offset + 3
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
function writeInt24LE(value, view, offset) {
|
|
979
|
+
if (value < 0) value += 0x1000000
|
|
980
|
+
view.setUint8(offset, value & 0xff)
|
|
981
|
+
view.setUint8(offset + 1, (value >> 8) & 0xff)
|
|
982
|
+
view.setUint8(offset + 2, (value >> 16) & 0xff)
|
|
983
|
+
return offset + 3
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
function writeUint48BE(value, view, offset) {
|
|
987
|
+
const hi = Math.floor(value / 0x100000000)
|
|
988
|
+
const lo = value >>> 0
|
|
989
|
+
view.setUint16(offset, hi, false)
|
|
990
|
+
view.setUint32(offset + 2, lo, false)
|
|
991
|
+
return offset + 6
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
function writeUint48LE(value, view, offset) {
|
|
995
|
+
const hi = Math.floor(value / 0x100000000)
|
|
996
|
+
const lo = value >>> 0
|
|
997
|
+
view.setUint32(offset, lo, true)
|
|
998
|
+
view.setUint16(offset + 4, hi, true)
|
|
999
|
+
return offset + 6
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
function writeUint40BE(value, view, offset) {
|
|
1003
|
+
const hi = Math.floor(value / 0x100000000)
|
|
1004
|
+
const lo = value >>> 0
|
|
1005
|
+
view.setUint8(offset, hi)
|
|
1006
|
+
view.setUint32(offset + 1, lo, false)
|
|
1007
|
+
return offset + 5
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
function writeUint40LE(value, view, offset) {
|
|
1011
|
+
const hi = Math.floor(value / 0x100000000)
|
|
1012
|
+
const lo = value >>> 0
|
|
1013
|
+
view.setUint32(offset, lo, true)
|
|
1014
|
+
view.setUint8(offset + 4, hi)
|
|
1015
|
+
return offset + 5
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
function writeUint24BE(value, view, offset) {
|
|
1019
|
+
view.setUint8(offset, (value >> 16) & 0xff)
|
|
1020
|
+
view.setUint8(offset + 1, (value >> 8) & 0xff)
|
|
1021
|
+
view.setUint8(offset + 2, value & 0xff)
|
|
1022
|
+
return offset + 3
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
function writeUint24LE(value, view, offset) {
|
|
1026
|
+
view.setUint8(offset, value & 0xff)
|
|
1027
|
+
view.setUint8(offset + 1, (value >> 8) & 0xff)
|
|
1028
|
+
view.setUint8(offset + 2, (value >> 16) & 0xff)
|
|
1029
|
+
return offset + 3
|
|
1030
|
+
}
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|