UnicodePathExtraField.php 3.0 KB

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