beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / luazlib / test_gzip.lua
blob96041f11357a85eb0688f121395e03249fc3868d
1 -- $Id: test_gzip.lua,v 1.2 2003/12/28 01:26:16 tngd Exp $
3 local function line(header, c)
4 header = header or ''
5 c = c or '-'
6 print(string.rep(string.sub(c, 1, 1), 78 - string.len(header))..header)
7 end
10 line(' gzip', '=')
12 line(' gzip writing')
13 local loops = 1000
14 local testfile = "test.gz"
16 local of = gzip.open(testfile, "wb9")
18 if (not of) then
19 error("Failed to open file test.gz for writing")
20 end
22 for i = 1, loops do
23 of:write(i, "\n")
24 end
26 of:close()
28 local i = 0
29 for l in gzip.lines(testfile) do
30 i = i + 1
31 if (tostring(i) ~= l) then
32 error(tostring(i))
33 end
34 end
36 assert(i == loops)
37 print('Ok.')
38 line(' gzip reading')
40 local inf = gzip.open(testfile)
42 if (not inf) then
43 error("Failed to open file test.gz for reading")
44 end
46 for i = 1, loops do
47 if (tostring(i) ~= inf:read("*l")) then
48 error(tostring(i))
49 end
50 end
52 inf:close()
54 print('Ok.')
55 line(' compress seek')
57 of = gzip.open(testfile, "wb1")
59 if (not of) then
60 error("Failed to open file test.gz for writing")
61 end
63 assert(of:seek("cur", 5) == 5)
64 assert(of:seek("set", 10) == 10)
66 of:write("1")
68 of:close()
70 print('Ok.')
71 line(' uncompress seek')
73 inf = gzip.open(testfile)
75 if (not inf) then
76 error("Failed to open file test.gz for reading")
77 end
79 assert(inf:seek("set", 6) == 6)
80 assert(inf:seek("set", 4) == 4)
81 assert(inf:seek("cur", 1) == 5)
82 assert(inf:seek("cur", -1) == 4)
83 assert(inf:seek("cur", 1) == 5)
84 assert(inf:seek("set", 6) == 6)
86 inf:read(4)
88 assert(inf:read(1) == "1")
90 inf:close()
92 os.remove(testfile)
94 print('Ok.')
96 line(' gzip', '=')