Initial commit

This commit is contained in:
2025-03-07 19:22:02 +01:00
commit 4a98255d83
55743 changed files with 5280367 additions and 0 deletions
+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2024 jsonjoy.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+13
View File
@@ -0,0 +1,13 @@
# util
Useful utilities for TypeScript programming.
This package includes the following utilities:
- `json-random`: Generate random JSON objects.
- `json-equal`: Very fast JSON deep equality comparison.
- `json-brand`: TypeScript branded type for JSON strings.
- `codegen`: JIT JavaScript code generation utilities.
- `buffers`: Various helper functions to work with `Uint8Array` and `Buffer` blobs.
- `strings`: Various helper functions to work with UTF-8 strings.
- `sort`: Fast sorting for small arrays.
+13
View File
@@ -0,0 +1,13 @@
/// <reference types="node" />
export declare class Fuzzer {
static randomInt(min: number, max: number): number;
static randomInt2([min, max]: [min: number, max: number]): number;
static pick<T>(elements: T[]): T;
static repeat<T>(times: number, callback: () => T): T[];
readonly seed: Buffer;
readonly random: () => number;
constructor(seed?: Buffer);
readonly randomInt: (min: number, max: number) => number;
readonly pick: <T>(elements: T[]) => T;
readonly repeat: <T>(times: number, callback: () => T) => T[];
}
+59
View File
@@ -0,0 +1,59 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Fuzzer = void 0;
const crypto_1 = require("crypto");
function xoshiro128ss(a, b, c, d) {
return () => {
const t = b << 9;
let r = b * 5;
r = ((r << 7) | (r >>> 25)) * 9;
c ^= a;
d ^= b;
b ^= c;
a ^= d;
c ^= t;
d = (d << 11) | (d >>> 21);
return (r >>> 0) / 4294967296;
};
}
class Fuzzer {
static randomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
static randomInt2([min, max]) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
static pick(elements) {
return elements[Math.floor(Math.random() * elements.length)];
}
static repeat(times, callback) {
const result = [];
for (let i = 0; i < times; i++)
result.push(callback());
return result;
}
constructor(seed) {
this.randomInt = (min, max) => {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
this.pick = (elements) => {
return elements[Math.floor(Math.random() * elements.length)];
};
this.repeat = (times, callback) => {
const result = [];
for (let i = 0; i < times; i++)
result.push(callback());
return result;
};
this.seed = seed = seed || (0, crypto_1.randomBytes)(4 * 4);
let i = 0;
const a = (seed[i++] << 24) | (seed[i++] << 16) | (seed[i++] << 8) | seed[i++];
const b = (seed[i++] << 24) | (seed[i++] << 16) | (seed[i++] << 8) | seed[i++];
const c = (seed[i++] << 24) | (seed[i++] << 16) | (seed[i++] << 8) | seed[i++];
const d = (seed[i++] << 24) | (seed[i++] << 16) | (seed[i++] << 8) | seed[i++];
this.random = xoshiro128ss(a, b, c, d);
Math.random = this.random;
}
}
exports.Fuzzer = Fuzzer;
//# sourceMappingURL=Fuzzer.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"Fuzzer.js","sourceRoot":"","sources":["../src/Fuzzer.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AAEnC,SAAS,YAAY,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS;IAC9D,OAAO,GAAG,EAAE;QACV,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACjB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACd,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;QAChC,CAAC,IAAI,CAAC,CAAC;QACP,CAAC,IAAI,CAAC,CAAC;QACP,CAAC,IAAI,CAAC,C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G,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;QAC/E,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;QAC/E,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC5B,CAAC;CAeF;AAhDD,wBAgDC"}
+1
View File
@@ -0,0 +1 @@
export declare const NullObject: new () => Record<string, unknown>;
+6
View File
@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NullObject = void 0;
exports.NullObject = function NullObject() { };
exports.NullObject.prototype = Object.create(null);
//# sourceMappingURL=NullObject.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"NullObject.js","sourceRoot":"","sources":["../src/NullObject.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG,SAAS,UAAU,KAAI,CAA6C,CAAC;AAC/F,kBAAU,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC"}
+22
View File
@@ -0,0 +1,22 @@
import type { IReader, IReaderResettable } from './types';
export declare class Reader implements IReader, IReaderResettable {
uint8: Uint8Array;
view: DataView;
x: number;
reset(uint8: Uint8Array): void;
peak(): number;
skip(length: number): void;
buf(size: number): Uint8Array;
u8(): number;
i8(): number;
u16(): number;
i16(): number;
u32(): number;
i32(): number;
u64(): bigint;
i64(): bigint;
f32(): number;
f64(): number;
utf8(size: number): string;
ascii(length: number): string;
}
+91
View File
@@ -0,0 +1,91 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Reader = void 0;
const decodeUtf8_1 = require("./utf8/decodeUtf8");
class Reader {
constructor() {
this.uint8 = new Uint8Array([]);
this.view = new DataView(this.uint8.buffer);
this.x = 0;
}
reset(uint8) {
this.x = 0;
this.uint8 = uint8;
this.view = new DataView(uint8.buffer, uint8.byteOffset, uint8.length);
}
peak() {
return this.view.getUint8(this.x);
}
skip(length) {
this.x += length;
}
buf(size) {
const end = this.x + size;
const bin = this.uint8.subarray(this.x, end);
this.x = end;
return bin;
}
u8() {
return this.uint8[this.x++];
}
i8() {
return this.view.getInt8(this.x++);
}
u16() {
let x = this.x;
const num = (this.uint8[x++] << 8) + this.uint8[x++];
this.x = x;
return num;
}
i16() {
const num = this.view.getInt16(this.x);
this.x += 2;
return num;
}
u32() {
const num = this.view.getUint32(this.x);
this.x += 4;
return num;
}
i32() {
const num = this.view.getInt32(this.x);
this.x += 4;
return num;
}
u64() {
const num = this.view.getBigUint64(this.x);
this.x += 8;
return num;
}
i64() {
const num = this.view.getBigInt64(this.x);
this.x += 8;
return num;
}
f32() {
const pos = this.x;
this.x += 4;
return this.view.getFloat32(pos);
}
f64() {
const pos = this.x;
this.x += 8;
return this.view.getFloat64(pos);
}
utf8(size) {
const start = this.x;
this.x += size;
return (0, decodeUtf8_1.decodeUtf8)(this.uint8, start, size);
}
ascii(length) {
const uint8 = this.uint8;
let str = '';
const end = this.x + length;
for (let i = this.x; i < end; i++)
str += String.fromCharCode(uint8[i]);
this.x = end;
return str;
}
}
exports.Reader = Reader;
//# sourceMappingURL=Reader.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"Reader.js","sourceRoot":"","sources":["../../src/buffers/Reader.ts"],"names":[],"mappings":";;;AAAA,kDAA6C;AAG7C,MAAa,MAAM;IAAnB;QACS,UAAK,GAAG,IAA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CAAC;QACnB,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAEM,IAAI,CAAC,IAAY;QACtB,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC;QACrB,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC;QACf,OAAO,IAAA,uBAAU,EAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,MAAc;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,IAAI,GAAG,GAAG,EAAE,CAAC;QACb,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC;QAC5B,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE;YAAE,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACxE,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC;QACb,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AArGD,wBAqGC"}
+8
View File
@@ -0,0 +1,8 @@
export declare class Slice {
readonly uint8: Uint8Array;
readonly view: DataView;
readonly start: number;
readonly end: number;
constructor(uint8: Uint8Array, view: DataView, start: number, end: number);
subarray(): Uint8Array;
}
+16
View File
@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Slice = void 0;
class Slice {
constructor(uint8, view, start, end) {
this.uint8 = uint8;
this.view = view;
this.start = start;
this.end = end;
}
subarray() {
return this.uint8.subarray(this.start, this.end);
}
}
exports.Slice = Slice;
//# sourceMappingURL=Slice.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"Slice.js","sourceRoot":"","sources":["../../src/buffers/Slice.ts"],"names":[],"mappings":";;;AAAA,MAAa,KAAK;IAChB,YACkB,KAAiB,EACjB,IAAc,EACd,KAAa,EACb,GAAW;QAHX,UAAK,GAAL,KAAK,CAAY;QACjB,SAAI,GAAJ,IAAI,CAAU;QACd,UAAK,GAAL,KAAK,CAAQ;QACb,QAAG,GAAH,GAAG,CAAQ;IAC1B,CAAC;IAEG,QAAQ;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACnD,CAAC;CACF;AAXD,sBAWC"}
+18
View File
@@ -0,0 +1,18 @@
export declare class StreamingOctetReader {
protected readonly chunks: Uint8Array[];
protected chunkSize: number;
protected x: number;
size(): number;
push(chunk: Uint8Array): void;
protected assertSize(size: number): void;
u8(): number;
u32(): number;
copy(size: number, dst: Uint8Array, pos: number): void;
copyXor(size: number, dst: Uint8Array, pos: number, mask: [number, number, number, number], maskIndex: number): void;
buf(size: number): Uint8Array;
bufXor(size: number, mask: [number, number, number, number], maskIndex: number): Uint8Array;
skipUnsafe(n: number): void;
skip(n: number): void;
peak(): number;
utf8(length: number, mask: [number, number, number, number], maskIndex: number): string;
}
+168
View File
@@ -0,0 +1,168 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StreamingOctetReader = void 0;
const fromCharCode = String.fromCharCode;
class StreamingOctetReader {
constructor() {
this.chunks = [];
this.chunkSize = 0;
this.x = 0;
}
size() {
return this.chunkSize - this.x;
}
push(chunk) {
this.chunks.push(chunk);
this.chunkSize += chunk.length;
}
assertSize(size) {
if (size > this.size())
throw new RangeError('OUT_OF_BOUNDS');
}
u8() {
this.assertSize(1);
const chunk = this.chunks[0];
let x = this.x;
const octet = chunk[x++];
if (x === chunk.length) {
this.chunks.shift();
this.chunkSize -= chunk.length;
x = 0;
}
this.x = x;
return octet;
}
u32() {
const octet0 = this.u8();
const octet1 = this.u8();
const octet2 = this.u8();
const octet3 = this.u8();
return (octet0 * 0x1000000 + (octet1 << 16) + (octet2 << 8)) | octet3;
}
copy(size, dst, pos) {
if (!size)
return;
this.assertSize(size);
const chunk0 = this.chunks[0];
const size0 = Math.min(chunk0.length - this.x, size);
dst.set(chunk0.subarray(this.x, this.x + size0), pos);
size -= size0;
if (size <= 0) {
this.skipUnsafe(size0);
return;
}
let chunkIndex = 1;
while (size > 0) {
const chunk1 = this.chunks[chunkIndex];
const size1 = Math.min(chunk1.length, size);
dst.set(chunk1.subarray(0, size1), pos + size0);
size -= size1;
chunkIndex++;
}
this.skipUnsafe(size);
}
copyXor(size, dst, pos, mask, maskIndex) {
if (!size)
return;
this.assertSize(size);
const chunk0 = this.chunks[0];
let x = this.x;
const size0 = Math.min(chunk0.length - x, size);
const end = x + size0;
for (; x < end;)
dst[pos++] = chunk0[x++] ^ mask[maskIndex++ % 4];
size -= size0;
if (size <= 0) {
this.skipUnsafe(size0);
return;
}
let chunkIndex = 1;
while (size > 0) {
const chunk1 = this.chunks[chunkIndex++];
const size1 = Math.min(chunk1.length, size);
for (let x = 0; x < size1;)
dst[pos++] = chunk1[x++] ^ mask[maskIndex++ % 4];
size -= size1;
}
this.skipUnsafe(size);
}
buf(size) {
this.assertSize(size);
const buf = new Uint8Array(size);
this.copy(size, buf, 0);
return buf;
}
bufXor(size, mask, maskIndex) {
this.assertSize(size);
const buf = new Uint8Array(size);
this.copyXor(size, buf, 0, mask, maskIndex);
return buf;
}
skipUnsafe(n) {
if (!n)
return;
const chunk = this.chunks[0];
const chunkLength = chunk.length;
const remaining = chunkLength - this.x;
if (remaining > n) {
this.x = this.x + n;
return;
}
this.x = 0;
this.chunks.shift();
this.chunkSize -= chunkLength;
n -= remaining;
this.skipUnsafe(n);
}
skip(n) {
this.assertSize(n);
this.skipUnsafe(n);
}
peak() {
this.assertSize(1);
return this.chunks[0][this.x];
}
utf8(length, mask, maskIndex) {
this.assertSize(length);
let i = 0;
const points = [];
while (i < length) {
let code = this.u8() ^ mask[maskIndex++ % 4];
i++;
if ((code & 0x80) !== 0) {
const octet2 = (this.u8() ^ mask[maskIndex++ % 4]) & 0x3f;
i++;
if ((code & 0xe0) === 0xc0) {
code = ((code & 0x1f) << 6) | octet2;
}
else {
const octet3 = (this.u8() ^ mask[maskIndex++ % 4]) & 0x3f;
i++;
if ((code & 0xf0) === 0xe0) {
code = ((code & 0x1f) << 12) | (octet2 << 6) | octet3;
}
else {
if ((code & 0xf8) === 0xf0) {
const octet4 = (this.u8() ^ mask[maskIndex++ % 4]) & 0x3f;
i++;
let unit = ((code & 0x07) << 0x12) | (octet2 << 0x0c) | (octet3 << 0x06) | octet4;
if (unit > 0xffff) {
unit -= 0x10000;
const unit0 = ((unit >>> 10) & 0x3ff) | 0xd800;
code = 0xdc00 | (unit & 0x3ff);
points.push(unit0);
}
else {
code = unit;
}
}
}
}
}
points.push(code);
}
return fromCharCode.apply(String, points);
}
}
exports.StreamingOctetReader = StreamingOctetReader;
//# sourceMappingURL=StreamingOctetReader.js.map
File diff suppressed because one or more lines are too long
+31
View File
@@ -0,0 +1,31 @@
import { Writer } from './Writer';
import type { IReader, IReaderResettable } from './types';
export declare class StreamingReader implements IReader, IReaderResettable {
protected readonly writer: Writer;
protected dx: number;
constructor(allocSize?: number);
size(): number;
protected assertSize(size: number): void;
push(uint8: Uint8Array): void;
consume(): void;
get uint8(): Uint8Array;
get view(): DataView;
get x(): number;
set x(x: number);
peak(): number;
skip(length: number): void;
buf(size: number): Uint8Array;
u8(): number;
i8(): number;
u16(): number;
i16(): number;
u32(): number;
i32(): number;
u64(): bigint;
i64(): bigint;
f32(): number;
f64(): number;
utf8(size: number): string;
ascii(length: number): string;
reset(uint8: Uint8Array): void;
}
+131
View File
@@ -0,0 +1,131 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StreamingReader = void 0;
const Writer_1 = require("./Writer");
const decodeUtf8_1 = require("./utf8/decodeUtf8");
class StreamingReader {
constructor(allocSize = 16 * 1024) {
this.dx = 0;
this.writer = new Writer_1.Writer(allocSize);
}
size() {
return this.writer.x - this.x;
}
assertSize(size) {
if (size > this.size())
throw new RangeError('OUT_OF_BOUNDS');
}
push(uint8) {
this.writer.buf(uint8, uint8.length);
}
consume() {
this.writer.x0 += this.dx;
this.dx = 0;
}
get uint8() {
return this.writer.uint8;
}
get view() {
return this.writer.view;
}
get x() {
return this.writer.x0 + this.dx;
}
set x(x) {
this.dx = x - this.writer.x0;
}
peak() {
this.assertSize(1);
return this.view.getUint8(this.x);
}
skip(length) {
this.assertSize(length);
this.x += length;
}
buf(size) {
this.assertSize(size);
const end = this.x + size;
const bin = this.uint8.subarray(this.x, end);
this.x = end;
return bin;
}
u8() {
this.assertSize(1);
return this.view.getUint8(this.x++);
}
i8() {
this.assertSize(1);
return this.view.getInt8(this.x++);
}
u16() {
this.assertSize(2);
const num = this.view.getUint16(this.x);
this.x += 2;
return num;
}
i16() {
this.assertSize(2);
const num = this.view.getInt16(this.x);
this.x += 2;
return num;
}
u32() {
this.assertSize(4);
const num = this.view.getUint32(this.x);
this.x += 4;
return num;
}
i32() {
this.assertSize(4);
const num = this.view.getInt32(this.x);
this.x += 4;
return num;
}
u64() {
this.assertSize(8);
const num = this.view.getBigUint64(this.x);
this.x += 8;
return num;
}
i64() {
this.assertSize(8);
const num = this.view.getBigInt64(this.x);
this.x += 8;
return num;
}
f32() {
this.assertSize(4);
const pos = this.x;
this.x += 4;
return this.view.getFloat32(pos);
}
f64() {
this.assertSize(8);
const pos = this.x;
this.x += 8;
return this.view.getFloat64(pos);
}
utf8(size) {
this.assertSize(size);
const start = this.x;
this.x += size;
return (0, decodeUtf8_1.decodeUtf8)(this.uint8, start, size);
}
ascii(length) {
this.assertSize(length);
const uint8 = this.uint8;
let str = '';
const end = this.x + length;
for (let i = this.x; i < end; i++)
str += String.fromCharCode(uint8[i]);
this.x = end;
return str;
}
reset(uint8) {
this.dx = 0;
this.writer.reset();
this.push(uint8);
}
}
exports.StreamingReader = StreamingReader;
//# sourceMappingURL=StreamingReader.js.map
+1
View File
@@ -0,0 +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AM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC;QACnB,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAEM,IAAI,CAAC,IAAY;QACtB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACtB,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC;QACrB,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC;QACf,OAAO,IAAA,uBAAU,EAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,MAAc;QACzB,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,IAAI,GAAG,GAAG,EAAE,CAAC;QACb,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC;QAC5B,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE;YAAE,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACxE,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC;QACb,OAAO,GAAG,CAAC;IACb,CAAC;IAIM,KAAK,CAAC,KAAiB;QAC5B,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;QACZ,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;CACF;AA9KD,0CA8KC"}
+6
View File
@@ -0,0 +1,6 @@
export declare class Uint8ArrayCut {
readonly uint8: Uint8Array;
readonly start: number;
readonly size: number;
constructor(uint8: Uint8Array, start: number, size: number);
}
+12
View File
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Uint8ArrayCut = void 0;
class Uint8ArrayCut {
constructor(uint8, start, size) {
this.uint8 = uint8;
this.start = start;
this.size = size;
}
}
exports.Uint8ArrayCut = Uint8ArrayCut;
//# sourceMappingURL=Uint8ArrayCut.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"Uint8ArrayCut.js","sourceRoot":"","sources":["../../src/buffers/Uint8ArrayCut.ts"],"names":[],"mappings":";;;AAAA,MAAa,aAAa;IACxB,YACkB,KAAiB,EACjB,KAAa,EACb,IAAY;QAFZ,UAAK,GAAL,KAAK,CAAY;QACjB,UAAK,GAAL,KAAK,CAAQ;QACb,SAAI,GAAJ,IAAI,CAAQ;IAC3B,CAAC;CACL;AAND,sCAMC"}
+33
View File
@@ -0,0 +1,33 @@
import { Slice } from './Slice';
import { IWriterGrowable, IWriter } from './types';
export declare class Writer implements IWriter, IWriterGrowable {
allocSize: number;
uint8: Uint8Array;
view: DataView;
x0: number;
x: number;
protected size: number;
constructor(allocSize?: number);
protected grow(size: number): void;
ensureCapacity(capacity: number): void;
move(capacity: number): void;
reset(): void;
newBuffer(size: number): void;
flush(): Uint8Array;
flushSlice(): Slice;
u8(char: number): void;
u16(word: number): void;
u32(dword: number): void;
i32(dword: number): void;
u64(qword: number | bigint): void;
f64(float: number): void;
u8u16(u8: number, u16: number): void;
u8u32(u8: number, u32: number): void;
u8u64(u8: number, u64: number | bigint): void;
u8f32(u8: number, f32: number): void;
u8f64(u8: number, f64: number): void;
buf(buf: Uint8Array, length: number): void;
utf8(str: string): number;
utf8Native(str: string): number;
ascii(str: string): void;
}
+217
View File
@@ -0,0 +1,217 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Writer = void 0;
const Slice_1 = require("./Slice");
const EMPTY_UINT8 = new Uint8Array([]);
const EMPTY_VIEW = new DataView(EMPTY_UINT8.buffer);
const hasBuffer = typeof Buffer === 'function';
const utf8Write = hasBuffer
? Buffer.prototype.utf8Write
: null;
const from = hasBuffer ? Buffer.from : null;
const textEncoder = typeof TextEncoder !== 'undefined' ? new TextEncoder() : null;
class Writer {
constructor(allocSize = 64 * 1024) {
this.allocSize = allocSize;
this.view = EMPTY_VIEW;
this.x0 = 0;
this.x = 0;
this.uint8 = new Uint8Array(allocSize);
this.size = allocSize;
this.view = new DataView(this.uint8.buffer);
}
grow(size) {
const x0 = this.x0;
const x = this.x;
const oldUint8 = this.uint8;
const newUint8 = new Uint8Array(size);
const view = new DataView(newUint8.buffer);
const activeSlice = oldUint8.subarray(x0, x);
newUint8.set(activeSlice, 0);
this.x = x - x0;
this.x0 = 0;
this.uint8 = newUint8;
this.size = size;
this.view = view;
}
ensureCapacity(capacity) {
const byteLength = this.size;
const remaining = byteLength - this.x;
if (remaining < capacity) {
const total = byteLength - this.x0;
const required = capacity - remaining;
const totalRequired = total + required;
this.grow(totalRequired <= this.allocSize ? this.allocSize : totalRequired * 2);
}
}
move(capacity) {
this.ensureCapacity(capacity);
this.x += capacity;
}
reset() {
this.x0 = this.x;
}
newBuffer(size) {
const uint8 = (this.uint8 = new Uint8Array(size));
this.size = size;
this.view = new DataView(uint8.buffer);
this.x = this.x0 = 0;
}
flush() {
const result = this.uint8.subarray(this.x0, this.x);
this.x0 = this.x;
return result;
}
flushSlice() {
const slice = new Slice_1.Slice(this.uint8, this.view, this.x0, this.x);
this.x0 = this.x;
return slice;
}
u8(char) {
this.ensureCapacity(1);
this.uint8[this.x++] = char;
}
u16(word) {
this.ensureCapacity(2);
this.view.setUint16(this.x, word);
this.x += 2;
}
u32(dword) {
this.ensureCapacity(4);
this.view.setUint32(this.x, dword);
this.x += 4;
}
i32(dword) {
this.ensureCapacity(4);
this.view.setInt32(this.x, dword);
this.x += 4;
}
u64(qword) {
this.ensureCapacity(8);
this.view.setBigUint64(this.x, BigInt(qword));
this.x += 8;
}
f64(float) {
this.ensureCapacity(8);
this.view.setFloat64(this.x, float);
this.x += 8;
}
u8u16(u8, u16) {
this.ensureCapacity(3);
let x = this.x;
this.uint8[x++] = u8;
this.uint8[x++] = u16 >>> 8;
this.uint8[x++] = u16 & 0xff;
this.x = x;
}
u8u32(u8, u32) {
this.ensureCapacity(5);
let x = this.x;
this.uint8[x++] = u8;
this.view.setUint32(x, u32);
this.x = x + 4;
}
u8u64(u8, u64) {
this.ensureCapacity(9);
let x = this.x;
this.uint8[x++] = u8;
this.view.setBigUint64(x, BigInt(u64));
this.x = x + 8;
}
u8f32(u8, f32) {
this.ensureCapacity(5);
let x = this.x;
this.uint8[x++] = u8;
this.view.setFloat32(x, f32);
this.x = x + 4;
}
u8f64(u8, f64) {
this.ensureCapacity(9);
let x = this.x;
this.uint8[x++] = u8;
this.view.setFloat64(x, f64);
this.x = x + 8;
}
buf(buf, length) {
this.ensureCapacity(length);
const x = this.x;
this.uint8.set(buf, x);
this.x = x + length;
}
utf8(str) {
const maxLength = str.length * 4;
if (maxLength < 168)
return this.utf8Native(str);
if (utf8Write) {
const writeLength = utf8Write.call(this.uint8, str, this.x, maxLength);
this.x += writeLength;
return writeLength;
}
else if (from) {
const uint8 = this.uint8;
const offset = uint8.byteOffset + this.x;
const buf = from(uint8.buffer).subarray(offset, offset + maxLength);
const writeLength = buf.write(str, 0, maxLength, 'utf8');
this.x += writeLength;
return writeLength;
}
else if (maxLength > 1024 && textEncoder) {
const writeLength = textEncoder.encodeInto(str, this.uint8.subarray(this.x, this.x + maxLength)).written;
this.x += writeLength;
return writeLength;
}
return this.utf8Native(str);
}
utf8Native(str) {
const length = str.length;
const uint8 = this.uint8;
let offset = this.x;
let pos = 0;
while (pos < length) {
let value = str.charCodeAt(pos++);
if ((value & 0xffffff80) === 0) {
uint8[offset++] = value;
continue;
}
else if ((value & 0xfffff800) === 0) {
uint8[offset++] = ((value >> 6) & 0x1f) | 0xc0;
}
else {
if (value >= 0xd800 && value <= 0xdbff) {
if (pos < length) {
const extra = str.charCodeAt(pos);
if ((extra & 0xfc00) === 0xdc00) {
pos++;
value = ((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000;
}
}
}
if ((value & 0xffff0000) === 0) {
uint8[offset++] = ((value >> 12) & 0x0f) | 0xe0;
uint8[offset++] = ((value >> 6) & 0x3f) | 0x80;
}
else {
uint8[offset++] = ((value >> 18) & 0x07) | 0xf0;
uint8[offset++] = ((value >> 12) & 0x3f) | 0x80;
uint8[offset++] = ((value >> 6) & 0x3f) | 0x80;
}
}
uint8[offset++] = (value & 0x3f) | 0x80;
}
const writeLength = offset - this.x;
this.x = offset;
return writeLength;
}
ascii(str) {
const length = str.length;
this.ensureCapacity(length);
const uint8 = this.uint8;
let x = this.x;
let pos = 0;
while (pos < length)
uint8[x++] = str.charCodeAt(pos++);
this.x = x;
}
}
exports.Writer = Writer;
//# sourceMappingURL=Writer.js.map
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
export declare const b: (...args: number[]) => Uint8Array;
+6
View File
@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.b = void 0;
const b = (...args) => new Uint8Array(args);
exports.b = b;
//# sourceMappingURL=b.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"b.js","sourceRoot":"","sources":["../../src/buffers/b.ts"],"names":[],"mappings":";;;AAAO,MAAM,CAAC,GAAG,CAAC,GAAG,IAAc,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;AAAhD,QAAA,CAAC,KAA+C"}
+2
View File
@@ -0,0 +1,2 @@
/// <reference types="node" />
export declare const bufferToUint8Array: (buf: Buffer) => Uint8Array;
+6
View File
@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bufferToUint8Array = void 0;
const bufferToUint8Array = (buf) => new Uint8Array(buf.buffer, buf.byteOffset, buf.length);
exports.bufferToUint8Array = bufferToUint8Array;
//# sourceMappingURL=bufferToUint8Array.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"bufferToUint8Array.js","sourceRoot":"","sources":["../../src/buffers/bufferToUint8Array.ts"],"names":[],"mappings":";;;AAAO,MAAM,kBAAkB,GAAG,CAAC,GAAW,EAAc,EAAE,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;AAAzG,QAAA,kBAAkB,sBAAuF"}
+1
View File
@@ -0,0 +1 @@
export declare const cmpUint8Array: (a: Uint8Array, b: Uint8Array) => boolean;
+14
View File
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cmpUint8Array = void 0;
const cmpUint8Array = (a, b) => {
const length = a.length;
if (length !== b.length)
return false;
for (let i = 0; i < length; i++)
if (a[i] !== b[i])
return false;
return true;
};
exports.cmpUint8Array = cmpUint8Array;
//# sourceMappingURL=cmpUint8Array.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"cmpUint8Array.js","sourceRoot":"","sources":["../../src/buffers/cmpUint8Array.ts"],"names":[],"mappings":";;;AAAO,MAAM,aAAa,GAAG,CAAC,CAAa,EAAE,CAAa,EAAW,EAAE;IACrE,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACxB,IAAI,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE;QAAE,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;IACjE,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AALW,QAAA,aAAa,iBAKxB"}
+1
View File
@@ -0,0 +1 @@
export declare const cmpUint8Array2: (a: Uint8Array, b: Uint8Array) => number;
+16
View File
@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cmpUint8Array2 = void 0;
const cmpUint8Array2 = (a, b) => {
const len1 = a.length;
const len2 = b.length;
const len = Math.min(len1, len2);
for (let i = 0; i < len; i++) {
const diffChar = a[i] - b[i];
if (diffChar !== 0)
return diffChar;
}
return len1 - len2;
};
exports.cmpUint8Array2 = cmpUint8Array2;
//# sourceMappingURL=cmpUint8Array2.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"cmpUint8Array2.js","sourceRoot":"","sources":["../../src/buffers/cmpUint8Array2.ts"],"names":[],"mappings":";;;AAQO,MAAM,cAAc,GAAG,CAAC,CAAa,EAAE,CAAa,EAAU,EAAE;IACrE,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC;IACtB,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC;IACtB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,QAAQ,KAAK,CAAC;YAAE,OAAO,QAAQ,CAAC;IACtC,CAAC;IACD,OAAO,IAAI,GAAG,IAAI,CAAC;AACrB,CAAC,CAAC;AATW,QAAA,cAAc,kBASzB"}
+1
View File
@@ -0,0 +1 @@
export declare const cmpUint8Array3: (a: Uint8Array, b: Uint8Array) => number;
+18
View File
@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cmpUint8Array3 = void 0;
const cmpUint8Array3 = (a, b) => {
const len1 = a.length;
const len2 = b.length;
const diff = len1 - len2;
if (diff !== 0)
return diff;
for (let i = 0; i < len1; i++) {
const diff = a[i] - b[i];
if (diff !== 0)
return diff;
}
return 0;
};
exports.cmpUint8Array3 = cmpUint8Array3;
//# sourceMappingURL=cmpUint8Array3.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"cmpUint8Array3.js","sourceRoot":"","sources":["../../src/buffers/cmpUint8Array3.ts"],"names":[],"mappings":";;;AAQO,MAAM,cAAc,GAAG,CAAC,CAAa,EAAE,CAAa,EAAU,EAAE;IACrE,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC;IACtB,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC;IACtB,MAAM,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IACzB,IAAI,IAAI,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACzB,IAAI,IAAI,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;IAC9B,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC,CAAC;AAVW,QAAA,cAAc,kBAUzB"}
+3
View File
@@ -0,0 +1,3 @@
export declare const concat: (a: Uint8Array, b: Uint8Array) => Uint8Array;
export declare const concatList: (list: Uint8Array[]) => Uint8Array;
export declare const listToUint8: (list: Uint8Array[]) => Uint8Array;
+36
View File
@@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.listToUint8 = exports.concatList = exports.concat = void 0;
const concat = (a, b) => {
const res = new Uint8Array(a.length + b.length);
res.set(a);
res.set(b, a.length);
return res;
};
exports.concat = concat;
const concatList = (list) => {
const length = list.length;
let size = 0, offset = 0;
for (let i = 0; i < length; i++)
size += list[i].length;
const res = new Uint8Array(size);
for (let i = 0; i < length; i++) {
const item = list[i];
res.set(item, offset);
offset += item.length;
}
return res;
};
exports.concatList = concatList;
const listToUint8 = (list) => {
switch (list.length) {
case 0:
return new Uint8Array(0);
case 1:
return list[0];
default:
return (0, exports.concatList)(list);
}
};
exports.listToUint8 = listToUint8;
//# sourceMappingURL=concat.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"concat.js","sourceRoot":"","sources":["../../src/buffers/concat.ts"],"names":[],"mappings":";;;AAAO,MAAM,MAAM,GAAG,CAAC,CAAa,EAAE,CAAa,EAAc,EAAE;IACjE,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;IAChD,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACX,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;IACrB,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AALW,QAAA,MAAM,UAKjB;AAEK,MAAM,UAAU,GAAG,CAAC,IAAkB,EAAc,EAAE;IAC3D,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3B,IAAI,IAAI,GAAG,CAAC,EACV,MAAM,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE;QAAE,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACxD,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;IACjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACrB,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACtB,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC;IACxB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAZW,QAAA,UAAU,cAYrB;AAEK,MAAM,WAAW,GAAG,CAAC,IAAkB,EAAc,EAAE;IAC5D,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC;YACJ,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;QAC3B,KAAK,CAAC;YACJ,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;QACjB;YACE,OAAO,IAAA,kBAAU,EAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;AACH,CAAC,CAAC;AATW,QAAA,WAAW,eAStB"}
+1
View File
@@ -0,0 +1 @@
export declare const copy: <T extends Uint8Array>(arr: T) => T;
+10
View File
@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.copy = void 0;
const copy = (arr) => {
const dupe = new Uint8Array(arr.length);
dupe.set(arr);
return dupe;
};
exports.copy = copy;
//# sourceMappingURL=copy.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"copy.js","sourceRoot":"","sources":["../../src/buffers/copy.ts"],"names":[],"mappings":";;;AAAO,MAAM,IAAI,GAAG,CAAuB,GAAM,EAAK,EAAE;IACtD,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,MAAM,CAAM,CAAC;IAC7C,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACd,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAJW,QAAA,IAAI,QAIf"}
+1
View File
@@ -0,0 +1 @@
export declare const decodeF16: (binary: number) => number;
+18
View File
@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodeF16 = void 0;
const pow = Math.pow;
const decodeF16 = (binary) => {
const exponent = (binary & 0x7c00) >> 10;
const fraction = binary & 0x03ff;
return ((binary >> 15 ? -1 : 1) *
(exponent
? exponent === 0x1f
? fraction
? NaN
: Infinity
: pow(2, exponent - 15) * (1 + fraction / 0x400)
: 6.103515625e-5 * (fraction / 0x400)));
};
exports.decodeF16 = decodeF16;
//# sourceMappingURL=f16.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"f16.js","sourceRoot":"","sources":["../../src/buffers/f16.ts"],"names":[],"mappings":";;;AAAA,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;AAEd,MAAM,SAAS,GAAG,CAAC,MAAc,EAAU,EAAE;IAClD,MAAM,QAAQ,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IACzC,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;IACjC,OAAO,CACL,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACvB,CAAC,QAAQ;YACP,CAAC,CAAC,QAAQ,KAAK,IAAI;gBACjB,CAAC,CAAC,QAAQ;oBACR,CAAC,CAAC,GAAG;oBACL,CAAC,CAAC,QAAQ;gBACZ,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,GAAG,KAAK,CAAC;YAClD,CAAC,CAAC,cAAc,GAAG,CAAC,QAAQ,GAAG,KAAK,CAAC,CAAC,CACzC,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,SAAS,aAapB"}
+1
View File
@@ -0,0 +1 @@
export * from './types';
+5
View File
@@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./types"), exports);
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/buffers/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB"}
+1
View File
@@ -0,0 +1 @@
export declare const isArrayBuffer: (value: unknown) => value is ArrayBuffer;
+8
View File
@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isArrayBuffer = void 0;
const isArrayBuffer = (value) => {
return value instanceof ArrayBuffer || toString.call(value) === '[object ArrayBuffer]';
};
exports.isArrayBuffer = isArrayBuffer;
//# sourceMappingURL=isArrayBuffer.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"isArrayBuffer.js","sourceRoot":"","sources":["../../src/buffers/isArrayBuffer.ts"],"names":[],"mappings":";;;AAAO,MAAM,aAAa,GAAG,CAAC,KAAc,EAAwB,EAAE;IACpE,OAAO,KAAK,YAAY,WAAW,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,sBAAsB,CAAC;AACzF,CAAC,CAAC;AAFW,QAAA,aAAa,iBAExB"}
+1
View File
@@ -0,0 +1 @@
export declare const isFloat32: (n: number) => boolean;
+10
View File
@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isFloat32 = void 0;
const view = new DataView(new ArrayBuffer(4));
const isFloat32 = (n) => {
view.setFloat32(0, n);
return n === view.getFloat32(0);
};
exports.isFloat32 = isFloat32;
//# sourceMappingURL=isFloat32.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"isFloat32.js","sourceRoot":"","sources":["../../src/buffers/isFloat32.ts"],"names":[],"mappings":";;;AAAA,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AAEvC,MAAM,SAAS,GAAG,CAAC,CAAS,EAAW,EAAE;IAC9C,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACtB,OAAO,CAAC,KAAK,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAClC,CAAC,CAAC;AAHW,QAAA,SAAS,aAGpB"}
+1
View File
@@ -0,0 +1 @@
export declare const isUint8Array: (x: unknown) => x is Uint8Array;
+7
View File
@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isUint8Array = void 0;
exports.isUint8Array = typeof Buffer === 'function'
? (x) => x instanceof Uint8Array || Buffer.isBuffer(x)
: (x) => x instanceof Uint8Array;
//# sourceMappingURL=isUint8Array.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"isUint8Array.js","sourceRoot":"","sources":["../../src/buffers/isUint8Array.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GACvB,OAAO,MAAM,KAAK,UAAU;IAC1B,CAAC,CAAC,CAAC,CAAU,EAAmB,EAAE,CAAC,CAAC,YAAY,UAAU,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAChF,CAAC,CAAC,CAAC,CAAU,EAAmB,EAAE,CAAC,CAAC,YAAY,UAAU,CAAC"}
+1
View File
@@ -0,0 +1 @@
export declare const printOctets: (octets: Uint8Array, max?: number) => string;
+23
View File
@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.printOctets = void 0;
const printOctets = (octets, max = 16) => {
let str = '';
if (!octets.length)
return str;
if (octets[0] < 16)
str += '0';
str += octets[0].toString(16);
for (let i = 1; i < octets.length && i < max; i++) {
const n = octets[i];
str += ' ';
if (n < 16)
str += '0';
str += n.toString(16);
}
if (octets.length > max)
str += `… (${octets.length - max} more)`;
return str;
};
exports.printOctets = printOctets;
//# sourceMappingURL=printOctets.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"printOctets.js","sourceRoot":"","sources":["../../src/buffers/printOctets.ts"],"names":[],"mappings":";;;AAAO,MAAM,WAAW,GAAG,CAAC,MAAkB,EAAE,MAAc,EAAE,EAAU,EAAE;IAC1E,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,CAAC,MAAM,CAAC,MAAM;QAAE,OAAO,GAAG,CAAC;IAC/B,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE;QAAE,GAAG,IAAI,GAAG,CAAC;IAC/B,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAClD,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACpB,GAAG,IAAI,GAAG,CAAC;QACX,IAAI,CAAC,GAAG,EAAE;YAAE,GAAG,IAAI,GAAG,CAAC;QACvB,GAAG,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,GAAG,GAAG;QAAE,GAAG,IAAI,MAAM,MAAM,CAAC,MAAM,GAAG,GAAG,QAAQ,CAAC;IAClE,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAbW,QAAA,WAAW,eAatB"}
+6
View File
@@ -0,0 +1,6 @@
export declare const ascii: (txt: TemplateStringsArray | string | [
string
]) => Uint8Array;
export declare const utf8: (txt: TemplateStringsArray | [
string
] | string) => Uint8Array;
+23
View File
@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.utf8 = exports.ascii = void 0;
const bufferToUint8Array_1 = require("./bufferToUint8Array");
const ascii = (txt) => {
if (typeof txt === 'string')
return (0, exports.ascii)([txt]);
[txt] = txt;
const len = txt.length;
const res = new Uint8Array(len);
for (let i = 0; i < len; i++)
res[i] = txt.charCodeAt(i);
return res;
};
exports.ascii = ascii;
const utf8 = (txt) => {
if (typeof txt === 'string')
return (0, exports.utf8)([txt]);
[txt] = txt;
return (0, bufferToUint8Array_1.bufferToUint8Array)(Buffer.from(txt, 'utf8'));
};
exports.utf8 = utf8;
//# sourceMappingURL=strings.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"strings.js","sourceRoot":"","sources":["../../src/buffers/strings.ts"],"names":[],"mappings":";;;AAAA,6DAAwD;AAEjD,MAAM,KAAK,GAAG,CAAC,GAA6C,EAAc,EAAE;IACjF,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,IAAA,aAAK,EAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACjD,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IACZ,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC;IACvB,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;IAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE;QAAE,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACzD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAPW,QAAA,KAAK,SAOhB;AAEK,MAAM,IAAI,GAAG,CAAC,GAA6C,EAAc,EAAE;IAChF,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,IAAA,YAAI,EAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAChD,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IACZ,OAAO,IAAA,uCAAkB,EAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC;AACtD,CAAC,CAAC;AAJW,QAAA,IAAI,QAIf"}
+1
View File
@@ -0,0 +1 @@
export declare const toBuf: (str: string) => Uint8Array;
+12
View File
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toBuf = void 0;
const encode_1 = require("./utf8/encode");
const toBuf = (str) => {
const maxLength = str.length * 4;
const arr = new Uint8Array(maxLength);
const strBufferLength = (0, encode_1.encode)(arr, str, 0, maxLength);
return arr.slice(0, strBufferLength);
};
exports.toBuf = toBuf;
//# sourceMappingURL=toBuf.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"toBuf.js","sourceRoot":"","sources":["../../src/buffers/toBuf.ts"],"names":[],"mappings":";;;AAAA,0CAAqC;AAE9B,MAAM,KAAK,GAAG,CAAC,GAAW,EAAc,EAAE;IAC/C,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC;IACtC,MAAM,eAAe,GAAG,IAAA,eAAM,EAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC;IACvD,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC;AACvC,CAAC,CAAC;AALW,QAAA,KAAK,SAKhB"}
+1
View File
@@ -0,0 +1 @@
export declare const toUint8Array: (data: unknown) => Uint8Array;
+19
View File
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toUint8Array = void 0;
const toUint8Array = (data) => {
if (data instanceof Uint8Array)
return data;
if (data instanceof ArrayBuffer)
return new Uint8Array(data);
if (Array.isArray(data))
return new Uint8Array(data);
if (typeof Buffer === 'function') {
if (Buffer.isBuffer(data))
return data;
return Buffer.from(data);
}
throw new Error('UINT8ARRAY_INCOMPATIBLE');
};
exports.toUint8Array = toUint8Array;
//# sourceMappingURL=toUint8Array.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"toUint8Array.js","sourceRoot":"","sources":["../../src/buffers/toUint8Array.ts"],"names":[],"mappings":";;;AAAO,MAAM,YAAY,GAAG,CAAC,IAAa,EAAc,EAAE;IACxD,IAAI,IAAI,YAAY,UAAU;QAAE,OAAO,IAAI,CAAC;IAC5C,IAAI,IAAI,YAAY,WAAW;QAAE,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;IAC7D,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;IACrD,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;QACjC,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;QACvC,OAAO,MAAM,CAAC,IAAI,CAAC,IAAW,CAAC,CAAC;IAClC,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;AAC7C,CAAC,CAAC;AATW,QAAA,YAAY,gBASvB"}
+54
View File
@@ -0,0 +1,54 @@
import type { Slice } from './Slice';
export interface IWriter {
uint8: Uint8Array;
view: DataView;
x0: number;
x: number;
u8(char: number): void;
u16(word: number): void;
u32(dword: number): void;
i32(dword: number): void;
u64(qword: number | bigint): void;
u8u16(u8: number, u16: number): void;
u8u32(u8: number, u32: number): void;
u8u64(u8: number, u64: number | bigint): void;
u8f32(u8: number, f64: number): void;
u8f64(u8: number, f64: number): void;
f64(dword: number): void;
buf(buf: Uint8Array, length: number): void;
utf8(str: string): number;
ascii(str: string): void;
}
export interface IWriterGrowable {
reset(): void;
ensureCapacity(capacity: number): void;
move(length: number): void;
flush(): Uint8Array;
flushSlice(): Slice;
newBuffer(size: number): void;
}
export interface IReaderBase {
peak(): number;
skip(length: number): void;
buf(size: number): Uint8Array;
u8(): number;
i8(): number;
u16(): number;
i16(): number;
u32(): number;
u64(): bigint;
i64(): bigint;
i32(): number;
f32(): number;
f64(): number;
utf8(size: number): string;
ascii(length: number): string;
}
export interface IReader extends IReaderBase {
uint8: Uint8Array;
view: DataView;
x: number;
}
export interface IReaderResettable {
reset(uint8: Uint8Array): void;
}
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/buffers/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
export declare class CachedUtf8Decoder {
private readonly caches;
constructor();
private get;
private store;
decode(bytes: Uint8Array, offset: number, size: number): string;
}
+60
View File
@@ -0,0 +1,60 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CachedUtf8Decoder = void 0;
const tslib_1 = require("tslib");
const v10_1 = tslib_1.__importDefault(require("./decodeUtf8/v10"));
let x = 1 + Math.round(Math.random() * ((-1 >>> 0) - 1));
function randomU32(min, max) {
x ^= x << 13;
x ^= x >>> 17;
x ^= x << 5;
return ((x >>> 0) % (max - min + 1)) + min;
}
class CacheItem {
constructor(bytes, value) {
this.bytes = bytes;
this.value = value;
}
}
class CachedUtf8Decoder {
constructor() {
this.caches = [];
for (let i = 0; i < 31; i++)
this.caches.push([]);
}
get(bytes, offset, size) {
const records = this.caches[size - 1];
const len = records.length;
FIND_CHUNK: for (let i = 0; i < len; i++) {
const record = records[i];
const recordBytes = record.bytes;
for (let j = 0; j < size; j++)
if (recordBytes[j] !== bytes[offset + j])
continue FIND_CHUNK;
return record.value;
}
return null;
}
store(bytes, value) {
const records = this.caches[bytes.length - 1];
const record = new CacheItem(bytes, value);
const length = records.length;
if (length >= 16)
records[randomU32(0, 16 - 1)] = record;
else
records.push(record);
}
decode(bytes, offset, size) {
if (!size)
return '';
const cachedValue = this.get(bytes, offset, size);
if (cachedValue !== null)
return cachedValue;
const value = (0, v10_1.default)(bytes, offset, size);
const copy = Uint8Array.prototype.slice.call(bytes, offset, offset + size);
this.store(copy, value);
return value;
}
}
exports.CachedUtf8Decoder = CachedUtf8Decoder;
//# sourceMappingURL=CachedUtf8Decoder.js.map
@@ -0,0 +1 @@
{"version":3,"file":"CachedUtf8Decoder.js","sourceRoot":"","sources":["../../../src/buffers/utf8/CachedUtf8Decoder.ts"],"names":[],"mappings":";;;;AAAA,mEAA0C;AAE1C,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAGzD,SAAS,SAAS,CAAC,GAAW,EAAE,GAAW;IACzC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IACb,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACd,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACZ,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,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G,IAAI,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC3C,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC9B,IAAI,MAAM,MAA8B;YAAE,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,KAA6B,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;;YACpG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAEM,MAAM,CAAC,KAAiB,EAAE,MAAc,EAAE,IAAY;QAC3D,IAAI,CAAC,IAAI;YAAE,OAAO,EAAE,CAAC;QACrB,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAClD,IAAI,WAAW,KAAK,IAAI;YAAE,OAAO,WAAW,CAAC;QAC7C,MAAM,KAAK,GAAG,IAAA,aAAU,EAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAE9C,MAAM,IAAI,GAAG,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;QAC3E,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACxB,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAtCD,8CAsCC"}
+2
View File
@@ -0,0 +1,2 @@
export declare const decodeAscii: (src: Uint8Array, position: number, length: number) => string | undefined;
export declare const decodeAsciiMax15: (src: Uint8Array, position: number, length: number) => string | undefined;
+163
View File
@@ -0,0 +1,163 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodeAsciiMax15 = exports.decodeAscii = void 0;
const fromCharCode = String.fromCharCode;
const decodeAscii = (src, position, length) => {
const bytes = [];
for (let i = 0; i < length; i++) {
const byte = src[position++];
if (byte & 0x80)
return;
bytes.push(byte);
}
return fromCharCode.apply(String, bytes);
};
exports.decodeAscii = decodeAscii;
const decodeAsciiMax15 = (src, position, length) => {
if (length < 4) {
if (length < 2) {
if (length === 0)
return '';
else {
const a = src[position++];
if ((a & 0x80) > 1) {
position -= 1;
return;
}
return fromCharCode(a);
}
}
else {
const a = src[position++];
const b = src[position++];
if ((a & 0x80) > 0 || (b & 0x80) > 0) {
position -= 2;
return;
}
if (length < 3)
return fromCharCode(a, b);
const c = src[position++];
if ((c & 0x80) > 0) {
position -= 3;
return;
}
return fromCharCode(a, b, c);
}
}
else {
const a = src[position++];
const b = src[position++];
const c = src[position++];
const d = src[position++];
if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
position -= 4;
return;
}
if (length < 6) {
if (length === 4)
return fromCharCode(a, b, c, d);
else {
const e = src[position++];
if ((e & 0x80) > 0) {
position -= 5;
return;
}
return fromCharCode(a, b, c, d, e);
}
}
else if (length < 8) {
const e = src[position++];
const f = src[position++];
if ((e & 0x80) > 0 || (f & 0x80) > 0) {
position -= 6;
return;
}
if (length < 7)
return fromCharCode(a, b, c, d, e, f);
const g = src[position++];
if ((g & 0x80) > 0) {
position -= 7;
return;
}
return fromCharCode(a, b, c, d, e, f, g);
}
else {
const e = src[position++];
const f = src[position++];
const g = src[position++];
const h = src[position++];
if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
position -= 8;
return;
}
if (length < 10) {
if (length === 8)
return fromCharCode(a, b, c, d, e, f, g, h);
else {
const i = src[position++];
if ((i & 0x80) > 0) {
position -= 9;
return;
}
return fromCharCode(a, b, c, d, e, f, g, h, i);
}
}
else if (length < 12) {
const i = src[position++];
const j = src[position++];
if ((i & 0x80) > 0 || (j & 0x80) > 0) {
position -= 10;
return;
}
if (length < 11)
return fromCharCode(a, b, c, d, e, f, g, h, i, j);
const k = src[position++];
if ((k & 0x80) > 0) {
position -= 11;
return;
}
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k);
}
else {
const i = src[position++];
const j = src[position++];
const k = src[position++];
const l = src[position++];
if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
position -= 12;
return;
}
if (length < 14) {
if (length === 12)
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l);
else {
const m = src[position++];
if ((m & 0x80) > 0) {
position -= 13;
return;
}
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m);
}
}
else {
const m = src[position++];
const n = src[position++];
if ((m & 0x80) > 0 || (n & 0x80) > 0) {
position -= 14;
return;
}
if (length < 15)
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
const o = src[position++];
if ((o & 0x80) > 0) {
position -= 15;
return;
}
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
}
}
}
}
};
exports.decodeAsciiMax15 = decodeAsciiMax15;
//# sourceMappingURL=decodeAscii.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,2 @@
import decodeUtf8 from './v16';
export { decodeUtf8 };
+7
View File
@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodeUtf8 = void 0;
const tslib_1 = require("tslib");
const v16_1 = tslib_1.__importDefault(require("./v16"));
exports.decodeUtf8 = v16_1.default;
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/buffers/utf8/decodeUtf8/index.ts"],"names":[],"mappings":";;;;AAAA,wDAA+B;AAEvB,qBAFD,aAAU,CAEC"}
+2
View File
@@ -0,0 +1,2 @@
declare const _default: (buf: Uint8Array, start: number, length: number) => string;
export default _default;
+46
View File
@@ -0,0 +1,46 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = (buf, start, length) => {
let offset = start;
const end = offset + length;
const units = [];
let result = '';
while (offset < end) {
const byte1 = buf[offset++];
if ((byte1 & 0x80) === 0) {
units.push(byte1);
}
else if ((byte1 & 0xe0) === 0xc0) {
const byte2 = buf[offset++] & 0x3f;
units.push(((byte1 & 0x1f) << 6) | byte2);
}
else if ((byte1 & 0xf0) === 0xe0) {
const byte2 = buf[offset++] & 0x3f;
const byte3 = buf[offset++] & 0x3f;
units.push(((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3);
}
else if ((byte1 & 0xf8) === 0xf0) {
const byte2 = buf[offset++] & 0x3f;
const byte3 = buf[offset++] & 0x3f;
const byte4 = buf[offset++] & 0x3f;
let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
if (unit > 0xffff) {
unit -= 0x10000;
units.push(((unit >>> 10) & 0x3ff) | 0xd800);
unit = 0xdc00 | (unit & 0x3ff);
}
units.push(unit);
}
else {
units.push(byte1);
}
if (units.length >= 1000) {
result += String.fromCharCode(...units);
units.length = 0;
}
}
if (units.length > 0)
result += String.fromCharCode(...units);
return result;
};
//# sourceMappingURL=v1.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"v1.js","sourceRoot":"","sources":["../../../../src/buffers/utf8/decodeUtf8/v1.ts"],"names":[],"mappings":";;AAAA,kBAAe,CAAC,GAAe,EAAE,KAAa,EAAE,MAAc,EAAU,EAAE;IACxE,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,MAAM,GAAG,GAAG,MAAM,GAAG,MAAM,CAAC;IAC5B,MAAM,KAAK,GAAkB,EAAE,CAAC;IAChC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,OAAO,MAAM,GAAG,GAAG,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,EAAE,CAAE,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;aAAM,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;YACnC,MAAM,KAAK,GAAG,GAAG,CAAC,MA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CAAC;YACD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;QACD,IAAI,KAAK,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;YACzB,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,CAAC;YACxC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,CAAC;IAC9D,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
+2
View File
@@ -0,0 +1,2 @@
declare const _default: (buf: Uint8Array, start: number, length: number) => string;
export default _default;
+43
View File
@@ -0,0 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fromCharCode = String.fromCharCode;
exports.default = (buf, start, length) => {
let offset = start;
const end = offset + length;
let str = '';
while (offset < end) {
const octet1 = buf[offset++];
if ((octet1 & 0x80) === 0) {
str += fromCharCode(octet1);
continue;
}
const octet2 = buf[offset++] & 0x3f;
if ((octet1 & 0xe0) === 0xc0) {
str += fromCharCode(((octet1 & 0x1f) << 6) | octet2);
continue;
}
const octet3 = buf[offset++] & 0x3f;
if ((octet1 & 0xf0) === 0xe0) {
str += fromCharCode(((octet1 & 0x1f) << 12) | (octet2 << 6) | octet3);
continue;
}
if ((octet1 & 0xf8) === 0xf0) {
const octet4 = buf[offset++] & 0x3f;
let unit = ((octet1 & 0x07) << 0x12) | (octet2 << 0x0c) | (octet3 << 0x06) | octet4;
if (unit > 0xffff) {
unit -= 0x10000;
const unit0 = ((unit >>> 10) & 0x3ff) | 0xd800;
unit = 0xdc00 | (unit & 0x3ff);
str += fromCharCode(unit0, unit);
}
else {
str += fromCharCode(unit);
}
}
else {
str += fromCharCode(octet1);
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AI,EAAE,CAAC;YAC7B,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,CAAE,GAAG,IAAI,CAAC;YACrC,IAAI,IAAI,GAAG,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,MAAM,CAAC;YACpF,IAAI,IAAI,GAAG,MAAM,EAAE,CAAC;gBAClB,IAAI,IAAI,OAAO,CAAC;gBAChB,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,GAAG,MAAM,CAAC;gBAC/C,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC;gBAC/B,GAAG,IAAI,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YACnC,CAAC;iBAAM,CAAC;gBACN,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
+2
View File
@@ -0,0 +1,2 @@
declare const _default: (buf: Uint8Array, start: number, length: number) => string;
export default _default;
+5
View File
@@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utf8Slice = Buffer.prototype.utf8Slice;
exports.default = (buf, start, length) => utf8Slice.call(buf, start, start + length);
//# sourceMappingURL=v11.js.map
@@ -0,0 +1 @@
{"version":3,"file":"v11.js","sourceRoot":"","sources":["../../../../src/buffers/utf8/decodeUtf8/v11.ts"],"names":[],"mappings":";;AAAA,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC;AAC7C,kBAAe,CAAC,GAAe,EAAE,KAAa,EAAE,MAAc,EAAU,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,CAAC"}
+2
View File
@@ -0,0 +1,2 @@
declare const _default: (arr: Uint8Array, start: number, length: number) => string;
export default _default;
+7
View File
@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const from = Buffer.from;
exports.default = (arr, start, length) => from(arr)
.subarray(start, start + length)
.toString();
//# sourceMappingURL=v12.js.map
@@ -0,0 +1 @@
{"version":3,"file":"v12.js","sourceRoot":"","sources":["../../../../src/buffers/utf8/decodeUtf8/v12.ts"],"names":[],"mappings":";;AAAA,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;AACzB,kBAAe,CAAC,GAAe,EAAE,KAAa,EAAE,MAAc,EAAU,EAAE,CACxE,IAAI,CAAC,GAAG,CAAC;KACN,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC;KAC/B,QAAQ,EAAE,CAAC"}
+2
View File
@@ -0,0 +1,2 @@
declare let decode: (buf: Uint8Array, start: number, length: number) => string;
export default decode;
+26
View File
@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const v10_1 = tslib_1.__importDefault(require("./v10"));
let decode = v10_1.default;
const hasBuffer = typeof Buffer !== 'undefined';
const utf8Slice = hasBuffer ? Buffer.prototype.utf8Slice : null;
if (utf8Slice) {
decode = (buf, start, length) => length <= 10 ? (0, v10_1.default)(buf, start, length) : utf8Slice.call(buf, start, start + length);
}
else {
const from = hasBuffer ? Buffer.from : null;
if (from) {
decode = (buf, start, length) => length < 30
? (0, v10_1.default)(buf, start, length)
: from(buf)
.subarray(start, start + length)
.toString();
}
else if (typeof TextDecoder !== 'undefined') {
const decoder = new TextDecoder();
decode = (buf, start, length) => length < 150 ? (0, v10_1.default)(buf, start, length) : decoder.decode(buf.subarray(start, start + length));
}
}
exports.default = decode;
//# sourceMappingURL=v13.js.map

Some files were not shown because too many files have changed in this diff Show More