@@ -66,7 +66,7 @@ public function __construct(
6666 $ this ->generalPurposeBitFlag |= GeneralPurposeBitFlag::ZERO_HEADER ;
6767 }
6868
69- $ this ->selectVersion () ;
69+ $ this ->version = $ this -> compressionMethod === CompressionMethod:: DEFLATE ? Version:: DEFLATE : Version:: STORE ;
7070 }
7171
7272 public function cloneSimulationExecution (): self
@@ -178,25 +178,32 @@ private function forecastSize(): ?int
178178 */
179179 private function addFileHeader (): void
180180 {
181- $ footer = $ this ->buildZip64ExtraBlock ($ this ->enableZeroHeader && $ this ->enableZip64 );
181+ $ forceEnableZip64 = $ this ->enableZeroHeader && $ this ->enableZip64 ;
182+
183+ $ footer = $ this ->buildZip64ExtraBlock ($ forceEnableZip64 );
184+
185+ $ zip64Enabled = $ footer !== '' ;
186+
187+ if ($ zip64Enabled ) {
188+ $ this ->version = Version::ZIP64 ;
189+ }
182190
183191 if ($ this ->generalPurposeBitFlag & GeneralPurposeBitFlag::EFS ) {
184192 // Put the tricky entry to
185193 // force Linux unzip to lookup EFS flag.
186194 $ footer .= Zs \ExtendedInformationExtraField::generate ();
187195 }
188196
189-
190197 $ data = LocalFileHeader::generate (
191198 versionNeededToExtract: $ this ->version ->value ,
192199 generalPurposeBitFlag: $ this ->generalPurposeBitFlag ,
193200 compressionMethod: $ this ->compressionMethod ,
194201 lastModificationDateTime: $ this ->lastModificationDateTime ,
195202 crc32UncompressedData: $ this ->crc ,
196- compressedSize: ( $ this -> enableZip64 || $ this -> enableZeroHeader || $ this -> compressedSize > 0xFFFFFFFF )
203+ compressedSize: $ zip64Enabled
197204 ? 0xFFFFFFFF
198205 : $ this ->compressedSize ,
199- uncompressedSize: ( $ this -> enableZip64 || $ this -> enableZeroHeader || $ this -> uncompressedSize > 0xFFFFFFFF )
206+ uncompressedSize: $ zip64Enabled
200207 ? 0xFFFFFFFF
201208 : $ this ->uncompressedSize ,
202209 fileName: $ this ->fileName ,
@@ -235,20 +242,6 @@ private function checkEncoding(): void
235242 }
236243 }
237244
238- private function selectVersion (): void
239- {
240- if ($ this ->enableZip64 ) {
241- $ this ->version = Version::ZIP64 ;
242- return ;
243- }
244- if ($ this ->compressionMethod === CompressionMethod::DEFLATE ) {
245- $ this ->version = Version::DEFLATE ;
246- return ;
247- }
248-
249- $ this ->version = Version::STORE ;
250- }
251-
252245 private function buildZip64ExtraBlock (bool $ force = false ): string
253246 {
254247 $ outputZip64ExtraBlock = false ;
@@ -278,7 +271,7 @@ private function buildZip64ExtraBlock(bool $force = false): string
278271 return '' ;
279272 }
280273
281- if ($ this ->version !== Version:: ZIP64 ) {
274+ if (! $ this ->enableZip64 ) {
282275 throw new OverflowException ();
283276 }
284277
0 commit comments