cdata_set (cdata_t *cd, int type, guint8 *data, size_t size)
{
    if (type > GCAB_COMPRESSION_MSZIP) {
        g_critical ("unsupported compression method %d", type);
        return FALSE;
    }

    cd->nubytes = size;

    if (type == 0) {
        memcpy (cd->in, data, size);
        cd->ncbytes = size;
    }

    if (type == GCAB_COMPRESSION_MSZIP) {
        z_stream stream = { 0, };

        stream.zalloc = zalloc;
        stream.zfree = zfree;
        if (deflateInit2 (&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY) != Z_OK)
            return FALSE;
        stream.next_in = data;
        stream.avail_in = size;
        stream.next_out = cd->in + 2;
        stream.avail_out = sizeof (cd->in) - 2;
        /* insert the signature */
        cd->in[0] = 'C';
        cd->in[1] = 'K';
        deflate (&stream, Z_FINISH);
        deflateEnd (&stream);
        cd->ncbytes = stream.total_out + 2;
    }

    return TRUE;
}
cdata_set (cdata_t *cd, int type, guint8 *data, size_t size)
{
    if (type > GCAB_COMPRESSION_MSZIP) {
        g_critical ("unsupported compression method %d", type);
        return FALSE;
    }

    cd->nubytes = size;

    if (type == 0) {
        memcpy (cd->in, data, size);
        cd->ncbytes = size;
    }

    if (type == GCAB_COMPRESSION_MSZIP) {
        z_stream stream = { 0, };

        stream.zalloc = zalloc;
        stream.zfree = zfree;
        if (deflateInit2 (&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY) != Z_OK)
            return FALSE;
        stream.next_in = data;
        stream.avail_in = size;
        stream.next_out = cd->in + 2;
        stream.avail_out = sizeof (cd->in) - 2;
         
        cd->in[0] = 'C';
        cd->in[1] = 'K';
        deflate (&stream, Z_FINISH);
        deflateEnd (&stream);
        cd->ncbytes = stream.total_out + 2;
    }

    return TRUE;
}