public function write($string)
    {
        $bytes = $this->remainder . $string;
        $len = strlen($bytes);
        if (($len % 3) !== 0) {
            $this->remainder = substr($bytes, -($len % 3));
            $bytes = substr($bytes, 0, $len - ($len % 3));
        } else {
            $this->remainder = '';
        }
        $this->stream->write(base64_encode($bytes));
        $written = strlen($string);
        $this->position += $len;
        return $written;
    }