-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_unzip.lua
More file actions
21 lines (19 loc) · 839 Bytes
/
debug_unzip.lua
File metadata and controls
21 lines (19 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
-- debug_unzip.lua
-- Create a small dbg.zip in the repo and exercise unzip_file.
local sep = package.config:sub(1,1)
local src = debug.getinfo(1, 'S').source or ''
local dir = src:match('@?(.*[\\/])') or './'
dir = dir:gsub('[\\/]+$', '')
local base = dir
-- Optionally load a local test helper if present; ignore errors.
pcall(function() dofile(base .. sep .. 'test.lua') end)
local outzip = base .. sep .. 'dbg.zip'
local outdir = base .. sep .. 'dbg_out'
pcall(function() os.remove(outzip) end)
local zw = ZipWriter.new(outzip, {compress=false})
zw:add_data('hello.txt','Hello World')
zw:close()
local ok, err = unzip_file(outzip, outdir)
print('unzip returned', ok, err)
local f = io.open(outdir..sep..'hello.txt','rb')
if not f then print('extracted file not found') else print('extracted file size', f:seek('end')); f:close() end