| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
if string.find (_VERSION, "Lua 5.0") and not package then |
| 8 |
if not LUA_PATH then |
| 9 |
LUA_PATH = os.getenv("LUA_PATH") or "./?.lua;" |
| 10 |
end |
| 11 |
require"compat-5.1" |
| 12 |
package.cpath = os.getenv("LUA_CPATH") or "./?.so;./?.dll;./?.dylib" |
| 13 |
end |
| 14 |
|
| 15 |
require('zip') |
| 16 |
|
| 17 |
function test_open () |
| 18 |
local zfile, err = zip.open('luazip.zip') |
| 19 |
|
| 20 |
assert(zfile, err) |
| 21 |
|
| 22 |
print("File list begin") |
| 23 |
for file in zfile:files() do |
| 24 |
print(file.filename) |
| 25 |
end |
| 26 |
print("File list ended OK!") |
| 27 |
print() |
| 28 |
|
| 29 |
print("Testing zfile:open") |
| 30 |
local f1, err = zfile:open('README') |
| 31 |
assert(f1, err) |
| 32 |
|
| 33 |
local f2, err = zfile:open('luazip.h') |
| 34 |
assert(f2, err) |
| 35 |
print("zfile:open OK!") |
| 36 |
print() |
| 37 |
|
| 38 |
print("Testing reading by number") |
| 39 |
local c = f1:read(1) |
| 40 |
while c ~= nil do |
| 41 |
io.write(c) |
| 42 |
c = f1:read(1) |
| 43 |
end |
| 44 |
|
| 45 |
print() |
| 46 |
print("OK") |
| 47 |
print() |
| 48 |
end |
| 49 |
|
| 50 |
function test_openfile () |
| 51 |
print("Testing the openfile magic") |
| 52 |
|
| 53 |
local d, err = zip.openfile('a/b/c/d.txt') |
| 54 |
assert(d, err) |
| 55 |
|
| 56 |
local e, err = zip.openfile('a/b/c/e.txt') |
| 57 |
assert(e == nil, err) |
| 58 |
|
| 59 |
local d2, err = zip.openfile('a2/b2/c2/d2.txt', "ext2") |
| 60 |
assert(d2, err) |
| 61 |
|
| 62 |
local e2, err = zip.openfile('a2/b2/c2/e2.txt', "ext2") |
| 63 |
assert(e2 == nil, err) |
| 64 |
|
| 65 |
local d3, err = zip.openfile('a3/b3/c3/d3.txt', {"ext2", "ext3"}) |
| 66 |
assert(d3, err) |
| 67 |
|
| 68 |
local e3, err = zip.openfile('a3/b3/c3/e3.txt', {"ext2", "ext3"}) |
| 69 |
assert(e3 == nil, err) |
| 70 |
|
| 71 |
print("Smooth magic!") |
| 72 |
print() |
| 73 |
end |
| 74 |
|
| 75 |
test_open() |
| 76 |
test_openfile() |