mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Issue #23688: Added support of arbitrary bytes-like objects and avoided
unnecessary copying of memoryview in gzip.GzipFile.write(). Original patch by Wolfgang Maier.
This commit is contained in:
		
							parent
							
								
									77d899726f
								
							
						
					
					
						commit
						bca63b362d
					
				
					 4 changed files with 56 additions and 8 deletions
				
			
		
							
								
								
									
										19
									
								
								Lib/gzip.py
									
										
									
									
									
								
							
							
						
						
									
										19
									
								
								Lib/gzip.py
									
										
									
									
									
								
							|  | @ -334,17 +334,20 @@ def write(self,data): | |||
|         if self.fileobj is None: | ||||
|             raise ValueError("write() on closed GzipFile object") | ||||
| 
 | ||||
|         # Convert data type if called by io.BufferedWriter. | ||||
|         if isinstance(data, memoryview): | ||||
|             data = data.tobytes() | ||||
|         if isinstance(data, bytes): | ||||
|             length = len(data) | ||||
|         else: | ||||
|             # accept any data that supports the buffer protocol | ||||
|             data = memoryview(data) | ||||
|             length = data.nbytes | ||||
| 
 | ||||
|         if len(data) > 0: | ||||
|             self.size = self.size + len(data) | ||||
|         if length > 0: | ||||
|             self.fileobj.write(self.compress.compress(data)) | ||||
|             self.size += length | ||||
|             self.crc = zlib.crc32(data, self.crc) & 0xffffffff | ||||
|             self.fileobj.write( self.compress.compress(data) ) | ||||
|             self.offset += len(data) | ||||
|             self.offset += length | ||||
| 
 | ||||
|         return len(data) | ||||
|         return length | ||||
| 
 | ||||
|     def read(self, size=-1): | ||||
|         self._check_closed() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Serhiy Storchaka
						Serhiy Storchaka