mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-19 11:36:41 +00:00
Gzip only content related data
This commit is contained in:
parent
37b9922f64
commit
1b9d6aac06
@ -79,9 +79,9 @@ class MTProtoState:
|
|||||||
msg_id = self._get_new_msg_id()
|
msg_id = self._get_new_msg_id()
|
||||||
seq_no = self._get_seq_no(content_related)
|
seq_no = self._get_seq_no(content_related)
|
||||||
if after_id is None:
|
if after_id is None:
|
||||||
body = GzipPacked.gzip_if_smaller(data)
|
body = GzipPacked.gzip_if_smaller(content_related, data)
|
||||||
else:
|
else:
|
||||||
body = GzipPacked.gzip_if_smaller(
|
body = GzipPacked.gzip_if_smaller(content_related,
|
||||||
bytes(InvokeAfterMsgRequest(after_id, data)))
|
bytes(InvokeAfterMsgRequest(after_id, data)))
|
||||||
|
|
||||||
buffer.write(struct.pack('<qii', msg_id, seq_no, len(body)))
|
buffer.write(struct.pack('<qii', msg_id, seq_no, len(body)))
|
||||||
|
@ -11,15 +11,14 @@ class GzipPacked(TLObject):
|
|||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def gzip_if_smaller(data):
|
def gzip_if_smaller(content_related, data):
|
||||||
"""Calls bytes(request), and based on a certain threshold,
|
"""Calls bytes(request), and based on a certain threshold,
|
||||||
optionally gzips the resulting data. If the gzipped data is
|
optionally gzips the resulting data. If the gzipped data is
|
||||||
smaller than the original byte array, this is returned instead.
|
smaller than the original byte array, this is returned instead.
|
||||||
|
|
||||||
Note that this only applies to content related requests.
|
Note that this only applies to content related requests.
|
||||||
"""
|
"""
|
||||||
# TODO Only content-related requests should be gzipped
|
if content_related and len(data) > 512:
|
||||||
if len(data) > 512:
|
|
||||||
gzipped = bytes(GzipPacked(data))
|
gzipped = bytes(GzipPacked(data))
|
||||||
return gzipped if len(gzipped) < len(data) else data
|
return gzipped if len(gzipped) < len(data) else data
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user