37 lines
1.2 KiB
Luau
37 lines
1.2 KiB
Luau
-- tools/fixtures/_unitypackage_encode: run by tools/fixtures/unitypackage.py (luau CLI, repo root): re-encodes every
|
|
-- package case and a package built from scratch, printing "<file>\t<hex>" lines for Python's tarfile to read.
|
|
local UnityPackage = require("@rosetta/archive/unitypackage")
|
|
local Bytes = require("@rosetta/core/Bytes")
|
|
local Fx = require("@tests/gen/unitypackage")
|
|
|
|
local HEX = {}
|
|
for i = 0, 255 do
|
|
HEX[i] = string.format("%02x", i)
|
|
end
|
|
local function hex(b: buffer): string
|
|
local out = table.create(buffer.len(b))
|
|
for i = 0, buffer.len(b) - 1 do
|
|
out[i + 1] = HEX[buffer.readu8(b, i)]
|
|
end
|
|
return table.concat(out)
|
|
end
|
|
|
|
for _, c in Fx.cases do
|
|
local a = UnityPackage.decode(Bytes.reader(buffer.fromstring(c.data)))
|
|
if a then
|
|
local out = UnityPackage.encode(a)
|
|
if out then
|
|
print(c.name .. ".unitypackage\t" .. hex(out))
|
|
end
|
|
end
|
|
end
|
|
local a = UnityPackage.new()
|
|
a:add("Assets/Models", "", { dir = true })
|
|
a:add("Assets/Models/cube.obj", "v 0 0 0\n")
|
|
a:add("Assets/readme.txt", "hello\n")
|
|
a:add("Assets/readme.txt.meta", "fileFormatVersion: 2\nguid: 0123456789abcdef0123456789abcdef\n")
|
|
local out = UnityPackage.encode(a)
|
|
if out then
|
|
print("scratch.unitypackage\t" .. hex(out))
|
|
end
|