From 03bcfc0c45c1410662b614461400abd3eef3e570 Mon Sep 17 00:00:00 2001 From: imSp4rky Date: Mon, 29 Jun 2026 09:55:08 -0600 Subject: [PATCH] perf(hls): rename single decrypted range instead of re-copying Short-circuit merge() to os.replace() when joining one already-merged file with no init prefix; saves a full track-size copy, falls back to streamed copy across devices. --- unshackle/core/manifests/hls.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/unshackle/core/manifests/hls.py b/unshackle/core/manifests/hls.py index 8a15f850..eacad66f 100644 --- a/unshackle/core/manifests/hls.py +++ b/unshackle/core/manifests/hls.py @@ -740,8 +740,15 @@ class HLS: delete: Delete the file once it's been merged. include_map_data: Whether to include the init map data. """ + prepend = include_map_data and map_data and map_data[1] + if len(via) == 1 and not prepend and delete: + try: + os.replace(via[0], to) + return + except OSError: + pass with open(to, "wb") as x: - if include_map_data and map_data and map_data[1]: + if prepend: x.write(map_data[1]) for file in via: with open(file, "rb") as segment: