const { test } = require('node:test'); const assert = require('node:assert/strict'); const { inspectBytes } = require('./direct-stream.js'); function box(type, payload = Buffer.alloc(0)) { const b = Buffer.alloc(8 + payload.length); b.writeUInt32BE(b.length); b.write(type, 4); payload.copy(b, 8); return b; } test('progressive playback only accepts a complete fragmented MP4 initialization', () => { const codec = box('avcC', Buffer.from([1, 0x64, 0, 0x1f])); const fragmented = Buffer.concat([box('ftyp'), box('moov', Buffer.concat([box('mvex'), codec, box('mp4a')]))]); assert.equal(inspectBytes(fragmented), 'video/mp4; codecs="avc1.64001f, mp4a.40.2"'); assert.equal(inspectBytes(Buffer.concat([box('ftyp'), box('moov', codec)])), null); assert.equal(inspectBytes(fragmented.subarray(0, fragmented.length - 1)), null); assert.equal(inspectBytes(Buffer.alloc(0)), null); });