1 Star 0 Fork 2

夏凉/tr

forked from gxl/tr 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
tools.py 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
myhub 提交于 2019-11-05 21:25 . new
import os, sys
import glob
BIG_FILES = ["./libtorch/lib/libtorch.so"]
_BASEDIR = os.path.dirname(os.path.abspath(__file__))
BIG_FILES = [os.path.join(_BASEDIR, _) for _ in BIG_FILES]
FILE_SIZE = 32 * 1024 * 1024
PART_SEP = ".part."
def split(file_path):
if not os.path.exists(file_path):
return
with open(file_path, "rb") as f:
file_data = f.read()
if len(file_data) <= FILE_SIZE:
return
pos = 0
num = 0
while pos < len(file_data):
with open(file_path + PART_SEP + str(num), "wb") as f:
f.write(file_data[pos:pos + FILE_SIZE])
pos += FILE_SIZE
num += 1
os.remove(file_path)
def join(file_path):
if os.path.exists(file_path):
return
file_parts = glob.glob(file_path + PART_SEP + "*")
if len(file_parts) < 1:
return
file_data = bytes()
for num in range(len(file_parts)):
with open(file_path + PART_SEP + str(num), "rb") as f:
file_data += f.read()
with open(file_path, "wb") as f:
f.write(file_data)
for file_part in file_parts:
os.remove(file_part)
if __name__ == '__main__':
for big_file in BIG_FILES:
split(big_file)
if len(sys.argv) > 1:
join(big_file)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zeroleon/tr.git
git@gitee.com:zeroleon/tr.git
zeroleon
tr
tr
master

搜索帮助