@@ -229,10 +229,12 @@ def decompress(data,
229
229
"""
230
230
cdef unsigned int hist_bits
231
231
cdef unsigned int flag
232
+ cdef bint is_gzip
233
+ data_is_gzip(data, & is_gzip)
232
234
wbits_to_flag_and_hist_bits_inflate(wbits,
233
235
& hist_bits,
234
236
& flag,
235
- data_is_gzip(data) )
237
+ is_gzip )
236
238
return igzip_decompress(data, flag, hist_bits, bufsize)
237
239
238
240
@@ -416,6 +418,7 @@ cdef class Decompress:
416
418
cdef public bint eof
417
419
cdef inflate_state stream
418
420
cdef bint method_set
421
+ cdef bint is_gzip
419
422
420
423
def __cinit__ (self , int wbits = ISAL_DEF_MAX_HIST_BITS, zdict = None ):
421
424
isal_inflate_init(& self .stream)
@@ -490,7 +493,8 @@ cdef class Decompress:
490
493
491
494
if not self .method_set:
492
495
# Try to detect method from the first two bytes of the data.
493
- self .stream.crc_flag = ISAL_GZIP if data_is_gzip(data) else ISAL_ZLIB
496
+ data_is_gzip(data, & self .is_gzip)
497
+ self .stream.crc_flag = ISAL_GZIP if self .is_gzip else ISAL_ZLIB
494
498
self .method_set = 1
495
499
496
500
# initialise input
@@ -576,20 +580,23 @@ cdef class Decompress:
576
580
PyBuffer_Release(buffer )
577
581
PyMem_Free(obuf)
578
582
579
- cdef bint data_is_gzip(object data):
583
+ cdef data_is_gzip(object data, bint * is_gzip ):
580
584
cdef Py_buffer buffer_data
581
585
cdef Py_buffer* buffer = & buffer_data
582
586
PyObject_GetBuffer(data, buffer , PyBUF_C_CONTIGUOUS)
583
587
if buffer .len < 2 :
584
588
PyBuffer_Release(buffer )
585
- return False
589
+ is_gzip[0 ] = False
590
+ return
586
591
cdef unsigned char * char_ptr = < unsigned char * > buffer .buf
587
592
if char_ptr[0 ] == 31 :
588
593
if char_ptr[1 ] == 139 :
589
594
PyBuffer_Release(buffer )
590
- return True
595
+ is_gzip[0 ] = True
596
+ return
591
597
PyBuffer_Release(buffer )
592
- return False
598
+ is_gzip[0 ] = False
599
+ return
593
600
594
601
595
602
cdef wbits_to_flag_and_hist_bits_deflate(int wbits,
0 commit comments