Skip to content

Commit c911ae5

Browse files
committed
Add file handle parameter to inflate.
1 parent 8b2fbbb commit c911ae5

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

arch/INFLATE.LUA

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ 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+
---@param f file The output file handle to allow seeking the sliding window
67
---@param z boolean Is this deflate64
7-
function inflate(r, w, z)
8+
function inflate(r, w, f, z)
89

910
-- TODO: Pass the file handle to inflate to allow file seeking backwards sliding window instead of using RAM
1011

@@ -166,9 +167,9 @@ function inflate(r, w, z)
166167

167168
while kg > 0 do
168169

169-
-- f = final
170+
-- a = final
170171
-- t = block type
171-
local f, t = rb(1), rb(2)
172+
local a, t = rb(1), rb(2)
172173

173174
if t == 0 then -- uncompressed block
174175

@@ -316,7 +317,7 @@ function inflate(r, w, z)
316317
error("!Unsupported", 0)
317318
end
318319

319-
if f == 1 then kg = 0 end
320+
if a == 1 then kg = 0 end
320321
end
321322

322323
-- Flush remaining data

arch/UNZIP.LUA

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function unzip(z, d, l, x)
111111
fn = d .. fn -- Prepend target directory
112112
M(fn) -- Create directory
113113

114-
of, E = io.open(fn, "wb") D()
114+
of, E = io.open(fn, "w+b") D()
115115
print("Extracting: " .. fn)
116116

117117
if of then
@@ -128,7 +128,7 @@ function unzip(z, d, l, x)
128128
if c then W(c) else break end
129129
end
130130
elseif (cm == 8 or cm == 9) and pcall(require, "INFLATE") then -- deflated file
131-
inflate(R, W, cm == 9)
131+
inflate(R, W, of, cm == 9)
132132
else
133133
print("!CM" .. cm)
134134
end

0 commit comments

Comments
 (0)