Example
58 | 59 |60 | Suppose we have the following file hierarchy: 61 |
62 | 63 |64 | /a 65 | /b 66 | c.zip 67 | /a2 68 | b2.ext2 69 | /a3.ext3 70 | /luazip.zip 71 |72 | 73 |
-
74 |
- c.zip contains the file 'd.txt' 75 |
- b2.ext2 is a zip file containing the file 'c2/d2.txt' 76 |
- a3.ext3 is a zip file containing the file 'b3/c3/d3.txt' 77 |
- luazip.zip contains the files 'luazip.h', 'luazip.c', 'Makefile', 'README' 78 |
83 | require "zip" 84 | 85 | local zfile, err = zip.open('luazip.zip') 86 | 87 | -- print the filenames of the files inside the zip 88 | for file in zfile:files() do 89 | print(file.filename) 90 | end 91 | 92 | -- open README and print it 93 | local f1, err = zfile:open('README') 94 | local s1 = f1:read("*a") 95 | print(s1) 96 | 97 | f1:close() 98 | zfile:close() 99 | 100 | -- open d.txt inside c.zip 101 | local d, err = zip.openfile('a/b/c/d.txt') 102 | assert(d, err) 103 | d:close() 104 | 105 | -- open d2.txt inside b2.ext2 106 | local d2, err = zip.openfile('a2/b2/c2/d2.txt', "ext2") 107 | assert(d2, err) 108 | d2:close() 109 | 110 | -- open d3.txt inside a3.ext3 111 | local d3, err = zip.openfile('a3/b3/c3/d3.txt', {"ext2", "ext3"}) 112 | assert(d3, err) 113 | d3:close() 114 |115 | 116 |