mirror of
https://github.com/Kiritow/OpenComputerScripts.git
synced 2024-03-22 13:10:46 +08:00
Add compress command line tool
This commit is contained in:
parent
306783ca2c
commit
02e9a703b0
39
bin/compress.lua
Normal file
39
bin/compress.lua
Normal file
|
@ -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] <source> <dest>")
|
||||||
|
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
|
|
@ -79,7 +79,8 @@
|
||||||
title="Compression Library",
|
title="Compression Library",
|
||||||
info="Inflate and deflate library for general purpose.",
|
info="Inflate and deflate library for general purpose.",
|
||||||
files={
|
files={
|
||||||
["libs/libcompress.lua"]="__lib__/"
|
["libs/libcompress.lua"]="__lib__/",
|
||||||
|
["bin/compress.lua"]="__bin__/"
|
||||||
},
|
},
|
||||||
requires={
|
requires={
|
||||||
"libkeepup"
|
"libkeepup"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user