# Zoo fixtures (tools/fixtures.py): no zoo archiver is packaged in nixpkgs, so the archives are assembled here per # zoo 2.10's zoo.h layout (type 1 and type 2 directory entries, long names, directory names, a deleted entry), with # data stored (method 0), LZW-compressed by the encoder below (method 1: 9..13-bit LSB-first codes, CLEAR 256, EOF 257) # and lzh-compressed (method 2: the -lh5- streams of LHa for UNIX archives); The Unarchiver (`lsar -j`, `unar`) # is the reference reader: its listing and extracted data are the expected entries. # tests/gen/zoo.luau { cases = { { name, data, entries = { { name, size, crc } } } } } import importlib.util, json, os, struct, 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"] TAG = 0xFDC4A7DC def crc16(data): c = 0 for b in data: c ^= b for _ in range(8): c = (c >> 1) ^ 0xA001 if c & 1 else c >> 1 return c def lzw(data): """zoo method 1: codes sized as the decoder (lzd.c) reads them""" out, acc, nbits = bytearray(), 0, 0 def put(code, size): nonlocal acc, nbits acc |= code << nbits nbits += size while nbits >= 8: out.append(acc & 255) acc >>= 8 nbits -= 8 def reset(): return {bytes([i]): i for i in range(256)}, 258, 258, 9, True table, enc_next, dec_next, size, first = reset() put(256, size) w = b"" for b in data: wc = w + bytes([b]) if wc in table: w = wc continue put(table[w], size) if not first: dec_next += 1 if dec_next >= (1 << size) and size < 13: size += 1 first = False if enc_next < 8192: table[wc] = enc_next enc_next += 1 w = bytes([b]) else: put(table[bytes([b])], size) # the last code before the clear put(256, size) table, enc_next, dec_next, size, first = reset() w = b"" continue if w: put(table[w], size) if not first: dec_next += 1 if dec_next >= (1 << size) and size < 13: size += 1 put(257, size) if nbits: out.append(acc & 255) return bytes(out) def lh5_streams(ctx, files, tmp): """{name: (packed bytes, crc)} from LHa for UNIX -o5 level 2 archives""" out = {} work = os.path.join(tmp, "lh5") A.tree(files, work) for name, data in files: if not data: continue arc = os.path.join(tmp, "one.lzh") if os.path.exists(arc): os.remove(arc) A.tool([], ["env", "NIXPKGS_ALLOW_UNFREE=1", "nix", "shell", "--impure", "nixpkgs#lha", "-c", "lha", "-a2o5q", arc, name], cwd=work) b = open(arc, "rb").read() total = struct.unpack_from("> 8, 0x40]) var += struct.pack(" zoo bytes""" hdr = b"ZOO 2.10 Archive.\x1a".ljust(20, b"\0") + struct.pack("