pydc_client.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:recobot 作者: h4ck3rk3y 项目源码 文件源码
def bz2_compress(self,file,type=True): # Compress/Decompress files into/from the bz2 format. compress if type else decompess
        if not os.path.exists(file) or os.path.isdir(file): return False
        try: filesize = os.path.getsize(file)
        except: return False
        if not type and not file.endswith(".bz2"): return False
        blocksize = 102400
        if type: compressor = bz2.BZ2Compressor()
        else: decompressor = bz2.BZ2Decompressor()
        handle1 = open(file,"rb")
        handle2 = open(file+".bz2","wb") if type else open(file[:-4],"wb")
        for i in range(int(math.ceil(float(filesize)/blocksize))):
            if type: handle2.write(compressor.compress(handle1.read(blocksize)))
            else: handle2.write(decompressor.decompress(handle1.read(blocksize)))
        if type: handle2.write(compressor.flush())
        handle1.close(); handle2.close()
        self.debug("Successfully "+("" if type else "de")+"compressed file : "+file)
        return True

    ################################################## Client Behaviour Functions ##################################################
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号