squish.gzip.lua: Write code without shebang to temporary file to avoid compressing the shebang and passing it to loadstring

Sun, 10 Oct 2010 01:32:54 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 10 Oct 2010 01:32:54 +0100
changeset 74
4a76d75a1456
parent 73
9827b66cd3b2
child 75
6028ae579fde

squish.gzip.lua: Write code without shebang to temporary file to avoid compressing the shebang and passing it to loadstring

gzip/squish.gzip.lua file | annotate | diff | comparison | revisions
--- 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);

mercurial