Skip to content

Commit b978857

Browse files
committed
Add Make corpus python file
1 parent 7ad9836 commit b978857

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

fuzzing/make-corpus.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/env python
2+
3+
# Copyright (c) 2025 Alexander Grund
4+
# Distributed under the Boost Software License, Version 1.0.
5+
# https://www.boost.org/LICENSE_1_0.txt.
6+
7+
import os
8+
import sys
9+
10+
def get_samples(input_files):
11+
for file_name in input_files:
12+
if not os.path.isfile(file_name):
13+
raise RuntimeError("Not a file: " + file_name)
14+
with open(file_name, 'r') as input_file:
15+
yield from input_file
16+
17+
18+
def process_files(output_folder, input_files):
19+
if not os.path.exists(output_folder):
20+
os.makedirs(output_folder)
21+
22+
for i, sample in enumerate(get_samples(input_files)):
23+
with open(os.path.join(output_folder, str(i) + ".txt"), 'w') as output_file:
24+
output_file.write(sample)
25+
26+
27+
if __name__ == "__main__":
28+
if len(sys.argv) < 3:
29+
print("Usage: python script.py <output_folder> <input_file1> [<input_file2> ...]")
30+
sys.exit(1)
31+
32+
process_files(output_folder=sys.argv[1], input_files=sys.argv[2:])

0 commit comments

Comments
 (0)