UnicodePathExtraField.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the nelexa/zip package.
  5. * (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. namespace PhpZip\Model\Extra\Fields;
  10. /**
  11. * Info-ZIP Unicode Path Extra Field (0x7075):
  12. * ==========================================.
  13. *
  14. * Stores the UTF-8 version of the file name field as stored in the
  15. * local header and central directory header. (Last Revision 20070912)
  16. *
  17. * Value Size Description
  18. * ----- ---- -----------
  19. * (UPath) 0x7075 Short tag for this extra block type ("up")
  20. * TSize Short total data size for this block
  21. * Version 1 byte version of this extra field, currently 1
  22. * NameCRC32 4 bytes File Name Field CRC32 Checksum
  23. * UnicodeName Variable UTF-8 version of the entry File Name
  24. *
  25. * Currently Version is set to the number 1. If there is a need
  26. * to change this field, the version will be incremented. Changes
  27. * may not be backward compatible so this extra field should not be
  28. * used if the version is not recognized.
  29. *
  30. * The NameCRC32 is the standard zip CRC32 checksum of the File Name
  31. * field in the header. This is used to verify that the header
  32. * File Name field has not changed since the Unicode Path extra field
  33. * was created. This can happen if a utility renames the File Name but
  34. * does not update the UTF-8 path extra field. If the CRC check fails,
  35. * this UTF-8 Path Extra Field should be ignored and the File Name field
  36. * in the header should be used instead.
  37. *
  38. * The UnicodeName is the UTF-8 version of the contents of the File Name
  39. * field in the header. As UnicodeName is defined to be UTF-8, no UTF-8
  40. * byte order mark (BOM) is used. The length of this field is determined
  41. * by subtracting the size of the previous fields from TSize. If both
  42. * the File Name and Comment fields are UTF-8, the new General Purpose
  43. * Bit Flag, bit 11 (Language encoding flag (EFS)), can be used to
  44. * indicate that both the header File Name and Comment fields are UTF-8
  45. * and, in this case, the Unicode Path and Unicode Comment extra fields
  46. * are not needed and should not be created. Note that, for backward
  47. * compatibility, bit 11 should only be used if the native character set
  48. * of the paths and comments being zipped up are already in UTF-8. It is
  49. * expected that the same file name storage method, either general
  50. * purpose bit 11 or extra fields, be used in both the Local and Central
  51. * Directory Header for a file.
  52. *
  53. * @see https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT section 4.6.9
  54. */
  55. final class UnicodePathExtraField extends AbstractUnicodeExtraField
  56. {
  57. public const HEADER_ID = 0x7075;
  58. /**
  59. * Returns the Header ID (type) of this Extra Field.
  60. * The Header ID is an unsigned short integer (two bytes)
  61. * which must be constant during the life cycle of this object.
  62. */
  63. public function getHeaderId(): int
  64. {
  65. return self::HEADER_ID;
  66. }
  67. public function __toString(): string
  68. {
  69. return sprintf(
  70. '0x%04x UnicodePath: "%s"',
  71. self::HEADER_ID,
  72. $this->getUnicodeValue()
  73. );
  74. }
  75. }