C2, the hierarchy (tools/move.py, every reference rewritten mechanically): - codecs/compress: Deflate Lzma Zstd Brotli Bzip2 Lzw; codecs/entropy: Huffman (from core) RangeCoder; codecs/image: Jpeg Dct Vp8 Vp8L Yuv Quantize Raster Blend Pixels; codecs/audio: Mdct Aac Alac Pcm Resample VorbisComment Tracker SoundFont Stream; codecs/video: H264 Mpeg1 Video; codecs/text: Json Xml Text Url; codecs/font: TrueType Cff; codecs/model: MeshFlatten Mat4. containers/ stays flat; core/ keeps Bytes Bits Err Crc32 Adler32 Base64 Md5 Input Sniff. - LAYERS lint: codecs must sit in a domain folder; gen_registry lists codecs by domain (docs/FORMATS.md). - Checked: build.py both targets, rojo build of build/roblox, the full suite on both runtimes. C3, generic code out of format folders: - containers/Chunks (new): the chunked-file walker (RIFF / RIFX / IFF / PNG / CAF layouts: endianness, size first, trailer, padding, lenient missing pad, open-ended ids, size hooks). containers/Riff walks with it (RF64 ds64 through the resize hook); image/png, audio/aiff and audio/caf list their chunk handlers over it. - codecs/audio/Stream (new): Stream.packets, the packet-decoder Decoder (read / seek with pre-roll / position, priming and end trimming) that aac, caf and m4a each carried (~70 lines each). - codecs/image/Pixels: image/bmp/Pixels promoted (+ rgb555); image/ico's DIB decoder uses its row loops instead of its own (the AND mask / alpha rule stay ICO's). - codecs/model/Mat4 (new): matrices / quaternions / TRS shared by FBX (Xform keeps only the FBX transform model), Collada (Math keeps only <lookat> / <skew>) and USD (its matrix helpers and general 4x4 inverse); Mat4.mul is Types.Scene.mul. The Collada normal matrix is now the inverse transpose (it was the inverse; same result for the fixtures' bind shapes). - README rewritten (install for Rojo and LÖVE / LuaJIT, quick start per category, F.* and F.ops, host notes: FORMATS_NO_JIT_TUNE, paths, layout); docs/STYLE.md: the codec domains, "what belongs in a format folder" with the shared building blocks and the DUP rule, conventions (WAVE order, lower-case tags, loops, the api hooks decodeImage / encodeImage / openAudio / plugins / resolve, the codecs/video/Video registry), Err.from, the type baseline. New tests: tests/containers/chunks, tests/codecs/mat4. Type baseline 93.
104 lines
4.7 KiB
Python
104 lines
4.7 KiB
Python
# 7z fixtures (tools/fixtures.py): a small tree (text, x86 machine code, runs, an empty file, empty and nested
|
|
# directories, UTF-16 names with accents and a surrogate pair) archived by 7-Zip 2x (nix _7zz) with many method chains:
|
|
# LZMA / LZMA2 / copy / Deflate, solid and non-solid, BCJ / ARM64 / delta filters, plain and compressed headers; plus
|
|
# BZip2 archives (codecs/compress/Bzip2), archives whose methods are not supported (PPMd, BCJ2, AES) and an empty archive.
|
|
# tests/gen/7z.luau { files = { { name, dir, data?, mtime } }, cases = { { name, data, unsupported? } } }
|
|
import os, random, subprocess, sys, tempfile
|
|
|
|
TOOL = "_7zz"
|
|
|
|
|
|
def tree(rng):
|
|
with open(os.path.realpath(sys.executable), "rb") as f:
|
|
code = f.read(60000)
|
|
base = os.path.dirname(os.__file__)
|
|
text = b""
|
|
for name in sorted(os.listdir(base)):
|
|
if name.endswith(".py"):
|
|
with open(os.path.join(base, name), "rb") as f:
|
|
text += f.read()
|
|
if len(text) > 50000:
|
|
break
|
|
return [
|
|
("readme.txt", text[:50000]),
|
|
("bin/code.bin", code),
|
|
("bin/runs.dat", b"ab" * 5000 + b"\0" * 9000 + bytes(range(256)) * 8),
|
|
("bin/random.dat", rng.randbytes(3000)),
|
|
("empty.txt", b""),
|
|
("emptydir/", None),
|
|
("a/b/c/deep.txt", b"deep\n" * 10),
|
|
("héllo wörld ☃.txt", "unicode ☃\n".encode()),
|
|
("\U0001d11e clef.txt", b"g clef\n"),
|
|
]
|
|
|
|
|
|
def generate(ctx):
|
|
rng = random.Random(77)
|
|
files = tree(rng)
|
|
mtime = 1600000000
|
|
out_files = []
|
|
cases = []
|
|
with tempfile.TemporaryDirectory() as d:
|
|
src = os.path.join(d, "src")
|
|
for name, data in files:
|
|
p = os.path.join(src, name)
|
|
if data is None:
|
|
os.makedirs(p, exist_ok=True)
|
|
os.utime(p, (mtime, mtime))
|
|
out_files.append({"name": name.rstrip("/"), "dir": True, "mtime": mtime})
|
|
else:
|
|
os.makedirs(os.path.dirname(p), exist_ok=True)
|
|
with open(p, "wb") as f:
|
|
f.write(data)
|
|
os.utime(p, (mtime + 60, mtime + 60))
|
|
out_files.append({"name": name, "dir": False, "data": data, "mtime": mtime + 60})
|
|
for sub in ("bin", "a", "a/b", "a/b/c"):
|
|
os.utime(os.path.join(src, sub), (mtime, mtime))
|
|
out_files.append({"name": sub, "dir": True, "mtime": mtime})
|
|
|
|
def make(name, args, unsupported=None):
|
|
arc = os.path.join(d, name + ".7z")
|
|
if os.path.exists(arc):
|
|
os.remove(arc)
|
|
subprocess.run(["nix", "shell", "nixpkgs#" + TOOL, "-c", "7zz", "a", "-bd", "-y", arc] + args + ["."],
|
|
cwd=src, capture_output=True, check=True)
|
|
with open(arc, "rb") as f:
|
|
c = {"name": name, "data": f.read()}
|
|
if unsupported:
|
|
c["unsupported"] = unsupported
|
|
cases.append(c)
|
|
|
|
make("lzma-nonsolid", ["-m0=LZMA", "-ms=off", "-mhc=off"])
|
|
make("lzma-solid", ["-m0=LZMA:d=1m", "-ms=on"])
|
|
make("lzma2-solid", ["-m0=LZMA2", "-ms=on"])
|
|
make("lzma2-mt-blocks", ["-m0=LZMA2:d=64k:c=20k", "-ms=on", "-mmt=4"])
|
|
make("lzma2-hc-off", ["-m0=LZMA2", "-mhc=off"])
|
|
make("copy", ["-m0=Copy", "-mhc=off"])
|
|
make("copy-hc", ["-m0=Copy"])
|
|
make("deflate", ["-m0=Deflate", "-ms=on"])
|
|
make("bcj-lzma", ["-m0=BCJ", "-m1=LZMA", "-ms=on"])
|
|
make("bcj-lzma2", ["-m0=BCJ", "-m1=LZMA2", "-ms=off"])
|
|
make("arm64-lzma2", ["-m0=ARM64", "-m1=LZMA2"])
|
|
make("arm-lzma2", ["-m0=ARM", "-m1=LZMA2"])
|
|
make("delta-lzma", ["-m0=Delta:4", "-m1=LZMA"])
|
|
make("ppc-sparc", ["-m0=PPC", "-m1=SPARC", "-m2=LZMA2"])
|
|
make("lzma-lc-lp", ["-m0=LZMA:lc=0:lp=2:pb=0", "-ms=e"])
|
|
make("auto", ["-mx=9"])
|
|
make("fast", ["-mx=1"])
|
|
make("bzip2", ["-m0=BZip2", "-mhc=off"])
|
|
make("bzip2-solid-bcj", ["-m0=BCJ", "-m1=BZip2", "-ms=on", "-mhc=on"])
|
|
make("ppmd", ["-m0=PPMd", "-mhc=off"], unsupported="ppmd")
|
|
make("bcj2", ["-m0=BCJ2", "-m1=LZMA", "-m2=LZMA", "-m3=LZMA", "-mb0s0:1", "-mb0s1:2", "-mb0s2:3", "-mhc=off"],
|
|
unsupported="bcj2")
|
|
make("aes", ["-m0=LZMA2", "-mhc=off", "-pSecret"], unsupported="aes")
|
|
# an empty archive
|
|
arc = os.path.join(d, "empty.7z")
|
|
empty = os.path.join(d, "emptysrc")
|
|
os.makedirs(empty)
|
|
subprocess.run(["nix", "shell", "nixpkgs#" + TOOL, "-c", "7zz", "a", "-bd", "-y", arc, "-x!*", "."],
|
|
cwd=empty, capture_output=True)
|
|
if os.path.exists(arc):
|
|
with open(arc, "rb") as f:
|
|
cases.append({"name": "empty", "data": f.read(), "empty": True})
|
|
ctx.emit("7z", {"files": out_files, "cases": cases})
|