KGzipFilter::Result KGzipFilter::uncompress_()
{
#ifndef NDEBUG
    if (d->mode == 0) {
        //qWarning() << "mode==0; KGzipFilter::init was not called!";
        return KFilterBase::Error;
    } else if (d->mode == QIODevice::WriteOnly) {
        //qWarning() << "uncompress called but the filter was opened for writing!";
        return KFilterBase::Error;
    }
    Q_ASSERT(d->mode == QIODevice::ReadOnly);
#endif

    if (d->compressed) {
#ifdef DEBUG_GZIP
        qDebug() << "Calling inflate with avail_in=" << inBufferAvailable() << " avail_out=" << outBufferAvailable();
        qDebug() << "    next_in=" << d->zStream.next_in;
#endif
        int result = inflate(&d->zStream, Z_SYNC_FLUSH);
#ifdef DEBUG_GZIP
        qDebug() << " -> inflate returned " << result;
        qDebug() << " now avail_in=" << inBufferAvailable() << " avail_out=" << outBufferAvailable();
        qDebug() << "     next_in=" << d->zStream.next_in;
#else
        if (result != Z_OK && result != Z_STREAM_END) {
            //qDebug() << "Warning: inflate() returned " << result;
        }
#endif
        return (result == Z_OK ? KFilterBase::Ok : (result == Z_STREAM_END ? KFilterBase::End : KFilterBase::Error));
    } else {
        return uncompress_noop();
    }
}
Beispiel #2
0
KGzipFilter::Result KGzipFilter::uncompress()
{
    Q_ASSERT ( d->mode == QIODevice::ReadOnly );
    if ( d->compressed )
    {
        int result = inflate(&d->zStream, Z_SYNC_FLUSH);
        return ( result == Z_OK ? KFilterBase::Ok : ( result == Z_STREAM_END ? KFilterBase::End : KFilterBase::Error ) );
    } else
        return uncompress_noop();
}
Beispiel #3
0
KGzipFilter::Result KGzipFilter::uncompress()
{
#ifndef NDEBUG
    if (d->mode == 0) {
        //qWarning() << "mode==0; KGzipFilter::init was not called!";
        return KFilterBase::Error;
    } else if (d->mode == QIODevice::WriteOnly) {
        //qWarning() << "uncompress called but the filter was opened for writing!";
        return KFilterBase::Error;
    }
    Q_ASSERT(d->mode == QIODevice::ReadOnly);
#endif

    if (!d->compressed) {
        return uncompress_noop();
    }

#ifdef DEBUG_GZIP
    qDebug() << "Calling inflate with avail_in=" << inBufferAvailable() << " avail_out=" << outBufferAvailable();
    qDebug() << "    next_in=" << d->zStream.next_in;
#endif

    while (d->zStream.avail_in > 0) {
        int result = inflate(&d->zStream, Z_SYNC_FLUSH);

#ifdef DEBUG_GZIP
        qDebug() << " -> inflate returned " << result;
        qDebug() << " now avail_in=" << inBufferAvailable() << " avail_out=" << outBufferAvailable();
        qDebug() << "     next_in=" << d->zStream.next_in;
#endif

        if (result == Z_OK) {
            return KFilterBase::Ok;
        }

        // We can't handle any other results
        if (result != Z_STREAM_END) {
            return KFilterBase::Error;
        }

        // It really was the end
        if (d->zStream.avail_in == 0) {
            return KFilterBase::End;
        }

        // Store before resetting
        Bytef *data = d->zStream.next_in; // This is increased appropriately by zlib beforehand
        uInt size = d->zStream.avail_in;

        // Reset the stream, if that fails we assume we're at the end
        if (!init(d->mode)) {
            return KFilterBase::End;
        }

        // Reset the data to where we left off
        d->zStream.next_in = data;
        d->zStream.avail_in = size;
    }

    return KFilterBase::End;
}