Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 7dbae04

Browse files
committed
fix: decode
1 parent 8e9374c commit 7dbae04

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

build/zephir/blobfolio/php/ascii85.php

+17-14
Original file line numberDiff line numberDiff line change
@@ -85,30 +85,33 @@ public static function decode(string $data) : string {
8585
}
8686

8787
$padding = 0;
88-
if ($mod = \strlen($data) % 5) {
88+
$length = \strlen($data);
89+
if ($mod = $length % 5) {
8990
$padding = 5 - $mod;
90-
$data .= \str_repeat('u', $padding);
91+
$data .= \str_repeat('#', $padding);
92+
$length += $padding;
9193
}
9294

9395
// Remap.
94-
$digits = \str_split($data, 5);
95-
$converted = \array_map(function ($value) {
96-
$accumulator = 0;
97-
$values = \unpack('C*', $value);
98-
foreach ($values as $char) {
99-
$index = \strpos(self::$map, \chr($char));
100-
$accumulator = $accumulator * 85 + $index;
96+
$fifths = \str_split($data, 5);
97+
$bytes = array();
98+
foreach ($fifths as $byte=>$chars) {
99+
$char = 0;
100+
$values = \unpack('C*', $chars);
101+
foreach ($values as $key) {
102+
$index = (int) \strpos(self::$map, \chr($key));
103+
$char = $char * 85 + $index;
101104
}
102-
return \pack('N', $accumulator);
103-
}, $digits);
105+
$bytes[$byte] = \pack('N', $char);
106+
}
104107

105108
// Kill any padding.
106109
if ($padding) {
107-
$last = \count($converted) - 1;
108-
$converted[$last] = \substr($converted[$last], 0, 4 - $padding);
110+
$last = \count($bytes) - 1;
111+
$bytes[$last] = \substr($bytes[$last], 0, 4 - $padding);
109112
}
110113

111-
return \implode('', $converted);
114+
return \implode('', $bytes);
112115
}
113116

114117
/**

0 commit comments

Comments
 (0)