Skip to content

Commit 6487bf5

Browse files
committed
archiver: add extract iterator
1 parent 784c521 commit 6487bf5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

ffi/archiver.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,31 @@ function Reader:seek(key)
113113
end
114114
end
115115

116+
function Reader:extractIterator(key)
117+
self.err = nil
118+
local entry = self:seek(key)
119+
if not entry or entry.mode ~= "file" then
120+
return
121+
end
122+
-- We can't consume the data twice: tweak the index
123+
-- to trigger a reset in case of subsequent attempt.
124+
self.index = self.index + 0.1
125+
local buff = ffi.new("const void *[1]")
126+
local size = ffi.new("size_t [1]")
127+
local offs = ffi.new("int64_t [1]")
128+
return function()
129+
local ok = libarchive.archive_read_data_block(self.archive, buff, size, offs)
130+
if ok == libarchive.ARCHIVE_EOF then
131+
return
132+
end
133+
if ok ~= libarchive.ARCHIVE_OK then
134+
self.err = archive_error_string(self.archive)
135+
return
136+
end
137+
return buff[0], size[0], offs[0]
138+
end
139+
end
140+
116141
function Reader:extractToMemory(key)
117142
self.err = nil
118143
local entry = self:seek(key)

0 commit comments

Comments
 (0)