@@ -3,7 +3,10 @@ if not LIB then print("Please run unzip instead") os.exit(1) end
33--- Inflate (a.k.a decompress) a deflated file inside a zip
44--- @param r function The reader function
55--- @param w function The writer function
6- function inflate (r , w )
6+ --- @param z boolean Is this deflate64
7+ function inflate (r , w , z )
8+
9+ local Z = z and 65536 or 32768
710
811 --- New bit stream
912 function nbs (rf )
@@ -77,7 +80,7 @@ function inflate(r, w)
7780
7881 -- Add to history window
7982 sw [wp ] = byte
80- wp = (wp + 1 ) % 32768
83+ wp = (wp + 1 ) % Z
8184 end
8285
8386 --- Make huffman
@@ -223,9 +226,25 @@ function inflate(r, w)
223226 {1 ,0 },{2 ,0 },{3 ,0 },{4 ,0 },{5 ,1 },{7 ,1 },{9 ,2 },{13 ,2 },{17 ,3 },{25 ,3 },
224227 {33 ,4 },{49 ,4 },{65 ,5 },{97 ,5 },{129 ,6 },{193 ,6 },{257 ,7 },{385 ,7 },{513 ,8 },
225228 {769 ,8 },{1025 ,9 },{1537 ,9 },{2049 ,10 },{3073 ,10 },{4097 ,11 },{6145 ,11 },
226- {8193 ,12 },{12289 ,12 },{16385 ,13 },{24577 ,13 }
229+ {8193 ,12 },{12289 ,12 },{16385 ,13 },{24577 ,13 },
230+ -- Inflate64 below
231+ {32769 ,13 },{49153 ,13 },{65537 ,14 },{98305 ,14 },{131073 ,15 },
232+ {196609 ,15 },{262145 ,16 },
233+ {393217 ,16 },{524289 ,17 },{786433 ,17 },{1048577 ,18 },{1572865 ,18 },
234+ {2097153 ,19 },{3145729 ,19 },{4194305 ,20 },{6291457 ,20 },{8388609 ,21 },
235+ {12582913 ,21 },{16777217 ,22 },{25165825 ,22 },{33554433 ,23 },
236+ {50331649 ,23 },{67108865 ,24 },{100663297 ,24 },{134217729 ,25 },
237+ {201326593 ,25 },{268435457 ,26 },{402653185 ,26 },{536870913 ,27 },
238+ {805306369 ,27 },{1073741825 ,28 },{1610612737 ,28 }
227239 }
228240
241+ -- Strip addition table values out when not in inflate64 mode
242+ if not z then
243+ for _ = 1 , 32 do
244+ table.remove (dix )
245+ end
246+ end
247+
229248 while true do
230249 -- s = sym
231250 local s = rh (h )
@@ -256,12 +275,12 @@ function inflate(r, w)
256275 dv = db + da
257276
258277 if dv <= 0 or dv > op then
259- error (" !Distance" , 0 )
278+ print (" !Distance" , dv , Z , op ) os.exit ( 1 )
260279 end
261280
262281 -- Read from window history
263282 for _ = 1 , l do
264- local p = (wp - dv ) % 32768
283+ local p = (wp - dv ) % Z
265284 ab (sw [p ] or 0 )
266285 end
267286 end
0 commit comments