From ad3bac6f96a39e654507a89118ff19b9e9c41578 Mon Sep 17 00:00:00 2001 From: wapplay Date: Wed, 10 Oct 2018 10:34:06 +0300 Subject: [PATCH] cp866 to utf8 converter --- src/PhpZip/Stream/ZipInputStream.php | 2 +- src/PhpZip/Util/StringUtil.php | 25 +++++++++++++++++++++++ src/PhpZip/Util/encodings/cp866-utf8.php | Bin 0 -> 3831 bytes 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/PhpZip/Util/encodings/cp866-utf8.php diff --git a/src/PhpZip/Stream/ZipInputStream.php b/src/PhpZip/Stream/ZipInputStream.php index 37dd6be..dea05de 100644 --- a/src/PhpZip/Stream/ZipInputStream.php +++ b/src/PhpZip/Stream/ZipInputStream.php @@ -311,7 +311,7 @@ class ZipInputStream implements ZipInputStreamInterface fread($this->in, 42) ); -// $utf8 = 0 !== ($data['gpbf'] & self::GPBF_UTF8); +// $utf8 = ($data['gpbf'] & ZipEntry::GPBF_UTF8) !== 0; // See appendix D of PKWARE's ZIP File Format Specification. $name = fread($this->in, $data['fileLength']); diff --git a/src/PhpZip/Util/StringUtil.php b/src/PhpZip/Util/StringUtil.php index 0b75040..b579eac 100644 --- a/src/PhpZip/Util/StringUtil.php +++ b/src/PhpZip/Util/StringUtil.php @@ -28,4 +28,29 @@ class StringUtil return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== false); } + + /** + * @param string $str + * @return string + */ + public static function cp866toUtf8($str) + { + if (function_exists('iconv')) { + /** @noinspection PhpComposerExtensionStubsInspection */ + return iconv('CP866', 'UTF-8//IGNORE', $str); + } elseif (function_exists('mb_convert_encoding')) { + /** @noinspection PhpComposerExtensionStubsInspection */ + return mb_convert_encoding($str, 'UTF-8', 'CP866'); + } elseif (class_exists('UConverter')) { + /** @noinspection PhpComposerExtensionStubsInspection */ + $converter = new \UConverter('UTF-8', 'CP866'); + return $converter->convert($str, false); + } else { + static $cp866Utf8Pairs; + if (empty($cp866Utf8Pairs)) { + $cp866Utf8Pairs = require __DIR__ . '/encodings/cp866-utf8.php'; + } + return strtr($str, $cp866Utf8Pairs); + } + } } diff --git a/src/PhpZip/Util/encodings/cp866-utf8.php b/src/PhpZip/Util/encodings/cp866-utf8.php new file mode 100644 index 0000000000000000000000000000000000000000..b61d753b0f50ae009c44a0f0092a3c60aca60f67 GIT binary patch literal 3831 zcmZwKWpoo+7{>9%A#iZl0ZIjmJE`FAE=58cXrYvnCO~m1P~6hs?(S~8tb18^>AJfc z^!}gwZ9mQXJMYb8?#%PfITI6~o}BJ-W%xb*ltd>i$>aApv5v>*^JF@aF2{*@D8h-2 z%RfZts{ks13ZjCj5GsTUqr#{NDuRllqNo@uhKi%&s01p3T*!q=qLQc-D)oOWOVcY& zuM8@K%A&HU94d#(qw=T%s(>n@il`E*ges%Ts0ylrs-mi>8mfk>qw1&zs)1^vny414 zg=(YPs1B-w9OR(7s4l99>Y@6mJ_BkF`Yq0Xo?>VmqUuBa>O zhPt8ds5|O`dZ3=DC+dZIq28!B>Vx{AzNjzihx(!Zs6QHj2B3jxAR2@Qp}}Y{8iIzP zp=c-?hK8ZxXgC^yMxc>sBpQWAq0wkG8iU55gar8DXfiz(jz#0pI5ZxOM-$KlYlhI_9jFM3bNyYkU{E{=bHqb1Bp!xa#3OL4coc3EkHPKYakxV~0e6Zg;V$tM z+%2Ald&DzvuXq;j6VJi@;(2&LyZ{f17vUlC5Yr>%88&sZz@&suA2p0n0~K5wo4yxhP<>z&4&FUN08s#_Tpw9P}^&0N)+j1xyzhj++-?i5I z_pEh4-nZ8C`T*Y(KNJ^pwmeZ`|43X)_hV6i{fW4Y?x*5%_?fr@elBVoUx+K|ekrbk zUx};X*P^!gjkuQXx8geZowy!;4|BD_AJo-!{iv>X^pm>E;?L@83%{tVN&Hn^{qJw; zD)+y`yLzww0rRpIqd(Qw+wd>j)>Qm0XX&l+kCrQ>|Ee9*5d5chKBL?&SD4S65lHnr evEh8ex?O>^46i@Ze9z`D@Ok|KUz($JZr6SP>0BBB literal 0 HcmV?d00001