From 4955cb6f6d16435933962ee449e68657f240108c Mon Sep 17 00:00:00 2001 From: mateuszanella Date: Mon, 28 Jul 2025 09:08:13 -0300 Subject: [PATCH 1/3] Remove mb from strings on zip stuff --- pint.json | 1 - src/Writers/Zip/Records/CentralDirectoryFileHeader.php | 6 +++--- .../Zip/Records/EndOfCentralDirectoryRecord.php | 2 +- src/Writers/Zip/Records/LocalFileHeader.php | 4 ++-- .../Zip/Zip64Records/EndOfCentralDirectoryRecord.php | 2 +- src/Writers/Zip/Zip64Writer.php | 10 ++++++---- src/Writers/Zip/ZipWriter.php | 8 ++++---- 7 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pint.json b/pint.json index 7268c09..737f899 100644 --- a/pint.json +++ b/pint.json @@ -17,7 +17,6 @@ "import_constants": true, "import_functions": true }, - "mb_str_functions": true, "modernize_types_casting": true, "new_with_parentheses": false, "no_superfluous_elseif": true, diff --git a/src/Writers/Zip/Records/CentralDirectoryFileHeader.php b/src/Writers/Zip/Records/CentralDirectoryFileHeader.php index 597561d..6c97d01 100644 --- a/src/Writers/Zip/Records/CentralDirectoryFileHeader.php +++ b/src/Writers/Zip/Records/CentralDirectoryFileHeader.php @@ -44,9 +44,9 @@ public static function generate( U32Field::create($crc32), U32Field::create($compressedSize), U32Field::create($uncompressedSize), - U16Field::create(mb_strlen($fileName)), - U16Field::create(mb_strlen($extraField)), - U16Field::create(mb_strlen($fileComment)), + U16Field::create(strlen($fileName)), + U16Field::create(strlen($extraField)), + U16Field::create(strlen($fileComment)), U16Field::create($diskNumberStart), U16Field::create($internalFileAttributes), U32Field::create($externalFileAttributes), diff --git a/src/Writers/Zip/Records/EndOfCentralDirectoryRecord.php b/src/Writers/Zip/Records/EndOfCentralDirectoryRecord.php index a290235..f6ba369 100644 --- a/src/Writers/Zip/Records/EndOfCentralDirectoryRecord.php +++ b/src/Writers/Zip/Records/EndOfCentralDirectoryRecord.php @@ -33,7 +33,7 @@ public static function generate( U16Field::create($totalCentralDirectoryRecords), U32Field::create($centralDirectorySize), U32Field::create($centralDirectoryOffset), - U16Field::create(mb_strlen($comment)), + U16Field::create(strlen($comment)), ).$comment; } } diff --git a/src/Writers/Zip/Records/LocalFileHeader.php b/src/Writers/Zip/Records/LocalFileHeader.php index 86ec484..8c0a224 100644 --- a/src/Writers/Zip/Records/LocalFileHeader.php +++ b/src/Writers/Zip/Records/LocalFileHeader.php @@ -37,8 +37,8 @@ public static function generate( U32Field::create($crc32), U32Field::create($compressedSize), U32Field::create($uncompressedSize), - U16Field::create(mb_strlen($fileName)), - U16Field::create(mb_strlen($extraField)), + U16Field::create(strlen($fileName)), + U16Field::create(strlen($extraField)), ).$fileName.$extraField; } } diff --git a/src/Writers/Zip/Zip64Records/EndOfCentralDirectoryRecord.php b/src/Writers/Zip/Zip64Records/EndOfCentralDirectoryRecord.php index fce8c9a..7a3296d 100644 --- a/src/Writers/Zip/Zip64Records/EndOfCentralDirectoryRecord.php +++ b/src/Writers/Zip/Zip64Records/EndOfCentralDirectoryRecord.php @@ -29,7 +29,7 @@ public static function generate( string $extensibleDataSector ): string { // Size = (SizeOfFixedFields - 12) + SizeOfVariableData. - $sizeOfEndOfCentralDirectoryRecord = 44 + mb_strlen($extensibleDataSector); + $sizeOfEndOfCentralDirectoryRecord = 44 + strlen($extensibleDataSector); return Packer::pack( U32Field::create(self::SIGNATURE), diff --git a/src/Writers/Zip/Zip64Writer.php b/src/Writers/Zip/Zip64Writer.php index 9bd8790..3a4e1de 100644 --- a/src/Writers/Zip/Zip64Writer.php +++ b/src/Writers/Zip/Zip64Writer.php @@ -56,6 +56,8 @@ public function __construct(WriteStream $outputPath, array $config = []) { $this->outputStream = $outputPath; + echo "\nUsing write stream class: " . get_class($this->outputStream) . "\n"; + $this->setDefaultCompressor(DeflateCompressor::class); } @@ -125,7 +127,7 @@ public function finish(): void foreach ($this->centralDirectoryHeaders as $header) { $this->outputStream->write($header); - $sizeOfCentralDirectory += mb_strlen($header); + $sizeOfCentralDirectory += strlen($header); } if ( @@ -209,16 +211,16 @@ protected function writeFile(ReadStream $stream, Compressor $compressor): array foreach ($stream->read() as $chunk) { $crc32->update($chunk); - $uncompressedSize += mb_strlen($chunk); + $uncompressedSize += strlen($chunk); $compressedChunk = $compressor->compress($chunk); - $compressedSize += mb_strlen($compressedChunk); + $compressedSize += strlen($compressedChunk); $this->outputStream->write($compressedChunk); } $finalCompressedChunk = $compressor->finish(); - $compressedSize += mb_strlen($finalCompressedChunk); + $compressedSize += strlen($finalCompressedChunk); $this->outputStream->write($finalCompressedChunk); diff --git a/src/Writers/Zip/ZipWriter.php b/src/Writers/Zip/ZipWriter.php index cf2664b..0004edd 100644 --- a/src/Writers/Zip/ZipWriter.php +++ b/src/Writers/Zip/ZipWriter.php @@ -120,7 +120,7 @@ public function finish(): void foreach ($this->centralDirectoryHeaders as $header) { $this->outputStream->write($header); - $sizeOfCentralDirectory += mb_strlen($header); + $sizeOfCentralDirectory += strlen($header); } $endOfCentralDirectory = EndOfCentralDirectoryRecord::generate( @@ -171,16 +171,16 @@ protected function writeFile(ReadStream $stream, Compressor $compressor): array foreach ($stream->read() as $chunk) { $crc32->update($chunk); - $uncompressedSize += mb_strlen($chunk); + $uncompressedSize += strlen($chunk); $compressedChunk = $compressor->compress($chunk); - $compressedSize += mb_strlen($compressedChunk); + $compressedSize += strlen($compressedChunk); $this->outputStream->write($compressedChunk); } $finalCompressedChunk = $compressor->finish(); - $compressedSize += mb_strlen($finalCompressedChunk); + $compressedSize += strlen($finalCompressedChunk); $this->outputStream->write($finalCompressedChunk); From aa37fb82e17dea0b15c368b31880c3267afc47c8 Mon Sep 17 00:00:00 2001 From: mateuszanella Date: Mon, 28 Jul 2025 09:09:20 -0300 Subject: [PATCH 2/3] Fix logic mistake in ArrayOutputStream --- src/IO/Output/ArrayOutputStream.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IO/Output/ArrayOutputStream.php b/src/IO/Output/ArrayOutputStream.php index 1c90940..d4e0aaf 100644 --- a/src/IO/Output/ArrayOutputStream.php +++ b/src/IO/Output/ArrayOutputStream.php @@ -52,7 +52,7 @@ public function write(string $s): int // Although this is not the best solution, we must ensure // that the bytes written variable contains a correct value. - return $this->bytesWritten += $this->streams[0]->getBytesWritten(); + return $this->bytesWritten = $this->streams[0]->getBytesWritten(); } /** From 9c90f13d59a7d60f8f12ca5dafc3c40d4e1b7e73 Mon Sep 17 00:00:00 2001 From: mateuszanella Date: Mon, 28 Jul 2025 09:10:30 -0300 Subject: [PATCH 3/3] Removed debug statement --- src/Writers/Zip/Zip64Writer.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Writers/Zip/Zip64Writer.php b/src/Writers/Zip/Zip64Writer.php index 3a4e1de..2fe3958 100644 --- a/src/Writers/Zip/Zip64Writer.php +++ b/src/Writers/Zip/Zip64Writer.php @@ -56,8 +56,6 @@ public function __construct(WriteStream $outputPath, array $config = []) { $this->outputStream = $outputPath; - echo "\nUsing write stream class: " . get_class($this->outputStream) . "\n"; - $this->setDefaultCompressor(DeflateCompressor::class); }