feat(normalize, author): the page's build moves an mp4's index to the front

Merged
AL
3d ago
+289-154

Part of #218: item 5, "The build page moves an mp4's index to the front". Item 4 is #258; item 6 and the open question stay in #218.

What changes

  • The normalizer's remux plan moves into ./mp4 as faststartPlan(read, size), on Uint8Array and DataView rather than Buffer, like mp4Info beside it. It returns { status, detail, pieces, size }: each piece a range of the file or the rewritten index. Only the index is read whole.
  • mp4-faststart.mjs's planFaststart(file, base, size) is now a wrapper: the file's bytes in, the ranges shifted by base. The remux exists once, and normalizeArchive is unchanged.
  • The page's build lays out an mp4 or an m4a with its index first, as Node's build does through the normalizer. The file is a Blob of the given file's slices and the rewritten index, so no byte of the media is copied, and its CRC is that of what is stored. Every stored file is asked of the plan, which tells an ISO media file by its first eight bytes and leaves any other file, and one with its index first already, as given: the page keeps no list of extensions beside the normalizer's.
  • An index of containers nested deeper than a real one is left alone. The walk through moov went into every container, so a crafted file of a hundred thousand trak atoms inside each other ended it with a RangeError, in the normalizer too, before this change. It now stops eight deep (a real index nests four) and the file comes back skipped.

Before, a phone's video built on the build page could start playing only once it had arrived whole.

Release order: the normalizer first, and the publish check holds it

The page build imports faststartPlan by name, and npm's record of a version lists entries, not what they export. So check-pack-published.mjs now refuses to publish the author while packages/normalize is below 1.5.0, the first version with it:

  1. normalize 1.5.0 (minor, new export);
  2. then the author, whose workspace:^ publishes as ^1.5.0, which the same check then finds on npm.

Run today, with the normalizer at 1.4.1, the check stops with that instruction. I have not bumped anything.

Tests

  • normalize: 35, two new. faststartPlan on bytes in memory gives the same bytes as the file path, and leaves the bytes it read unchanged; a faststart file and a web page come back as one whole-file piece. The crafted index is skipped, and one nested as a real one is moved.
  • author: 280 Node and 2 Chromium tests. The page test now unzips the built package: the clip is stored, the same size, moov before mdat, and its CRC checks out on read.
  • embed 83, skills 82, type checks of normalize and author.

Docs

The author README ("In a page"), the normalizer README (faststartPlan), docs/compatibility.md, design/author.md, design/normalize.md and design/layout.md.