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