mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 21:38:04 +00:00
Add file_id codec
This commit is contained in:
parent
1d9bb22789
commit
692539f6a2
@ -1,3 +1,5 @@
|
|||||||
|
from base64 import b64encode, b64decode
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import types
|
from pyrogram.api import types
|
||||||
|
|
||||||
@ -163,3 +165,39 @@ def parse_message_service(message: types.MessageService, users: dict, chats: dic
|
|||||||
migrate_from_chat_id=migrate_from_chat_id,
|
migrate_from_chat_id=migrate_from_chat_id,
|
||||||
group_chat_created=group_chat_created
|
group_chat_created=group_chat_created
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def decode(s):
|
||||||
|
s = b64decode(s + "=" * (-len(s) % 4), "-_")
|
||||||
|
r = b""
|
||||||
|
|
||||||
|
assert s[-1] == 2
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
while i < len(s) - 1:
|
||||||
|
if s[i] != 0:
|
||||||
|
r += bytes([s[i]])
|
||||||
|
else:
|
||||||
|
r += b"\x00" * s[i + 1]
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
def encode(s):
|
||||||
|
r = b""
|
||||||
|
n = 0
|
||||||
|
|
||||||
|
for i in s + bytes([2]):
|
||||||
|
if i == 0:
|
||||||
|
n += 1
|
||||||
|
else:
|
||||||
|
if n:
|
||||||
|
r += b"\x00" + bytes([n])
|
||||||
|
n = 0
|
||||||
|
|
||||||
|
r += bytes([i])
|
||||||
|
|
||||||
|
return b64encode(r, b"-_").decode().rstrip("=")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user