-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit_block_list_v1.py
More file actions
48 lines (37 loc) · 1.33 KB
/
Copy pathsplit_block_list_v1.py
File metadata and controls
48 lines (37 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
Splits a combined text file of blocklist filters.
"""
# Version 1.0.1
# Edited: 2026-07-03 13:39:10 +10:00
# Generated using AI (duck.ai)
# Tested on local PC and on GitHub
# IMPORTS
import os
def split_file_by_size(filename, chunk_size_mb=47):
"""
Splits a file into chunks of specified size (in MB).
Output files are named: *_000.txt, *_001.txt, etc.
"""
chunk_size = chunk_size_mb * 1024 * 1024 # Convert MB to bytes
file_number = 0
with open(filename, 'rb') as f_in:
while True:
chunk = f_in.read(chunk_size)
if not chunk:
break
# Create output filename with 3-digit numbering (e.g., .000, .001)
out_filename = f"{filename}_{file_number:03d}.txt"
with open(out_filename, 'wb') as f_out:
f_out.write(chunk)
print(f"Created {out_filename} ({len(chunk)} bytes)")
file_number += 1
# Usage
BLOCKLIST_COMBINED = 'blocklist_combined_filterlist.txt'
split_file_by_size(BLOCKLIST_COMBINED, 47)
try:
os.remove(BLOCKLIST_COMBINED)
print(f"{BLOCKLIST_COMBINED} deleted successfully.")
except FileNotFoundError:
print(f"{BLOCKLIST_COMBINED} does not exist.")
except PermissionError:
print(f"Permission denied to delete {BLOCKLIST_COMBINED}.")