This commit is contained in:
2026-07-23 10:37:26 +08:00
parent 090abf48fa
commit 40add876cd
3503 changed files with 838201 additions and 5 deletions
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace ZipStream\Test\Zip64;
use PHPUnit\Framework\TestCase;
use ZipStream\Zip64\DataDescriptor;
class DataDescriptorTest extends TestCase
{
public function testSerializesCorrectly(): void
{
$descriptor = DataDescriptor::generate(
crc32UncompressedData: 0x11111111,
compressedSize: (0x77777777 << 32) + 0x66666666,
uncompressedSize: (0x99999999 << 32) + 0x88888888,
);
$this->assertSame(
bin2hex($descriptor),
'504b0708' // 4 bytes; Optional data descriptor signature = 0x08074b50
. '11111111' // 4 bytes; CRC-32 of uncompressed data
. '6666666677777777' // 8 bytes; Compressed size
. '8888888899999999' // 8 bytes; Uncompressed size
);
}
}
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace ZipStream\Test\Zip64;
use PHPUnit\Framework\TestCase;
use ZipStream\Zip64\EndOfCentralDirectoryLocator;
class EndOfCentralDirectoryLocatorTest extends TestCase
{
public function testSerializesCorrectly(): void
{
$descriptor = EndOfCentralDirectoryLocator::generate(
numberOfTheDiskWithZip64CentralDirectoryStart: 0x11111111,
zip64centralDirectoryStartOffsetOnDisk: (0x22222222 << 32) + 0x33333333,
totalNumberOfDisks: 0x44444444,
);
$this->assertSame(
bin2hex($descriptor),
'504b0607' // 4 bytes; zip64 end of central dir locator signature - 0x07064b50
. '11111111' // 4 bytes; number of the disk with the start of the zip64 end of central directory
. '3333333322222222' // 28 bytes; relative offset of the zip64 end of central directory record
. '44444444' // 4 bytes;total number of disks
);
}
}
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace ZipStream\Test\Zip64;
use PHPUnit\Framework\TestCase;
use ZipStream\Zip64\EndOfCentralDirectory;
class EndOfCentralDirectoryTest extends TestCase
{
public function testSerializesCorrectly(): void
{
$descriptor = EndOfCentralDirectory::generate(
versionMadeBy: 0x3333,
versionNeededToExtract: 0x4444,
numberOfThisDisk: 0x55555555,
numberOfTheDiskWithCentralDirectoryStart: 0x66666666,
numberOfCentralDirectoryEntriesOnThisDisk: (0x77777777 << 32) + 0x88888888,
numberOfCentralDirectoryEntries: (0x99999999 << 32) + 0xAAAAAAAA,
sizeOfCentralDirectory: (0xBBBBBBBB << 32) + 0xCCCCCCCC,
centralDirectoryStartOffsetOnDisk: (0xDDDDDDDD << 32) + 0xEEEEEEEE,
extensibleDataSector: 'foo',
);
$this->assertSame(
bin2hex($descriptor),
'504b0606' // 4 bytes;zip64 end of central dir signature - 0x06064b50
. '2f00000000000000' // 8 bytes; size of zip64 end of central directory record
. '3333' // 2 bytes; version made by
. '4444' // 2 bytes; version needed to extract
. '55555555' // 4 bytes; number of this disk
. '66666666' // 4 bytes; number of the disk with the start of the central directory
. '8888888877777777' // 8 bytes; total number of entries in the central directory on this disk
. 'aaaaaaaa99999999' // 8 bytes; total number of entries in the central directory
. 'ccccccccbbbbbbbb' // 8 bytes; size of the central directory
. 'eeeeeeeedddddddd' // 8 bytes; offset of start of central directory with respect to the starting disk number
. bin2hex('foo')
);
}
}
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace ZipStream\Test\Zip64;
use PHPUnit\Framework\TestCase;
use ZipStream\Zip64\ExtendedInformationExtraField;
class ExtendedInformationExtraFieldTest extends TestCase
{
public function testSerializesCorrectly(): void
{
$extraField = ExtendedInformationExtraField::generate(
originalSize: (0x77777777 << 32) + 0x66666666,
compressedSize: (0x99999999 << 32) + 0x88888888,
relativeHeaderOffset: (0x22222222 << 32) + 0x11111111,
diskStartNumber: 0x33333333,
);
$this->assertSame(
bin2hex($extraField),
'0100' // 2 bytes; Tag for this "extra" block type
. '1c00' // 2 bytes; Size of this "extra" block
. '6666666677777777' // 8 bytes; Original uncompressed file size
. '8888888899999999' // 8 bytes; Size of compressed data
. '1111111122222222' // 8 bytes; Offset of local header record
. '33333333' // 4 bytes; Number of the disk on which this file starts
);
}
public function testSerializesEmptyCorrectly(): void
{
$extraField = ExtendedInformationExtraField::generate();
$this->assertSame(
bin2hex($extraField),
'0100' // 2 bytes; Tag for this "extra" block type
. '0000' // 2 bytes; Size of this "extra" block
);
}
}