程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python implements split volume compression

編輯:Python

First , In the first volume file created test.z01 Add... To the front of \x50\x4b\x07\x08 This is the file header of volume compression (header), Occupy 4 Bytes . In fact, a single compressed file itself header That's it , The volume compression requires two emmm. Then it is from a single large compressed file test.zip Read from " One subvolume size -4 Bytes " The data of , write in test.zip.001 in , How to read data of a sub volume size , write in test.zip.002, And so on .

import os
import random
import sys
import zipfile
def zip_by_volume(file_path, block_size):
file_size = os.path.getsize(file_path)
path, file_name = os.path.split(file_path)
suffix = file_name.split('.')[-1]
zip_file = file_path + '.zip'
with zipfile.ZipFile(zip_file, 'w') as zf:
zf.write(file_path, arcname=file_name)
if file_size <= block_size:
return zip_file
else:
fp = open(zip_file, 'rb')
count = file_size // block_size 

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved