ws-cleanup-types: containers, ops: type the tables and locals the solver cannot infer
This commit is contained in:
1 parent
f209801579
commit
cfe325dcf8
12 files changed
+37
-32
No files matched your search
@@ -45,7 +45,7 @@ local function public(e: Entry): Types.ArchiveEntry
|
||||
end
|
||||
|
||||
function Methods.list(self: any): { Types.ArchiveEntry }
|
||||
local out = table.create(#self._entries)
|
||||
local out = table.create(#self._entries) :: { Types.ArchiveEntry }
|
||||
for i, e in self._entries do
|
||||
out[i] = public(e)
|
||||
end
|
||||
@@ -91,7 +91,7 @@ end
|
||||
|
||||
-- write(opts?) -> buffer | nil, Err: the archive's own format (opts.format is handled by the api)
|
||||
function Methods.write(self: any, opts: any?): (buffer?, Err.Err?)
|
||||
local enc = self._encode
|
||||
local enc: Encoder? = self._encode
|
||||
if not enc then
|
||||
return nil, Err.new(Err.UNSUPPORTED, self.format .. " archives are read-only")
|
||||
end
|
||||
|
||||
@@ -18,8 +18,13 @@ local Mux = require("@formats/containers/Ogg/Mux")
|
||||
|
||||
local AudioWrap = {}
|
||||
|
||||
local function allPackets(dmx: any, track: Types.Track): { Types.Packet }
|
||||
local out = {}
|
||||
type PacketSource = {
|
||||
count: ((self: any, track: number) -> number)?,
|
||||
get: ((self: any, track: number, k: number) -> Types.Packet?)?,
|
||||
}
|
||||
|
||||
local function allPackets(dmx: PacketSource, track: Types.Track): { Types.Packet }
|
||||
local out: { Types.Packet } = {}
|
||||
local n = if dmx.count then dmx:count(track.id) else 0
|
||||
if n > 0 and dmx.get then
|
||||
for k = 1, n do
|
||||
@@ -437,11 +442,11 @@ function AudioWrap.wrap(dmx: any, track: Types.Track): (buffer?, string?, Err.Er
|
||||
return granule
|
||||
end
|
||||
local mb = 0
|
||||
while 2 ^ mb < #modes do
|
||||
while 2 ^ mb < #(modes :: { boolean }) do
|
||||
mb += 1
|
||||
end
|
||||
local m = if mb > 0 and buffer.len(d) * 8 > mb then bits(d, 1, mb) else 0
|
||||
local cur = sizes[if modes[m + 1] then 2 else 1]
|
||||
local cur = sizes[if (modes :: { boolean })[m + 1] then 2 else 1]
|
||||
if prev then
|
||||
granule += (prev + cur) // 4
|
||||
end
|
||||
|
||||
@@ -491,7 +491,7 @@ function Avi.write(opts: WOptions, chunks: { { any } }): buffer
|
||||
w:u32le(0)
|
||||
local moviBase = w:tell()
|
||||
w:string("movi")
|
||||
local index = table.create(#chunks)
|
||||
local index = table.create(#chunks) :: { { any } }
|
||||
for _, c in chunks do
|
||||
local si, data, key = c[1], c[2], c[3]
|
||||
local s = opts.streams[si]
|
||||
|
||||
@@ -324,9 +324,9 @@ local function track(b: buffer, trak: Box.Box, movieTimescale: number, trex: { [
|
||||
r:skip(3)
|
||||
local n = r:u32be()
|
||||
if n <= (elst.stop - elst.data) // 12 then
|
||||
local edits = {}
|
||||
local edits: { Edit } = {}
|
||||
for _ = 1, n do
|
||||
local dur, mt
|
||||
local dur: number, mt: number
|
||||
if v == 1 then
|
||||
dur, mt = r:u64be(), r:i64be()
|
||||
else
|
||||
@@ -522,7 +522,7 @@ local function track(b: buffer, trak: Box.Box, movieTimescale: number, trex: { [
|
||||
if n * 12 > r:remaining() then
|
||||
return nil, Err.new(Err.TRUNCATED, "stsc table runs past its box", stsc.start)
|
||||
end
|
||||
local first, per, desc = {}, {}, {}
|
||||
local first: { number }, per: { number }, desc: { number } = {}, {}, {}
|
||||
for k = 1, n do
|
||||
first[k], per[k], desc[k] = r:u32be(), r:u32be(), r:u32be()
|
||||
end
|
||||
@@ -739,7 +739,7 @@ export type Movie = {
|
||||
|
||||
-- parse(r, opts) -> Movie | nil, Err: the box tree, ftyp, mvhd and every track (fragments included)
|
||||
function Demux.parse(r: Bytes.Reader, opts: Options?): (Movie?, Err.Err?)
|
||||
local o = opts or {}
|
||||
local o: Options = opts or {}
|
||||
local b = r.buf
|
||||
local top, terr = Box.list(b, r.base, r.limit)
|
||||
if #top == 0 then
|
||||
|
||||
@@ -187,7 +187,7 @@ function Meta.items(b: buffer, meta: Box.Box): (Items?, Err.Err?)
|
||||
it = {
|
||||
id = id, type = "", name = "", hidden = false, construction = 0, baseOffset = 0, extents = {},
|
||||
properties = {}, essential = {}, refs = {},
|
||||
}
|
||||
} :: Item
|
||||
out.items[id] = it
|
||||
table.insert(out.order, id)
|
||||
end
|
||||
@@ -496,7 +496,7 @@ function Meta.writeIlst(w: Bytes.Writer, tags: { [string]: string }, pictures: {
|
||||
end
|
||||
if pictures and #pictures > 0 then
|
||||
box(w, "covr", function()
|
||||
for _, p in pictures do
|
||||
for _, p in pictures :: { Picture } do
|
||||
dataBox(w, if p.mime == "image/png" then 14 elseif p.mime == "image/bmp" then 27 else 13, p.data)
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -193,7 +193,7 @@ function MpegPs.read(b: buffer, base: number, limit: number): (File?, Err.Err?)
|
||||
if ok and q <= stop then
|
||||
local s = file.streams[id]
|
||||
if not s then
|
||||
s = { id = id, kind = kind, codec = codec, streamType = st, pes = {} }
|
||||
s = { id = id, kind = kind, codec = codec, streamType = st, pes = {} } :: Stream
|
||||
file.streams[id] = s
|
||||
table.insert(file.order, id)
|
||||
end
|
||||
|
||||
@@ -350,7 +350,7 @@ function Tar.write(entries: { WriteEntry }, opts: WriteOptions?): (buffer?, Err.
|
||||
end
|
||||
local data = e.data or buffer.create(0)
|
||||
local typ = e.type or (if e.dir then "5" else "0")
|
||||
local name = e.name
|
||||
local name: string = e.name
|
||||
if typ == "5" and string.sub(name, -1) ~= "/" then
|
||||
name ..= "/"
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user