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:
4DBug committed 2026-11-01 18:38:20 -06:00
1 parent 0b6773db8b
commit 5096eb4898
8 files changed
+538 -1

No files matched your search

+21
View File
@@ -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).