Compress DATA

This commit is contained in:
Maxim Khomutov 2023-07-18 22:40:27 +03:00
parent 69348e9339
commit a226b17612

View File

@ -113,11 +113,7 @@ class Client:
continue continue
if not to_udp or code in ['V', 'W', 'Y', 'E']: if not to_udp or code in ['V', 'W', 'Y', 'E']:
if code in ['O', 'T'] or len(data) > 1000: if code in ['O', 'T'] or len(data) > 1000:
if len(data) > 400: await client._send(data)
# TODO: Compress data
await client._send(data)
else:
await client._send(data)
else: else:
await client._send(data) await client._send(data)
else: else:
@ -125,6 +121,9 @@ class Client:
self.log.debug(f"UDP Part not ready: {code}") self.log.debug(f"UDP Part not ready: {code}")
return return
if len(data) > 400:
data = b"ABG:" + zlib.compress(data, level=zlib.Z_BEST_COMPRESSION)
header = len(data).to_bytes(4, "little", signed=True) header = len(data).to_bytes(4, "little", signed=True)
self.log.debug(f'len: {len(data)}; send: {header + data!r}') self.log.debug(f'len: {len(data)}; send: {header + data!r}')
try: try: