ws-cleanup: one base64 (core/Base64)

core/Base64 takes over codecs/Base64's API (encode(buf | string, { url, pad, wrap }, offset, length), decode of both
alphabets, decodeDataUri, dataUri) plus line wrapping (opts.wrap) for plist; codecs/Base64 is removed and glTF /
DAE require core/Base64. The private copies in data/plist (Base64.luau), data/yaml (Parse / Emit) and codecs/Brotli
(the static tables) are gone. tests/codecs/base64 merged into tests/core/base64.
This commit is contained in:
4DBug committed 2026-10-31 10:50:40 -05:00
1 parent 52a34f50ed
commit 4f2ceec735
18 files changed
+202 -410

No files matched your search

+3 -30
View File
@@ -13,6 +13,7 @@
-- Never throws: bad data and bad arguments return nil, Err (TRUNCATED / CORRUPT / LIMIT / UNSUPPORTED / ARG).
local Err = require("@formats/core/Err")
local Crc32 = require("@formats/core/Crc32")
local Base64 = require("@formats/core/Base64")
local Deflate = require("@formats/codecs/Deflate")
local Decode = require("@formats/codecs/Brotli/Decode")
local StaticData = require("@formats/codecs/Brotli/Static")
@@ -25,37 +26,9 @@ export type Options = {
}
-- ------------------------------------------------------------------------------------------------ static data
local B64 = {}
do
local alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
for i = 1, 64 do
B64[string.byte(alphabet, i)] = i - 1
end
end
-- the tables are base64 text (trusted, generated by tools/brotli_static.py)
local function unbase64(s: string): buffer
local n = #s
local pad = 0
if string.sub(s, -2) == "==" then
pad = 2
elseif string.sub(s, -1) == "=" then
pad = 1
end
local out = buffer.create(n // 4 * 3 - pad)
local o = 0
for i = 1, n, 4 do
local a, b, c, d = string.byte(s, i, i + 3)
local v = B64[a] * 262144 + B64[b] * 4096 + (B64[c] or 0) * 64 + (B64[d] or 0)
buffer.writeu8(out, o, v // 65536)
if o + 1 < buffer.len(out) then
buffer.writeu8(out, o + 1, (v // 256) % 256)
end
if o + 2 < buffer.len(out) then
buffer.writeu8(out, o + 2, v % 256)
end
o += 3
end
return out
return Base64.decode(s) or buffer.create(0)
end
local static: Decode.Static? = nil