@@ -715,6 +715,36 @@ class ZstdTestsWithSourceFile(AbstractTestsWithSourceFile,
715715 unittest .TestCase ):
716716 compression = zipfile .ZIP_ZSTANDARD
717717
718+ def test_read_multiframe (self ):
719+ first = b'first frame' * 20
720+ second = b'second frame' * 20
721+ data = first + second
722+
723+ class MultiframeCompressor :
724+ def compress (self , value ):
725+ value = bytes (value )
726+ return (zipfile .zstd .compress (value [:len (first )]) +
727+ zipfile .zstd .compress (value [len (first ):]))
728+
729+ def flush (self ):
730+ return b''
731+
732+ archive = io .BytesIO ()
733+ with mock .patch .object (zipfile , '_get_compressor' ,
734+ return_value = MultiframeCompressor ()):
735+ with zipfile .ZipFile (archive , 'w' , self .compression ) as zipfp :
736+ zipfp .writestr ('multiframe' , data )
737+
738+ with zipfile .ZipFile (archive ) as zipfp :
739+ self .assertEqual (zipfp .read ('multiframe' ), data )
740+
741+ # Exercise a frame boundary between two reads from the archive.
742+ with zipfile .ZipFile (archive ) as zipfp :
743+ with zipfp .open ('multiframe' ) as fp :
744+ fp .MIN_READ_SIZE = 1
745+ self .assertEqual (b'' .join (iter (lambda : fp .read (1 ), b'' )),
746+ data )
747+
718748class AbstractTestZip64InSmallFiles :
719749 # These tests test the ZIP64 functionality without using large files,
720750 # see test_zipfile64 for proper tests.
0 commit comments