local zzlib = require('arti-pack.vendor.zzlib') local M = {} local function le(n, bytes) local out = {} for _ = 1, bytes do table.insert(out, string.char(n % 256)) n = math.floor(n / 256) end return table.concat(out) end -- A stored-entry zip built here rather than shelled out to the zip binary, so -- tests that need a real archive run wherever nvim does. function M.bytes(entries) local locals, central, offset = {}, {}, 0 for _, e in ipairs(entries) do local data = e.data or '' local crc = zzlib.crc32(data) local head = 'PK\3\4' .. le(20, 2) .. le(0, 2) .. le(0, 2) .. le(0, 4) .. le(crc, 4) .. le(#data, 4) .. le(#data, 4) .. le(#e.name, 2) .. le(0, 2) .. e.name table.insert(locals, head .. data) table.insert( central, 'PK\1\2' .. le(3 * 256 + 20, 2) .. le(20, 2) .. le(0, 2) .. le(0, 2) .. le(0, 4) .. le(crc, 4) .. le(#data, 4) .. le(#data, 4) .. le(#e.name, 2) .. le(0, 2) .. le(0, 2) .. le(0, 2) .. le(0, 2) .. le(0, 4) .. le(offset, 4) .. e.name ) offset = offset + #head + #data end local body = table.concat(locals) local cd = table.concat(central) local eocd = 'PK\5\6' .. le(0, 2) .. le(0, 2) .. le(#entries, 2) .. le(#entries, 2) .. le(#cd, 4) .. le(#body, 4) .. le(0, 2) return body .. cd .. eocd end -- Mirrors an upstream source archive: everything under one "-" root. function M.write(path, root, marker) local fd = assert(io.open(path, 'wb')) fd:write(M.bytes({ { name = root .. '/lua/marker.lua', data = 'return "' .. marker .. '"' } })) fd:close() return path end return M