28
28
import struct
29
29
import sys
30
30
import time
31
- from typing import List , Optional
31
+ from typing import List , Optional , SupportsInt
32
32
33
33
from . import isal_zlib
34
34
@@ -223,15 +223,21 @@ def _add_read_data(self, data):
223
223
224
224
225
225
def _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
+ """
227
233
if mtime is None :
228
- mtime = int ( time .time () )
234
+ mtime = time .time ()
229
235
# There is no best compression level. ISA-L only provides algorithms for
230
236
# fast and medium levels.
231
237
xfl = 4 if compresslevel == _COMPRESS_LEVEL_FAST else 0
232
238
# Pack ID1 and ID2 magic bytes, method (8=deflate), header flags (no extra
233
239
# 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 )
235
241
236
242
237
243
def compress (data , compresslevel = _COMPRESS_LEVEL_BEST , * , mtime = None ):
@@ -248,6 +254,11 @@ def compress(data, compresslevel=_COMPRESS_LEVEL_BEST, *, mtime=None):
248
254
249
255
250
256
def _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
+ """
251
262
if len (data ) < 10 :
252
263
raise BadGzipFile ("Gzip header should be 10 bytes or more" )
253
264
# We are not interested in mtime, xfl and os flags.
0 commit comments