Skip to content

Commit 936ab95

Browse files
committed
Cleaned up output on common user errors in UNZIP.LUA script.
1 parent 9d99dfc commit 936ab95

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

util/UNZIP.LUA

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,10 @@ local function le32(s, i) local a,b,c,d = s:byte(i, i+3) return a + b * 256 + c
276276
local function unzip(path)
277277

278278
-- f = file
279-
-- d = data
279+
-- d = data (or error string string if file can't be opened)
280280
-- p = position
281-
local f, d, p = assert(io.open(path, "rb"))
281+
local f, d, p = io.open(path, "rb")
282+
if d then print(d) os.exit(1) end
282283
d, p = f:read("*a"), 1 f:close()
283284

284285
while true do
@@ -305,10 +306,13 @@ local function unzip(path)
305306
print("Extracting: " .. fn)
306307

307308
if cm == 0 then
309+
-- no compression
308310
os = cd
309311
elseif cm == 8 then
312+
-- deflate
310313
os = inflate(cd)
311314
else
315+
-- unsupported compression
312316
io.stderr:write("Unsupported compression method: "..tostring(cm).."\n")
313317
end
314318

@@ -342,8 +346,8 @@ local function unzip(path)
342346
end
343347
end
344348

345-
if not arg[1] then
346-
io.stderr:write("Usage: lua unzip_fixed.lua <file.zip>\n")
349+
if #arg < 1 then
350+
print((arg[-1] or "?") .. " " .. (arg[0] or "?") .. " file[.zip]")
347351
os.exit(1)
348352
end
349353
unzip(arg[1])

0 commit comments

Comments
 (0)