2828import struct
2929import sys
3030import time
31- from typing import List , Optional
31+ from typing import List , Optional , SupportsInt
3232
3333from . import isal_zlib
3434
@@ -223,15 +223,21 @@ def _add_read_data(self, data):
223223
224224
225225def _create_simple_gzip_header (compresslevel : int ,
226- mtime : Optional [int ] = None ) -> bytes :
226+ mtime : Optional [SupportsInt ] = None ) -> bytes :
227+ """
228+ Write a simple gzip header with no extra fields.
229+ :param compresslevel: Compresslevel used to determine the xfl bytes.
230+ :param mtime: The mtime (must support conversion to a 32-bit integer).
231+ :return: A bytes object representing the gzip header.
232+ """
227233 if mtime is None :
228- mtime = int ( time .time () )
234+ mtime = time .time ()
229235 # There is no best compression level. ISA-L only provides algorithms for
230236 # fast and medium levels.
231237 xfl = 4 if compresslevel == _COMPRESS_LEVEL_FAST else 0
232238 # Pack ID1 and ID2 magic bytes, method (8=deflate), header flags (no extra
233239 # fields added to header), mtime, xfl and os (255 for unknown OS).
234- return struct .pack ("<BBBBLBB" , 0x1f , 0x8b , 8 , 0 , mtime , xfl , 255 )
240+ return struct .pack ("<BBBBLBB" , 0x1f , 0x8b , 8 , 0 , int ( mtime ) , xfl , 255 )
235241
236242
237243def compress (data , compresslevel = _COMPRESS_LEVEL_BEST , * , mtime = None ):
@@ -248,6 +254,11 @@ def compress(data, compresslevel=_COMPRESS_LEVEL_BEST, *, mtime=None):
248254
249255
250256def _gzip_header_end (data : bytes ) -> int :
257+ """
258+ Find the start of the raw deflate block in a gzip file.
259+ :param data: Compressed data that starts with a gzip header.
260+ :return: The end of the header / start of the raw deflate block.
261+ """
251262 if len (data ) < 10 :
252263 raise BadGzipFile ("Gzip header should be 10 bytes or more" )
253264 # We are not interested in mtime, xfl and os flags.
0 commit comments