diff --git a/package.json b/package.json index 14d0175..4a5e9ca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mux-web-streams", - "version": "1.1.0", + "version": "1.1.1", "description": "Multiplex and demultiplex web streams.", "author": "Ben Brook", "license": "MIT", diff --git a/src/muxer.ts b/src/muxer.ts index 185d807..60061b4 100644 --- a/src/muxer.ts +++ b/src/muxer.ts @@ -64,14 +64,9 @@ function serializeChunk({ id, end, value, -}: Omit & { value: SerializableData }): Uint8Array | null { +}: Omit & { value: SerializableData }): Uint8Array { const { data, isRaw } = serializeData({ value }); - // No data in this chunk; skip writing anything at all - if (data.length === 0) { - return null; - } - // Create the header const header = headerToArray({ id, @@ -179,11 +174,8 @@ export const muxer = ( value: result.value, }); - // If the byteChunk is not empty (sometimes streams have empty chunks) - if (byteChunk !== null) { - // Write it to the muxed output - controller.enqueue(byteChunk); - } + // Write it to the muxed output + controller.enqueue(byteChunk); } else { // This incoming stream is finished // Mark this incoming stream as done, so we no longer attempt to read from it. @@ -196,9 +188,9 @@ export const muxer = ( const byteChunk = serializeChunk({ id: currentReader.id, end: true, - value: '\u0004', // arbitrarily chosen; value just needs to have length > 0 to distinguish cases + value: 0x03, // "end of text" control code }); - controller.enqueue(byteChunk!); + controller.enqueue(byteChunk); } })(); }, diff --git a/test/mux-web-streams.test.ts b/test/mux-web-streams.test.ts index 23e3602..8a289dd 100644 --- a/test/mux-web-streams.test.ts +++ b/test/mux-web-streams.test.ts @@ -42,14 +42,14 @@ const inputData: SerializableData[][] = [ [{ a: 1 }, { b: 2 }, { c: 3 }], [1, 2], ['A'], - [[1, 2], 3, 'a', new Uint8Array([12, 1, 100, 255, 0])], + [[1, 2], 3, 'a', new Uint8Array([12, 1, 3, 100, 255, 0])], [true, false], [[1, 2], 3, null, 'a'], [[1, 2], 3, 'a'], [[1, 2], 3, false], [[1, 2], 3, 0], [[1, 2], 3, []], - [new Uint8Array([12, 1, 100, 255, 0])], + [new Uint8Array([12, 1, 3, 100, 255, 0])], [null, null, null], [[1, 2], 3, 'a', {}], [[1, 2], 3, null, 'a'],