upgraded copy method

This commit is contained in:
Luxferre
2025-12-24 17:35:06 +02:00
parent 47c713b6a9
commit b8c7b3cb5f
+21 -6
View File
@@ -40,12 +40,27 @@ def umount_sd(path='/sd'):
sd_ok = False sd_ok = False
return sd_ok return sd_ok
# TODO: switch to buffered copying to avoid RAM overflow def copy(source_path, dest_path, buffer_size=8192):
def copy(p1, p2): """
with open(p1, 'rb') as f1: Copies a file from source_path to dest_path
content = f1.read() """
with open(p2, 'wb') as f2: try:
f2.write(content) with open(source_path, "rb") as src:
with open(dest_path, "wb") as dst:
while True:
# Read a chunk from the source
buffer = src.read(buffer_size)
if not buffer:
break
# Write the chunk to the destination
dst.write(buffer)
return True
except OSError as e:
print(f"Error copying file: {e}")
return False
except Exception as e:
print(f"An unexpected error occurred: {e}")
return False
cp = copy # shortcut export cp = copy # shortcut export