Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local function unrip(contents)
- local str = ''
- for s in contents:gmatch("([^,]+)") do
- str = str .. string.char(s)
- end
- return str
- end
- local function unpack(filename)
- if not fs.exists(filename) then return end
- local file = fs.open('output.hlpk',args[2] or 'r')
- local input = {
- dir = {},
- file = {}
- }
- repeat
- local str = file.readLine()
- if not str then break end
- if str:sub(1,1) == '@' then
- table.insert(input.dir,str:sub(2))
- end
- if str:sub(1,1) == '$' then
- --print(str)
- table.insert(input.file,{
- name = str:sub(str:find("/[^/]*$")+1, str:find('{')-1),
- path = str:sub(2,(str:find("/[^/]*$")-1))..'/',
- contents = str:sub(str:find('{')+1,str:find('}')-1)
- })
- end
- until (false)
- file.close()
- for k,v in pairs(input.dir) do
- fs.makeDir(v)
- end
- for k,v in pairs(input.file) do
- local str = unrip(v.contents)
- local file = fs.open(v.path..'/'..v.name,'w')
- file.write(str)
- file.close()
- end
- end
- local function rip(str)
- local acc = ''
- for s in str:gmatch('.') do
- acc = acc .. (acc ~= '' and ',' or '') .. string.byte(s)
- end
- return acc
- end
- local function compress(path,n)
- n = n or 0
- local output = fs.open(args[3] or 'output.hlpk','a')
- print(output)
- if not fs.isDir(path) then return end
- if path:sub(-1) ~= '/' then
- path = path .. '/'
- end
- for k,v in pairs(fs.list(path)) do
- if fs.isDir(path..v) then
- output.writeLine('@'..path..v..'')
- output.flush()
- compress(path..v..'/',n + 1)
- elseif fs.exists(path..v) then
- local file = fs.open(path..v,'r')
- output.write('$'..path..v..'{')
- output.write(rip(file.readAll()))
- output.writeLine('}')
- file.close()
- end
- end
- output.close()
- end
- if args[1] == 'pk' then
- local dir = args[2]
- fs.open(args[3] or 'output.hlpk','w').close()
- compress(dir)
- elseif args[1] == 'up' then
- unpack(args[3] or 'output.hlpk')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement