Pl_ASCII85Decoder::write(unsigned char* buf, size_t len)
{
    if (eod > 1)
    {
	return;
    }
    for (size_t i = 0; i < len; ++i)
    {
	if (eod > 1)
	{
	    break;
	}
	else if (eod == 1)
	{
	    if (buf[i] == '>')
	    {
		flush();
		eod = 2;
	    }
	    else
	    {
		throw std::runtime_error(
		    "broken end-of-data sequence in base 85 data");
	    }
	}
	else
	{
	    switch (buf[i])
	    {
	      case ' ':
	      case '\f':
	      case '\v':
	      case '\t':
	      case '\r':
	      case '\n':
		QTC::TC("libtests", "Pl_ASCII85Decoder ignore space");
		// ignore whitespace
		break;

	      case '~':
		eod = 1;
		break;

	      case 'z':
		if (pos != 0)
		{
		    throw std::runtime_error(
			"unexpected z during base 85 decode");
		}
		else
		{
		    QTC::TC("libtests", "Pl_ASCII85Decoder read z");
                    unsigned char zeroes[4];
                    memset(zeroes, '\0', 4);
		    getNext()->write(zeroes, 4);
		}
		break;

	      default:
		if ((buf[i] < 33) || (buf[i] > 117))
		{
		    throw std::runtime_error(
			"character out of range during base 85 decode");
		}
		else
		{
		    this->inbuf[this->pos++] = buf[i];
		    if (pos == 5)
		    {
			flush();
		    }
		}
		break;
	    }
	}
    }
}
Pl_ASCII85Decoder::write(unsigned char* buf, size_t len)
{
    if (eod > 1)
    {
	return;
    }
    for (size_t i = 0; i < len; ++i)
    {
	if (eod > 1)
	{
	    break;
	}
	else if (eod == 1)
	{
	    if (buf[i] == '>')
	    {
		flush();
		eod = 2;
	    }
	    else
	    {
		throw std::runtime_error(
		    "broken end-of-data sequence in base 85 data");
	    }
	}
	else
	{
	    switch (buf[i])
	    {
	      case ' ':
	      case '\f':
	      case '\v':
	      case '\t':
	      case '\r':
	      case '\n':
		QTC::TC("libtests", "Pl_ASCII85Decoder ignore space");
		 
		break;

	      case '~':
		eod = 1;
		break;

	      case 'z':
		if (pos != 0)
		{
		    throw std::runtime_error(
			"unexpected z during base 85 decode");
		}
		else
		{
		    QTC::TC("libtests", "Pl_ASCII85Decoder read z");
                    unsigned char zeroes[4];
                    memset(zeroes, '\0', 4);
		    getNext()->write(zeroes, 4);
		}
		break;

	      default:
		if ((buf[i] < 33) || (buf[i] > 117))
		{
		    throw std::runtime_error(
			"character out of range during base 85 decode");
		}
		else
		{
		    this->inbuf[this->pos++] = buf[i];
		    if (pos == 5)
		    {
			flush();
		    }
		}
		break;
	    }
	}
    }
}