From ff3c4ab5f764002644808b999b0041fb61d18ee1 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 20 May 2026 00:15:01 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Fast=20yEnc=20decoding=20vi?= =?UTF-8?q?a=20bytes.translate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: xbmc4lyfe <273732874+xbmc4lyfe@users.noreply.github.com> --- verify_nzb.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/verify_nzb.py b/verify_nzb.py index 953dccd..8043a23 100644 --- a/verify_nzb.py +++ b/verify_nzb.py @@ -115,19 +115,24 @@ def _parse_yenc_attrs(line: bytes) -> dict[str, str]: return attrs +_YENC_TRANS = bytes((i - 42) % 256 for i in range(256)) + + def _decode_yenc_lines(lines: Iterable[bytes]) -> bytes: + """Decodes yEnc lines efficiently using C-level string operations.""" decoded = bytearray() for line in lines: - index = 0 - while index < len(line): - byte = line[index] - if byte == 61: - index += 1 - if index >= len(line): + if b"=" not in line: + decoded.extend(line.translate(_YENC_TRANS)) + else: + parts = line.split(b"=") + decoded.extend(parts[0].translate(_YENC_TRANS)) + for part in parts[1:]: + if not part: raise ValueError("dangling yEnc escape") - byte = (line[index] - 64) % 256 - decoded.append((byte - 42) % 256) - index += 1 + decoded.append((part[0] - 106) % 256) + if len(part) > 1: + decoded.extend(part[1:].translate(_YENC_TRANS)) return bytes(decoded)