@bare-ts/lib 0.3.0 → 0.5.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/LICENSE +21 -201
- package/README.md +7 -8
- package/dist/codec/data.d.ts +1 -1
- package/dist/codec/data.js +10 -12
- package/dist/codec/float-array.d.ts +7 -12
- package/dist/codec/float-array.js +53 -45
- package/dist/codec/i16-array.d.ts +4 -7
- package/dist/codec/i16-array.js +35 -27
- package/dist/codec/i32-array.d.ts +4 -7
- package/dist/codec/i32-array.js +35 -27
- package/dist/codec/i64-array.d.ts +4 -7
- package/dist/codec/i64-array.js +35 -27
- package/dist/codec/i8-array.d.ts +3 -3
- package/dist/codec/i8-array.js +12 -14
- package/dist/codec/primitive.d.ts +3 -1
- package/dist/codec/primitive.js +227 -149
- package/dist/codec/string.d.ts +1 -1
- package/dist/codec/string.js +45 -31
- package/dist/codec/u16-array.d.ts +4 -7
- package/dist/codec/u16-array.js +35 -27
- package/dist/codec/u32-array.d.ts +4 -7
- package/dist/codec/u32-array.js +35 -27
- package/dist/codec/u64-array.d.ts +4 -7
- package/dist/codec/u64-array.js +35 -27
- package/dist/codec/u8-array.d.ts +9 -3
- package/dist/codec/u8-array.js +23 -18
- package/dist/codec/u8-clamped-array.d.ts +3 -3
- package/dist/codec/u8-clamped-array.js +13 -15
- package/dist/core/bare-error.d.ts +4 -1
- package/dist/core/bare-error.js +4 -8
- package/dist/core/byte-cursor.d.ts +22 -28
- package/dist/core/byte-cursor.js +33 -29
- package/dist/core/config.d.ts +4 -10
- package/dist/core/config.js +15 -20
- package/dist/env/dev.d.ts +1 -0
- package/dist/env/dev.development.d.ts +1 -0
- package/dist/env/dev.development.js +2 -0
- package/dist/env/dev.js +2 -0
- package/dist/env/dev.node.d.ts +1 -0
- package/dist/env/dev.node.js +2 -0
- package/dist/index.cjs +545 -324
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +16 -2
- package/dist/index.js +17 -4
- package/dist/util/assert.d.ts +6 -8
- package/dist/util/assert.js +10 -13
- package/dist/util/constants.d.ts +4 -7
- package/dist/util/constants.js +11 -30
- package/dist/util/validator.d.ts +1 -1
- package/dist/util/validator.js +12 -24
- package/package.json +31 -25
- package/dist/codec/index.d.ts +0 -13
- package/dist/codec/index.js +0 -15
- package/dist/core/index.d.ts +0 -3
- package/dist/core/index.js +0 -5
- package/dist/util/util.d.ts +0 -1
- package/dist/util/util.js +0 -6
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare const readU16FixedArray:
|
|
3
|
-
export declare function readU16Array(bc: ByteCursor): Uint16Array
|
|
4
|
-
declare
|
|
5
|
-
export declare const writeU16FixedArray: typeof writeU16FixedArrayLE;
|
|
1
|
+
import { type ByteCursor } from "../core/byte-cursor.js";
|
|
2
|
+
export declare const readU16FixedArray: (bc: ByteCursor, len: number) => Uint16Array<ArrayBuffer>;
|
|
3
|
+
export declare function readU16Array(bc: ByteCursor): Uint16Array<ArrayBuffer>;
|
|
4
|
+
export declare const writeU16FixedArray: (bc: ByteCursor, x: Uint16Array) => void;
|
|
6
5
|
export declare function writeU16Array(bc: ByteCursor, x: Uint16Array): void;
|
|
7
|
-
declare function writeU16FixedArrayLE(bc: ByteCursor, x: Uint16Array): void;
|
|
8
|
-
export {};
|
package/dist/codec/u16-array.js
CHANGED
|
@@ -1,43 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
"use strict";
|
|
2
|
+
import { check, reserve } from "../core/byte-cursor.js";
|
|
3
|
+
import { assert, DEV } from "../util/assert.js";
|
|
4
|
+
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/constants.js";
|
|
5
|
+
import { isU32 } from "../util/validator.js";
|
|
4
6
|
import { readFixedData } from "./data.js";
|
|
5
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
readU16,
|
|
9
|
+
readUintSafe32,
|
|
10
|
+
writeU16,
|
|
11
|
+
writeUintSafe32
|
|
12
|
+
} from "./primitive.js";
|
|
6
13
|
import { writeU8FixedArray } from "./u8-array.js";
|
|
7
|
-
|
|
8
|
-
function readU16Array(bc) {
|
|
9
|
-
return readU16FixedArray(bc,
|
|
14
|
+
export const readU16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readU16FixedArrayLe : readU16FixedArrayBe;
|
|
15
|
+
export function readU16Array(bc) {
|
|
16
|
+
return readU16FixedArray(bc, readUintSafe32(bc));
|
|
10
17
|
}
|
|
11
|
-
function
|
|
12
|
-
|
|
18
|
+
function readU16FixedArrayLe(bc, len) {
|
|
19
|
+
if (DEV) {
|
|
20
|
+
assert(isU32(len));
|
|
21
|
+
}
|
|
22
|
+
const byteCount = len * 2;
|
|
13
23
|
return new Uint16Array(readFixedData(bc, byteCount));
|
|
14
24
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
25
|
+
function readU16FixedArrayBe(bc, len) {
|
|
26
|
+
if (DEV) {
|
|
27
|
+
assert(isU32(len));
|
|
28
|
+
}
|
|
29
|
+
check(bc, len * 2);
|
|
17
30
|
const result = new Uint16Array(len);
|
|
18
|
-
for (let i = 0; i < len; i++)
|
|
31
|
+
for (let i = 0; i < len; i++) {
|
|
19
32
|
result[i] = readU16(bc);
|
|
33
|
+
}
|
|
20
34
|
return result;
|
|
21
35
|
}
|
|
22
|
-
|
|
23
|
-
function writeU16Array(bc, x) {
|
|
24
|
-
|
|
25
|
-
if (x.length
|
|
36
|
+
export const writeU16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeU16FixedArrayLe : writeU16FixedArrayBe;
|
|
37
|
+
export function writeU16Array(bc, x) {
|
|
38
|
+
writeUintSafe32(bc, x.length);
|
|
39
|
+
if (x.length > 0) {
|
|
26
40
|
writeU16FixedArray(bc, x);
|
|
27
41
|
}
|
|
28
42
|
}
|
|
29
|
-
function
|
|
43
|
+
function writeU16FixedArrayLe(bc, x) {
|
|
30
44
|
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
31
45
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
for (let i = 0; i < x.length; i++)
|
|
46
|
+
function writeU16FixedArrayBe(bc, x) {
|
|
47
|
+
reserve(bc, x.length * 2);
|
|
48
|
+
for (let i = 0; i < x.length; i++) {
|
|
35
49
|
writeU16(bc, x[i]);
|
|
50
|
+
}
|
|
36
51
|
}
|
|
37
|
-
export {
|
|
38
|
-
readU16Array,
|
|
39
|
-
readU16FixedArray,
|
|
40
|
-
writeU16Array,
|
|
41
|
-
writeU16FixedArray
|
|
42
|
-
};
|
|
43
|
-
//# sourceMappingURL=u16-array.js.map
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare const readU32FixedArray:
|
|
3
|
-
export declare function readU32Array(bc: ByteCursor): Uint32Array
|
|
4
|
-
declare
|
|
5
|
-
export declare const writeU32FixedArray: typeof writeU32FixedArrayLE;
|
|
1
|
+
import { type ByteCursor } from "../core/byte-cursor.js";
|
|
2
|
+
export declare const readU32FixedArray: (bc: ByteCursor, len: number) => Uint32Array<ArrayBuffer>;
|
|
3
|
+
export declare function readU32Array(bc: ByteCursor): Uint32Array<ArrayBuffer>;
|
|
4
|
+
export declare const writeU32FixedArray: (bc: ByteCursor, x: Uint32Array) => void;
|
|
6
5
|
export declare function writeU32Array(bc: ByteCursor, x: Uint32Array): void;
|
|
7
|
-
declare function writeU32FixedArrayLE(bc: ByteCursor, x: Uint32Array): void;
|
|
8
|
-
export {};
|
package/dist/codec/u32-array.js
CHANGED
|
@@ -1,43 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
"use strict";
|
|
2
|
+
import { check, reserve } from "../core/byte-cursor.js";
|
|
3
|
+
import { assert, DEV } from "../util/assert.js";
|
|
4
|
+
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/constants.js";
|
|
5
|
+
import { isU32 } from "../util/validator.js";
|
|
4
6
|
import { readFixedData } from "./data.js";
|
|
5
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
readU32,
|
|
9
|
+
readUintSafe32,
|
|
10
|
+
writeU32,
|
|
11
|
+
writeUintSafe32
|
|
12
|
+
} from "./primitive.js";
|
|
6
13
|
import { writeU8FixedArray } from "./u8-array.js";
|
|
7
|
-
|
|
8
|
-
function readU32Array(bc) {
|
|
9
|
-
return readU32FixedArray(bc,
|
|
14
|
+
export const readU32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readU32FixedArrayLe : readU32FixedArrayBe;
|
|
15
|
+
export function readU32Array(bc) {
|
|
16
|
+
return readU32FixedArray(bc, readUintSafe32(bc));
|
|
10
17
|
}
|
|
11
|
-
function
|
|
12
|
-
|
|
18
|
+
function readU32FixedArrayLe(bc, len) {
|
|
19
|
+
if (DEV) {
|
|
20
|
+
assert(isU32(len));
|
|
21
|
+
}
|
|
22
|
+
const byteCount = len * 4;
|
|
13
23
|
return new Uint32Array(readFixedData(bc, byteCount));
|
|
14
24
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
25
|
+
function readU32FixedArrayBe(bc, len) {
|
|
26
|
+
if (DEV) {
|
|
27
|
+
assert(isU32(len));
|
|
28
|
+
}
|
|
29
|
+
check(bc, len * 4);
|
|
17
30
|
const result = new Uint32Array(len);
|
|
18
|
-
for (let i = 0; i < len; i++)
|
|
31
|
+
for (let i = 0; i < len; i++) {
|
|
19
32
|
result[i] = readU32(bc);
|
|
33
|
+
}
|
|
20
34
|
return result;
|
|
21
35
|
}
|
|
22
|
-
|
|
23
|
-
function writeU32Array(bc, x) {
|
|
24
|
-
|
|
25
|
-
if (x.length
|
|
36
|
+
export const writeU32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeU32FixedArrayLe : writeU32FixedArrayBe;
|
|
37
|
+
export function writeU32Array(bc, x) {
|
|
38
|
+
writeUintSafe32(bc, x.length);
|
|
39
|
+
if (x.length > 0) {
|
|
26
40
|
writeU32FixedArray(bc, x);
|
|
27
41
|
}
|
|
28
42
|
}
|
|
29
|
-
function
|
|
43
|
+
function writeU32FixedArrayLe(bc, x) {
|
|
30
44
|
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
31
45
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
for (let i = 0; i < x.length; i++)
|
|
46
|
+
function writeU32FixedArrayBe(bc, x) {
|
|
47
|
+
reserve(bc, x.length * 4);
|
|
48
|
+
for (let i = 0; i < x.length; i++) {
|
|
35
49
|
writeU32(bc, x[i]);
|
|
50
|
+
}
|
|
36
51
|
}
|
|
37
|
-
export {
|
|
38
|
-
readU32Array,
|
|
39
|
-
readU32FixedArray,
|
|
40
|
-
writeU32Array,
|
|
41
|
-
writeU32FixedArray
|
|
42
|
-
};
|
|
43
|
-
//# sourceMappingURL=u32-array.js.map
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare const readU64FixedArray:
|
|
3
|
-
export declare function readU64Array(bc: ByteCursor): BigUint64Array
|
|
4
|
-
declare
|
|
5
|
-
export declare const writeU64FixedArray: typeof writeU64FixedArrayLE;
|
|
1
|
+
import { type ByteCursor } from "../core/byte-cursor.js";
|
|
2
|
+
export declare const readU64FixedArray: (bc: ByteCursor, len: number) => BigUint64Array<ArrayBuffer>;
|
|
3
|
+
export declare function readU64Array(bc: ByteCursor): BigUint64Array<ArrayBuffer>;
|
|
4
|
+
export declare const writeU64FixedArray: (bc: ByteCursor, x: BigUint64Array) => void;
|
|
6
5
|
export declare function writeU64Array(bc: ByteCursor, x: BigUint64Array): void;
|
|
7
|
-
declare function writeU64FixedArrayLE(bc: ByteCursor, x: BigUint64Array): void;
|
|
8
|
-
export {};
|
package/dist/codec/u64-array.js
CHANGED
|
@@ -1,43 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
"use strict";
|
|
2
|
+
import { check, reserve } from "../core/byte-cursor.js";
|
|
3
|
+
import { assert, DEV } from "../util/assert.js";
|
|
4
|
+
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/constants.js";
|
|
5
|
+
import { isU32 } from "../util/validator.js";
|
|
4
6
|
import { readFixedData } from "./data.js";
|
|
5
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
readU64,
|
|
9
|
+
readUintSafe32,
|
|
10
|
+
writeU64,
|
|
11
|
+
writeUintSafe32
|
|
12
|
+
} from "./primitive.js";
|
|
6
13
|
import { writeU8FixedArray } from "./u8-array.js";
|
|
7
|
-
|
|
8
|
-
function readU64Array(bc) {
|
|
9
|
-
return readU64FixedArray(bc,
|
|
14
|
+
export const readU64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readU64FixedArrayLe : readU64FixedArrayBe;
|
|
15
|
+
export function readU64Array(bc) {
|
|
16
|
+
return readU64FixedArray(bc, readUintSafe32(bc));
|
|
10
17
|
}
|
|
11
|
-
function
|
|
12
|
-
|
|
18
|
+
function readU64FixedArrayLe(bc, len) {
|
|
19
|
+
if (DEV) {
|
|
20
|
+
assert(isU32(len));
|
|
21
|
+
}
|
|
22
|
+
const byteCount = len * 8;
|
|
13
23
|
return new BigUint64Array(readFixedData(bc, byteCount));
|
|
14
24
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
25
|
+
function readU64FixedArrayBe(bc, len) {
|
|
26
|
+
if (DEV) {
|
|
27
|
+
assert(isU32(len));
|
|
28
|
+
}
|
|
29
|
+
check(bc, len * 8);
|
|
17
30
|
const result = new BigUint64Array(len);
|
|
18
|
-
for (let i = 0; i < len; i++)
|
|
31
|
+
for (let i = 0; i < len; i++) {
|
|
19
32
|
result[i] = readU64(bc);
|
|
33
|
+
}
|
|
20
34
|
return result;
|
|
21
35
|
}
|
|
22
|
-
|
|
23
|
-
function writeU64Array(bc, x) {
|
|
24
|
-
|
|
25
|
-
if (x.length
|
|
36
|
+
export const writeU64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeU64FixedArrayLe : writeU64FixedArrayBe;
|
|
37
|
+
export function writeU64Array(bc, x) {
|
|
38
|
+
writeUintSafe32(bc, x.length);
|
|
39
|
+
if (x.length > 0) {
|
|
26
40
|
writeU64FixedArray(bc, x);
|
|
27
41
|
}
|
|
28
42
|
}
|
|
29
|
-
function
|
|
43
|
+
function writeU64FixedArrayLe(bc, x) {
|
|
30
44
|
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
31
45
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
for (let i = 0; i < x.length; i++)
|
|
46
|
+
function writeU64FixedArrayBe(bc, x) {
|
|
47
|
+
reserve(bc, x.length * 8);
|
|
48
|
+
for (let i = 0; i < x.length; i++) {
|
|
35
49
|
writeU64(bc, x[i]);
|
|
50
|
+
}
|
|
36
51
|
}
|
|
37
|
-
export {
|
|
38
|
-
readU64Array,
|
|
39
|
-
readU64FixedArray,
|
|
40
|
-
writeU64Array,
|
|
41
|
-
writeU64FixedArray
|
|
42
|
-
};
|
|
43
|
-
//# sourceMappingURL=u64-array.js.map
|
package/dist/codec/u8-array.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare function readU8Array(bc: ByteCursor): Uint8Array
|
|
1
|
+
import { type ByteCursor } from "../core/byte-cursor.js";
|
|
2
|
+
export declare function readU8Array(bc: ByteCursor): Uint8Array<ArrayBuffer>;
|
|
3
3
|
export declare function writeU8Array(bc: ByteCursor, x: Uint8Array): void;
|
|
4
|
-
export declare function readU8FixedArray(bc: ByteCursor, len: number): Uint8Array
|
|
4
|
+
export declare function readU8FixedArray(bc: ByteCursor, len: number): Uint8Array<ArrayBuffer>;
|
|
5
5
|
export declare function writeU8FixedArray(bc: ByteCursor, x: Uint8Array): void;
|
|
6
|
+
/**
|
|
7
|
+
* Advance `bc` by `len` bytes and return a view of the read bytes.
|
|
8
|
+
*
|
|
9
|
+
* WARNING: The returned array should not be modified.
|
|
10
|
+
*/
|
|
11
|
+
export declare function readUnsafeU8FixedArray(bc: ByteCursor, len: number): Uint8Array;
|
package/dist/codec/u8-array.js
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
import { check, reserve } from "../core/byte-cursor.js";
|
|
3
|
+
import { assert, DEV } from "../util/assert.js";
|
|
4
|
+
import { isU32 } from "../util/validator.js";
|
|
5
|
+
import { readUintSafe32, writeUintSafe32 } from "./primitive.js";
|
|
6
|
+
export function readU8Array(bc) {
|
|
7
|
+
return readU8FixedArray(bc, readUintSafe32(bc));
|
|
5
8
|
}
|
|
6
|
-
function writeU8Array(bc, x) {
|
|
7
|
-
|
|
9
|
+
export function writeU8Array(bc, x) {
|
|
10
|
+
writeUintSafe32(bc, x.length);
|
|
8
11
|
writeU8FixedArray(bc, x);
|
|
9
12
|
}
|
|
10
|
-
function readU8FixedArray(bc, len) {
|
|
11
|
-
return bc
|
|
13
|
+
export function readU8FixedArray(bc, len) {
|
|
14
|
+
return readUnsafeU8FixedArray(bc, len).slice();
|
|
12
15
|
}
|
|
13
|
-
function writeU8FixedArray(bc, x) {
|
|
16
|
+
export function writeU8FixedArray(bc, x) {
|
|
14
17
|
const len = x.length;
|
|
15
|
-
if (len
|
|
16
|
-
|
|
18
|
+
if (len > 0) {
|
|
19
|
+
reserve(bc, len);
|
|
17
20
|
bc.bytes.set(x, bc.offset);
|
|
18
21
|
bc.offset += len;
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
|
-
export {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
export function readUnsafeU8FixedArray(bc, len) {
|
|
25
|
+
if (DEV) {
|
|
26
|
+
assert(isU32(len));
|
|
27
|
+
}
|
|
28
|
+
check(bc, len);
|
|
29
|
+
const offset = bc.offset;
|
|
30
|
+
bc.offset += len;
|
|
31
|
+
return bc.bytes.subarray(offset, offset + len);
|
|
32
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ByteCursor } from "../core/
|
|
2
|
-
export declare function readU8ClampedArray(bc: ByteCursor): Uint8ClampedArray
|
|
1
|
+
import type { ByteCursor } from "../core/byte-cursor.js";
|
|
2
|
+
export declare function readU8ClampedArray(bc: ByteCursor): Uint8ClampedArray<ArrayBuffer>;
|
|
3
3
|
export declare function writeU8ClampedArray(bc: ByteCursor, x: Uint8ClampedArray): void;
|
|
4
|
-
export declare function readU8ClampedFixedArray(bc: ByteCursor, len: number): Uint8ClampedArray
|
|
4
|
+
export declare function readU8ClampedFixedArray(bc: ByteCursor, len: number): Uint8ClampedArray<ArrayBuffer>;
|
|
5
5
|
export declare function writeU8ClampedFixedArray(bc: ByteCursor, x: Uint8ClampedArray): void;
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
import { assert, DEV } from "../util/assert.js";
|
|
3
|
+
import { isU32 } from "../util/validator.js";
|
|
2
4
|
import { readFixedData } from "./data.js";
|
|
3
|
-
import {
|
|
5
|
+
import { readUintSafe32, writeUintSafe32 } from "./primitive.js";
|
|
4
6
|
import { writeU8FixedArray } from "./u8-array.js";
|
|
5
|
-
function readU8ClampedArray(bc) {
|
|
6
|
-
return readU8ClampedFixedArray(bc,
|
|
7
|
+
export function readU8ClampedArray(bc) {
|
|
8
|
+
return readU8ClampedFixedArray(bc, readUintSafe32(bc));
|
|
7
9
|
}
|
|
8
|
-
function writeU8ClampedArray(bc, x) {
|
|
9
|
-
|
|
10
|
+
export function writeU8ClampedArray(bc, x) {
|
|
11
|
+
writeUintSafe32(bc, x.length);
|
|
10
12
|
writeU8ClampedFixedArray(bc, x);
|
|
11
13
|
}
|
|
12
|
-
function readU8ClampedFixedArray(bc, len) {
|
|
14
|
+
export function readU8ClampedFixedArray(bc, len) {
|
|
15
|
+
if (DEV) {
|
|
16
|
+
assert(isU32(len));
|
|
17
|
+
}
|
|
13
18
|
return new Uint8ClampedArray(readFixedData(bc, len));
|
|
14
19
|
}
|
|
15
|
-
function writeU8ClampedFixedArray(bc, x) {
|
|
20
|
+
export function writeU8ClampedFixedArray(bc, x) {
|
|
16
21
|
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
17
22
|
}
|
|
18
|
-
export {
|
|
19
|
-
readU8ClampedArray,
|
|
20
|
-
readU8ClampedFixedArray,
|
|
21
|
-
writeU8ClampedArray,
|
|
22
|
-
writeU8ClampedFixedArray
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=u8-clamped-array.js.map
|
package/dist/core/bare-error.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
export class BareError extends Error {
|
|
3
3
|
constructor(offset, issue, opts) {
|
|
4
4
|
super(`(byte:${offset}) ${issue}`);
|
|
5
5
|
this.name = "BareError";
|
|
6
6
|
this.issue = issue;
|
|
7
7
|
this.offset = offset;
|
|
8
|
-
this.cause = opts
|
|
8
|
+
this.cause = opts?.cause;
|
|
9
9
|
}
|
|
10
|
-
}
|
|
11
|
-
export {
|
|
12
|
-
BareError
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=bare-error.js.map
|
|
10
|
+
}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import type { Config } from "./config.js";
|
|
2
2
|
/**
|
|
3
|
-
* @invariant bytes.buffer === view.buffer
|
|
4
|
-
* @invariant bytes.byteOffset === view.byteOffset
|
|
5
|
-
* @invariant bytes.byteLength === view.byteLength
|
|
6
|
-
* @invariant 0 <= offset <= bytes.byteLength
|
|
7
|
-
* @invariant bytes.byteLength <= config.maxBufferLength
|
|
3
|
+
* @invariant `bytes.buffer === view.buffer`
|
|
4
|
+
* @invariant `bytes.byteOffset === view.byteOffset`
|
|
5
|
+
* @invariant `bytes.byteLength === view.byteLength`
|
|
6
|
+
* @invariant `0 <= offset <= bytes.byteLength`
|
|
7
|
+
* @invariant `bytes.byteLength <= config.maxBufferLength`
|
|
8
8
|
*
|
|
9
|
+
* ```txt
|
|
9
10
|
* | {bytes,view}.buffer |
|
|
10
11
|
* | bytes |
|
|
11
12
|
* | view |
|
|
12
13
|
* |<------ offset ------>|
|
|
13
14
|
* |<----------- config.maxBufferLength ------------>|
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @sealed
|
|
14
18
|
*/
|
|
15
19
|
export declare class ByteCursor {
|
|
16
20
|
bytes: Uint8Array;
|
|
@@ -21,29 +25,19 @@ export declare class ByteCursor {
|
|
|
21
25
|
offset: number;
|
|
22
26
|
view: DataView;
|
|
23
27
|
/**
|
|
24
|
-
* @
|
|
25
|
-
* @param config runtime configuration
|
|
26
|
-
* @throw BareError when the buffer exceeds the maximum allowed length
|
|
27
|
-
* `config.maxBufferLength`
|
|
28
|
+
* @throws {BareError} Buffer exceeds `config.maxBufferLength`
|
|
28
29
|
*/
|
|
29
30
|
constructor(bytes: Uint8Array, config: Config);
|
|
30
|
-
/**
|
|
31
|
-
* @param min number of needed bytes
|
|
32
|
-
* @throw BareError when there is not enough bytes
|
|
33
|
-
*/
|
|
34
|
-
check(min: number): void;
|
|
35
|
-
/**
|
|
36
|
-
* @param min number of bytes to reserve
|
|
37
|
-
* @throw BareError when the buffer exceeds the maximum allowed length
|
|
38
|
-
* `config.maxBufferLength`
|
|
39
|
-
*/
|
|
40
|
-
reserve(min: number): void;
|
|
41
|
-
/**
|
|
42
|
-
* Advance cursor by {@code len} bytes and return a view of the read bytes.
|
|
43
|
-
* The returned array should not be modified.
|
|
44
|
-
*
|
|
45
|
-
* @param len number of bytes to read
|
|
46
|
-
* @returns read bytes
|
|
47
|
-
*/
|
|
48
|
-
read(len: number): Uint8Array;
|
|
49
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Check that `min` number of bytes are available.
|
|
34
|
+
*
|
|
35
|
+
* @throws {BareError} bytes are missing.
|
|
36
|
+
*/
|
|
37
|
+
export declare function check(bc: ByteCursor, min: number): void;
|
|
38
|
+
/**
|
|
39
|
+
* Reserve `min` number of bytes.
|
|
40
|
+
*
|
|
41
|
+
* @throws {BareError} Buffer exceeds `config.maxBufferLength`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function reserve(bc: ByteCursor, min: number): void;
|
package/dist/core/byte-cursor.js
CHANGED
|
@@ -1,42 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
import { assert, DEV } from "../util/assert.js";
|
|
2
3
|
import { TOO_LARGE_BUFFER } from "../util/constants.js";
|
|
4
|
+
import { isU32 } from "../util/validator.js";
|
|
3
5
|
import { BareError } from "./bare-error.js";
|
|
4
|
-
|
|
6
|
+
export class ByteCursor {
|
|
7
|
+
/**
|
|
8
|
+
* @throws {BareError} Buffer exceeds `config.maxBufferLength`
|
|
9
|
+
*/
|
|
5
10
|
constructor(bytes, config) {
|
|
11
|
+
/**
|
|
12
|
+
* Read and write Offset in {@link view} and {@link bytes}
|
|
13
|
+
*/
|
|
14
|
+
this.offset = 0;
|
|
6
15
|
if (bytes.length > config.maxBufferLength) {
|
|
7
16
|
throw new BareError(0, TOO_LARGE_BUFFER);
|
|
8
17
|
}
|
|
9
18
|
this.bytes = bytes;
|
|
10
19
|
this.config = config;
|
|
11
|
-
this.offset = 0;
|
|
12
20
|
this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.length);
|
|
13
21
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
}
|
|
23
|
+
export function check(bc, min) {
|
|
24
|
+
if (DEV) {
|
|
25
|
+
assert(isU32(min));
|
|
18
26
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (minLen > this.bytes.length) {
|
|
22
|
-
if (minLen > this.config.maxBufferLength) {
|
|
23
|
-
throw new BareError(0, TOO_LARGE_BUFFER);
|
|
24
|
-
}
|
|
25
|
-
const newLen = Math.min(minLen << 1, this.config.maxBufferLength);
|
|
26
|
-
const newBytes = new Uint8Array(newLen);
|
|
27
|
-
newBytes.set(this.bytes);
|
|
28
|
-
this.bytes = newBytes;
|
|
29
|
-
this.view = new DataView(newBytes.buffer);
|
|
30
|
-
}
|
|
27
|
+
if (bc.offset + min > bc.bytes.length) {
|
|
28
|
+
throw new BareError(bc.offset, "missing bytes");
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
}
|
|
31
|
+
export function reserve(bc, min) {
|
|
32
|
+
if (DEV) {
|
|
33
|
+
assert(isU32(min));
|
|
34
|
+
}
|
|
35
|
+
const minLen = bc.offset + min | 0;
|
|
36
|
+
if (minLen > bc.bytes.length) {
|
|
37
|
+
if (minLen > bc.config.maxBufferLength) {
|
|
38
|
+
throw new BareError(0, TOO_LARGE_BUFFER);
|
|
39
|
+
}
|
|
40
|
+
const newLen = Math.min(minLen << 1, bc.config.maxBufferLength);
|
|
41
|
+
const newBytes = new Uint8Array(newLen);
|
|
42
|
+
newBytes.set(bc.bytes);
|
|
43
|
+
bc.bytes = newBytes;
|
|
44
|
+
bc.view = new DataView(newBytes.buffer);
|
|
37
45
|
}
|
|
38
|
-
}
|
|
39
|
-
export {
|
|
40
|
-
ByteCursor
|
|
41
|
-
};
|
|
42
|
-
//# sourceMappingURL=byte-cursor.js.map
|
|
46
|
+
}
|
package/dist/core/config.d.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type Config = {
|
|
2
2
|
readonly initialBufferLength: number;
|
|
3
3
|
readonly maxBufferLength: number;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare function Config({ initialBufferLength, maxBufferLength, textDecoderThreshold, textEncoderThreshold, }: {
|
|
8
|
-
initialBufferLength?: number | undefined;
|
|
9
|
-
maxBufferLength?: number | undefined;
|
|
10
|
-
textDecoderThreshold?: number | undefined;
|
|
11
|
-
textEncoderThreshold?: number | undefined;
|
|
12
|
-
}): Config;
|
|
4
|
+
};
|
|
5
|
+
export declare function Config({ initialBufferLength, maxBufferLength, }: Partial<Config>): Config;
|
|
6
|
+
export declare const DEFAULT_CONFIG: Config;
|
package/dist/core/config.js
CHANGED
|
@@ -1,27 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
import { assert } from "../util/assert.js";
|
|
1
|
+
"use strict";
|
|
2
|
+
import { assert, DEV } from "../util/assert.js";
|
|
3
3
|
import { TOO_LARGE_NUMBER } from "../util/constants.js";
|
|
4
4
|
import { isU32 } from "../util/validator.js";
|
|
5
|
-
function Config({
|
|
5
|
+
export function Config({
|
|
6
6
|
initialBufferLength = 1024,
|
|
7
|
-
maxBufferLength = 1024 * 1024 * 32
|
|
8
|
-
textDecoderThreshold = 256,
|
|
9
|
-
textEncoderThreshold = 256
|
|
7
|
+
maxBufferLength = 1024 * 1024 * 32
|
|
10
8
|
}) {
|
|
11
|
-
|
|
9
|
+
if (DEV) {
|
|
10
|
+
assert(isU32(initialBufferLength), TOO_LARGE_NUMBER);
|
|
11
|
+
assert(isU32(maxBufferLength), TOO_LARGE_NUMBER);
|
|
12
|
+
assert(
|
|
13
|
+
initialBufferLength <= maxBufferLength,
|
|
14
|
+
"initialBufferLength must be lower than or equal to maxBufferLength"
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
12
18
|
initialBufferLength,
|
|
13
|
-
maxBufferLength
|
|
14
|
-
textDecoderThreshold,
|
|
15
|
-
textEncoderThreshold
|
|
19
|
+
maxBufferLength
|
|
16
20
|
};
|
|
17
|
-
assert(isU32(config.initialBufferLength), TOO_LARGE_NUMBER);
|
|
18
|
-
assert(isU32(config.maxBufferLength), TOO_LARGE_NUMBER);
|
|
19
|
-
assert(isU32(config.textDecoderThreshold), TOO_LARGE_NUMBER);
|
|
20
|
-
assert(isU32(config.textEncoderThreshold), TOO_LARGE_NUMBER);
|
|
21
|
-
assert(config.initialBufferLength <= config.maxBufferLength, "initialBufferLength must be lower than or equal to maxBufferLength");
|
|
22
|
-
return config;
|
|
23
21
|
}
|
|
24
|
-
export {
|
|
25
|
-
Config
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=config.js.map
|
|
22
|
+
export const DEFAULT_CONFIG = /* @__PURE__ */ Config({});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DEV = false;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DEV = true;
|
package/dist/env/dev.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DEV: boolean;
|