Fold All / Expand All

2016年3月1日 星期二

maybe a 32-bit fwrite test script

$fp = fopen($path, 'rb');
$out = fopen($output, 'wb');
$count = '0';

echo "bad size:".filesize($path)."\n";
while (false === feof($fp)) {
        $buffer = fread($fp, 65536);
        $written = fwrite($out, $buffer);

        $count = bcadd($count, (string)$written);

        $len = strlen($count);

        if ($len > 9) {
                $r3 = substr($count, -3, 3);
                $r6 = substr($count, -6, 3);
                $r9 = substr($count, -9, 3);
                $left = substr($count, 0, -9);
                $strval = "$left,$r9,$r6,$r3";
        } elseif ($len > 6) {
                $r3 = substr($count, -3, 3);
                $r6 = substr($count, -6, 3);
                $left = substr($count, 0, -6);
                $strval = "$left,$r6,$r3";
        } elseif ($len > 3) {
                $r3 = substr($count, -3, 3);
                $left = substr($count, 0, -3);
                $strval = "$left,$r3";
        } else {
                $strval = $count;
        }

        $strval = str_pad($strval, 16, ' ', STR_PAD_LEFT);
        echo "written: " . $strval."\n";
}

echo "\n == end == \n";
結果最多的 code 是在如何 pretty print…

沒有留言: