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