diff --git a/bin/compress.lua b/bin/compress.lua new file mode 100644 index 0000000..5cd9886 --- /dev/null +++ b/bin/compress.lua @@ -0,0 +1,39 @@ +-- Compress command line tool +-- Powered by libcompress + +local shell=require('shell') +local libcompress=require('libcompress') +local args,opts=shell.parse(...) + +if(args<2) then + print("Usage:\n\tcompress [-dv] ") +end + +local verbose=opts["v"] and print or function() end + +local f=io.open(args[1],"rb") +if(not f) then + print("[Error] Failed to open file for read: " .. args[1]) + return +end +local str=f:read("a") +f:close() + +local nSource=str:len() +str=opts["d"] and libcompress.inflate(str) or libcompress.deflate(str) +local nDest=str:len() +verbose(string.format("SourceLen: %d DestLen: %d Rate: %.2f",nSource,nDest,nDest/nSource)) + +f=io.open(args[2],"wb") +if(not f) then + print("[Error] Failed to open file for write: " .. args[2]) + return +end + +local ok,msg=f:write(str) +f:close() + +if(not ok) then + print("[Error] Failed to write file: " .. args[2] .. ": " .. msg) + return +end \ No newline at end of file diff --git a/programs.info b/programs.info index 649c8b4..3635393 100644 --- a/programs.info +++ b/programs.info @@ -79,7 +79,8 @@ title="Compression Library", info="Inflate and deflate library for general purpose.", files={ - ["libs/libcompress.lua"]="__lib__/" + ["libs/libcompress.lua"]="__lib__/", + ["bin/compress.lua"]="__bin__/" }, requires={ "libkeepup"