1
0
mirror of https://github.com/Ne-Lexa/php-zip.git synced 2025-10-10 21:04:36 +02:00

zip extra tests, php 32-bit compat

This commit is contained in:
Ne-Lexa
2020-01-14 16:31:22 +03:00
parent d21fdb35bb
commit 8487dac9df
13 changed files with 246 additions and 122 deletions

View File

@@ -29,16 +29,6 @@ abstract class AbstractUnicodeExtraField implements ZipExtraField
$this->unicodeValue = (string) $unicodeValue;
}
/**
* @param string $unicodeValue
*
* @return static
*/
public static function create($unicodeValue)
{
return new static(crc32($unicodeValue), $unicodeValue);
}
/**
* @return int the CRC32 checksum of the filename or comment as
* encoded in the central directory of the zip file
@@ -48,6 +38,14 @@ abstract class AbstractUnicodeExtraField implements ZipExtraField
return $this->crc32;
}
/**
* @param int $crc32
*/
public function setCrc32($crc32)
{
$this->crc32 = (int) $crc32;
}
/**
* @return string
*/
@@ -62,7 +60,6 @@ abstract class AbstractUnicodeExtraField implements ZipExtraField
public function setUnicodeValue($unicodeValue)
{
$this->unicodeValue = $unicodeValue;
$this->crc32 = crc32($unicodeValue);
}
/**
@@ -78,19 +75,18 @@ abstract class AbstractUnicodeExtraField implements ZipExtraField
public static function unpackLocalFileData($buffer, ZipEntry $entry = null)
{
if (\strlen($buffer) < 5) {
throw new ZipException('UniCode path extra data must have at least 5 bytes.');
throw new ZipException('Unicode path extra data must have at least 5 bytes.');
}
$version = unpack('C', $buffer)[1];
$data = unpack('Cversion/Vcrc32', $buffer);
if ($version !== self::DEFAULT_VERSION) {
throw new ZipException(sprintf('Unsupported version [%d] for UniCode path extra data.', $version));
if ($data['version'] !== self::DEFAULT_VERSION) {
throw new ZipException(sprintf('Unsupported version [%d] for Unicode path extra data.', $data['version']));
}
$crc32 = unpack('V', substr($buffer, 1))[1];
$unicodeValue = substr($buffer, 5);
return new static($crc32, $unicodeValue);
return new static($data['crc32'], $unicodeValue);
}
/**