ws-arch2: archive/uu (uuencode / xxencode / base64 blocks, read + write), core/Crc16 (ccitt / arc), Archive.files helper, shared fixture helpers (_arch2.py / _arch2_ours.luau) and tests/archive/_entries.luau
core/Crc16 is new (CRC-16/XMODEM for BinHex / MacBinary, CRC-16/ARC for LHA / Zoo). containers/Archive gains Archive.files(value, name?) (additive).
This commit is contained in:
1 parent
51117f9732
commit
8cdb65367a
10 files changed
+679
No files matched your search
@@ -0,0 +1,61 @@
|
||||
# uuencode / xxencode / base64 fixtures (tools/fixtures.py): blocks made by GNU sharutils `uuencode` (classic and -m)
|
||||
# and uudeview's `uuenview` (-u, -x), alone and several in one text with mail-like text around them; our writer's uu /
|
||||
# xx / base64 output (tools/fixtures/_arch2_ours.luau) decoded by `uudecode` / `uudeview`.
|
||||
# tests/gen/uu.luau { cases = { { name, data, entries = { { name, size, crc, mode } } } }, gnu = { { name, data } },
|
||||
# ours = { { variant, 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/uu"]
|
||||
PKGS = ["sharutils", "uudeview"]
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
tmp = A.tmpdir()
|
||||
try:
|
||||
A.tree(A.FILES, tmp)
|
||||
for name, _ in A.FILES:
|
||||
os.chmod(os.path.join(tmp, name), 0o644)
|
||||
ents = {n: {"name": n, "size": len(d), "crc": zlib.crc32(d), "mode": 0o644} for n, d in A.FILES}
|
||||
cases, gnu = [], []
|
||||
for name, _ in A.FILES:
|
||||
uu = A.tool(PKGS, ["uuencode", name, name], cwd=tmp)
|
||||
b64 = A.tool(PKGS, ["uuencode", "-m", name, name], cwd=tmp)
|
||||
gnu.append({"name": name, "uu": uu, "base64": b64})
|
||||
cases.append({"name": "uuencode " + name, "data": uu, "entries": [ents[name]]})
|
||||
cases.append({"name": "uuencode -m " + name, "data": b64, "entries": [ents[name]]})
|
||||
for flag in ("-u", "-x"):
|
||||
out = A.tool(PKGS, ["uuenview", flag, name], cwd=tmp)
|
||||
cases.append({"name": "uuenview %s %s" % (flag, name), "data": out, "entries": [{"name": name, "size": ents[name]["size"], "crc": ents[name]["crc"]}]})
|
||||
# several blocks in one mail-like text
|
||||
text = b"From: someone\nSubject: files\n\nHere they are:\n\n" + gnu[0]["uu"] + b"\nand the other one\n" + gnu[1]["base64"] + b"\n-- \nsig\n"
|
||||
cases.append({"name": "mail with two blocks", "data": text, "entries": [ents["hello.txt"], ents["data.bin"]]})
|
||||
crlf = gnu[1]["uu"].replace(b"\n", b"\r\n")
|
||||
cases.append({"name": "crlf lines", "data": crlf, "entries": [ents["data.bin"]]})
|
||||
ours = []
|
||||
for variant in ("uu", "xx", "base64"):
|
||||
data = A.ours(ctx, "uu", "variant=" + variant)
|
||||
d = A.tmpdir()
|
||||
try:
|
||||
# one block per file: uudecode reads the first block only
|
||||
end = b"====\n" if variant == "base64" else b"end\n"
|
||||
for k, block in enumerate(data.split(end)[:-1]):
|
||||
p = os.path.join(d, "in%d.txt" % k)
|
||||
open(p, "wb").write(block + end)
|
||||
if variant != "xx":
|
||||
A.tool(PKGS, ["uudecode", p], cwd=d)
|
||||
if variant == "xx":
|
||||
p = os.path.join(d, "all.txt")
|
||||
open(p, "wb").write(data)
|
||||
A.tool(PKGS, ["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)
|
||||
ours.append({"variant": variant, "ok": ok})
|
||||
finally:
|
||||
shutil.rmtree(d)
|
||||
ctx.emit("uu", {"cases": cases, "gnu": gnu, "ours": ours})
|
||||
finally:
|
||||
shutil.rmtree(tmp)
|
||||
Reference in new issue
Block a user