66--- Halt and catch fire if E is set
77function D () if E then error (E , 0 ) end end
88
9+ --- Calculates the CRC32 checksum of a string.
10+ --- @param s string The input string to process.
11+ --- @param c number An initial CRC32 value for incremental calculation if applicable
12+ --- @return number The calculated 32-bit CRC32 checksum.
913function crc32 (s , c )
1014
1115 -- x = maximum
@@ -21,6 +25,9 @@ function crc32(s, c)
2125 return c ~ x
2226end
2327
28+ --- Unzips a ZIP archive file, extracting its contents to the local directory.
29+ --- Always supports store. Deflate is supported if the 'INFLATE' module can be found.
30+ --- @param p string The path to the ZIP file to extract.
2431function unzip (p )
2532
2633 -- C = read chunk size
@@ -45,19 +52,18 @@ function unzip(p)
4552
4653 while true do
4754
48- -- s = signature
49- -- v = version needed
50- -- fl = flags
55+ -- s = Signature
56+ -- v = Version needed
57+ -- fl = Flags
5158 -- cm = Compression method
5259 -- cr = Calculated crc32 checksum
5360 -- cs = Compressed size
5461 -- us = Uncompressed size
5562 -- nl = Length of file name
5663 -- el = Extra length in the file name
57- -- os = The output stream
58- -- di = directory
59- -- of = output file
60- -- re = remaining bytes
64+ -- di = Directory
65+ -- of = Output file
66+ -- re = Remaining bytes
6167 -- ec = Expected crc32 checksum
6268 local s , v , fl , cm , cr , cs , us , nl , el , fn , di , of , re , ec = f :read (4 )
6369 if not s or # s < 4 then break end
@@ -93,6 +99,7 @@ function unzip(p)
9399 -- Setup output file
94100 di = fn :match (" (.+)/" )
95101 if di and os.execute then
102+ -- TODO: DOS friendly version
96103 os.execute (' mkdir -p "' .. di .. ' "' )
97104 end
98105
@@ -134,4 +141,4 @@ if arg[-1] then
134141 unzip (arg [1 ])
135142end
136143
137- -- If arg[-1] == nil then the script was loaded by an interactive intepreter (most likely to swap disks).
144+ -- If arg[-1] == nil then the script was loaded by an interactive interpreter (most likely to swap disks).
0 commit comments