Read and unpack data from the header of the recorded game file.

@see https://secure.php.net/pack For documentation on data unpack format.
@param string  $type  Data type.
@param int  $size  Size of the data.
@return mixed Result.
430104
protected function readHeader($type, $size)
    {
        if ($this->position + $size > $this->headerSize) {
            throw new \Exception('Can\'t read ' . $size . ' bytes');
        }
        $data = unpack($type, substr($this->header, $this->position, $size));
        $this->position += $size;
        return $data[1];
    }
1368584
public function readUIntBySize($size)
    {
        if ($size === self::UNSIGNED_CHAR_LENGTH) {
            return $this->readUInt8();
        }
        if ($size === self::UNSIGNED_SHORT_LENGTH) {
            return $this->readUInt16();
        }
        if ($size === self::UNSIGNED_INT24_LENGTH) {
            return $this->readUInt24();
        }
        if ($size === self::UNSIGNED_INT32_LENGTH) {
            return $this->readUInt32();
        }
        if ($size === self::UNSIGNED_INT40_LENGTH) {
            return $this->readUInt40();
        }
        if ($size === self::UNSIGNED_INT48_LENGTH) {
            return $this->readUInt48();
        }
        if ($size === self::UNSIGNED_INT56_LENGTH) {
            return $this->readUInt56();
        }
        if ($size === self::UNSIGNED_INT64_LENGTH) {
            return $this->readUInt64();
        }

        throw new BinaryDataReaderException('$size ' . $size . ' not handled');
    }
930267
public function read($size)
    {
        $this->_checkStream();
        $data = @fread($this->_stream, $size);
        if ($data === false) {
            throw new Client\Exception('Error reading data from socket');
        }
        return $data;
    }
1032086
protected function readLine($size = 1024)
    {
        $line = '';

        if (!$size) {
            $size = 1024;
        }

        do {
            if ($this->eof()) {
                return $line ?: null;
            }

            $buffer = fgets($this->fp, $size);

            if ($buffer === false) {
                $this->closeSocket();
                break;
            }

            if ($this->debug) {
                $this->debug('S: '. rtrim($buffer));
            }

            $line .= $buffer;
        }
        while (substr($buffer, -1) != "\n");

        return $line;
    }
103674
public function column(string $name, int $type, int $size = 0): bool
    {
        list($type, $size) = $this->validateColumn($type, $size);
        $this->columns[] = [$name, [$type, $size]];
        return true;
    }
1359496
public function getDefaultTypeSize($type)
    {
        $sizes = $this->getDefaultTypeSizes();

        return isset($sizes[strtolower($type)]) ? $sizes[strtolower($type)] : null;
    }
1350204
public static function humanReadableFilesize($size)
    {
        $mod = 1024;
        $units = explode(' ', 'B KB MB GB TB PB');
        for ($i = 0; $size > $mod; ++$i) {
            $size /= $mod;
        }

        return round($size, 2).' '.$units[$i];
    }
1171982
public function packServerMessageBody($type, $message, string $func = null)
    {
        $data['type'] = $type;
        $data['message'] = $message;
        $data['func'] = $func;
        return $data;
    }
1324806
public static function filesizeToBytes($size)
    {
        $unit = preg_replace('/[^bkmgtpezy]/i', '', $size);
        $size = preg_replace('/[^0-9\.]/', '', $size);

        if ($unit) {
            return round($size * pow(1024, stripos('bkmgtpezy', $unit[0])));
        }

        return round($size);
    }
842198
public static function bytes( $size, $round = 2 ) 
	{
		$unit = array( 'b', 'kb', 'mb', 'gb', 'tb', 'pb' );
		return @round( $size / pow( 1024, ( $i = floor( log( $size, 1024 ) ) ) ), $round ).$unit[$i];
	}
174879
public function chunk(int $size): CollectionInterface
    {
        if ($size <= 0) {
            return new static();
        }

        $chunks = [];

        foreach (array_chunk($this->data->getValues(), $size, true) as $chunk) {
            $chunks[] = new static($chunk);
        }

        return new static($chunks);
    }
726425
public function translateBytes($size)
    {
        $units = [
            'k' => 1,
            'm' => 2,
            'g' => 3,
            't' => 4,
            'p' => 5
        ];
        $size = strtolower($size);
        $bytes = intval($size);
        foreach ($units as $key => $value) {
            if (strpos($size, $key)) {
                $bytes = $bytes * pow(1024, $value);
                break;
            }
        }
        return $bytes;
    }
447374
public static function iniSizeToBytes($size)
    {
        if (\is_numeric($size)) {
            return (int)$size;
        }

        $suffix = \strtoupper(\substr($size, -1));
        $strippedSize = \substr($size, 0, -1);

        if (!\is_numeric($strippedSize)) {
            throw new \InvalidArgumentException("$size is not a valid ini size");
        }

        if ($strippedSize <= 0) {
            throw new \InvalidArgumentException("Expect $size to be higher isn't zero or lower");
        }

        if ($suffix === 'K') {
            return $strippedSize * 1024;
        }
        if ($suffix === 'M') {
            return $strippedSize * 1024 * 1024;
        }
        if ($suffix === 'G') {
            return $strippedSize * 1024 * 1024 * 1024;
        }
        if ($suffix === 'T') {
            return $strippedSize * 1024  * 1024 * 1024 * 1024;
        }

        return (int)$size;
    }
514682
public function getPackageDownloads($type)
    {
        $statsType = 'get' . ucfirst($type);
        if (($download = $this->getDownloads()) && $download instanceof \Packagist\Api\Result\Package\Downloads) {
            return $download->{$statsType}();
        }
    }
1227816
public function get_chunks($type) {
        if (!isset($this->_chunks[$type]) || $this->_chunks[$type] === null)
            return null;

        $chunks = array ();

        foreach ($this->_chunks[$type] as $chunk) {
            if ($chunk['size'] > 0) {
                fseek($this->_fp, $chunk['offset'], SEEK_SET);
                $chunks[] = fread($this->_fp, $chunk['size']);
            } else {
                $chunks[] = '';
            }
        }

        return $chunks;
    }
959291
public function get($type)
    {
        if (!isset($this->instances[$type])) {
            $this->instances[$type] = $this->loadFile($type);
        }

        return $this->instances[$type];
    }
242335
public function getImage($type, $size, array $attributes = array())
	{
		if (empty($this->$type))
		{
			return null;
		}
		$html = '<img src="' . $this->getImageSrc($type, $size) . '"';
		$html .= ' alt="' . $this->{$type.'_alt'} . '"';
		$html .= ' width="' . $this->getImageWidth($type, $size) . '"';
		$html .= ' height="' . $this->getImageHeight($type, $size) . '"';
		
		$html_attributes = '';
		if (!empty($attributes)) {
			$html_attributes = join(' ', array_map(function($key) use ($attributes) {
				if(is_bool($attributes[$key]))
				{
					return $attributes[$key] ? $key : '';
				}
				return "{$key}=\"{$attributes[$key]}\"";
			}, array_keys($attributes)));
		}
		
		return $html;
	}