Get X bytes of data from file.

@param int $offset
@param int $bytes

@return string
321228
protected function getData(int $offset, int $bytes) : string
    {
        $file   = new File;
        $handle = $file->open($this->getFilePath(), $file::READ_BINARY);

        $file->seek($handle, $offset);

        $data = $file->read($handle, $bytes);

        $file->close($handle);

        return (string) $data;
    }
100955
protected function formatBytes(int $bytes)
    {
        if (!$this->useFormatting) {
            return $bytes;
        }

        if ($bytes > 1024 * 1024) {
            return round($bytes / 1024 / 1024, 2).' MB';
        } elseif ($bytes > 1024) {
            return round($bytes / 1024, 2).' KB';
        }

        return $bytes . ' B';
    }
221884
protected function checkForBytes(array $bytes, int $offset = 0, array $mask = []): bool
    {
        if (empty($bytes) || empty($this->byteCache)) {
            return false;
        }

        // make sure we have nummeric indices
        $bytes = array_values($bytes);

        foreach ($bytes as $i => $byte) {
            if (!empty($mask)) {
                if (!isset($this->byteCache[$offset + $i]) ||
                    !isset($mask[$i]) ||
                    $byte !== ($mask[$i] & $this->byteCache[$offset + $i])
                ) {
                    return false;
                }
            } elseif (!isset($this->byteCache[$offset + $i]) || $this->byteCache[$offset + $i] != $byte) {
                return false;
            }
        }

        return true;
    }
56945
private function read($bytes)
    {
        if (false === ($read = @fread($this->handle(), $bytes))) {
            throw FileException::lastError();
        }

        if (($actual = strlen($read)) !== $bytes) {
            throw FileException::create(
                'Only read %d of %d bytes from "%s".',
                $actual,
                $bytes,
                $this->file
            );
        }

        return $read;
    }
526363
public function readUint16($offset = 0)
    {
        $s = $this->read(2, $offset);
        list(, $ret) = unpack("n", $s);
        return $ret;
    }
426873
private function memGet(int $offset, int $size): string
    {
        $data = \shmop_read($this->handle, $offset, $size);
        if ($data === false) {
            throw new SharedMemoryException('Failed to read from shared memory block.');
        }
        return $data;
    }
185889
public static char bytesToChar(byte[] bytes, int offset) {
        char result = 0x0;
        for (int i = offset; i < offset + 2; ++i) {
            result = (char) ((result) << 8);
            result |= (bytes[i] & 0x00FF);
        }
        return result;
    }
1327674
protected function sendPatchRequest(int $bytes, int $offset) : int
    {
        $data    = $this->getData($offset, $bytes);
        $headers = [
            'Content-Type' => self::HEADER_CONTENT_TYPE,
            'Content-Length' => strlen($data),
            'Upload-Checksum' => $this->getUploadChecksumHeader(),
        ];

        if ($this->isPartial()) {
            $headers += ['Upload-Concat' => self::UPLOAD_TYPE_PARTIAL];
        } else {
            $headers += ['Upload-Offset' => $offset];
        }

        try {
            $response = $this->getClient()->patch($this->getUrl(), [
                'body' => $data,
                'headers' => $headers,
            ]);

            return (int) current($response->getHeader('upload-offset'));
        } catch (ClientException $e) {
            throw $this->handleClientException($e);
        } catch (ConnectException $e) {
            throw new ConnectionException("Couldn't connect to server.");
        }
    }
47414
public static function getSlice($string, $offset, $length = null)
    {
        if (self::checkMB()) {
            return mb_substr($string, $offset, $length, '8bit');
        }
        if ($length === null) {
            $length = strlen($string);
        }
        return substr($string, $offset, $length);
    }
372626
public function &offsetGet($offset)
    {
        if (!isset($this->data[$offset])) {
            $this->extraKeys[$offset] = true;
        }
        return $this->data[$offset];
    }
123974
public function offsetGet($offset)
    {
        if (($offset < 0) || ($offset >= $this->charLen)) {
            return null;
        }

        $delta = $offset - $this->charIdx;

        if ($delta > 0) {
            // Fast forwarding.
            while ($delta-- > 0) {
                $this->byteIdx += static::getCharLength($this->str[$this->byteIdx]);
                ++$this->charIdx;
            }
        } elseif ($delta < 0) {
            // Rewinding.
            while ($delta++ < 0) {
                do {
                    $byte = ord($this->str[--$this->byteIdx]);
                } while (($byte >= 128) && ($byte < 192));
                --$this->charIdx;
            }
        }

        $bytesCount = static::getCharLength($this->str[$this->byteIdx]);

        $ret = '';
        for ($i = 0; $bytesCount-- > 0; ++$i) {
            $ret .= $this->str[$this->byteIdx + $i];
        }

        return $ret;
    }
1150596
public static function addressFromBytes(array $bytes)
    {
        $result = null;
        if ($result === null) {
            $result = Address\IPv4::fromBytes($bytes);
        }
        if ($result === null) {
            $result = Address\IPv6::fromBytes($bytes);
        }

        return $result;
    }
697085
public function getData($offset)
    {
        $this->parserPosition = null;
        $this->parserLevel    = 0;
        $data        = "";
        $parser      = @\xml_parser_create();
        $filePointer = $this->getIndex()->getFile()->getFilePointer();

        if (! \is_resource($parser)) {
            $error = \error_get_last();
            throw new ReadDataIndexException(
                "Could not create a xml parser: $error[message]"
            );

        }

        \xml_set_element_handler(
            $parser,
            array($this, "onStartElement"),
            array($this, "onEndElement")
        );

        \fseek($filePointer, $offset);
        while (\is_null($this->parserPosition)
                    && $chunk = \fread($filePointer, $this->getIndex()->getFile()->getBlockSize())
        ) {
            $data .= $chunk;
            \xml_parse($parser, $chunk);

        }

        \xml_parser_free($parser);

        if (\is_null($this->parserPosition)) {
            throw new ReadDataIndexException("Did not read any data");

        }
        return \substr($data, 0, $this->parserPosition);
    }
1229409
public function offsetGet($offset)
    {
        $hash = $this->hashAlgo->hash($offset);
        $filePath = $this->getCachePath() . $this->buildKeysCachingPath($hash) . $hash;

        return $this->offsetExists($offset) ? $this->codec->decode(file_get_contents($filePath)) : null;
    }
999128
final public function fileGetContents($offset = -1, $maxlen = null)
	{
		$this->fseek($offset + 1, SEEK_SET);
		return $this->fread($maxlen);
	}
636732
public function offsetGet($offset)
    {

        list($url, $key) = $this->fileUrlAndKey($offset);

        $storage = $this->getOrCreateStorage($url);

        if (!$key) {
            return $storage->toArray();
        }

        return $storage->offsetGet($key);
    }
1290458
public static int getValue(byte[] bytes, int offset) {
    int value = (bytes[offset + 1] << BYTE_1_SHIFT) & BYTE_1_MASK;
    value += (bytes[offset] & BYTE_MASK);
    return value;
  }