Posted 28 April 2018 - 04:21 PM
So, for the love of God, I made a decision I never really thought I'd make: making an archiving API (for folders and folders ONLY). Did the basic compression script. Now, the API is supposed to compress in the shape of a table like this (it's serialized):
stored in an "archive" (just a file containing this table), so I did it. Trying to compress a folder w/ the exact same files, I get this error: "compact:19: attempt to index ? (a nil value)" when inserting the file data into the "filedata" subtable. I inserted a print(textutils.serialize(archive)) (serializes the archive table) and read() (so the code continues execution ONLY when I press enter) to make sure the table is in the right shape for the job. This is the output:
which looks OK imo, so idk why is it not working. Anyway, the compression function:
Any help is appreciated!
{
files = {
"1.lua",
"2.lua",
"3.lua",
},
filedata = {
"1.lua" = "file 1",
"2.lua" = "file 2",
"3.lua" = "file 3",
},
}
stored in an "archive" (just a file containing this table), so I did it. Trying to compress a folder w/ the exact same files, I get this error: "compact:19: attempt to index ? (a nil value)" when inserting the file data into the "filedata" subtable. I inserted a print(textutils.serialize(archive)) (serializes the archive table) and read() (so the code continues execution ONLY when I press enter) to make sure the table is in the right shape for the job. This is the output:
{
files = {
"1.lua",
},
filedata = {
"1.lua",
},
}
which looks OK imo, so idk why is it not working. Anyway, the compression function:
function compress(dir, archive)
if fs.isDir(dir) then
filelist = fs.list(dir)
local archive = {
files = {
},
filedata = {
}
}
for i=1, #filelist do
local filehandle = fs.open(filelist[i], "r")
table.insert(archive.files, filelist[i])
table.insert(archive.filedata, filelist[i])
print(textutils.serialize(archive))
read()
archive.filedata.filelist[i] = filehandle.readAll() --the erroring line
filehandle.close()
end
local fArchive = fs.open(archive, "w")
fArchive.write(textutils.serialize(archive))
fArchive.close()
return true
else
return false
end
end
Any help is appreciated!
Edited on 01 May 2018 - 08:48 AM