ws-cleanup: shared helpers instead of copies (CRCs, codec arguments, utf8char, keyLess / isArray)
A sweep for duplicated function bodies, CRC tables and base64 across src/Formats: - core/Crc32.msb / MSB_TABLE: the MSB-first 0x04C11DB7 CRC-32 that containers/Ogg (Page + Mux), containers/MpegTs and codecs/Bzip2 each built (test vectors CRC-32/MPEG-2 and /BZIP2 in tests/core/bytes). - audio/flac/Encode uses audio/flac/Frame's CRC-8 / CRC-16 tables (Frame.crc8 added) instead of its own copy. - core/Bytes.toBuffer / Bytes.span: the (buffer | string, offset, length) argument checking codecs/Deflate, codecs/Lzma and codecs/Brotli each carried. - codecs/Text.utf8char: one copy instead of four (codecs/Json, codecs/Xml, data/yaml, data/toml). - Types.keyLess / Types.isArray (small additions to Types, backward compatible): data/msgpack, data/cbor and data/yaml/Emit had identical copies. - playlist/pls: dead copies of m3u's attributes / extinf removed. Left on purpose: per-codec bit readers / writers in hot loops (STYLE.md: inner loops keep their own bit buffers), same-folder helpers (Alac signExtend, Vorbis ilog), Zip's DOS-date civil() (a different epoch helper).
This commit is contained in:
1 parent
7169f2cc2c
commit
f784b4eb9b
22 files changed
+152
-311
No files matched your search
+20
-1
@@ -1,5 +1,6 @@
|
||||
-- core/Bytes, core/Err, core/Crc32, core/Adler32, core/Input tests: every Reader / Writer method both endians, the
|
||||
-- sticky TRUNCATED error (never a throw), sub-readers without copies, Writer growth and patching.
|
||||
-- sticky TRUNCATED error (never a throw), sub-readers without copies, Writer growth and patching, Bytes.span, the
|
||||
-- MSB-first CRC-32 (MPEG-2 / bzip2 check values).
|
||||
local T = require("@tests/T")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
@@ -181,4 +182,22 @@ do
|
||||
t:check(w.code == Err.CORRUPT and w.format == "gif", "wrap a string")
|
||||
end
|
||||
|
||||
-- Bytes.span: codec argument checking
|
||||
do
|
||||
local b, o, n = Bytes.span("x", "hello", 1, 10)
|
||||
t:check(type(b) == "buffer" and o == 1 and n == 4, "span clamps the length")
|
||||
local _, _, _, e = Bytes.span("x", 5)
|
||||
t:check(e and e.code == Err.ARG, "span: not a buffer")
|
||||
local _, _, _, e2 = Bytes.span("x", "abc", 4)
|
||||
t:check(e2 and e2.code == Err.ARG, "span: offset past the end")
|
||||
local _, _, _, e3 = Bytes.span("x", "abc", 0.5)
|
||||
t:check(e3 and e3.code == Err.ARG, "span: fractional offset")
|
||||
end
|
||||
-- the MSB-first CRC-32: CRC-32/MPEG-2 and CRC-32/BZIP2 of "123456789"
|
||||
do
|
||||
local nine = buffer.fromstring("123456789")
|
||||
t:eq(Crc32.msb(nine, 0, 9, 0xFFFFFFFF), 0x0376E6E7, "CRC-32/MPEG-2")
|
||||
t:eq(bit32.bxor(Crc32.msb(nine, 0, 9, 0xFFFFFFFF), 0xFFFFFFFF), 0xFC891918, "CRC-32/BZIP2")
|
||||
end
|
||||
|
||||
t:done()
|
||||
Reference in new issue
Block a user