22
33package.path = package.path .. " ;?.LUA" -- In case of a case sensitive operating system
44LIB = 1
5+ S = os.getenv (" COMSPEC" ) and " \\ " or " /"
56
67--- Halt and catch fire if E is set
78function D () if E then error (E , 0 ) end end
3435function unzip (z , d , l , x )
3536
3637 -- C = Read chunk size
37- -- v = System path seperator/Version needed
3838 -- f = File
39- local C , v , f = 4096 , package.config : sub ( 1 , 1 )
39+ local C , f = 4096
4040 f = io.open (z , " rb" )
4141 if not f then f , E = io.open (z .. " .zip" , " rb" ) D () end
4242 if not d then d = " ." end
43- if d :sub (- 1 ) ~= v then d = d .. v end
43+ if d :sub (- 1 ) ~= S then d = d .. S end
4444
4545 while true do
4646
4747 -- s = Signature
48+ -- v = Version needed
4849 -- fl = Flags
4950 -- cm = Compression method
5051 -- cr = Calculated crc32 checksum
@@ -56,7 +57,7 @@ function unzip(z, d, l, x)
5657 -- of = Output file
5758 -- re = Remaining bytes
5859 -- ec = Expected crc32 checksum
59- local s , re , fl , cm , cr , cs , us , nl , el , fn , of , ec = f :read (30 ), " cur"
60+ local s , re , v , fl , cm , cr , cs , us , nl , el , fn , of , ec = f :read (30 ), " cur"
6061 if not s or # s < 30 or not s :find (" ^PK\3\4 " ) then break end
6162 v , fl , cm , _ , _ , ec , cs , us , nl , el = string.unpack (" <HHHHHIIIHH" , s , 5 )
6263
@@ -82,17 +83,17 @@ function unzip(z, d, l, x)
8283 --- @return string The created directory.
8384 local function M (p )
8485
85- -- e = path seperator
8686 -- c = current path
87- local e , c , t = os.getenv (" COMSPEC" ) and " \\ " or " /" , " " , {}
87+ -- t = table of paths
88+ local c , t = " " , {}
8889
89- p = p :gsub (" [\\ /]" , e ) -- Normalize separators to the current OS
90- for i in p :gmatch (" [^" .. e .. " ]+" ) do table.insert (t , i ) end
90+ p = p :gsub (" [\\ /]" , S ) -- Normalize separators to the current OS
91+ for i in p :gmatch (" [^" .. S .. " ]+" ) do table.insert (t , i ) end
9192
9293 -- i = directory
9394 for i = 1 , # t - 1 do
94- c = c == " " and t [i ] or c .. e .. t [i ]
95- os.execute (' mkdir "' .. c .. ' " ' .. (e == " /" and ' >/dev/null 2>&1' or ' >nul' ))
95+ c = c == " " and t [i ] or c .. S .. t [i ]
96+ os.execute (' mkdir "' .. c .. ' " ' .. (S == " /" and ' >/dev/null 2>&1' or ' >nul' ))
9697 end
9798 end
9899
0 commit comments