17
17
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
18
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
19
# SOFTWARE.
20
-
20
+ import gzip
21
21
import itertools
22
22
import os
23
23
import pickle
24
+ import zlib
24
25
from typing import NamedTuple
25
26
26
27
from isal import igzip_lib
@@ -43,6 +44,8 @@ class Flag(NamedTuple):
43
44
44
45
45
46
DATA = RAW_DATA [:128 * 1024 ]
47
+ ZLIB_COMPRESSED = zlib .compress (DATA )
48
+ GZIP_COMPRESSED = gzip .compress (DATA )
46
49
47
50
COMPRESS_LEVELS = list (range (4 ))
48
51
HIST_BITS = list (range (16 ))
@@ -223,3 +226,29 @@ def test_failure(self):
223
226
# Make sure there are no internal consistencies
224
227
with pytest .raises (Exception ):
225
228
igzd .decompress (self .BAD_DATA * 30 )
229
+
230
+
231
+ @pytest .mark .parametrize ("test_offset" , range (5 ))
232
+ def test_igzip_decompressor_raw_deflate_unused_data_zlib (test_offset ):
233
+ data = zlib .compress (b"bla" )
234
+ no_header = data [2 :]
235
+ trailer = data [- 4 :]
236
+ raw_deflate_incomplete_trailer = no_header [:- test_offset ]
237
+ true_unused_data = trailer [:- test_offset ]
238
+ igzd = IgzipDecompressor (flag = DECOMP_DEFLATE )
239
+ igzd .decompress (raw_deflate_incomplete_trailer )
240
+ if igzd .eof :
241
+ assert igzd .unused_data == true_unused_data
242
+
243
+
244
+ @pytest .mark .parametrize ("test_offset" , range (9 ))
245
+ def test_igzip_decompressor_raw_deflate_unused_data_gzip (test_offset ):
246
+ data = gzip .compress (b"bla" )
247
+ no_header = data [10 :]
248
+ trailer = data [- 8 :]
249
+ raw_deflate_incomplete_trailer = no_header [:- test_offset ]
250
+ true_unused_data = trailer [:- test_offset ]
251
+ igzd = IgzipDecompressor (flag = DECOMP_DEFLATE )
252
+ igzd .decompress (raw_deflate_incomplete_trailer )
253
+ if igzd .eof :
254
+ assert igzd .unused_data == true_unused_data
0 commit comments