public function encode($data, $encoding = FORCE_GZIP, $level = 4)
    {
        // Verify that the server supports gzip compression before we attempt to gzip encode the data.
        if (!static::isSupported()) {
            throw new CompressException(
                'Your system does not support HTTP compression, please check zlib has benn enabled' .
                ' or zlib.output_compression in php.ini has set to "On".'
            );
        }

        // Verify that headers have not yet been sent, and that our connection is still alive.
        if ($this->checkHeadersSent()) {
            throw new CompressException('Header has been sent or connection is not alive, compression can not work.');
        }

        if (!$this->checkConnectionAlive()) {
            throw new CompressException('Connection is not alive, compression can not work.');
        }

        return gzencode((string) $data, $level, $encoding);
    }