forked from LuaDist/lzlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_gzip.lua
101 lines (68 loc) · 1.54 KB
/
test_gzip.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
local gzip = require 'gzip'
local function line(header, c)
header = header or ''
c = c or '-'
print(string.rep(string.sub(c, 1, 1), 78 - string.len(header))..header)
end
line(' gzip', '=')
line(' gzip writing')
local loops = 1000
local testfile = "test.gz"
local of = gzip.open(testfile, "wb9")
if (not of) then
error("Failed to open file test.gz for writing")
end
for i = 1, loops do
of:write(i, "\n")
end
of:close()
local i = 0
for l in gzip.lines(testfile) do
i = i + 1
if (tostring(i) ~= l) then
error(tostring(i))
end
end
assert(i == loops)
print('Ok.')
line(' gzip reading')
local inf = gzip.open(testfile)
if (not inf) then
error("Failed to open file test.gz for reading")
end
for i = 1, loops do
if (tostring(i) ~= inf:read("*l")) then
error(tostring(i))
end
end
inf:close()
print('Ok.')
if false then
line(' compress seek')
of = gzip.open(testfile, "wb1")
if (not of) then
error("Failed to open file test.gz for writing")
end
assert(of:seek("cur", 5) == 5)
assert(of:seek("set", 10) == 10)
of:write("1")
of:close()
print('Ok.')
line(' uncompress seek')
inf = gzip.open(testfile)
if (not inf) then
error("Failed to open file test.gz for reading")
end
assert(inf:seek("set", 6) == 6)
assert(inf:seek("set", 4) == 4)
assert(inf:seek("cur", 1) == 5)
assert(inf:seek("cur", -1) == 4)
assert(inf:seek("cur", 1) == 5)
assert(inf:seek("set", 6) == 6)
inf:read(4)
assert(inf:read(1) == "1")
inf:close()
print('Ok.')
end
os.remove(testfile)
line(' gzip', '=')