archive/unitypackage: Unity asset packages read + write as an Archive keyed by asset paths (.meta beside each asset, guids, folders, previews)
This commit is contained in:
1 parent
0b6773db8b
commit
5096eb4898
8 files changed
+538
-1
No files matched your search
@@ -129,6 +129,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
| archive | pak | .pak .sin | yes | yes | variants: "quake", "sin" | `tests/archive/pak.luau` |
|
||||
| archive | rpm | .rpm | yes | - | compressors: "gzip", "bzip2", "xz", "lzma", "zstd" | `tests/archive/rpm.luau` |
|
||||
| archive | tar | .tar | yes | yes | variants: "ustar", "pax", "gnu" | `tests/archive/tar.luau` |
|
||||
| archive | unitypackage | .unitypackage | yes | yes | | `tests/archive/unitypackage.luau` |
|
||||
| archive | uu | .uu .uue .xxe .b64 | yes | yes | variants: "uu", "xx", "base64" | `tests/archive/uu.luau` |
|
||||
| archive | vpk | .vpk | yes | yes | versions: 1, 2, multipart: true | `tests/archive/vpk.luau` |
|
||||
| archive | wad | .wad | yes | yes | images: true, maps: true, variants: "iwad", "pwad" | `tests/archive/wad.luau` |
|
||||
|
||||
@@ -418,6 +418,26 @@ local out = assert(F.save(cab, nil, { format = "cab", compression = "none" }))
|
||||
assert(F.archive.load(out):list()[1].method == "store")
|
||||
```
|
||||
|
||||
## Unity packages
|
||||
|
||||
A `.unitypackage` is a gzip'd tar of one folder per asset guid (`asset`, `asset.meta`, `pathname`). It loads as an
|
||||
Archive keyed by the asset paths, each `.meta` next to its asset as in a Unity project folder; folders are `dir`
|
||||
entries with their own `.meta`. Every entry carries its `guid`, and an asset's `preview` (when the package has a
|
||||
`preview.png`) is a function returning its bytes. Without a name the file is plain gzip (it unwraps to the tar of
|
||||
guid folders): pass a `.unitypackage` name or `format = "unitypackage"`. Any Archive saves as a package: guids come
|
||||
from `entry.guid`, then the `.meta` entry's `guid:` line, else the path's MD5; missing `.meta` files are made.
|
||||
|
||||
```luau
|
||||
local pack = F.format("unitypackage").new()
|
||||
pack:add("Assets/Scripts", "", { dir = true })
|
||||
pack:add("Assets/Scripts/Player.cs", "public class Player { }\n")
|
||||
local bytes = assert(F.save(pack))
|
||||
local back = assert(F.load(bytes, { name = "game.unitypackage" }))
|
||||
assert(back.format == "unitypackage")
|
||||
local meta = buffer.tostring(assert(back:read("Assets/Scripts/Player.cs.meta")))
|
||||
assert(string.match(meta, "guid: (%x+)") == back:list()[3].guid)
|
||||
```
|
||||
|
||||
## Formats
|
||||
|
||||
| Format | Read | Write | Notes |
|
||||
@@ -452,6 +472,7 @@ assert(F.archive.load(out):list()[1].method == "store")
|
||||
| C64 disks (`.d64`, `.d71`, `.d81`) | yes | yes | PETSCII names; no GEOS VLIR |
|
||||
| Amiga disks (`.adf`) | yes | - | OFS / FFS; no long-name (DOS 6 / 7) volumes |
|
||||
| FAT images (`.img`, `.ima`) | yes | yes | FAT12 / 16 / 32, VFAT names, MBR partitions; writes FAT12 floppies |
|
||||
| Unity package (`.unitypackage`) | yes | yes | assets by path, `.meta` files beside them, guids, previews; needs the extension to beat gzip |
|
||||
| Cabinet (`.cab`) | yes | yes | stored / MSZIP / LZX / Quantum (read), stored / MSZIP (write); no spanned files |
|
||||
|
||||
Full capability list: [FORMATS.md](../FORMATS.md).
|
||||
|
||||
Reference in new issue
Block a user