archive/unitypackage: type annotations
This commit is contained in:
1 parent
5096eb4898
commit
524179ec67
6 files changed
+4070
-1081
No files matched your search
+1490
File diff suppressed because it is too large.
Load diff
+540
-535
File diff suppressed because it is too large.
Load diff
+1490
File diff suppressed because it is too large.
Load diff
+540
-535
File diff suppressed because it is too large.
Load diff
@@ -61,14 +61,14 @@ local function encode(archive: any, opts: any?): (buffer?, Err.Err?)
|
|||||||
return UnityPackage.encode(archive, opts)
|
return UnityPackage.encode(archive, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
type Asset = { asset: Tar.Entry?, meta: Tar.Entry?, pathname: Tar.Entry?, preview: Tar.Entry? }
|
type Asset = { asset: Tar.Entry?, meta: Tar.Entry?, pathname: Tar.Entry?, preview: Tar.Entry?, [string]: any }
|
||||||
|
|
||||||
local function text(b: buffer, e: Tar.Entry): string
|
local function text(b: buffer, e: Tar.Entry): string
|
||||||
return buffer.readstring(b, e.offset, e.size)
|
return buffer.readstring(b, e.offset, e.size)
|
||||||
end
|
end
|
||||||
|
|
||||||
function UnityPackage.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?)
|
function UnityPackage.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?)
|
||||||
local o = opts or {}
|
local o: DecodeOptions = opts or {}
|
||||||
local tar, err = Deflate.gunzip(r.buf, r.base, r.limit - r.base)
|
local tar, err = Deflate.gunzip(r.buf, r.base, r.limit - r.base)
|
||||||
if not tar then
|
if not tar then
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -87,7 +87,7 @@ function UnityPackage.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.E
|
|||||||
if guid and not e.dir then
|
if guid and not e.dir then
|
||||||
local a = byGuid[guid]
|
local a = byGuid[guid]
|
||||||
if not a then
|
if not a then
|
||||||
a = {}
|
a = {} :: Asset
|
||||||
byGuid[guid] = a
|
byGuid[guid] = a
|
||||||
table.insert(order, guid)
|
table.insert(order, guid)
|
||||||
end
|
end
|
||||||
@@ -162,7 +162,7 @@ local function defaultMeta(guid: string, dir: boolean): string
|
|||||||
end
|
end
|
||||||
|
|
||||||
function UnityPackage.encode(archive: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
function UnityPackage.encode(archive: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||||
local o = opts or {}
|
local o: EncodeOptions = opts or {}
|
||||||
local items = Archive.entries(archive)
|
local items = Archive.entries(archive)
|
||||||
if not items then
|
if not items then
|
||||||
return nil, Err.new(Err.ARG, "expected an Archive")
|
return nil, Err.new(Err.ARG, "expected an Archive")
|
||||||
@@ -196,13 +196,12 @@ function UnityPackage.encode(archive: any, opts: EncodeOptions?): (buffer?, Err.
|
|||||||
end
|
end
|
||||||
metaData = mb
|
metaData = mb
|
||||||
end
|
end
|
||||||
local guid = if type(e.guid) == "string" and #e.guid == 32 and string.match(e.guid, "^%x+$") then string.lower(e.guid) else nil
|
local given: string? = if type(e.guid) == "string" and #e.guid == 32 and string.match(e.guid, "^%x+$") then string.lower(e.guid) else nil
|
||||||
guid = guid or (if metaData then metaGuid(metaData) else nil) or Md5.of(buffer.fromstring(path))
|
local g: string = given or (if metaData then metaGuid(metaData) else nil) or Md5.of(buffer.fromstring(path))
|
||||||
if used[guid :: string] then
|
if used[g] then
|
||||||
guid = Md5.of(buffer.fromstring(path .. "\0" .. guid))
|
g = Md5.of(buffer.fromstring(path .. "\0" .. g))
|
||||||
end
|
end
|
||||||
used[guid :: string] = true
|
used[g] = true
|
||||||
local g = guid :: string
|
|
||||||
metaData = metaData or buffer.fromstring(defaultMeta(g, e.dir == true))
|
metaData = metaData or buffer.fromstring(defaultMeta(g, e.dir == true))
|
||||||
table.insert(list, { name = g .. "/", dir = true, mtime = mtime })
|
table.insert(list, { name = g .. "/", dir = true, mtime = mtime })
|
||||||
if data then
|
if data then
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ for _, c in Fx.cases do
|
|||||||
e = x
|
e = x
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local pv = e and e.preview and e.preview()
|
local pv: any = e and (e :: any).preview and (e :: any).preview()
|
||||||
t:check(pv and buffer.readstring(pv, 8, 7) == "preview", c.name .. ": preview.png")
|
t:check(pv and buffer.readstring(pv, 8, 7) == "preview", c.name .. ": preview.png")
|
||||||
-- round trip through our writer
|
-- round trip through our writer
|
||||||
local out, werr = UnityPackage.encode(a)
|
local out, werr = UnityPackage.encode(a)
|
||||||
|
|||||||
Reference in new issue
Block a user