ws-cleanup: shared plumbing: Err.from, core/Sniff, Pcm.drain, Bits.msbPut; DUP lint; tools/move.py

- core/Err.from(message, offset?, kind?): the private-submodule -> Err plumbing (a kind, or a 'code: ' prefix /
  'truncated' / 'past the end' in the message) that Brotli, Bzip2, Zstd, Jpeg, WOFF2, FBX, plist, msgpack and
  bmfont each wrote.
- core/Sniff (new): Sniff.text(r, n, trim?) (the start of a text file without its BOM), Sniff.dropBom(s),
  Sniff.magic(r, s); 13 text formats' sniff / decode BOM handling goes through it.
- codecs/Pcm.drain(dec, source?, maxFrames?): a format's decode() through its open(); the collect-the-Decoder
  loops of aac, aiff, au, caf, flac, m4a, mp3, opus, vorbis and wav are one call each.
- core/Bits.msbPut: the MSB-first bit writer the MP3 / MP2 / FLAC encoders each copied.
- tools/lint_rules.py DUP: a function body of 12+ code lines repeated token for token in another module fails.
- tools/move.py: moves a module and rewrites every reference (requires, deps, headers, fixture INPUTS, docs).
- tools/fixtures/zstd.py: the incompressible corpus is smaller (zstd.luau 15.1 -> 13.4 MB; every fixture module is
  now under 14.3 MB).
- tools/bench.luau: MPEG-1 also runs with the api's LuaJIT trace limits; the sections that compare tuned / default
  limits set them explicitly (jitTune), so the order of sections no longer leaks the tuning.
This commit is contained in:
4DBug committed 2026-10-31 12:00:59 -05:00
1 parent 3243404374
commit 763f4a7c04
44 files changed
+374 -370

No files matched your search

+4 -8
View File
@@ -12,6 +12,7 @@
-- ------------------------------------------------------------------------------------------------ requires
local Err = require("@formats/core/Err")
local Sniff = require("@formats/core/Sniff")
local Bytes = require("@formats/core/Bytes")
local Types = require("@formats/Types")
@@ -21,7 +22,7 @@ local Ass = {
category = "subtitle",
extensions = { "ass", "ssa" },
mime = { "text/x-ssa", "text/x-ass" },
deps = { "core/Err", "core/Bytes", "Types" },
deps = { "core/Err", "core/Bytes", "Types", "core/Sniff" },
caps = { decode = true, encode = true, styles = true },
}
@@ -144,10 +145,7 @@ end
-- ------------------------------------------------------------------------------------------------ sniff
function Ass.sniff(r: Bytes.Reader): number
local head = r:peek(64)
if string.sub(head, 1, 3) == "\239\187\191" then
head = string.sub(head, 4)
end
local head = Sniff.text(r, 64)
if string.match(head, "^%s*%[[Ss]cript [Ii]nfo%]") then
return 1
end
@@ -167,9 +165,7 @@ function Ass.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Subtitles?, E
if string.find(s, "\0", 1, true) then
return nil, Err.new(Err.CORRUPT, "binary data (NUL bytes) in a text format")
end
if string.sub(s, 1, 3) == "\239\187\191" then
s = string.sub(s, 4)
end
s = Sniff.dropBom(s)
s = string.gsub(s, "\r\n", "\n")
s = string.gsub(s, "\r", "\n")
local subs = Types.Subtitles.new()
+4 -8
View File
@@ -9,6 +9,7 @@
-- ------------------------------------------------------------------------------------------------ requires
local Err = require("@formats/core/Err")
local Sniff = require("@formats/core/Sniff")
local Bytes = require("@formats/core/Bytes")
local Types = require("@formats/Types")
@@ -18,7 +19,7 @@ local Srt = {
category = "subtitle",
extensions = { "srt" },
mime = { "application/x-subrip", "text/srt" },
deps = { "core/Err", "core/Bytes", "Types" },
deps = { "core/Err", "core/Bytes", "Types", "core/Sniff" },
caps = { decode = true, encode = true, styles = false },
}
@@ -38,9 +39,7 @@ local function text(r: Bytes.Reader): string?
if string.find(s, "\0", 1, true) then
return nil
end
if string.sub(s, 1, 3) == "\239\187\191" then
s = string.sub(s, 4)
end
s = Sniff.dropBom(s)
s = string.gsub(s, "\r\n", "\n")
s = string.gsub(s, "\r", "\n")
return s
@@ -63,10 +62,7 @@ end
-- ------------------------------------------------------------------------------------------------ sniff
function Srt.sniff(r: Bytes.Reader): number
local head = r:peek(512)
if string.sub(head, 1, 3) == "\239\187\191" then
head = string.sub(head, 4)
end
local head = Sniff.text(r, 512)
head = string.gsub(head, "\r", "\n")
local first, second = string.match(head, "^%s*([^\n]*)\n([^\n]*)")
if first and string.match(first, "^%d+%s*$") and second and timing(second) then
+4 -8
View File
@@ -8,6 +8,7 @@
-- ------------------------------------------------------------------------------------------------ requires
local Err = require("@formats/core/Err")
local Sniff = require("@formats/core/Sniff")
local Bytes = require("@formats/core/Bytes")
local Types = require("@formats/Types")
@@ -17,7 +18,7 @@ local Vtt = {
category = "subtitle",
extensions = { "vtt", "webvtt" },
mime = { "text/vtt" },
deps = { "core/Err", "core/Bytes", "Types" },
deps = { "core/Err", "core/Bytes", "Types", "core/Sniff" },
caps = { decode = true, encode = true, styles = true },
}
@@ -64,10 +65,7 @@ end
-- ------------------------------------------------------------------------------------------------ sniff
function Vtt.sniff(r: Bytes.Reader): number
local head = r:peek(10)
if string.sub(head, 1, 3) == "\239\187\191" then
head = string.sub(head, 4)
end
local head = Sniff.text(r, 10)
if string.sub(head, 1, 6) == "WEBVTT" then
local c = string.sub(head, 7, 7)
if c == "" or c == " " or c == "\t" or c == "\n" or c == "\r" then
@@ -90,9 +88,7 @@ function Vtt.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Subtitles?, E
if string.find(s, "\0", 1, true) then
return nil, Err.new(Err.CORRUPT, "binary data (NUL bytes) in a text format")
end
if string.sub(s, 1, 3) == "\239\187\191" then
s = string.sub(s, 4)
end
s = Sniff.dropBom(s)
s = string.gsub(s, "\r\n", "\n")
s = string.gsub(s, "\r", "\n")
local lines = string.split(s, "\n")