Skip to content

Commit 1fa24ee

Browse files
committed
Merge branch 'pr/13' - thanks L-A-Sutherland :)
2 parents b080973 + a6078d9 commit 1fa24ee

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

bricklayers.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2034,6 +2034,17 @@ def expand_ranges(ranges):
20342034

20352035
error_marker = "❌ Error: " if sys.stderr.encoding.lower() == "utf-8" else "[ERROR] "
20362036

2037+
2038+
def gcode_opener(path, flags):
2039+
file=os.open(path, flags)
2040+
header=os.pread(file,4,0)
2041+
if header==bytes("GCDE","ascii"):
2042+
os.close(file) #do not leak the file descriptor
2043+
print(f"{error_marker}The file '{input_file}' is a binary gcode file, which is not supported. Disable Binary G-code in your slicer settings", file=sys.stderr)
2044+
sys.exit(1) # Exit immediately
2045+
return file
2046+
2047+
20372048
# Only process the file if Brick Layers if enabled
20382049
if args_dict["enabled"] > 0:
20392050

@@ -2169,7 +2180,7 @@ def expand_ranges(ranges):
21692180
# print(final_output_file)
21702181

21712182
# Open the input and output files using Generators:
2172-
with open(input_file, "r", encoding="utf-8", errors="replace", newline="") as infile, open(final_output_file, "w", encoding="utf-8", newline="\n") as outfile:
2183+
with open(input_file, 'r', encoding="utf8", newline="",opener=gcode_opener) as infile, open(final_output_file, 'w', encoding="utf-8", newline="\n") as outfile:
21732184
# Pass the file generator (line-by-line) to process_gcode
21742185
gcode_stream = (line for line in infile) # Efficient generator
21752186

0 commit comments

Comments
 (0)