| 1 |
|
| 2 |
|
| 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 |
| 8 |
|
| 9 |
|
| 10 |
line(' gzip', '=') |
| 11 |
|
| 12 |
line(' gzip writing') |
| 13 |
local loops = 1000 |
| 14 |
local testfile = "test.gz" |
| 15 |
|
| 16 |
local of = gzip.open(testfile, "wb9") |
| 17 |
|
| 18 |
if (not of) then |
| 19 |
error("Failed to open file test.gz for writing") |
| 20 |
end |
| 21 |
|
| 22 |
for i = 1, loops do |
| 23 |
of:write(i, "\n") |
| 24 |
end |
| 25 |
|
| 26 |
of:close() |
| 27 |
|
| 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 |
| 35 |
|
| 36 |
assert(i == loops) |
| 37 |
print('Ok.') |
| 38 |
line(' gzip reading') |
| 39 |
|
| 40 |
local inf = gzip.open(testfile) |
| 41 |
|
| 42 |
if (not inf) then |
| 43 |
error("Failed to open file test.gz for reading") |
| 44 |
end |
| 45 |
|
| 46 |
for i = 1, loops do |
| 47 |
if (tostring(i) ~= inf:read("*l")) then |
| 48 |
error(tostring(i)) |
| 49 |
end |
| 50 |
end |
| 51 |
|
| 52 |
inf:close() |
| 53 |
|
| 54 |
print('Ok.') |
| 55 |
line(' compress seek') |
| 56 |
|
| 57 |
of = gzip.open(testfile, "wb1") |
| 58 |
|
| 59 |
if (not of) then |
| 60 |
error("Failed to open file test.gz for writing") |
| 61 |
end |
| 62 |
|
| 63 |
assert(of:seek("cur", 5) == 5) |
| 64 |
assert(of:seek("set", 10) == 10) |
| 65 |
|
| 66 |
of:write("1") |
| 67 |
|
| 68 |
of:close() |
| 69 |
|
| 70 |
print('Ok.') |
| 71 |
line(' uncompress seek') |
| 72 |
|
| 73 |
inf = gzip.open(testfile) |
| 74 |
|
| 75 |
if (not inf) then |
| 76 |
error("Failed to open file test.gz for reading") |
| 77 |
end |
| 78 |
|
| 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) |
| 85 |
|
| 86 |
inf:read(4) |
| 87 |
|
| 88 |
assert(inf:read(1) == "1") |
| 89 |
|
| 90 |
inf:close() |
| 91 |
|
| 92 |
os.remove(testfile) |
| 93 |
|
| 94 |
print('Ok.') |
| 95 |
|
| 96 |
line(' gzip', '=') |