ws-arch2: archive/yenc (yEnc 1.3 read incl. multi-part in one text, write; CRC checks)
This commit is contained in:
1 parent
8cdb65367a
commit
fe44292f58
6 files changed
+387
No files matched your search
@@ -31,6 +31,7 @@ def tool(pkgs, argv, cwd=None, input=None, check=True):
|
||||
def ours(ctx, fmt, opts=""):
|
||||
"""our writer's output for the standard file set (bytes)"""
|
||||
script = os.path.join(ctx.root, "tools", "fixtures", "_arch2_ours.luau")
|
||||
subprocess.run(["python3", "-I", os.path.join(ctx.root, "tools", "gen_registry.py")], check=True, capture_output=True)
|
||||
exe = shutil.which("luau")
|
||||
argv = ([exe] if exe else ["nix", "shell", "nixpkgs#luau", "-c", "luau"]) + [script, "-a", fmt, opts]
|
||||
out = subprocess.run(argv, check=True, capture_output=True, cwd=ctx.root).stdout
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
# yEnc fixtures (tools/fixtures.py): single-part files by uudeview's `uuenview -y`, a multi-part posting (uuenview -y
|
||||
# -200 split into parts, concatenated into one text, parts in reverse order too), a text with two files; our writer's
|
||||
# output (tools/fixtures/_arch2_ours.luau) decoded by `uudeview`.
|
||||
# tests/gen/yenc.luau { cases = { { name, data, entries = { { name, size, crc } } } }, ours = { ok } }
|
||||
import importlib.util, os, shutil, zlib
|
||||
|
||||
_s = importlib.util.spec_from_file_location("_arch2", os.path.join(os.path.dirname(os.path.abspath(__file__)), "_arch2.py"))
|
||||
A = importlib.util.module_from_spec(_s)
|
||||
_s.loader.exec_module(A)
|
||||
|
||||
INPUTS = ["tools/fixtures/_arch2.py", "tools/fixtures/_arch2_ours.luau", "src/Formats/archive/yenc"]
|
||||
PKG = ["uudeview"]
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
tmp = A.tmpdir()
|
||||
try:
|
||||
big = ("big.bin", ctx.rng(9).randbytes(90000))
|
||||
files = A.FILES + [big, ("crit.bin", bytes(range(256)) * 3 + b"\x00\r\n=\t . " * 50)]
|
||||
A.tree(files, tmp)
|
||||
ent = {n: {"name": n, "size": len(d), "crc": zlib.crc32(d)} for n, d in files}
|
||||
cases, texts = [], {}
|
||||
for n, _ in files:
|
||||
texts[n] = A.tool(PKG, ["uuenview", "-y", n], cwd=tmp)
|
||||
cases.append({"name": "uuenview -y " + n, "data": texts[n], "entries": [ent[n]]})
|
||||
A.tool(PKG, ["uuenview", "-y", "-200", "-od", tmp, "big.bin"], cwd=tmp)
|
||||
parts = sorted(f for f in os.listdir(tmp) if f.startswith("big.") and f[4:].isdigit())
|
||||
assert len(parts) >= 2, parts
|
||||
bodies = [open(os.path.join(tmp, p), "rb").read() for p in parts]
|
||||
cases.append({"name": "multipart (%d parts)" % len(parts), "data": b"".join(bodies), "entries": [ent["big.bin"]]})
|
||||
cases.append({"name": "multipart reversed", "data": b"\n".join(reversed(bodies)), "entries": [ent["big.bin"]]})
|
||||
cases.append({"name": "two files", "data": b"header text\n" + texts["hello.txt"] + b"\nbetween\n" + texts["crit.bin"], "entries": [ent["hello.txt"], ent["crit.bin"]]})
|
||||
d = A.tmpdir()
|
||||
try:
|
||||
p = os.path.join(d, "ours.txt")
|
||||
open(p, "wb").write(A.ours(ctx, "yenc"))
|
||||
A.tool(PKG, ["uudeview", "-i", "-p", d + "/", p], cwd=d)
|
||||
got = A.read_tree(d)
|
||||
ok = all(got.get(n) == zlib.crc32(b) for n, b in A.FILES if b)
|
||||
finally:
|
||||
shutil.rmtree(d)
|
||||
ctx.emit("yenc", {"cases": cases, "ours": {"ok": ok}, "partial": bodies[0]})
|
||||
finally:
|
||||
shutil.rmtree(tmp)
|
||||
Reference in new issue
Block a user