gzip/squish.gzip.lua

changeset 74
4a76d75a1456
parent 73
9827b66cd3b2
child 75
6028ae579fde
equal deleted inserted replaced
73:9827b66cd3b2 74:4a76d75a1456
17 local shebang, newdata = data:match("^(#.-\n)(.+)$"); 17 local shebang, newdata = data:match("^(#.-\n)(.+)$");
18 local code = newdata or data; 18 local code = newdata or data;
19 if shebang then 19 if shebang then
20 outfile:write(shebang) 20 outfile:write(shebang)
21 end 21 end
22
23 local file_with_no_shebang, err = io.open(outfile_fn..".pregzip", "wb+");
24 if not file_with_no_shebang then
25 print_err("Can't open temp file for writing: "..tostring(err));
26 return;
27 end
28
29 file_with_no_shebang:write(code);
30 file_with_no_shebang:close();
22 31
23 local compressed = io.popen("gzip -c '"..infile_fn.."'"); 32 local compressed = io.popen("gzip -c '"..outfile_fn..".pregzip'");
24 code = compressed:read("*a"); 33 code = compressed:read("*a");
34 compressed:close();
35 os.remove(outfile_fn..".pregzip");
25 36
26 local maxequals = 0; 37 local maxequals = 0;
27 code:gsub("(=+)", function (equals_string) maxequals = math.max(maxequals, #equals_string); end); 38 code:gsub("(=+)", function (equals_string) maxequals = math.max(maxequals, #equals_string); end);
28 39
29 outfile:write("local ungz = (function ()", require_resource "gunzip.lua", " end)()\n"); 40 outfile:write("local ungz = (function ()", require_resource "gunzip.lua", " end)()\n");

mercurial