代码拉取完成,页面将自动刷新
import os
import glob
import argparse
def split(file, out_dir, split_size):
_, filename = os.path.split(file)
fsize = os.path.getsize(file)
print(file, "size =", fsize)
n = fsize // split_size
if n > 99:
print("spint parts > 99 not support now, please increase split size")
return
if n * split_size < fsize:
n += 1
print("split into", n, "parts size = ", split_size)
with open(file, "rb") as fd_in:
for i in range(n):
print("part", i + 1)
outfile = "%s.part%02d" %(os.path.join(out_dir, filename), i + 1)
with open(outfile, "wb") as fd_out:
fd_out.write(fd_in.read(split_size))
print("split success")
def merge(in_file, out_file):
files_in = glob.glob(in_file)
with open(out_file, "wb") as fd_out:
for file in files_in:
with open(file, "rb") as fd_in:
fd_out.write(fd_in.read())
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--file", type=str, help="file to split")
parser.add_argument("--out-dir", type=str, default=".", help="out dir")
parser.add_argument("--split-size", type=int, default=41943040, help="split the file into size")
opt = parser.parse_args()
split(opt.file, opt.out_dir, opt.split_size)
# merge(opt.file + ".part*", opt.file)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。