-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
97 lines (74 loc) · 2.68 KB
/
main.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
function compress(strInputFile, strOutputFile)
if(not fileExists(strInputFile)) then
outputDebugString("LibDeflate: Input file "..strInputFile.." not found!", 1);
return false;
end
if(fileExists(strOutputFile)) then
outputDebugString("LibDeflate: Output file "..strOutputFile.." exists already!", 1);
return false;
end
local uFileHandle = fileOpen(strInputFile);
local strFileData = "";
if(uFileHandle) then
strFileData = fileRead(uFileHandle, fileGetSize(uFileHandle));
fileClose(uFileHandle);
else
outputDebugString("LibDeflate: Cannot open file "..strInputFile.."!", 1);
return false;
end
if(#strFileData == 0) then
outputDebugString("LibDeflate: Reading from "..strInputFile.." returned 0 bytes!", 1);
return false;
end
local uNewFileHandle = fileCreate(strOutputFile);
if(not uNewFileHandle) then
outputDebugString("LibDeflate: Cannot create file "..strOutputFile.."!", 1);
return false;
end
local strCompressedData = LibDeflate:CompressDeflate(strFileData);
if(strCompressedData == nil) then
outputDebugString("LibDeflate: Compression failed for "..strInputFile.."!", 1);
return false;
end
fileWrite(uNewFileHandle, strCompressedData);
fileClose(uNewFileHandle);
outputDebugString("LibDeflate: Compression succeded for "..strInputFile.." - Output file: "..strOutputFile);
return true;
end
function decompress(strInputFile, strOutputFile)
if(not fileExists(strInputFile)) then
outputDebugString("LibDeflate: Input file "..strInputFile.." not found!", 1);
return false;
end
if(fileExists(strOutputFile)) then
outputDebugString("LibDeflate: Output file "..strOutputFile.." exists already!", 1);
return false;
end
local uFileHandle = fileOpen(strInputFile);
local strFileData = "";
if(uFileHandle) then
strFileData = fileRead(uFileHandle, fileGetSize(uFileHandle));
fileClose(uFileHandle);
else
outputDebugString("LibDeflate: Cannot open file "..strInputFile.."!", 1);
return false;
end
if(#strFileData == 0) then
outputDebugString("LibDeflate: Reading from "..strInputFile.." returned 0 bytes!", 1);
return false;
end
local uNewFileHandle = fileCreate(strOutputFile);
if(not uNewFileHandle) then
outputDebugString("LibDeflate: Cannot create file "..strOutputFile.."!", 1);
return false;
end
local strDecompressedData = LibDeflate:DecompressDeflate(strFileData);
if(strDecompressedData == nil) then
outputDebugString("LibDeflate: Decompression failed for "..strInputFile.."!", 1);
return false;
end
fileWrite(uNewFileHandle, strDecompressedData);
fileClose(uNewFileHandle);
outputDebugString("LibDeflate: Decompression succeded for "..strInputFile.." - Output file: "..strOutputFile);
return true;
end