@@ -22,7 +22,7 @@ public function testCompressEmpty()
2222 $ this ->markTestSkipped ('Not supported on Windows ' );
2323 }
2424
25- $ os = DIRECTORY_SEPARATOR === '\\' ? "\x0a " : "\x03" ; // NTFS(0x0a) or UNIX (0x03)
25+ $ os = DIRECTORY_SEPARATOR === '\\' ? "\x0b " : "\x03" ; // NTFS(0x0a) or UNIX (0x03)
2626 $ this ->compressor ->on ('data ' , $ this ->expectCallableOnceWith ("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00" . $ os . "\x03\x00" . "\x00\x00\x00\x00\x00\x00\x00\x00" ));
2727 $ this ->compressor ->on ('end ' , $ this ->expectCallableOnce ());
2828
@@ -58,4 +58,45 @@ public function testCompressBig()
5858 // PHP < 5.4 does not support gzdecode(), so let's assert this the other way around…
5959 $ this ->assertEquals (gzencode ($ data ), $ buffered );
6060 }
61+
62+ public function testWriteWillOnlyFlushHeaderByDefaultToBufferDataBeforeFlushing ()
63+ {
64+ $ compressor = new Compressor (ZLIB_ENCODING_GZIP );
65+
66+ $ os = DIRECTORY_SEPARATOR === '\\' ? "\x0a" : "\x03" ; // NTFS(0x0a) or UNIX (0x03)
67+ $ compressor ->on ('data ' , $ this ->expectCallableOnceWith ("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00" . $ os ));
68+
69+ $ compressor ->write ('hello ' );
70+ }
71+
72+ public function testWriteWithSyncFlushWillFlushHeaderWithFirstChunkImmediately ()
73+ {
74+ $ compressor = new Compressor (ZLIB_ENCODING_GZIP , -1 , ZLIB_SYNC_FLUSH );
75+
76+ $ os = DIRECTORY_SEPARATOR === '\\' ? "\x0a" : "\x03" ; // NTFS(0x0a) or UNIX (0x03)
77+ $ compressor ->on ('data ' , $ this ->expectCallableOnceWith ("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00" . $ os . "\xca\x48\xcd\xc9\xc9\x07\x00\x00\x00\xff\xff" ));
78+
79+ $ compressor ->write ('hello ' );
80+ }
81+
82+ public function testWriteWithFinishFlushWillFlushEntireGzipHeaderAndFooterWithFirstChunkImmediately ()
83+ {
84+ $ compressor = new Compressor (ZLIB_ENCODING_GZIP , -1 , ZLIB_FINISH );
85+
86+ $ os = DIRECTORY_SEPARATOR === '\\' ? "\x0a" : "\x03" ; // NTFS(0x0a) or UNIX (0x03)
87+ $ compressor ->on ('data ' , $ this ->expectCallableOnceWith ("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00" . $ os . "\xcb\x48\xcd\xc9\xc9\x07\x00\x86\xa6\x10\x36" . "\x05\x00\x00\x00" ));
88+
89+ $ compressor ->write ('hello ' );
90+ }
91+
92+ public function testWriteAfterFinishFlushWillFlushEntireGzipWithSyncFlushWillFlushEntireGzipHeaderAndFooterAgainImmediately ()
93+ {
94+ $ compressor = new Compressor (ZLIB_ENCODING_GZIP , -1 , ZLIB_FINISH );
95+ $ compressor ->write ('hello ' );
96+
97+ $ os = DIRECTORY_SEPARATOR === '\\' ? "\x0a" : "\x03" ; // NTFS(0x0a) or UNIX (0x03)
98+ $ compressor ->on ('data ' , $ this ->expectCallableOnceWith ("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00" . $ os . "\xcb\x48\xcd\xc9\xc9\x07\x00\x86\xa6\x10\x36" . "\x05\x00\x00\x00" ));
99+
100+ $ compressor ->write ('hello ' );
101+ }
61102}
0 commit comments