ws-cleanup: merge ws/cleanup-types (type annotations)

This commit is contained in:
4DBug committed 2026-10-31 11:27:42 -05:00
commit 5d7c223ab8
115 files changed
+583 -515

No files matched your search

+4 -3
View File
@@ -177,7 +177,8 @@ local function folder(r: Bytes.Reader): Folder
check(r)
local nin, nout = 1, 1
if bit32.band(flags, 0x10) ~= 0 then
nin, nout = number(r), number(r)
nin = number(r)
nout = number(r)
if nin > 64 or nout > 64 then
bad(r, "bad coder stream count")
end
@@ -416,11 +417,11 @@ local function filesInfo(r: Bytes.Reader): { File }
if n > 1000000 then
bad(r, "too many files", Err.LIMIT)
end
local files: { File } = table.create(n)
local files: { File } = table.create(n) :: { File }
for i = 1, n do
files[i] = { name = "", emptyStream = false, emptyFile = false, anti = false }
end
local empties = {}
local empties: { number } = {}
while true do
local t = byte(r)
if t == K.End then
+16 -12
View File
@@ -144,7 +144,9 @@ local function decodeFolder(ctx: Ctx, s: Header.Streams, f: Header.Folder): (buf
if not b then
return nil, e
end
src, so, sl = b, 0, buffer.len(b)
src = b
so = 0
sl = buffer.len(b)
else
local k = table.find(f.packed, inIdx)
if not k then
@@ -162,14 +164,14 @@ local function decodeFolder(ctx: Ctx, s: Header.Streams, f: Header.Folder): (buf
src = ctx.buf
end
local id = c.id
local opts = { maxBytes = ctx.maxBytes }
local opts: { maxBytes: number?, verify: boolean? } = { maxBytes = ctx.maxBytes }
if id == "\0" then
if sl < size then
return nil, Err.new(Err.TRUNCATED, "short stored stream")
end
local b = buffer.create(size)
buffer.copy(b, 0, src, so, size)
return b
return b, nil
elseif id == "\3\1\1" then
if buffer.len(c.props) < 5 then
return nil, Err.new(Err.CORRUPT, "bad LZMA properties")
@@ -195,7 +197,7 @@ local function decodeFolder(ctx: Ctx, s: Header.Streams, f: Header.Folder): (buf
if buffer.len(b) ~= size then
return nil, Err.new(Err.CORRUPT, methodName(id) .. " stream decodes to the wrong size")
end
return b
return b, nil
elseif FILTERS[id] then
if sl ~= size then
return nil, Err.new(Err.CORRUPT, "filter size mismatch")
@@ -206,7 +208,7 @@ local function decodeFolder(ctx: Ctx, s: Header.Streams, f: Header.Folder): (buf
if not ok then
return nil, e
end
return b
return b, nil
end
return nil, Err.new(Err.UNSUPPORTED, methodName(id) .. " is not supported")
end
@@ -226,7 +228,7 @@ local function folderMethod(f: Header.Folder): string
end
function SevenZip.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Archive?, Err.Err?)
local o = opts or {}
local o: DecodeOptions = opts or {}
local maxBytes = if type(o.maxBytes) == "number" then o.maxBytes else 2 ^ 30
local checkCrc = o.checkCrc ~= false
local b, base, limit = r.buf, r.base, r.limit
@@ -280,17 +282,19 @@ function SevenZip.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Archive?
if f.crc and Crc32.raw(hb, 0, buffer.len(hb)) ~= f.crc then
return nil, Err.new(Err.CHECKSUM, "encoded header CRC-32 mismatch")
end
hbuf, hoff, hlen = hb, 0, buffer.len(hb)
hbuf = hb
hoff = 0
hlen = buffer.len(hb)
end
if not parsed then
return nil, Err.new(Err.CORRUPT, "nested encoded headers")
end
local s = parsed.streams or { packPos = 0, packSizes = {}, folders = {}, subSizes = {}, subCrcs = {} }
local s: Header.Streams = parsed.streams or { packPos = 0, packSizes = {}, folders = {}, subSizes = {}, subCrcs = {} }
a.meta.folders = #s.folders
a.meta.solid = false
-- folder caches and the substream -> folder map
local cache: { [number]: buffer } = {}
local subFolder, subOffset = {}, {}
local subFolder: { number }, subOffset: { number } = {}, {}
do
local si = 1
for fi, f in s.folders do
@@ -311,7 +315,7 @@ function SevenZip.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Archive?
local function folderData(fi: number): (buffer?, Err.Err?)
local c = cache[fi]
if c then
return c
return c, nil
end
local f = s.folders[fi]
local d, e = decodeFolder(ctx, s, f)
@@ -322,7 +326,7 @@ function SevenZip.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Archive?
return nil, Err.new(Err.CHECKSUM, "folder CRC-32 mismatch")
end
cache[fi] = d
return d
return d, nil
end
local si = 0
for _, file in parsed.files do
@@ -376,7 +380,7 @@ function SevenZip.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Archive?
if checkCrc and want and Crc32.raw(out, 0, size) ~= want then
return nil, Err.new(Err.CHECKSUM, "CRC-32 mismatch in " .. file.name)
end
return out
return out, nil
end
end
Archive.put(a, e)
+4 -4
View File
@@ -49,7 +49,7 @@ local function header(b: buffer, o: number, e: number): { [string]: any }
if bit32.band(flg, 4) ~= 0 and q + 2 <= e then
q += 2 + buffer.readu16(b, q)
end
for _, f in { { 8, "name" }, { 16, "comment" } } do
for _, f in { { 8, "name" }, { 16, "comment" } } :: { { any } } do
if bit32.band(flg, f[1]) ~= 0 then
local s = q
while q < e and buffer.readu8(b, q) ~= 0 do
@@ -85,7 +85,7 @@ function Gzip.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?)
size = buffer.len(out),
compressedSize = r.limit - r.base,
method = "deflate",
mtime = if h.mtime and h.mtime > 0 then h.mtime else nil,
mtime = if h.mtime and h.mtime > 0 then h.mtime :: number else nil,
dir = false,
data = out,
})
@@ -94,7 +94,7 @@ end
-- ------------------------------------------------------------------------------------------------ encode
function Gzip.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
local o = opts or {}
local o: EncodeOptions = opts or {}
local level = if o.level == nil then 6 else o.level
if type(level) ~= "number" or level < 0 or level > 9 or level % 1 ~= 0 then
return nil, Err.new(Err.ARG, "level must be 0..9")
@@ -111,7 +111,7 @@ function Gzip.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
if not items then
return nil, Err.new(Err.ARG, "expected an Archive, a buffer or a string")
end
local files = {}
local files: typeof(items) = {}
for _, it in items do
if not it.entry.dir then
table.insert(files, it)
+1 -1
View File
@@ -70,7 +70,7 @@ end
-- ------------------------------------------------------------------------------------------------ decode
function Xz.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Archive?, Err.Err?)
local o = opts or {}
local o: DecodeOptions = opts or {}
local n = r.limit - r.base
local out, res
local method