Menu ▾ ▴

#503 Refactor: extract a shared RIFF magic-byte helper

open
nobody
2026-10-03
2026-10-03
Anonymous
No

Originally created by: Redo-San

Three near-identical RIFF validators are duplicated across two files. They all check RIFF at offset 0..3 and a fourcc at offset 8..11; only four bytes differ.

Locations

  • Style/shared_validation.js:95-111 (image/webp), :128-144 (audio/wav), :158-174 (video/avi)
  • cli/utils.js:483-499, :519-535, :549-565

Change

Introduce one isRiffContainer(buf, fourcc) helper in each module and replace the three copies, removing ~50 duplicated lines.

Acceptance criteria

  • [ ] node --test cli/tests/validation_test.js passes (covers WebP/WAV/AVI at cli/tests/validation_test.js:821-905).
  • [ ] node --test cli/tests/cli_utils_test.js passes (covers checkMagicBytes for webp/wav/mp4/avi at cli/tests/cli_utils_test.js:59-163).
  • [ ] npm run lint passes.

Discussion


Log in to post a comment.