def expand_bz2(file_path):
sys.stdout.write("\tExpanding bz2... ")
if not os.path.isfile(file_path[:-4]):
file_size = os.path.getsize(file_path)
estimated_file_size = (float(5)*float(file_size))/1000.0
sys.stdout.write("Estimated "+str(estimated_file_size)+" MB\n")
try:
with open(file_path[:-4], 'wb') as new_file, bz2.BZ2File(file_path, 'rb') as file:
for data in iter(lambda : file.read(100 * 1024), b''):
new_file.write(data)
num_items = int( float(file.tell())/float(file_size)*float(5) )
progress_string = ""
for prog_index in range(25):
if prog_index <= num_items: progress_string+="-"
else: progress_string += " "
sys.stdout.write("\r\t\t["+progress_string+"] "+str(100.0*file.tell()/file_size)[:5]+"% done")
sys.stdout.flush()
sys.stdout.write("\n")
except:
print("\t\tCould not expand file.")
else:
print("\t\tFile already expanded.")
return file_path[:-4]
评论列表
文章目录