Posted 26 August 2013 - 04:09 PM
Hello everyone.
This is a little api I wrote that lets you save a directory to a single file. It's like a zip/rar/whatever file, but without compression (for now), so in most cases the file will be larger than the directory.
The package is a binary file, so you can include any binary files and they should pack/unpack correctly.
I wrote it while working on something bigger, but I thought that someone might find this usefull (probably not, but whatever :P/>).
So, here it is:
Download:
pastebin get gx10mzbk
Functions:
Examples:
Pack:
Unpack:
Any feedback and bug reports are welcome.
This is a little api I wrote that lets you save a directory to a single file. It's like a zip/rar/whatever file, but without compression (for now), so in most cases the file will be larger than the directory.
The package is a binary file, so you can include any binary files and they should pack/unpack correctly.
I wrote it while working on something bigger, but I thought that someone might find this usefull (probably not, but whatever :P/>).
So, here it is:
Download:
pastebin get gx10mzbk
Functions:
package.pack(path, outPath) -- pack directory "path" to file "outPath"
--[[
Packs a directory
Parameters:
- path: the path to the directory to pack
- outPath: the path to save the package file
Return Values:
- result: boolean indicating if the operation was successful
- error: error message in case of error
--]]
package.load(path)
--[[
Loads a package file
Parameters:
- path: the path to the package file
Return Values:
- entries: table containing the package entries. nil in case of error
- error: error message in case of error
--]]
package.unpack(path, outPath)
--[[
Unpacks a package file
Parameters:
- path: the path to the package file
- outPath: the path to save the directory
Return Values:
- result: boolean indicating if the operation was successful
- error: error message in case of error
--]]
Examples:
Pack:
Spoiler
local tArgs = {...}
if #tArgs ~= 2 then
print("Usage: pack <intput path> <output path>")
return
end
if not package then
os.loadAPI("package")
if not package then
printError("Error loading package API")
return
end
end
local ok, err = package.pack(tArgs[1], tArgs[2])
if not ok then
printError(err)
end
Spoiler
local tArgs = {...}
if #tArgs ~= 2 then
print("Usage: unpack <intput path> <output path>")
return
end
if not package then
os.loadAPI("package")
if not package then
printError("Error loading package API")
return
end
end
local ok, err = package.unpack(tArgs[1], tArgs[2])
if not ok then
printError(err)
end
Any feedback and bug reports are welcome.