mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-11-04 01:47:27 +03: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()
 | 
			
		||||
        seq_no = self._get_seq_no(content_related)
 | 
			
		||||
        if after_id is None:
 | 
			
		||||
            body = GzipPacked.gzip_if_smaller(data)
 | 
			
		||||
            body = GzipPacked.gzip_if_smaller(content_related, data)
 | 
			
		||||
        else:
 | 
			
		||||
            body = GzipPacked.gzip_if_smaller(
 | 
			
		||||
            body = GzipPacked.gzip_if_smaller(content_related,
 | 
			
		||||
                bytes(InvokeAfterMsgRequest(after_id, data)))
 | 
			
		||||
 | 
			
		||||
        buffer.write(struct.pack('<qii', msg_id, seq_no, len(body)))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,15 +11,14 @@ class GzipPacked(TLObject):
 | 
			
		|||
        self.data = data
 | 
			
		||||
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def gzip_if_smaller(data):
 | 
			
		||||
    def gzip_if_smaller(content_related, data):
 | 
			
		||||
        """Calls bytes(request), and based on a certain threshold,
 | 
			
		||||
           optionally gzips the resulting data. If the gzipped data is
 | 
			
		||||
           smaller than the original byte array, this is returned instead.
 | 
			
		||||
 | 
			
		||||
           Note that this only applies to content related requests.
 | 
			
		||||
        """
 | 
			
		||||
        # TODO Only content-related requests should be gzipped
 | 
			
		||||
        if len(data) > 512:
 | 
			
		||||
        if content_related and len(data) > 512:
 | 
			
		||||
            gzipped = bytes(GzipPacked(data))
 | 
			
		||||
            return gzipped if len(gzipped) < len(data) else data
 | 
			
		||||
        else:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user