feat: add backpressure support

This commit is contained in:
2025-03-19 01:05:24 +08:00
parent 9a402b0921
commit 6cc8dfab7c
8 changed files with 167 additions and 64 deletions

View File

@@ -28,7 +28,7 @@ async function collectTags(decoder: Decoder): Promise<EbmlTagType[]> {
return tags;
}
describe('EbmlStreamDecoder', () => {
describe('Ebml Decoder', () => {
it('should wait for more data if a tag is longer than the buffer', async () => {
const decoder = getDecoderWithNullSink();
const writer = decoder.writable.getWriter();

View File

@@ -56,7 +56,9 @@ const makeEncoderTest = async (tags: EbmlTagTrait[]) => {
controller.close();
},
});
const encoder = new EbmlStreamEncoder();
const chunks: ArrayBuffer[] = [];
await new Promise<void>((resolve, reject) => {
@@ -70,6 +72,9 @@ const makeEncoderTest = async (tags: EbmlTagTrait[]) => {
close() {
resolve();
},
abort: (e) => {
reject(e);
},
})
)
.catch(reject);
@@ -106,16 +111,15 @@ describe('EBML Encoder', () => {
]);
});
describe('#writeTag', () => {
it('throws with an incomplete tag data', async () => {
await expect(() => makeEncoderTest([incompleteTag])).rejects.toThrow(
/should only accept embl tag but not/
);
});
it('throws with an invalid tag id', async () => {
await expect(() => makeEncoderTest([invalidTag])).rejects.toThrow(
/should only accept embl tag but not/
);
});
it('throws with an incomplete tag data', async () => {
await expect(() => makeEncoderTest([incompleteTag])).rejects.toThrow(
/should only accept embl tag but not/
);
});
it('throws with an invalid tag id', async () => {
await expect(() => makeEncoderTest([invalidTag])).rejects.toThrow(
/should only accept embl tag but not/
);
});
});