用python解压routeros npk包的脚本【转】
im大家都知道,npk包是用zlib压缩的,但要解压和压缩它没有直接的工具,很麻烦!下面是两个脚本,用于解压或者压缩npk包。使用前先在机器上安装python。
port zlib
def compress(infile, dst, level=9):
infile = open(infile, 'rb')
dst = open(dst, 'wb')
compress = zlib.compressobj(level)
data = infile.read(1024)
while data:
dst.write(compress.compress(data))
data = infile.read(1024)
dst.write(compress.flush())
def decompress(infile, dst):
infile = open(infile, 'rb')
dst = open(dst, 'wb')
decompress = zlib.decompressobj()
data = infile.read(1024)
while data:
dst.write(decompress.decompress(data))
data = infile.read(1024)
dst.write(decompress.flush())
decompress("要解压的文件名", "解压后的文件名")
页:
[1]