xref: /dokuwiki/vendor/phpseclib/phpseclib/phpseclib/System/SSH/Common/Traits/ReadBytes.php (revision 927933f55f286c8bea68959a13975cbcb59eb8ee)
1<?php
2
3/**
4 * ReadBytes trait
5 *
6 * PHP version 5
7 *
8 * @author    Jim Wigginton <terrafrost@php.net>
9 * @copyright 2015 Jim Wigginton
10 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
11 * @link      http://phpseclib.sourceforge.net
12 */
13
14namespace phpseclib3\System\SSH\Common\Traits;
15
16/**
17 * ReadBytes trait
18 *
19 * @author  Jim Wigginton <terrafrost@php.net>
20 */
21trait ReadBytes
22{
23    /**
24     * Read data
25     *
26     * @param int $length
27     * @throws \RuntimeException on connection errors
28     */
29    public function readBytes($length)
30    {
31        $temp = fread($this->fsock, $length);
32        if (strlen($temp) != $length) {
33            throw new \RuntimeException("Expected $length bytes; got " . strlen($temp));
34        }
35        return $temp;
36    }
37}
38