first commit

This commit is contained in:
Stefan Hacker
2026-04-03 09:38:48 +02:00
commit 37ad745546
47450 changed files with 3120798 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
import type { IReader, IReaderResettable } from './types';
export declare class Reader implements IReader, IReaderResettable {
uint8: Uint8Array;
view: DataView;
x: number;
end: number;
constructor(uint8?: Uint8Array, view?: DataView, x?: number, end?: number);
reset(uint8: Uint8Array): void;
size(): number;
/**
* Get current byte value without advancing the cursor.
*/
peek(): number;
/**
* @deprecated Use peek() instead.
*/
peak(): number;
skip(length: number): void;
buf(size?: number): Uint8Array;
subarray(start?: number, end?: number): Uint8Array;
/**
* Creates a new {@link Reader} that references the same underlying memory
* buffer. But with independent cursor and end.
*
* Preferred over {@link buf} since it also provides a DataView and is much
* faster to allocate a new {@link Slice} than a new {@link Uint8Array}.
*
* @param start Start offset relative to the current cursor position.
* @param end End offset relative to the current cursor position.
* @returns A new {@link Reader} instance.
*/
slice(start?: number, end?: number): Reader;
/**
* Similar to {@link slice} but also advances the cursor. Returns a new
* {@link Reader} that references the same underlying memory buffer, starting
* from the current cursor position.
*
* @param size Number of bytes to cut from the current position.
* @returns A new {@link Reader} instance.
*/
cut(size?: number): Reader;
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;
}
+145
View File
@@ -0,0 +1,145 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Reader = void 0;
const decodeUtf8_1 = require("./utf8/decodeUtf8");
class Reader {
constructor(uint8 = new Uint8Array([]), view = new DataView(uint8.buffer, uint8.byteOffset, uint8.length), x = 0, end = uint8.length) {
this.uint8 = uint8;
this.view = view;
this.x = x;
this.end = end;
}
reset(uint8) {
this.x = 0;
this.uint8 = uint8;
this.view = new DataView(uint8.buffer, uint8.byteOffset, uint8.length);
}
size() {
return this.end - this.x;
}
/**
* Get current byte value without advancing the cursor.
*/
peek() {
return this.view.getUint8(this.x);
}
/**
* @deprecated Use peek() instead.
*/
peak() {
return this.peek();
}
skip(length) {
this.x += length;
}
buf(size = this.size()) {
const x = this.x;
const end = x + size;
const bin = this.uint8.subarray(x, end);
this.x = end;
return bin;
}
subarray(start = 0, end) {
const x = this.x;
const actualStart = x + start;
const actualEnd = typeof end === 'number' ? x + end : this.end;
return this.uint8.subarray(actualStart, actualEnd);
}
/**
* Creates a new {@link Reader} that references the same underlying memory
* buffer. But with independent cursor and end.
*
* Preferred over {@link buf} since it also provides a DataView and is much
* faster to allocate a new {@link Slice} than a new {@link Uint8Array}.
*
* @param start Start offset relative to the current cursor position.
* @param end End offset relative to the current cursor position.
* @returns A new {@link Reader} instance.
*/
slice(start = 0, end) {
const x = this.x;
const actualStart = x + start;
const actualEnd = typeof end === 'number' ? x + end : this.end;
return new Reader(this.uint8, this.view, actualStart, actualEnd);
}
/**
* Similar to {@link slice} but also advances the cursor. Returns a new
* {@link Reader} that references the same underlying memory buffer, starting
* from the current cursor position.
*
* @param size Number of bytes to cut from the current position.
* @returns A new {@link Reader} instance.
*/
cut(size = this.size()) {
const slice = this.slice(0, size);
this.skip(size);
return slice;
}
u8() {
return this.uint8[this.x++];
// return this.view.getUint8(this.x++);
}
i8() {
return this.view.getInt8(this.x++);
}
u16() {
// const num = this.view.getUint16(this.x);
// this.x += 2;
// return num;
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/Reader.ts"],"names":[],"mappings":";;;AAAA,kDAA6C;AAG7C,MAAa,MAAM;IACjB,YACS,QAAoB,IAAI,UAAU,CAAC,EAAE,CAAC,EACtC,OAAiB,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAqB,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,EAC1F,IAAY,CAAC,EACb,MAAc,KAAK,CAAC,MAAM;QAH1B,UAAK,GAAL,KAAK,CAAiC;QACtC,SAAI,GAAJ,IAAI,CAAsF;QAC1F,MAAC,GAAD,CAAC,CAAY;QACb,QAAG,GAAH,GAAG,CAAuB;IAChC,CAAC;IAEG,KAAK,CAAC,KAAiB;QAC5B,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAqB,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACxF,CAAC;IAEM,IAAI;QACT,OAAO,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC;IAC3B,CAAC;IAED;;OAEG;IACI,IAAI;QACT,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACI,IAAI;QACT,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;IACrB,CAAC;IAEM,IAAI,CAAC,MAAc;QACxB,IAAI,CAAC,C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AAC,CAAC,GAAG,GAAG,CAAC;QACb,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AA9JD,wBA8JC"}
+11
View File
@@ -0,0 +1,11 @@
/**
* @deprecated Use {@link Reader} instead.
*/
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;
}
+19
View File
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Slice = void 0;
/**
* @deprecated Use {@link Reader} instead.
*/
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/Slice.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,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"}
+30
View File
@@ -0,0 +1,30 @@
/**
* A streaming reader which internally manages multiple chunks of
* Uint8Array instances. For performance it does not merge the chunks into
* a single Uint8Array instance. Instead it keeps track of the chunks and
* reads across chunk boundaries as needed.
*/
export declare class StreamingOctetReader {
protected readonly chunks: Uint8Array[];
/** Total size of all chunks. */
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;
peek(): number;
/**
* Get current byte value without advancing the cursor.
* @deprecated Use peek() instead.
*/
peak(): number;
utf8(length: number, mask: [number, number, number, number], maskIndex: number): string;
}
+182
View File
@@ -0,0 +1,182 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StreamingOctetReader = void 0;
const fromCharCode = String.fromCharCode;
/**
* A streaming reader which internally manages multiple chunks of
* Uint8Array instances. For performance it does not merge the chunks into
* a single Uint8Array instance. Instead it keeps track of the chunks and
* reads across chunk boundaries as needed.
*/
class StreamingOctetReader {
constructor() {
this.chunks = [];
/** Total size of all 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);
}
peek() {
this.assertSize(1);
return this.chunks[0][this.x];
}
/**
* Get current byte value without advancing the cursor.
* @deprecated Use peek() instead.
*/
peak() {
return this.peek();
}
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
+78
View File
@@ -0,0 +1,78 @@
import { Writer } from './Writer';
import type { IReader, IReaderResettable } from './types';
import { Reader } from './Reader';
export declare class StreamingReader implements IReader, IReaderResettable {
protected readonly writer: Writer;
/**
* Offset from the start of the buffer (x0 in Writer).
*/
protected dx: number;
constructor(allocSize?: number);
/**
* Returns the number of bytes remaining in the buffer.
*/
size(): number;
/**
* Assert that there is enough data in the buffer to read `size` bytes.
*
* @param size Number of bytes to read.
*/
protected assertSize(size: number): void;
/**
* Add a chunk of data to be decoded. The chunk is copied into the
* internal buffer, so you can reuse the chunk after calling this method; or
* this chunk can be neutered by the caller.
*
* @param uint8 `Uint8Array` chunk of data to be decoded.
*/
push(uint8: Uint8Array): void;
/**
* Mark the current position as consumed. This will free up memory
* for reuse.
*/
consume(): void;
get uint8(): Uint8Array;
get view(): DataView;
get x(): number;
set x(x: number);
peek(): number;
/**
* Get current byte value without advancing the cursor.
* @deprecated Use peek() instead.
*/
peak(): number;
skip(length: number): void;
buf(size?: number): Uint8Array;
subarray(start?: number, end?: number): Uint8Array;
/**
* Creates a new {@link Reader} that references the same underlying memory
* buffer. But with independent cursor and end.
*
* @param start Start offset relative to the current cursor position.
* @param end End offset relative to the current cursor position.
* @returns A new {@link Reader} instance.
*/
slice(start?: number, end?: number): Reader;
/**
* Similar to {@link slice} but also advances the cursor. Returns a new
* {@link Reader} that references the same underlying memory buffer, starting
* from the current cursor position.
*
* @param size Number of bytes to cut from the current position.
* @returns A new {@link Reader} instance.
*/
cut(size?: number): Reader;
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;
}
+196
View File
@@ -0,0 +1,196 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StreamingReader = void 0;
const Writer_1 = require("./Writer");
const decodeUtf8_1 = require("./utf8/decodeUtf8");
const Reader_1 = require("./Reader");
class StreamingReader {
constructor(allocSize = 16 * 1024) {
/**
* Offset from the start of the buffer (x0 in Writer).
*/
this.dx = 0;
this.writer = new Writer_1.Writer(allocSize);
}
/**
* Returns the number of bytes remaining in the buffer.
*/
size() {
return this.writer.x - this.x;
}
/**
* Assert that there is enough data in the buffer to read `size` bytes.
*
* @param size Number of bytes to read.
*/
assertSize(size) {
if (size > this.size())
throw new RangeError('OUT_OF_BOUNDS');
}
/**
* Add a chunk of data to be decoded. The chunk is copied into the
* internal buffer, so you can reuse the chunk after calling this method; or
* this chunk can be neutered by the caller.
*
* @param uint8 `Uint8Array` chunk of data to be decoded.
*/
push(uint8) {
this.writer.buf(uint8, uint8.length);
}
/**
* Mark the current position as consumed. This will free up memory
* for reuse.
*/
consume() {
this.writer.x0 += this.dx;
this.dx = 0;
}
// ------------------------------------------------------------------ IReader
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;
}
peek() {
this.assertSize(1);
return this.view.getUint8(this.x);
}
/**
* Get current byte value without advancing the cursor.
* @deprecated Use peek() instead.
*/
peak() {
return this.peek();
}
skip(length) {
this.assertSize(length);
this.x += length;
}
buf(size = this.size()) {
this.assertSize(size);
const end = this.x + size;
const bin = this.uint8.subarray(this.x, end);
this.x = end;
return bin;
}
subarray(start = 0, end) {
const x = this.x;
const actualStart = x + start;
const actualEnd = typeof end === 'number' ? x + end : this.size() + x - start;
return this.uint8.subarray(actualStart, actualEnd);
}
/**
* Creates a new {@link Reader} that references the same underlying memory
* buffer. But with independent cursor and end.
*
* @param start Start offset relative to the current cursor position.
* @param end End offset relative to the current cursor position.
* @returns A new {@link Reader} instance.
*/
slice(start = 0, end) {
const x = this.x;
const actualStart = x + start;
const actualEnd = typeof end === 'number' ? x + end : this.size() + x - start;
return new Reader_1.Reader(this.uint8, this.view, actualStart, actualEnd);
}
/**
* Similar to {@link slice} but also advances the cursor. Returns a new
* {@link Reader} that references the same underlying memory buffer, starting
* from the current cursor position.
*
* @param size Number of bytes to cut from the current position.
* @returns A new {@link Reader} instance.
*/
cut(size = this.size()) {
const slice = this.slice(0, size);
this.skip(size);
return slice;
}
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;
}
// -------------------------------------------------------- IReaderResettable
reset(uint8) {
this.dx = 0;
this.writer.reset();
this.push(uint8);
}
}
exports.StreamingReader = StreamingReader;
//# sourceMappingURL=StreamingReader.js.map
File diff suppressed because one or more lines are too long
+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/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"}
+69
View File
@@ -0,0 +1,69 @@
import { Slice } from './Slice';
import type { IWriterGrowable, IWriter } from './types';
/**
* Writer class provides an efficient way to encode binary data. It grows the
* internal memory buffer automatically as more space is required. It is useful
* in cases when it is not known in advance the size of memory needed.
*/
export declare class Writer implements IWriter, IWriterGrowable {
allocSize: number;
/** @ignore */
uint8: Uint8Array;
/** @ignore */
view: DataView;
/** @ignore */
x0: number;
/** @ignore */
x: number;
protected size: number;
/**
* @param allocSize Number of bytes to allocate at a time when buffer ends.
*/
constructor(allocSize?: number);
/** @ignore */
protected grow(size: number): void;
/**
* Make sure the internal buffer has enough space to write the specified number
* of bytes, otherwise resize the internal buffer to accommodate for more size.
*
* @param capacity Number of bytes.
*/
ensureCapacity(capacity: number): void;
/** @todo Consider renaming to "skip"? */
move(capacity: number): void;
reset(): void;
/**
* Allocates a new {@link ArrayBuffer}, useful when the underlying
* {@link ArrayBuffer} cannot be shared between threads.
*
* @param size Size of memory to allocate.
*/
newBuffer(size: number): void;
/**
* @returns Encoded memory buffer contents.
*/
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;
/**
* Encodes string as UTF-8. You need to call .ensureCapacity(str.length * 4)
* before calling
*
* @param str String to encode as UTF-8.
* @returns The number of bytes written
*/
utf8(str: string): number;
utf8Native(str: string): number;
ascii(str: string): void;
}
+254
View File
@@ -0,0 +1,254 @@
"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;
/**
* Writer class provides an efficient way to encode binary data. It grows the
* internal memory buffer automatically as more space is required. It is useful
* in cases when it is not known in advance the size of memory needed.
*/
class Writer {
/**
* @param allocSize Number of bytes to allocate at a time when buffer ends.
*/
constructor(allocSize = 64 * 1024) {
this.allocSize = allocSize;
/** @ignore */
this.view = EMPTY_VIEW;
/** @ignore */
this.x0 = 0;
/** @ignore */
this.x = 0;
this.uint8 = new Uint8Array(allocSize);
this.size = allocSize;
this.view = new DataView(this.uint8.buffer);
}
/** @ignore */
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;
}
/**
* Make sure the internal buffer has enough space to write the specified number
* of bytes, otherwise resize the internal buffer to accommodate for more size.
*
* @param capacity Number of bytes.
*/
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);
}
}
/** @todo Consider renaming to "skip"? */
move(capacity) {
this.ensureCapacity(capacity);
this.x += capacity;
}
reset() {
this.x0 = this.x;
}
/**
* Allocates a new {@link ArrayBuffer}, useful when the underlying
* {@link ArrayBuffer} cannot be shared between threads.
*
* @param size Size of memory to allocate.
*/
newBuffer(size) {
const uint8 = (this.uint8 = new Uint8Array(size));
this.size = size;
this.view = new DataView(uint8.buffer);
this.x = this.x0 = 0;
}
/**
* @returns Encoded memory buffer contents.
*/
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;
}
/**
* Encodes string as UTF-8. You need to call .ensureCapacity(str.length * 4)
* before calling
*
* @param str String to encode as UTF-8.
* @returns The number of bytes written
*/
utf8(str) {
const theoreticalMaxLength = str.length * 4;
if (theoreticalMaxLength < 168)
return this.utf8Native(str);
this.ensureCapacity(theoreticalMaxLength);
const maxLength = this.size - this.x;
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 (theoreticalMaxLength > 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<ArrayBuffer>;
+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/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"}
+1
View File
@@ -0,0 +1 @@
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/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/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"}
+9
View File
@@ -0,0 +1,9 @@
/**
* Compares two `Uint8Arrays` byte-by-byte. Returns a negative number if `a` is
* less than `b`, a positive number if `a` is greater than `b`, or 0 if `a` is
* equal to `b`.
*
* @returns A negative number if a is less than b, a positive number if a is
* greater than b, or 0 if a is equal to b.
*/
export declare const cmpUint8Array2: (a: Uint8Array, b: Uint8Array) => number;
+24
View File
@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cmpUint8Array2 = void 0;
/**
* Compares two `Uint8Arrays` byte-by-byte. Returns a negative number if `a` is
* less than `b`, a positive number if `a` is greater than `b`, or 0 if `a` is
* equal to `b`.
*
* @returns A negative number if a is less than b, a positive number if a is
* greater than b, or 0 if a is equal to b.
*/
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/cmpUint8Array2.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACI,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"}
+9
View File
@@ -0,0 +1,9 @@
/**
* Compares two `Uint8Arrays`, first by length, then by each byte. Returns a
* negative number if `a` is less than `b`, a positive number if `a` is greater
* than `b`, or 0 if `a` is equal to `b`.
*
* @returns A negative number if a is less than b, a positive number if a is
* greater than b, or 0 if a is equal to b.
*/
export declare const cmpUint8Array3: (a: Uint8Array, b: Uint8Array) => number;
+26
View File
@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cmpUint8Array3 = void 0;
/**
* Compares two `Uint8Arrays`, first by length, then by each byte. Returns a
* negative number if `a` is less than `b`, a positive number if `a` is greater
* than `b`, or 0 if `a` is equal to `b`.
*
* @returns A negative number if a is less than b, a positive number if a is
* greater than b, or 0 if a is equal to b.
*/
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/cmpUint8Array3.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACI,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/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/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/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/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/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/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/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/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"}
+2
View File
@@ -0,0 +1,2 @@
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/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/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/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"}
+134
View File
@@ -0,0 +1,134 @@
import type { Slice } from './Slice';
export interface IWriter {
/**
* Uint8Array view of the current memory buffer.
*/
uint8: Uint8Array;
/**
* DataView view of the current memory buffer.
*/
view: DataView;
/**
* Position where last flush happened.
*/
x0: number;
/**
* Current position in the internal buffer.
*/
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;
/**
* Write contents of a buffer.
*
* @param buf Buffer to copy from.
* @param length Number of octets to copy.
*/
buf(buf: Uint8Array, length: number): void;
/**
* Write string as UTF-8. You need to call .ensureCapacity(str.length * 4)
* before calling
*
* @param str JavaScript string to encode as UTF-8 byte sequence.
*/
utf8(str: string): number;
ascii(str: string): void;
}
export interface IWriterGrowable {
/** @deprecated */
reset(): void;
/**
* Calling this method might reset the internal buffer. So, your references
* (such as `x`, `uint8`, `view`) to the internal buffer might become invalid.
*
* @param capacity How many octets to ensure are available after `x`.
*/
ensureCapacity(capacity: number): void;
move(length: number): void;
flush(): Uint8Array;
flushSlice(): Slice;
newBuffer(size: number): void;
}
export interface IReaderBase {
/**
* Creates a new {@link IReaderBase} that references the same underlying memory
* buffer. But with independent cursor and end.
*
* @param start Start offset relative to the current cursor position.
* @param end End offset relative to the current cursor position.
* @returns A new {@link IReaderBase} instance.
*/
slice(start?: number, end?: number): IReaderBase;
/**
* Similar to {@link slice} but also advances the cursor. Returns a new
* {@link IReaderBase} that references the same underlying memory buffer, starting
* from the current cursor position.
*
* @param size Number of bytes to cut from the current position.
* @returns A new {@link IReaderBase} instance.
*/
cut(size?: number): IReaderBase;
subarray(start?: number, end?: number): Uint8Array;
/** Get current byte value without advancing the cursor. */
peek(): number;
/**
* Get current byte value without advancing the cursor.
* @deprecated Use peek() instead.
*/
peak(): number;
/** Advance the cursor given number of octets. */
skip(length: number): void;
/**
* Create a new Uint8Array view of provided length starting at
* the current cursor position.
*
* If size is not provided, it will return a view of all remaining bytes.
*
* @param size Length of the returned Uint8Array.
*/
buf(size?: number): Uint8Array;
u8(): number;
i8(): number;
u16(): number;
i16(): number;
u32(): number;
u64(): bigint;
i64(): bigint;
i32(): number;
f32(): number;
f64(): number;
/**
* Decode a UTF-8 string.
*
* @param size Length of the string.
*/
utf8(size: number): string;
ascii(length: number): string;
}
export interface IReader extends IReaderBase {
/**
* Uint8Array view of the current memory buffer.
*/
uint8: Uint8Array;
/**
* DataView view of the current memory buffer.
*/
view: DataView;
/**
* Cursor in the current memory buffer.
*/
x: number;
}
export interface IReaderResettable {
/** Set a new underlying buffer and reset cursor position to 0. */
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/types.ts"],"names":[],"mappings":""}
+7
View File
@@ -0,0 +1,7 @@
export declare class CachedUtf8Decoder {
private readonly caches;
constructor();
private get;
private store;
decode(bytes: Uint8Array, offset: number, size: number): string;
}
+62
View File
@@ -0,0 +1,62 @@
"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));
/** Generate a random 32-bit unsigned integer in the specified [min, max] range. */
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 /* CONST.MAX_CACHED_STR_LEN */; 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 /* CONST.MAX_RECORDS_PER_SIZE */)
records[randomU32(0, 16 /* CONST.MAX_RECORDS_PER_SIZE */ - 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);
// Ensure to copy a slice of bytes because the byte may be NodeJS Buffer and Buffer#slice() returns a reference to its internal ArrayBuffer.
const copy = Uint8Array.prototype.slice.call(bytes, offset, offset + size);
this.store(copy, value);
return value;
}
}
exports.CachedUtf8Decoder = CachedUtf8Decoder;
//# sourceMappingURL=CachedUtf8Decoder.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"CachedUtf8Decoder.js","sourceRoot":"","sources":["../../src/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;AAEzD,mFAAmF;AACnF,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,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;AAC7C,CAAC;AAED,MAAM,SAAS;IACb,YACkB,KAAiB,EACjB,KAAa;QADb,UAAK,GAAL,KAAK,CAAY;QACjB,UAAK,GAAL,KAAK,CAAQ;IAC5B,CAAC;CACL;AAOD,MAAa,iBAAiB;IAG5B;QACE,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,oCAA2B,EAAE,CAAC,EAAE;YAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1E,CAAC;IAEO,GAAG,CAAC,KAAiB,EAAE,MAAc,EAAE,IAAY;QACzD,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAE,CAAC;QACvC,MAAM,GAAG,GA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,EAAE,IAAI,CAAC,CAAC;QAC9C,4IAA4I;QAC5I,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"}
+3
View File
@@ -0,0 +1,3 @@
/** This code was borrowed form cbor-x under the MIT license. */
export declare const decodeAscii: (src: Uint8Array, position: number, length: number) => string | undefined;
export declare const decodeAsciiMax15: (src: Uint8Array, position: number, length: number) => string | undefined;
+181
View File
@@ -0,0 +1,181 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodeAsciiMax15 = exports.decodeAscii = void 0;
const fromCharCode = String.fromCharCode;
/** This code was borrowed form cbor-x under the MIT license. */
// MIT License
// Copyright (c) 2020 Kris Zyp
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
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
+2
View File
@@ -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
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/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/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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,EAAE,CAAC,GAAG,KAAK,CAAC,GAAG,MAAM,CAAC,CAAC;gBAC7C,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC;YACjC,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);
}
}
return str;
};
//# sourceMappingURL=v10.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"v10.js","sourceRoot":"","sources":["../../../src/utf8/decodeUtf8/v10.ts"],"names":[],"mappings":";;AAAA,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;AAEzC,kBAAe,CAAC,GAAe,EAAE,KAAa,EAAE,MAAc,EAAU,EAAE;IACxE,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,MAAM,GAAG,GAAG,MAAM,GAAG,MAAM,CAAC;IAC5B,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,OAAO,MAAM,GAAG,GAAG,EAAE,CAAC;QACpB,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,CAAE,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;YAC5B,SAAS;QACX,CAAC;QACD,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,CAAE,GAAG,IAAI,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;YAC7B,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;YACrD,SAAS;QACX,CAAC;QACD,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,CAAE,GAAG,IAAI,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;YAC7B,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;YACtE,SAAS;QACX,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,IAAI,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
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"v11.js","sourceRoot":"","sources":["../../../src/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
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"v12.js","sourceRoot":"","sources":["../../../src/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
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"v13.js","sourceRoot":"","sources":["../../../src/utf8/decodeUtf8/v13.ts"],"names":[],"mappings":";;;AAAA,wDAAwB;AAExB,IAAI,MAAM,GAAG,aAAG,CAAC;AAEjB,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;AAChD,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;AAEhE,IAAI,SAAS,EAAE,CAAC;IACd,MAAM,GAAG,CAAC,GAAe,EAAE,KAAa,EAAE,MAAc,EAAU,EAAE,CAClE,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,IAAA,aAAG,EAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,CAAC;AACxF,CAAC;KAAM,CAAC;IACN,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IAC5C,IAAI,IAAI,EAAE,CAAC;QACT,MAAM,GAAG,CAAC,GAAe,EAAE,KAAa,EAAE,MAAc,EAAU,EAAE,CAClE,MAAM,GAAG,EAAE;YACT,CAAC,CAAC,IAAA,aAAG,EAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC;YACzB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;iBACN,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC;iBAC/B,QAAQ,EAAE,CAAC;IACtB,CAAC;SAAM,IAAI,OAAO,WAAW,KAAK,WAAW,EAAE,CAAC;QAC9C,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,MAAM,GAAG,CAAC,GAAe,EAAE,KAAa,EAAE,MAAc,EAAU,EAAE,CAClE,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,IAAA,aAAG,EAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC;IACjG,CAAC;AACH,CAAC;AAED,kBAAe,MAAM,CAAC"}
+2
View File
@@ -0,0 +1,2 @@
declare const _default: (buf: Uint8Array, start: number, length: number) => string;
export default _default;
+10
View File
@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const v10_1 = tslib_1.__importDefault(require("./v10"));
const hasBuffer = typeof Buffer !== 'undefined';
const utf8Slice = hasBuffer ? Buffer.prototype.utf8Slice : null;
exports.default = utf8Slice
? (buf, start, length) => utf8Slice.call(buf, start, start + length)
: v10_1.default;
//# sourceMappingURL=v14.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"v14.js","sourceRoot":"","sources":["../../../src/utf8/decodeUtf8/v14.ts"],"names":[],"mappings":";;;AAAA,wDAAwB;AAExB,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;AAChD,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;AAEhE,kBAAe,SAAS;IACtB,CAAC,CAAC,CAAC,GAAe,EAAE,KAAa,EAAE,MAAc,EAAU,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC;IACxG,CAAC,CAAC,aAAG,CAAC"}
+2
View File
@@ -0,0 +1,2 @@
declare const _default: (buf: Uint8Array, start: number, length: number) => string;
export default _default;
+18
View File
@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const v10_1 = tslib_1.__importDefault(require("./v10"));
const hasBuffer = typeof Buffer !== 'undefined';
const utf8Slice = hasBuffer ? Buffer.prototype.utf8Slice : null;
const from = hasBuffer ? Buffer.from : null;
exports.default = (buf, start, length) => {
const end = start + length;
return length > 8
? utf8Slice
? utf8Slice.call(buf, start, end)
: from
? from(buf).subarray(start, end).toString('utf8')
: (0, v10_1.default)(buf, start, length)
: (0, v10_1.default)(buf, start, length);
};
//# sourceMappingURL=v15.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"v15.js","sourceRoot":"","sources":["../../../src/utf8/decodeUtf8/v15.ts"],"names":[],"mappings":";;;AAAA,wDAAwB;AAExB,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;AAChD,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;AAChE,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AAE5C,kBAAe,CAAC,GAAe,EAAE,KAAa,EAAE,MAAc,EAAU,EAAE;IACxE,MAAM,GAAG,GAAG,KAAK,GAAG,MAAM,CAAC;IAC3B,OAAO,MAAM,GAAG,CAAC;QACf,CAAC,CAAC,SAAS;YACT,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC;YACjC,CAAC,CAAC,IAAI;gBACJ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;gBACjD,CAAC,CAAC,IAAA,aAAG,EAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC;QAC7B,CAAC,CAAC,IAAA,aAAG,EAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAC9B,CAAC,CAAC"}
+3
View File
@@ -0,0 +1,3 @@
type Decoder = (buf: Uint8Array, start: number, length: number) => string;
declare const decoder: Decoder;
export default decoder;

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