1717# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1818# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919# SOFTWARE.
20-
20+ import gzip
2121import itertools
2222import os
2323import pickle
24+ import zlib
2425from typing import NamedTuple
2526
2627from isal import igzip_lib
@@ -43,6 +44,8 @@ class Flag(NamedTuple):
4344
4445
4546DATA = RAW_DATA [:128 * 1024 ]
47+ ZLIB_COMPRESSED = zlib .compress (DATA )
48+ GZIP_COMPRESSED = gzip .compress (DATA )
4649
4750COMPRESS_LEVELS = list (range (4 ))
4851HIST_BITS = list (range (16 ))
@@ -223,3 +226,29 @@ def test_failure(self):
223226 # Make sure there are no internal consistencies
224227 with pytest .raises (Exception ):
225228 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