feat: a better type system and type hints that depend on it
This commit is contained in:
@@ -4,7 +4,7 @@ import {
|
||||
EbmlElementType,
|
||||
EbmlStreamDecoder as Decoder,
|
||||
EbmlDataTag,
|
||||
type EbmlTagTrait,
|
||||
type EbmlTagType,
|
||||
} from 'konoebml';
|
||||
|
||||
const bufFrom = (data: Uint8Array | readonly number[]): ArrayBuffer =>
|
||||
@@ -16,8 +16,8 @@ const getDecoderWithNullSink = () => {
|
||||
return decoder;
|
||||
};
|
||||
|
||||
async function collectTags(decoder: Decoder): Promise<EbmlTagTrait[]> {
|
||||
const tags: EbmlTagTrait[] = [];
|
||||
async function collectTags(decoder: Decoder): Promise<EbmlTagType[]> {
|
||||
const tags: EbmlTagType[] = [];
|
||||
await decoder.readable.pipeTo(
|
||||
new WritableStream({
|
||||
write: (tag) => {
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
EbmlTagIdEnum,
|
||||
type EbmlBlockTag,
|
||||
createEbmlTagForManuallyBuild,
|
||||
type EbmlTagType,
|
||||
} from 'konoebml';
|
||||
import { concatArrayBuffers } from 'konoebml/tools';
|
||||
|
||||
@@ -69,7 +70,7 @@ describe('EBML Pipeline', () => {
|
||||
block.payload = payload;
|
||||
const encoder = new EbmlStreamEncoder();
|
||||
const decoder = new EbmlStreamDecoder();
|
||||
const tags: EbmlTagTrait[] = [];
|
||||
const tags: EbmlTagType[] = [];
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const source = new ReadableStream<EbmlTagTrait>({
|
||||
pull(controller) {
|
||||
@@ -81,7 +82,7 @@ describe('EBML Pipeline', () => {
|
||||
.pipeThrough(encoder)
|
||||
.pipeThrough(decoder)
|
||||
.pipeTo(
|
||||
new WritableStream<EbmlTagTrait>({
|
||||
new WritableStream({
|
||||
write(tag) {
|
||||
tags.push(tag);
|
||||
},
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
EbmlTagIdEnum,
|
||||
EbmlSimpleBlockTag as SimpleBlock,
|
||||
EbmlDataTag,
|
||||
type EbmlMasterTag,
|
||||
type EbmlTagType,
|
||||
} from 'konoebml';
|
||||
import { Readable } from 'node:stream';
|
||||
import { WritableStream } from 'node:stream/web';
|
||||
@@ -19,14 +19,14 @@ const createReadStream = (file: string) =>
|
||||
|
||||
const makeDataStreamTest =
|
||||
(stream: () => ReadableStream<Uint8Array>) =>
|
||||
async (cb: (tag: EbmlMasterTag | EbmlDataTag, done: () => void) => void) => {
|
||||
async (cb: (tag: EbmlTagType, done: () => void) => void) => {
|
||||
await new Promise((resolve, reject) => {
|
||||
stream()
|
||||
.pipeThrough(new EbmlStreamDecoder())
|
||||
.pipeTo(
|
||||
new WritableStream({
|
||||
write: async (tag) => {
|
||||
cb(tag as EbmlMasterTag | EbmlDataTag, () => resolve(true));
|
||||
cb(tag, () => resolve(true));
|
||||
},
|
||||
close: () => {
|
||||
reject('hit end of file without calling done');
|
||||
@@ -75,7 +75,7 @@ describe('EBML Values in tags', () => {
|
||||
|
||||
it('should get a correct TrackUID value from a file (56-bit integer in hex)', () =>
|
||||
makeAVC1StreamTest((tag, done) => {
|
||||
if (tag instanceof EbmlDataTag && tag.id === EbmlTagIdEnum.TrackUID) {
|
||||
if (tag.id === EbmlTagIdEnum.TrackUID) {
|
||||
assert.strictEqual(tag.data, 7990710658693702);
|
||||
done();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user