# HG changeset patch # User Matthew Wild # Date 1286670774 -3600 # Node ID 4a76d75a14569191675d3465b8149662c01ef6fc # Parent 9827b66cd3b23d5e5d2ec4ba75485eca334ae4e6 squish.gzip.lua: Write code without shebang to temporary file to avoid compressing the shebang and passing it to loadstring diff -r 9827b66cd3b2 -r 4a76d75a1456 gzip/squish.gzip.lua --- a/gzip/squish.gzip.lua Sun Oct 10 01:32:11 2010 +0100 +++ b/gzip/squish.gzip.lua Sun Oct 10 01:32:54 2010 +0100 @@ -19,9 +19,20 @@ if shebang then outfile:write(shebang) end + + local file_with_no_shebang, err = io.open(outfile_fn..".pregzip", "wb+"); + if not file_with_no_shebang then + print_err("Can't open temp file for writing: "..tostring(err)); + return; + end + + file_with_no_shebang:write(code); + file_with_no_shebang:close(); - local compressed = io.popen("gzip -c '"..infile_fn.."'"); + local compressed = io.popen("gzip -c '"..outfile_fn..".pregzip'"); code = compressed:read("*a"); + compressed:close(); + os.remove(outfile_fn..".pregzip"); local maxequals = 0; code:gsub("(=+)", function (equals_string) maxequals = math.max(maxequals, #equals_string); end);