UnicodeCommentExtraField.php 3.0 KB

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