Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions pyrogram/file_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import struct
from enum import IntEnum
from io import BytesIO
from typing import List

from pyrogram.raw.core import Bytes, String

Expand Down Expand Up @@ -63,36 +64,36 @@ def rle_encode(s: bytes) -> bytes:
Returns:
``bytes``: The encoded bytes
"""
r: bytes = b""
r: List[int] = []
n: int = 0

for b in s:
if not b:
n += 1
else:
if n:
r += bytes([0, n])
r.extend((0, n))
n = 0

r += bytes([b])
r.append(b)

if n:
r += bytes([0, n])
r.extend((0, n))

return r
return bytes(r)


def rle_decode(s: bytes) -> bytes:
"""Zero-value RLE decoder

Parameters:
s (``bytes``):
Bytes to encode
Bytes to decode

Returns:
``bytes``: The encoded bytes
``bytes``: The decoded bytes
"""
r: bytes = b""
r: List[int] = []
z: bool = False

for b in s:
Expand All @@ -101,12 +102,12 @@ def rle_decode(s: bytes) -> bytes:
continue

if z:
r += b"\x00" * b
r.extend((0,) * b)
z = False
else:
r += bytes([b])
r.append(b)

return r
return bytes(r)


class FileType(IntEnum):
Expand Down