-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.lua
56 lines (53 loc) · 1.8 KB
/
tests.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
local inflate = require('inflate')
local http = require('https')
local start, finish
local files = {
['zip_10MB/'] = false,
['zip_10MB/file_example_JPG_1MB.jpg'] = false,
['zip_10MB/file-example_PDF_1MB.pdf'] = false,
['zip_10MB/file_example_ODS_5000.ods'] = false,
['zip_10MB/file_example_TIFF_10MB.tiff'] = false,
['zip_10MB/file_example_PNG_2500kB.jpg'] = false,
['zip_10MB/file_example_PPT_1MB.ppt'] = false,
['zip_10MB/file-sample_1MB.doc'] = false
}
http.get('https://files-example-com.github.io/uploads/zip_10MB.zip', function(response)
if response.statusCode ~= 200 then
print('Failed to get the sample ZIP archive.')
return
end
local buffer = {}
response:on('data', function(chunk)
buffer[#buffer + 1] = chunk
end)
response:on('end', function()
local stream = inflate.new(table.concat(buffer))
local success, err = pcall(function()
start = os.clock()
for name, offset, _, _, crc in stream:files() do
files[name] = true
if name:sub(-1) ~= "/" then
stream:inflate(offset, crc)
end
end
finish = os.clock()
print('Took '..(finish - start)..'ms to traverse and inflate the ZIP archive')
stream:unzip('zip_10MB/file_example_JPG_1MB.jpg')
end)
if not success then
print('Exception during inlation: '..err)
if process then
process:exit(0)
else
os.exit(0)
end
end
for name, seen in pairs(files) do
if not seen then
print('File "'..name..'" not seen in ZIP archive.')
return
end
end
print('Test passed.')
end)
end)