发送文件，一般用于文件下载
@param string $filename 要发送的文件名称，文件不存在或没有访问权限sendfile会失败
@param integer $offset 上传文件的偏移量，可以指定从文件的中间部分开始传输数据。此特性可用于支持断点续传。
@param integer $length 发送数据的尺寸，默认为整个文件的尺寸
@return static
349826
public function sendFile(string $filename, int $offset = 0, int $length = 0)
    {
        $this->sendHeaders();
        $this->swooleResponse->sendfile($filename, $offset, $length);
        $this->isEnded = true;
        return $this;
    }
1332238
public static function substr($string, $offset, $length = null)
    {
        return mb_substr($string, $offset, $length === null ? mb_strlen($string, static::ENC_UTF8) : $length, static::ENC_UTF8);
    }
991915
public function last($length = null) {
		if ($length === null) {
			$length = 1;
		}

		$offset = $this->length() - $length;

		$rawString = mb_substr($this->rawString, $offset, null, $this->charset);

		return new static($rawString, $this->charset);
	}
856149
public static function includeFileExtension($fileName, $extension)
    {
        $fileExtension = self::getFileExtension($fileName, true);

        /*
         * File has given extension?
         * Nothing to do
         */
        if ($fileExtension === strtolower($extension)) {
            return $fileName;
        }

        return sprintf('%s.%s', $fileName, $extension);
    }
447199
static function sendFile($file_path,$display_name = null){
        if($display_name ===null){
            $display_name = basename($file_path);
        }
        header('Content-Description: File Transfer');
        header('Content-Disposition: attachment; filename='.urlencode($display_name));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Content-Length: '.filesize($file_path));
        readfile($file_path);
    }
170338
public function read( $offset = NULL, $limit = NULL )
	{
		return $this->load( $this->fileName, $offset, $limit );
	}
918114
public function slice(int $offset, int $length = null) : self {
      $this->items = array_slice($this->items, $offset, $length);
      return $this;
    }
1170077
protected function readString($fr,$length,$offset=null)
	{
		if($offset!==null)
			fseek($fr,$offset);
		return $this->readByte($fr,$length);
	}
980859
public function slice($offset, $length = null)
    {
        return new static(array_slice($this->objects, $offset, $length, true));
    }
1105393
public function fgets( $length = null )
    {
        return $this->validHandle() ? fgets( $this->_fileHandle, $length ) : false;
    }
445054
public static function downloadContent( $file, $startOffset = 0, $length = false )
    {
        if ( !file_exists( $file ) )
        {
            eZDebug::writeError( "'$file' does not exist", __METHOD__ );
            return false;
        }
        if ( ( $fp = fopen( $file, 'rb' ) ) === false )
        {
            eZDebug::writeError( "An error occured opening '$file' for reading", __METHOD__ );
            return false;
        }

        $fileSize = filesize( $file );

        // an offset has been given: move the pointer to that offset if it seems valid
        if ( $startOffset !== false && $startOffset <= $fileSize && fseek( $fp, $startOffset ) === -1 )
        {
            eZDebug::writeError( "Error while setting offset on '{$file}'", __METHOD__ );
            return false;
        }

        $transferred = $startOffset;
        $packetSize = self::READ_PACKET_SIZE;
        $endOffset = ( $length === false ) ? $fileSize - 1 : $length + $startOffset - 1;

        while ( !feof( $fp ) && $transferred < $endOffset + 1 )
        {
            if ( $transferred + $packetSize > $endOffset + 1 )
            {
                $packetSize = $endOffset + 1 - $transferred;
            }
            echo fread( $fp, $packetSize );
            $transferred += $packetSize;
        }
        fclose( $fp );

        return true;
    }
487394
protected function encodeLength(int $length, int $offset)
    {
        // if (!is_int($length) || !is_int($offset)) {
        //     throw new InvalidArgumentException('Length and offset must be int when call encodeLength.');
        // }
        if ($length < 56) {
            // var_dump($length, $offset);
            return new Buffer(strval($length + $offset));
        }
        $hexLength = $this->intToHex($length);
        $firstByte = $this->intToHex($offset + 55 + (strlen($hexLength) / 2));
        return new Buffer(strval($firstByte . $hexLength), 'hex');
    }
121008
public function getContents($path, $offset = 0, $length = null)
    {
        if ($length === null) {
            return $this->stat($path)->then(function ($stat) use ($path, $offset) {
                return $this->getContents($path, $offset, $stat['size']);
            });
        }

        return $this->open($path, 'r')->then(function ($fd) use ($offset, $length) {
            return $this->read($fd, $length, $offset)->always(function () use ($fd) {
                return $this->close($fd);
            });
        });
    }
1127473
public function sliceSegments($offset, $length = null)
    {
        return new self(implode('/', array_slice($this->getSegments(), $offset, $length)));
    }
62083
public function offsetSet ($offset, $value) {
		if (static::Length($value) !== 1) {
			throw new \Exception('1文字しか設定できません。');
		}
		$this->_string = $this->offsetBefore($offset) . $value . $this->offsetAfter($offset + 1);
		$this->_length++;
	}
1327548
public function limit($offset, $length = null)
    {
        if (is_null($length) && strpos($offset, ',')) {
            list($offset, $length) = explode(',', $offset);
        }

        $this->options['limit'] = intval($offset) . ($length ? ',' . intval($length) : '');

        return $this;
    }
566682
public function getSlice($offset, $length)
    {
        $this->resultSet = $this->searchable->search($this->query, array(
            'from' => $offset,
            'size' => $length
        ));

        return $this->convertResultSet($this->resultSet);
    }