Skip to content

Commit

Permalink
3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueSkyXN committed Jul 17, 2023
1 parent 2246ebd commit 6408553
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/Run-Python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
python Scripts/Merge-Rules-Renew.py
python Scripts/Merge-Rules-ALL.py
python Scripts/ALL-Lite-Convert.py
python Scripts/ALL-Lite-Split.py
- name: Upload ALL-Rule
uses: actions/upload-artifact@v2
Expand Down
35 changes: 35 additions & 0 deletions Scripts/ALL-Lite-Split.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os

def split_file(filename, chunk_size):
# 创建子目录 /Part
os.makedirs("Part", exist_ok=True)

# 读取原始文件
with open(filename, 'r') as file:
data = file.read()

# 计算切割后的子文件数量
num_chunks = (len(data) + chunk_size - 1) // chunk_size

# 切割并保存子文件
for i in range(num_chunks):
start = i * chunk_size
end = start + chunk_size
chunk_data = data[start:end]

# 构建子文件名
file_parts = os.path.splitext(filename)
new_filename = os.path.join("Part", f"{file_parts[0]}-p{i+1}{file_parts[1]}")

# 保存子文件
with open(new_filename, 'w') as new_file:
new_file.write(chunk_data)

print(f"Created chunk file: {new_filename}")

# 指定要切割的文件和子文件大小(9MB)
file_to_split = "all-lite.txt"
chunk_size = 9 * 1024 * 1024

# 调用函数进行切割
split_file(file_to_split, chunk_size)

0 comments on commit 6408553

Please sign in to comment.