@sarakusha/ebml 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/README.md +43 -0
- package/build/CancelError.cjs +14 -0
- package/build/CancelError.cjs.map +1 -0
- package/build/CancelError.d.cts +1 -0
- package/build/CancelError.d.mts +7 -0
- package/build/CancelError.d.mts.map +1 -0
- package/build/CancelError.mjs +10 -0
- package/build/CancelError.mjs.map +1 -0
- package/build/Deferred-7Cu0KIje.mjs +28 -0
- package/build/Deferred-7Cu0KIje.mjs.map +1 -0
- package/build/Deferred-CB69mtbF.cjs +33 -0
- package/build/Deferred-CB69mtbF.cjs.map +1 -0
- package/build/Element-8JyOKTYb.cjs +73 -0
- package/build/Element-8JyOKTYb.cjs.map +1 -0
- package/build/Element-CC4E6wMR.d.mts +134 -0
- package/build/Element-CC4E6wMR.d.mts.map +1 -0
- package/build/Element-ChEar-fo.mjs +20 -0
- package/build/Element-ChEar-fo.mjs.map +1 -0
- package/build/FadeTransform.cjs +90 -0
- package/build/FadeTransform.cjs.map +1 -0
- package/build/FadeTransform.d.cts +1 -0
- package/build/FadeTransform.d.mts +17 -0
- package/build/FadeTransform.d.mts.map +1 -0
- package/build/FadeTransform.mjs +86 -0
- package/build/FadeTransform.mjs.map +1 -0
- package/build/RangeFetcher.cjs +63 -0
- package/build/RangeFetcher.cjs.map +1 -0
- package/build/RangeFetcher.d.cts +1 -0
- package/build/RangeFetcher.d.mts +14 -0
- package/build/RangeFetcher.d.mts.map +1 -0
- package/build/RangeFetcher.mjs +59 -0
- package/build/RangeFetcher.mjs.map +1 -0
- package/build/ReducingValve.cjs +129 -0
- package/build/ReducingValve.cjs.map +1 -0
- package/build/ReducingValve.d.cts +1 -0
- package/build/ReducingValve.d.mts +17 -0
- package/build/ReducingValve.d.mts.map +1 -0
- package/build/ReducingValve.mjs +125 -0
- package/build/ReducingValve.mjs.map +1 -0
- package/build/VideoChunkGenerator.cjs +131 -0
- package/build/VideoChunkGenerator.cjs.map +1 -0
- package/build/VideoChunkGenerator.d.cts +1 -0
- package/build/VideoChunkGenerator.d.mts +13 -0
- package/build/VideoChunkGenerator.d.mts.map +1 -0
- package/build/VideoChunkGenerator.mjs +127 -0
- package/build/VideoChunkGenerator.mjs.map +1 -0
- package/build/VideoFrameGenerator.cjs +133 -0
- package/build/VideoFrameGenerator.cjs.map +1 -0
- package/build/VideoFrameGenerator.d.cts +1 -0
- package/build/VideoFrameGenerator.d.mts +10 -0
- package/build/VideoFrameGenerator.d.mts.map +1 -0
- package/build/VideoFrameGenerator.mjs +129 -0
- package/build/VideoFrameGenerator.mjs.map +1 -0
- package/build/index.cjs +6315 -0
- package/build/index.cjs.map +1 -0
- package/build/index.d.cts +1 -0
- package/build/index.d.mts +31 -0
- package/build/index.d.mts.map +1 -0
- package/build/index.mjs +6292 -0
- package/build/index.mjs.map +1 -0
- package/build/tools-CYLlbo9J.mjs +79 -0
- package/build/tools-CYLlbo9J.mjs.map +1 -0
- package/build/tools-DQrZvGBN.cjs +138 -0
- package/build/tools-DQrZvGBN.cjs.map +1 -0
- package/package.json +213 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
//#region src/tools.ts
|
|
2
|
+
const readVINT = (uint8) => {
|
|
3
|
+
if (!uint8.length) return null;
|
|
4
|
+
if (!uint8[0]) throw new Error(`Invalid VINT, VINT_MARKER not found`);
|
|
5
|
+
const marker = Math.floor(Math.log2(uint8[0]));
|
|
6
|
+
const mask = (1 << marker) - 1;
|
|
7
|
+
const width = 8 - marker;
|
|
8
|
+
if (uint8.length < width) return { width };
|
|
9
|
+
if (width === 8 && uint8[1] >= 32 && uint8.subarray(2, 8).some((b) => b !== 0)) return {
|
|
10
|
+
width: 8,
|
|
11
|
+
data: -1
|
|
12
|
+
};
|
|
13
|
+
return {
|
|
14
|
+
width,
|
|
15
|
+
data: uint8.subarray(1, width).reduce((acc, b) => acc * 256 + b, uint8[0] & mask)
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const readHexString = (uint8) => uint8.reduce((acc, b) => `${acc}${b.toString(16).padStart(2, "0")}`, "").toUpperCase();
|
|
19
|
+
const readUnsigned = (uint8) => uint8.byteLength <= 6 ? uint8.reduce((acc, b) => acc * 256 + b) : uint8.reduce((acc, b) => (acc << 8n) + BigInt(b), 0n);
|
|
20
|
+
const readSigned = (uint8) => {
|
|
21
|
+
const unsigned = readUnsigned(uint8);
|
|
22
|
+
const sign = uint8[0] & 128;
|
|
23
|
+
if (typeof unsigned === "bigint") return sign ? unsigned - (1n << 8n * BigInt(uint8.byteLength)) : unsigned;
|
|
24
|
+
return sign ? unsigned - 2 ** (uint8.byteLength * 8) : unsigned;
|
|
25
|
+
};
|
|
26
|
+
const readFloat = (uint8) => {
|
|
27
|
+
const view = new DataView(uint8.buffer, uint8.byteOffset, uint8.byteLength);
|
|
28
|
+
switch (uint8.byteLength) {
|
|
29
|
+
case 4: return view.getFloat32(0);
|
|
30
|
+
case 8: return view.getFloat64(0);
|
|
31
|
+
default: return NaN;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const readUtf8 = (uint8) => new TextDecoder().decode(uint8);
|
|
35
|
+
const readAscii = (uint8) => new TextDecoder("ascii").decode(uint8);
|
|
36
|
+
const readDate = (uint8) => {
|
|
37
|
+
if (uint8.byteLength !== 8) throw new TypeError(`Invalid date (size: ${uint8.byteLength}`);
|
|
38
|
+
const date = /* @__PURE__ */ new Date("2001-01-01T00:00:00");
|
|
39
|
+
const offset = Number(readSigned(uint8));
|
|
40
|
+
date.setMilliseconds(offset);
|
|
41
|
+
return date;
|
|
42
|
+
};
|
|
43
|
+
const delay = (ms) => new Promise((resolve) => {
|
|
44
|
+
setTimeout(resolve, ms);
|
|
45
|
+
});
|
|
46
|
+
const mergeStreams = (...streams) => {
|
|
47
|
+
const { readable, writable } = new TransformStream();
|
|
48
|
+
let total = 0;
|
|
49
|
+
let ready = Promise.resolve();
|
|
50
|
+
const result = Object.defineProperties(readable, {
|
|
51
|
+
add: {
|
|
52
|
+
value: (...args) => {
|
|
53
|
+
total += args.length;
|
|
54
|
+
ready = args.reduce((prev, stream) => prev.then(() => stream.pipeTo(writable, { preventClose: true }).then(() => {
|
|
55
|
+
total -= 1;
|
|
56
|
+
})), ready);
|
|
57
|
+
return ready;
|
|
58
|
+
},
|
|
59
|
+
enumerable: true,
|
|
60
|
+
configurable: false
|
|
61
|
+
},
|
|
62
|
+
length: {
|
|
63
|
+
get() {
|
|
64
|
+
return total;
|
|
65
|
+
},
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: false
|
|
68
|
+
},
|
|
69
|
+
ready: { get() {
|
|
70
|
+
return ready;
|
|
71
|
+
} }
|
|
72
|
+
});
|
|
73
|
+
result.add(...streams);
|
|
74
|
+
return result;
|
|
75
|
+
};
|
|
76
|
+
//#endregion
|
|
77
|
+
export { readFloat as a, readUnsigned as c, readDate as i, readUtf8 as l, mergeStreams as n, readHexString as o, readAscii as r, readSigned as s, delay as t, readVINT as u };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=tools-CYLlbo9J.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools-CYLlbo9J.mjs","names":[],"sources":["../src/tools.ts"],"sourcesContent":["export type VINT_WIDTH = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;\n\nexport type VINT = {\n data?: number;\n width: VINT_WIDTH;\n};\n\nexport const readVINT = (uint8: Uint8Array): VINT | null => {\n if (!uint8.length) return null;\n if (!uint8[0]) throw new Error(`Invalid VINT, VINT_MARKER not found`);\n const marker = Math.floor(Math.log2(uint8[0]));\n const mask = (1 << marker) - 1;\n const width = (8 - marker) as VINT_WIDTH;\n\n if (uint8.length < width) return { width };\n\n // Max representable integer in JS\n if (width === 8 && uint8[1] >= 0x20 && uint8.subarray(2, 8).some((b) => b !== 0)) {\n return {\n width: 8,\n data: -1,\n };\n }\n\n const data = uint8.subarray(1, width).reduce((acc, b) => acc * 256 + b, uint8[0] & mask);\n\n return {\n width,\n data,\n };\n};\n\nexport const readHexString = (uint8: Uint8Array): string =>\n uint8.reduce((acc, b) => `${acc}${b.toString(16).padStart(2, '0')}`, '').toUpperCase();\n\nexport const readUnsigned = (uint8: Uint8Array): number | bigint =>\n uint8.byteLength <= 6\n ? uint8.reduce((acc, b) => acc * 256 + b)\n : uint8.reduce((acc, b) => (acc << 8n) + BigInt(b), 0n);\n\nexport const readSigned = (uint8: Uint8Array): number | bigint => {\n const unsigned = readUnsigned(uint8);\n const sign = uint8[0] & 0x80;\n if (typeof unsigned === 'bigint')\n return sign ? unsigned - (1n << (8n * BigInt(uint8.byteLength))) : unsigned;\n return sign ? unsigned - 2 ** (uint8.byteLength * 8) : unsigned;\n};\n\nexport const readFloat = (uint8: Uint8Array): number => {\n const view = new DataView(uint8.buffer, uint8.byteOffset, uint8.byteLength);\n switch (uint8.byteLength) {\n case 4:\n return view.getFloat32(0);\n case 8:\n return view.getFloat64(0);\n default:\n return NaN;\n }\n};\n\nexport const readUtf8 = (uint8: Uint8Array): string => new TextDecoder().decode(uint8);\n\nexport const readAscii = (uint8: Uint8Array): string => new TextDecoder('ascii').decode(uint8);\n\nexport const readDate = (uint8: Uint8Array): Date => {\n if (uint8.byteLength !== 8) throw new TypeError(`Invalid date (size: ${uint8.byteLength}`);\n const date = new Date('2001-01-01T00:00:00');\n const offset = Number(readSigned(uint8));\n date.setMilliseconds(offset);\n return date;\n};\n\nexport const delay = (ms: number): Promise<void> =>\n new Promise((resolve) => {\n setTimeout(resolve, ms);\n });\n\nexport interface MergeableStream<T> extends ReadableStream<T> {\n add(...streams: ReadableStream<T>[]): Promise<void>;\n length: number;\n ready: Promise<void>;\n}\n\nexport const mergeStreams = <T>(...streams: ReadableStream<T>[]): MergeableStream<T> => {\n const passThrough = new TransformStream<T, T>();\n const { readable, writable } = passThrough;\n let total = 0;\n let ready = Promise.resolve();\n const result = Object.defineProperties(readable, {\n add: {\n value: (...args: ReadableStream<T>[]): Promise<void> => {\n total += args.length;\n ready = args.reduce(\n (prev, stream) =>\n prev.then(() =>\n stream.pipeTo(writable, { preventClose: true }).then(() => {\n total -= 1;\n }),\n ),\n ready,\n );\n return ready;\n },\n enumerable: true,\n configurable: false,\n },\n length: {\n get() {\n return total;\n },\n enumerable: true,\n configurable: false,\n },\n ready: {\n get() {\n return ready;\n },\n },\n }) as MergeableStream<T>;\n result.add(...streams);\n return result;\n};\n"],"mappings":";AAOA,MAAa,YAAY,UAAmC;CAC1D,IAAI,CAAC,MAAM,QAAQ,OAAO;CAC1B,IAAI,CAAC,MAAM,IAAI,MAAM,IAAI,MAAM,qCAAqC;CACpE,MAAM,SAAS,KAAK,MAAM,KAAK,KAAK,MAAM,EAAE,CAAC;CAC7C,MAAM,QAAQ,KAAK,UAAU;CAC7B,MAAM,QAAS,IAAI;CAEnB,IAAI,MAAM,SAAS,OAAO,OAAO,EAAE,MAAM;CAGzC,IAAI,UAAU,KAAK,MAAM,MAAM,MAAQ,MAAM,SAAS,GAAG,CAAC,EAAE,MAAM,MAAM,MAAM,CAAC,GAC7E,OAAO;EACL,OAAO;EACP,MAAM;CACR;CAKF,OAAO;EACL;EACA,MAJW,MAAM,SAAS,GAAG,KAAK,EAAE,QAAQ,KAAK,MAAM,MAAM,MAAM,GAAG,MAAM,KAAK,IAI9E;CACL;AACF;AAEA,MAAa,iBAAiB,UAC5B,MAAM,QAAQ,KAAK,MAAM,GAAG,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,KAAK,EAAE,EAAE,YAAY;AAEvF,MAAa,gBAAgB,UAC3B,MAAM,cAAc,IAChB,MAAM,QAAQ,KAAK,MAAM,MAAM,MAAM,CAAC,IACtC,MAAM,QAAQ,KAAK,OAAO,OAAO,MAAM,OAAO,CAAC,GAAG,EAAE;AAE1D,MAAa,cAAc,UAAuC;CAChE,MAAM,WAAW,aAAa,KAAK;CACnC,MAAM,OAAO,MAAM,KAAK;CACxB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AAY;GACZ,cAAc;EAChB;EACA,OAAO,EACL,MAAM;GACJ,OAAO;EACT,EACF;CACF,CAAC;CACD,OAAO,IAAI,GAAG,OAAO;CACrB,OAAO;AACT"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
//#region src/tools.ts
|
|
2
|
+
const readVINT = (uint8) => {
|
|
3
|
+
if (!uint8.length) return null;
|
|
4
|
+
if (!uint8[0]) throw new Error(`Invalid VINT, VINT_MARKER not found`);
|
|
5
|
+
const marker = Math.floor(Math.log2(uint8[0]));
|
|
6
|
+
const mask = (1 << marker) - 1;
|
|
7
|
+
const width = 8 - marker;
|
|
8
|
+
if (uint8.length < width) return { width };
|
|
9
|
+
if (width === 8 && uint8[1] >= 32 && uint8.subarray(2, 8).some((b) => b !== 0)) return {
|
|
10
|
+
width: 8,
|
|
11
|
+
data: -1
|
|
12
|
+
};
|
|
13
|
+
return {
|
|
14
|
+
width,
|
|
15
|
+
data: uint8.subarray(1, width).reduce((acc, b) => acc * 256 + b, uint8[0] & mask)
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const readHexString = (uint8) => uint8.reduce((acc, b) => `${acc}${b.toString(16).padStart(2, "0")}`, "").toUpperCase();
|
|
19
|
+
const readUnsigned = (uint8) => uint8.byteLength <= 6 ? uint8.reduce((acc, b) => acc * 256 + b) : uint8.reduce((acc, b) => (acc << 8n) + BigInt(b), 0n);
|
|
20
|
+
const readSigned = (uint8) => {
|
|
21
|
+
const unsigned = readUnsigned(uint8);
|
|
22
|
+
const sign = uint8[0] & 128;
|
|
23
|
+
if (typeof unsigned === "bigint") return sign ? unsigned - (1n << 8n * BigInt(uint8.byteLength)) : unsigned;
|
|
24
|
+
return sign ? unsigned - 2 ** (uint8.byteLength * 8) : unsigned;
|
|
25
|
+
};
|
|
26
|
+
const readFloat = (uint8) => {
|
|
27
|
+
const view = new DataView(uint8.buffer, uint8.byteOffset, uint8.byteLength);
|
|
28
|
+
switch (uint8.byteLength) {
|
|
29
|
+
case 4: return view.getFloat32(0);
|
|
30
|
+
case 8: return view.getFloat64(0);
|
|
31
|
+
default: return NaN;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const readUtf8 = (uint8) => new TextDecoder().decode(uint8);
|
|
35
|
+
const readAscii = (uint8) => new TextDecoder("ascii").decode(uint8);
|
|
36
|
+
const readDate = (uint8) => {
|
|
37
|
+
if (uint8.byteLength !== 8) throw new TypeError(`Invalid date (size: ${uint8.byteLength}`);
|
|
38
|
+
const date = /* @__PURE__ */ new Date("2001-01-01T00:00:00");
|
|
39
|
+
const offset = Number(readSigned(uint8));
|
|
40
|
+
date.setMilliseconds(offset);
|
|
41
|
+
return date;
|
|
42
|
+
};
|
|
43
|
+
const delay = (ms) => new Promise((resolve) => {
|
|
44
|
+
setTimeout(resolve, ms);
|
|
45
|
+
});
|
|
46
|
+
const mergeStreams = (...streams) => {
|
|
47
|
+
const { readable, writable } = new TransformStream();
|
|
48
|
+
let total = 0;
|
|
49
|
+
let ready = Promise.resolve();
|
|
50
|
+
const result = Object.defineProperties(readable, {
|
|
51
|
+
add: {
|
|
52
|
+
value: (...args) => {
|
|
53
|
+
total += args.length;
|
|
54
|
+
ready = args.reduce((prev, stream) => prev.then(() => stream.pipeTo(writable, { preventClose: true }).then(() => {
|
|
55
|
+
total -= 1;
|
|
56
|
+
})), ready);
|
|
57
|
+
return ready;
|
|
58
|
+
},
|
|
59
|
+
enumerable: true,
|
|
60
|
+
configurable: false
|
|
61
|
+
},
|
|
62
|
+
length: {
|
|
63
|
+
get() {
|
|
64
|
+
return total;
|
|
65
|
+
},
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: false
|
|
68
|
+
},
|
|
69
|
+
ready: { get() {
|
|
70
|
+
return ready;
|
|
71
|
+
} }
|
|
72
|
+
});
|
|
73
|
+
result.add(...streams);
|
|
74
|
+
return result;
|
|
75
|
+
};
|
|
76
|
+
//#endregion
|
|
77
|
+
Object.defineProperty(exports, "delay", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function() {
|
|
80
|
+
return delay;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(exports, "mergeStreams", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
get: function() {
|
|
86
|
+
return mergeStreams;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(exports, "readAscii", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
get: function() {
|
|
92
|
+
return readAscii;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(exports, "readDate", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
get: function() {
|
|
98
|
+
return readDate;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
Object.defineProperty(exports, "readFloat", {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
get: function() {
|
|
104
|
+
return readFloat;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(exports, "readHexString", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
get: function() {
|
|
110
|
+
return readHexString;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
Object.defineProperty(exports, "readSigned", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
get: function() {
|
|
116
|
+
return readSigned;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
Object.defineProperty(exports, "readUnsigned", {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
get: function() {
|
|
122
|
+
return readUnsigned;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
Object.defineProperty(exports, "readUtf8", {
|
|
126
|
+
enumerable: true,
|
|
127
|
+
get: function() {
|
|
128
|
+
return readUtf8;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
Object.defineProperty(exports, "readVINT", {
|
|
132
|
+
enumerable: true,
|
|
133
|
+
get: function() {
|
|
134
|
+
return readVINT;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
//# sourceMappingURL=tools-DQrZvGBN.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools-DQrZvGBN.cjs","names":[],"sources":["../src/tools.ts"],"sourcesContent":["export type VINT_WIDTH = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;\n\nexport type VINT = {\n data?: number;\n width: VINT_WIDTH;\n};\n\nexport const readVINT = (uint8: Uint8Array): VINT | null => {\n if (!uint8.length) return null;\n if (!uint8[0]) throw new Error(`Invalid VINT, VINT_MARKER not found`);\n const marker = Math.floor(Math.log2(uint8[0]));\n const mask = (1 << marker) - 1;\n const width = (8 - marker) as VINT_WIDTH;\n\n if (uint8.length < width) return { width };\n\n // Max representable integer in JS\n if (width === 8 && uint8[1] >= 0x20 && uint8.subarray(2, 8).some((b) => b !== 0)) {\n return {\n width: 8,\n data: -1,\n };\n }\n\n const data = uint8.subarray(1, width).reduce((acc, b) => acc * 256 + b, uint8[0] & mask);\n\n return {\n width,\n data,\n };\n};\n\nexport const readHexString = (uint8: Uint8Array): string =>\n uint8.reduce((acc, b) => `${acc}${b.toString(16).padStart(2, '0')}`, '').toUpperCase();\n\nexport const readUnsigned = (uint8: Uint8Array): number | bigint =>\n uint8.byteLength <= 6\n ? uint8.reduce((acc, b) => acc * 256 + b)\n : uint8.reduce((acc, b) => (acc << 8n) + BigInt(b), 0n);\n\nexport const readSigned = (uint8: Uint8Array): number | bigint => {\n const unsigned = readUnsigned(uint8);\n const sign = uint8[0] & 0x80;\n if (typeof unsigned === 'bigint')\n return sign ? unsigned - (1n << (8n * BigInt(uint8.byteLength))) : unsigned;\n return sign ? unsigned - 2 ** (uint8.byteLength * 8) : unsigned;\n};\n\nexport const readFloat = (uint8: Uint8Array): number => {\n const view = new DataView(uint8.buffer, uint8.byteOffset, uint8.byteLength);\n switch (uint8.byteLength) {\n case 4:\n return view.getFloat32(0);\n case 8:\n return view.getFloat64(0);\n default:\n return NaN;\n }\n};\n\nexport const readUtf8 = (uint8: Uint8Array): string => new TextDecoder().decode(uint8);\n\nexport const readAscii = (uint8: Uint8Array): string => new TextDecoder('ascii').decode(uint8);\n\nexport const readDate = (uint8: Uint8Array): Date => {\n if (uint8.byteLength !== 8) throw new TypeError(`Invalid date (size: ${uint8.byteLength}`);\n const date = new Date('2001-01-01T00:00:00');\n const offset = Number(readSigned(uint8));\n date.setMilliseconds(offset);\n return date;\n};\n\nexport const delay = (ms: number): Promise<void> =>\n new Promise((resolve) => {\n setTimeout(resolve, ms);\n });\n\nexport interface MergeableStream<T> extends ReadableStream<T> {\n add(...streams: ReadableStream<T>[]): Promise<void>;\n length: number;\n ready: Promise<void>;\n}\n\nexport const mergeStreams = <T>(...streams: ReadableStream<T>[]): MergeableStream<T> => {\n const passThrough = new TransformStream<T, T>();\n const { readable, writable } = passThrough;\n let total = 0;\n let ready = Promise.resolve();\n const result = Object.defineProperties(readable, {\n add: {\n value: (...args: ReadableStream<T>[]): Promise<void> => {\n total += args.length;\n ready = args.reduce(\n (prev, stream) =>\n prev.then(() =>\n stream.pipeTo(writable, { preventClose: true }).then(() => {\n total -= 1;\n }),\n ),\n ready,\n );\n return ready;\n },\n enumerable: true,\n configurable: false,\n },\n length: {\n get() {\n return total;\n },\n enumerable: true,\n configurable: false,\n },\n ready: {\n get() {\n return ready;\n },\n },\n }) as MergeableStream<T>;\n result.add(...streams);\n return result;\n};\n"],"mappings":";AAOA,MAAa,YAAY,UAAmC;CAC1D,IAAI,CAAC,MAAM,QAAQ,OAAO;CAC1B,IAAI,CAAC,MAAM,IAAI,MAAM,IAAI,MAAM,qCAAqC;CACpE,MAAM,SAAS,KAAK,MAAM,KAAK,KAAK,MAAM,EAAE,CAAC;CAC7C,MAAM,QAAQ,KAAK,UAAU;CAC7B,MAAM,QAAS,IAAI;CAEnB,IAAI,MAAM,SAAS,OAAO,OAAO,EAAE,MAAM;CAGzC,IAAI,UAAU,KAAK,MAAM,MAAM,MAAQ,MAAM,SAAS,GAAG,CAAC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CACvC,KAAK,gBAAgB,MAAM;CAC3B,OAAO;AACT;AAEA,MAAa,SAAS,OACpB,IAAI,SAAS,YAAY;CACvB,WAAW,SAAS,EAAE;AACxB,CAAC;AAQH,MAAa,gBAAmB,GAAG,YAAqD;CAEtF,MAAM,EAAE,UAAU,aAAa,IADP,gBACiB;CACzC,IAAI,QAAQ;CACZ,IAAI,QAAQ,QAAQ,QAAQ;CAC5B,MAAM,SAAS,OAAO,iBAAiB,UAAU;EAC/C,KAAK;GACH,QAAQ,GAAG,SAA6C;IACtD,SAAS,KAAK;IACd,QAAQ,KAAK,QACV,MAAM,WACL,KAAK,WACH,OAAO,OAAO,UAAU,EAAE,cAAc,KAAK,CAAC,EAAE,WAAW;KACzD,SAAS;IACX,CAAC,CACH,GACF,KACF;IACA,OAAO;GACT;GACA,YAAY;GACZ,cAAc;EAChB;EACA,QAAQ;GACN,MAAM;IACJ,OAAO;GACT;GACA,YAAY;GACZ,cAAc;EAChB;EACA,OAAO,EACL,MAAM;GACJ,OAAO;EACT,EACF;CACF,CAAC;CACD,OAAO,IAAI,GAAG,OAAO;CACrB,OAAO;AACT"}
|
package/package.json
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sarakusha/ebml",
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "./build/index.cjs",
|
|
6
|
+
"types": "./build/index.d.mts",
|
|
7
|
+
"module": "./build/index.mjs",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./build/index.d.mts",
|
|
12
|
+
"default": "./build/index.mjs"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./build/index.d.cts",
|
|
16
|
+
"default": "./build/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"./VideoChunkGenerator": {
|
|
20
|
+
"import": {
|
|
21
|
+
"types": "./build/VideoChunkGenerator.d.mts",
|
|
22
|
+
"default": "./build/VideoChunkGenerator.mjs"
|
|
23
|
+
},
|
|
24
|
+
"require": {
|
|
25
|
+
"types": "./build/VideoChunkGenerator.d.cts",
|
|
26
|
+
"default": "./build/VideoChunkGenerator.cjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"./VideoFrameGenerator": {
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./build/VideoFrameGenerator.d.mts",
|
|
32
|
+
"default": "./build/VideoFrameGenerator.mjs"
|
|
33
|
+
},
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./build/VideoFrameGenerator.d.cts",
|
|
36
|
+
"default": "./build/VideoFrameGenerator.cjs"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"./FadeTransform": {
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./build/FadeTransform.d.mts",
|
|
42
|
+
"default": "./build/FadeTransform.mjs"
|
|
43
|
+
},
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./build/FadeTransform.d.cts",
|
|
46
|
+
"default": "./build/FadeTransform.cjs"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"./ReducingValve": {
|
|
50
|
+
"import": {
|
|
51
|
+
"types": "./build/ReducingValve.d.mts",
|
|
52
|
+
"default": "./build/ReducingValve.mjs"
|
|
53
|
+
},
|
|
54
|
+
"require": {
|
|
55
|
+
"types": "./build/ReducingValve.d.cts",
|
|
56
|
+
"default": "./build/ReducingValve.cjs"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"./RangeFetcher": {
|
|
60
|
+
"import": {
|
|
61
|
+
"types": "./build/RangeFetcher.d.mts",
|
|
62
|
+
"default": "./build/RangeFetcher.mjs"
|
|
63
|
+
},
|
|
64
|
+
"require": {
|
|
65
|
+
"types": "./build/RangeFetcher.d.cts",
|
|
66
|
+
"default": "./build/RangeFetcher.cjs"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"./CancelError": {
|
|
70
|
+
"import": {
|
|
71
|
+
"types": "./build/CancelError.d.mts",
|
|
72
|
+
"default": "./build/CancelError.mjs"
|
|
73
|
+
},
|
|
74
|
+
"require": {
|
|
75
|
+
"types": "./build/CancelError.d.cts",
|
|
76
|
+
"default": "./build/CancelError.cjs"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"./package.json": "./package.json"
|
|
80
|
+
},
|
|
81
|
+
"typesVersions": {
|
|
82
|
+
"*": {
|
|
83
|
+
"VideoChunkGenerator": [
|
|
84
|
+
"./build/VideoChunkGenerator.d.mts"
|
|
85
|
+
],
|
|
86
|
+
"VideoFrameGenerator": [
|
|
87
|
+
"./build/VideoFrameGenerator.d.mts"
|
|
88
|
+
],
|
|
89
|
+
"FadeTransform": [
|
|
90
|
+
"./build/FadeTransform.d.mts"
|
|
91
|
+
],
|
|
92
|
+
"ReducingValve": [
|
|
93
|
+
"./build/ReducingValve.d.mts"
|
|
94
|
+
],
|
|
95
|
+
"RangeFetcher": [
|
|
96
|
+
"./build/RangeFetcher.d.mts"
|
|
97
|
+
],
|
|
98
|
+
"CancelError": [
|
|
99
|
+
"./build/CancelError.d.mts"
|
|
100
|
+
],
|
|
101
|
+
"index": [
|
|
102
|
+
"./build/index.d.mts"
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
"files": [
|
|
107
|
+
"build",
|
|
108
|
+
"!**/*.test.*",
|
|
109
|
+
"!**/*.spec.*",
|
|
110
|
+
"!**/*.tsbuildinfo",
|
|
111
|
+
"CHANGELOG.md",
|
|
112
|
+
"LICENSE",
|
|
113
|
+
"README.md"
|
|
114
|
+
],
|
|
115
|
+
"repository": "https://github.com/sarakusha/ebml",
|
|
116
|
+
"homepage": "https://sarakusha.github.io/ebml",
|
|
117
|
+
"author": {
|
|
118
|
+
"email": "sarakusha@gmail.com",
|
|
119
|
+
"name": "Andrei Sarakeev"
|
|
120
|
+
},
|
|
121
|
+
"scripts": {
|
|
122
|
+
"rsync:ubuntu": "rsync -avz --delete --exclude=.git --include=.gitignore --filter=':- .gitignore' . user@192.168.0.80:~/src/ebml",
|
|
123
|
+
"rsync:vm": "rsync -avz --delete --exclude=.git --include=.gitignore --filter=':- .gitignore' . admin@$(tart ip ubuntu):~/src/ebml",
|
|
124
|
+
"yalc:push": "yalc push",
|
|
125
|
+
"build": "tsdown",
|
|
126
|
+
"fix": "run-s fix:*",
|
|
127
|
+
"fix:prettier": "prettier \"src/**/*.ts\" --write",
|
|
128
|
+
"fix:lint": "eslint src --fix",
|
|
129
|
+
"test": "run-s build test:*",
|
|
130
|
+
"test:lint": "eslint src",
|
|
131
|
+
"test:prettier": "prettier \"src/**/*.ts\" --check",
|
|
132
|
+
"test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"",
|
|
133
|
+
"test:unit": "jest src",
|
|
134
|
+
"typecheck": "tsc --noEmit",
|
|
135
|
+
"watch:build": "tsdown --watch",
|
|
136
|
+
"watch:test": "jest src --watch",
|
|
137
|
+
"cov": "run-s build cov:html && open-cli coverage/index.html",
|
|
138
|
+
"cov:html": "jest src --coverage --coverageReporters=html",
|
|
139
|
+
"cov:lcov": "jest src --coverage --coverageReporters=lcov",
|
|
140
|
+
"cov:send": "run-s cov:lcov && curl -s https://codecov.io/bash | bash",
|
|
141
|
+
"doc": "run-s doc:html && open-cli build/docs/index.html",
|
|
142
|
+
"doc:html": "typedoc --entryPointStrategy expand src/ --exclude **/*.spec.ts --out build/docs ",
|
|
143
|
+
"doc:json": "typedoc --entryPointStrategy expand src/ --exclude **/*.spec.ts --json build/docs/typedoc.json",
|
|
144
|
+
"doc:publish": "gh-pages -m \"[ci skip] Updates\" -d build/docs",
|
|
145
|
+
"release:version": "standard-version",
|
|
146
|
+
"release:publish": "git push --follow-tags origin main && npm publish",
|
|
147
|
+
"release:dry-run": "npm publish --registry=http://localhost:4873",
|
|
148
|
+
"download:win": "run-p download:win:*",
|
|
149
|
+
"download:nix": "run-p download:nix:*",
|
|
150
|
+
"download:win:ebml": "npx --yes download-cli https://raw.githubusercontent.com/ietf-wg-cellar/ebml-specification/master/ebml.xml --out schema/",
|
|
151
|
+
"download:nix:ebml": "wget https://raw.githubusercontent.com/ietf-wg-cellar/ebml-specification/master/ebml.xml -O schema/ebml.xml",
|
|
152
|
+
"download:win:matroska": "npx --yes download-cli https://raw.githubusercontent.com/ietf-wg-cellar/matroska-specification/master/ebml_matroska.xml --out schema/",
|
|
153
|
+
"download:nix:matroska": "wget https://raw.githubusercontent.com/ietf-wg-cellar/matroska-specification/master/ebml_matroska.xml -O schema/ebml_matroska.xml",
|
|
154
|
+
"gen:schema": "echo '// generated automatically\nexport default' > src/matroska.ts && npx fxparser -ns -c ./schema/ebml_matroska.xml >> src/matroska.ts && echo '// generated automatically\nexport default' > src/ebml.ts && npx fxparser -ns -c ./schema/ebml.xml >> src/ebml.ts && prettier src/{matroska,ebml}.ts --write"
|
|
155
|
+
},
|
|
156
|
+
"engines": {
|
|
157
|
+
"node": ">=16"
|
|
158
|
+
},
|
|
159
|
+
"devDependencies": {
|
|
160
|
+
"@commitlint/cli": "^21.0.1",
|
|
161
|
+
"@commitlint/config-conventional": "^21.0.1",
|
|
162
|
+
"@eslint/js": "^10.0.1",
|
|
163
|
+
"@types/dom-webcodecs": "^0.1.18",
|
|
164
|
+
"@types/jest": "^30.0.0",
|
|
165
|
+
"@types/node": "^25.9.1",
|
|
166
|
+
"@types/offscreencanvas": "^2019.7.3",
|
|
167
|
+
"codecov": "^3.8.3",
|
|
168
|
+
"cspell": "^10.0.0",
|
|
169
|
+
"cz-conventional-changelog": "^3.3.0",
|
|
170
|
+
"eslint": "^10.4.0",
|
|
171
|
+
"eslint-config-prettier": "^10.1.8",
|
|
172
|
+
"fast-xml-parser": "^5.8.0",
|
|
173
|
+
"gh-pages": "^6.3.0",
|
|
174
|
+
"husky": "^9.1.7",
|
|
175
|
+
"jest": "^30.4.2",
|
|
176
|
+
"npm-run-all": "^4.1.5",
|
|
177
|
+
"open-cli": "^9.0.0",
|
|
178
|
+
"prettier": "^3.8.3",
|
|
179
|
+
"standard-version": "^9.5.0",
|
|
180
|
+
"ts-jest": "^29.4.11",
|
|
181
|
+
"ts-node": "^10.9.2",
|
|
182
|
+
"tsdown": "^0.22.0",
|
|
183
|
+
"typedoc": "^0.28.19",
|
|
184
|
+
"typedoc-plugin-rename-defaults": "^0.7.3",
|
|
185
|
+
"typescript": "^6.0.3",
|
|
186
|
+
"typescript-eslint": "^8.59.4"
|
|
187
|
+
},
|
|
188
|
+
"jest": {
|
|
189
|
+
"transform": {
|
|
190
|
+
"^.+\\.tsx?$": [
|
|
191
|
+
"ts-jest",
|
|
192
|
+
{
|
|
193
|
+
"tsconfig": {
|
|
194
|
+
"module": "CommonJS",
|
|
195
|
+
"moduleResolution": "Node",
|
|
196
|
+
"verbatimModuleSyntax": false
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
]
|
|
200
|
+
},
|
|
201
|
+
"testEnvironment": "node",
|
|
202
|
+
"collectCoverage": true,
|
|
203
|
+
"coverageReporters": [
|
|
204
|
+
"lcov",
|
|
205
|
+
"html"
|
|
206
|
+
],
|
|
207
|
+
"testPathIgnorePatterns": [
|
|
208
|
+
"/node_modules/",
|
|
209
|
+
"/build/"
|
|
210
|
+
]
|
|
211
|
+
},
|
|
212
|
+
"packageManager": "pnpm@10.28.1+sha512.7d7dbbca9e99447b7c3bf7a73286afaaf6be99251eb9498baefa7d406892f67b879adb3a1d7e687fc4ccc1a388c7175fbaae567a26ab44d1067b54fcb0d6a316"
|
|
213
|
+
}
|