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)
|
||||
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
|
||||
return buffer.readstring(b, e.offset, e.size)
|
||||
end
|
||||
|
||||
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)
|
||||
if not tar then
|
||||
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
|
||||
local a = byGuid[guid]
|
||||
if not a then
|
||||
a = {}
|
||||
a = {} :: Asset
|
||||
byGuid[guid] = a
|
||||
table.insert(order, guid)
|
||||
end
|
||||
@@ -162,7 +162,7 @@ local function defaultMeta(guid: string, dir: boolean): string
|
||||
end
|
||||
|
||||
function UnityPackage.encode(archive: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||
local o = opts or {}
|
||||
local o: EncodeOptions = opts or {}
|
||||
local items = Archive.entries(archive)
|
||||
if not items then
|
||||
return nil, Err.new(Err.ARG, "expected an Archive")
|
||||
@@ -196,13 +196,12 @@ function UnityPackage.encode(archive: any, opts: EncodeOptions?): (buffer?, Err.
|
||||
end
|
||||
metaData = mb
|
||||
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
|
||||
guid = guid or (if metaData then metaGuid(metaData) else nil) or Md5.of(buffer.fromstring(path))
|
||||
if used[guid :: string] then
|
||||
guid = Md5.of(buffer.fromstring(path .. "\0" .. guid))
|
||||
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
|
||||
local g: string = given or (if metaData then metaGuid(metaData) else nil) or Md5.of(buffer.fromstring(path))
|
||||
if used[g] then
|
||||
g = Md5.of(buffer.fromstring(path .. "\0" .. g))
|
||||
end
|
||||
used[guid :: string] = true
|
||||
local g = guid :: string
|
||||
used[g] = true
|
||||
metaData = metaData or buffer.fromstring(defaultMeta(g, e.dir == true))
|
||||
table.insert(list, { name = g .. "/", dir = true, mtime = mtime })
|
||||
if data then
|
||||
|
||||
@@ -57,7 +57,7 @@ for _, c in Fx.cases do
|
||||
e = x
|
||||
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")
|
||||
-- round trip through our writer
|
||||
local out, werr = UnityPackage.encode(a)
|
||||
|
||||
Reference in new issue
Block a user